Re: [f2fs-dev] [PATCH v2 1/2] f2fs: compress: introduce page array slab cache

From: Jaegeuk Kim
Date: Tue Sep 29 2020 - 05:12:02 EST


On 09/29, Jaegeuk Kim wrote:
> On 09/29, Chao Yu wrote:
> > On 2020/9/29 16:23, Jaegeuk Kim wrote:
> > > I found a bug related to the number of page pointer allocation related to
> > > nr_cpages.
> >
> > Jaegeuk,
> >
> > If I didn't miss anything, you mean that nr_cpages could be larger
> > than nr_rpages, right? the problematic case here is lzo/lzo-rle:
> >
> > cc->clen = lzo1x_worst_compress(PAGE_SIZE << cc->log_cluster_size);
> >
> > As we can't limited clen as we did for lz4/zstd:
> >
> > cc->clen = cc->rlen - PAGE_SIZE - COMPRESS_HEADER_SIZE;
>
> Yes, I've seen some memory corruption in lzo test. Here is another patch to fix
> mem leak.
>
One more fix:

---
fs/f2fs/compress.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index ba2d4897744d8..b9557865d627b 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -662,7 +662,7 @@ static int f2fs_compress_pages(struct compress_ctx *cc)

/* Now we're going to cut unnecessary tail pages */
new_cpages = page_array_alloc(cc->inode, new_nr_cpages);
- if (new_cpages) {
+ if (!new_cpages) {
ret = -ENOMEM;
goto out_vunmap_cbuf;
}
@@ -1186,7 +1186,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
*/
down_read(&sbi->node_write);
} else if (!f2fs_trylock_op(sbi)) {
- return -EAGAIN;
+ goto out_free;
}

set_new_dnode(&dn, cc->inode, NULL, NULL, 0);
@@ -1325,8 +1325,6 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
continue;
f2fs_put_page(cc->cpages[i], 1);
}
- page_array_free(cc->inode, cc->cpages, cc->nr_cpages);
- cc->cpages = NULL;
out_put_cic:
kmem_cache_free(cic_entry_slab, cic);
out_put_dnode:
@@ -1336,6 +1334,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
up_read(&sbi->node_write);
else
f2fs_unlock_op(sbi);
+out_free:
+ page_array_free(cc->inode, cc->cpages, cc->nr_cpages);
+ cc->cpages = NULL;
return -EAGAIN;
}

--
2.28.0.709.gb0816b6eb0-goog