From: David Sterba Date: Mon, 14 Jun 2021 10:45:18 +0000 (+0200) Subject: btrfs: compression: don't try to compress if we don't have enough pages X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=039f1a721cd2e33f22ba92e808d725dc2ee5e617;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git btrfs: compression: don't try to compress if we don't have enough pages commit f2165627319ffd33a6217275e5690b1ab5c45763 upstream 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 [sudip: adjust context] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 4b671e5c33ce..a55d23a73cdb 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -484,7 +484,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(inode)) { + if (nr_pages > 1 && inode_need_compress(inode)) { WARN_ON(pages); pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); if (!pages) {