Skip to contentSkip to conversation

f2fs: compress: fix deadlock in prepare_compress_overwrite()

PATCH New Chao Yu 1 participant 1 message Jan 3, 2020 F2FS file system

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs: compress: fix deadlock in prepare_compress_overwrite()

100.00% 13.65% fsstress [f2fs] [k] prepare_compress_overwrite

            |
            |--86.35%--prepare_compress_overwrite
            |          |
            |          |--46.78%--f2fs_read_multi_pages
            |          |          |
            |          |          |--19.81%--f2fs_decompress_end_io
            |          |          |          |
            |          |          |           --5.77%--unlock_page
            |          |          |
            |          |          |--19.53%--f2fs_get_dnode_of_data

In prepare_compress_overwrite(), we need to check cluster state before read cluster data, otherwise, read normal cluster as a compressed one will always cause failure and retry.

---
 fs/f2fs/compress.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
fs/f2fs/compress.c +13 -10
index 9e8fba78db4d..f993b4ce1970 100644
@@ -570,8 +570,7 @@ static void set_cluster_dirty(struct compress_ctx *cc)
 }
 
 static int prepare_compress_overwrite(struct compress_ctx *cc,
-		struct page **pagep, pgoff_t index, void **fsdata,
-		bool prealloc)
+		struct page **pagep, pgoff_t index, void **fsdata)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(cc->inode);
 	struct address_space *mapping = cc->inode->i_mapping;
@@ -582,11 +581,20 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 	unsigned int start_idx = start_idx_of_cluster(cc);
 	int i, idx;
 	int ret;
+	bool prealloc;
+
+retry:
+	ret = is_compressed_cluster(cc);
+	if (ret <= 0)
+		return ret;
+
+	/* compressed case */
+	prealloc = (ret == CLUSTER_HAS_SPACE);
 
 	ret = f2fs_init_compress_ctx(cc);
 	if (ret)
 		return ret;
-retry:
+
 	/* keep page reference to avoid page reclaim */
 	for (i = 0; i < cc->cluster_size; i++) {
 		page = f2fs_pagecache_get_page(mapping, start_idx + i,
@@ -632,6 +640,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 						(idx <= i) ? 1 : 0);
 				cc->rpages[idx] = NULL;
 			}
+			kvfree(cc->rpages);
 			cc->nr_rpages = 0;
 			goto retry;
 		}
@@ -687,14 +696,8 @@ int f2fs_prepare_compress_overwrite(struct inode *inode,
 		.rpages = NULL,
 		.nr_rpages = 0,
 	};
-	int ret = is_compressed_cluster(&cc);
-
-	if (ret <= 0)
-		return ret;
 
-	/* compressed case */
-	return prepare_compress_overwrite(&cc, pagep, index,
-			fsdata, ret == CLUSTER_HAS_SPACE);
+	return prepare_compress_overwrite(&cc, pagep, index, fsdata);
 }
 
 bool f2fs_compress_write_end(struct inode *inode, void *fsdata,
Signature · 1 line
2.18.0.rc1