aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2021-06-14 12:45:18 +0200
committerDavid Sterba <dsterba@suse.com>2021-06-22 14:11:57 +0200
commitf2165627319ffd33a6217275e5690b1ab5c45763 (patch)
treee50aa6f191623b4a05bf4970425d80f7ae7ff19b /fs/btrfs
parentbtrfs: fix unbalanced unlock in qgroup_account_snapshot() (diff)
downloadlinux-dev-f2165627319ffd33a6217275e5690b1ab5c45763.tar.xz
linux-dev-f2165627319ffd33a6217275e5690b1ab5c45763.zip
btrfs: compression: don't try to compress if we don't have enough pages
The early check if we should attempt compression does not take into account the number of input pages. It can happen that there's only one page, eg. a tail page after some ranges of the BTRFS_MAX_UNCOMPRESSED have been processed, or an isolated page that won't be converted to an inline extent. The single page would be compressed but a later check would drop it again because the result size must be at least one block shorter than the input. That can never work with just one page. CC: stable@vger.kernel.org # 4.4+ Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/inode.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index a2494c645681..e6eb20987351 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -629,7 +629,7 @@ again:
* inode has not been flagged as nocompress. This flag can
* change at any time if we discover bad compression ratios.
*/
- if (inode_need_compress(BTRFS_I(inode), start, end)) {
+ if (nr_pages > 1 && inode_need_compress(BTRFS_I(inode), start, end)) {
WARN_ON(pages);
pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
if (!pages) {