]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: fix the memory leak caused in lzo_compress_pages()
authorQu Wenruo <wqu@suse.com>
Sat, 20 Nov 2021 08:34:11 +0000 (16:34 +0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 26 Nov 2021 15:10:05 +0000 (16:10 +0100)
commita6b76c9d43f9e0116b4ea0bb8c716bb3695db07c
tree28e8dbee575ea177897e2b62e6b834fab5d11616
parent86b3cfac9b999ecfd1a852d1ccd465db5be3d7a4
btrfs: fix the memory leak caused in lzo_compress_pages()

[BUG]
Fstests generic/027 is pretty easy to trigger a slow but steady memory
leak if run with "-o compress=lzo" mount option.

Normally one single run of generic/027 is enough to eat up at least 4G ram.

[CAUSE]
In commit 98d42dc1537d ("btrfs: subpage: make lzo_compress_pages()
compatible") we changed how @page_in is released.

But that refactoring makes @page_in only released after all pages being
compressed.

This leaves error path not releasing @page_in. And by "error path"
things like incompressible data will also be treated as an error
(-E2BIG).

Thus it can cause a memory leak if even nothing wrong happened.

[FIX]
Add check under @out label to release @page_in when needed, so when we
hit any error, the input page is properly released.

Reported-by: Josef Bacik <josef@toxicpanda.com>
Fixes: 98d42dc1537d ("btrfs: subpage: make lzo_compress_pages() compatible")
Reviewed-and-tested-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/lzo.c