]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
btrfs: compression: don't try to compress if we don't have enough pages
authorDavid Sterba <dsterba@suse.com>
Mon, 14 Jun 2021 10:45:18 +0000 (12:45 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Jul 2021 09:13:52 +0000 (11:13 +0200)
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 <dsterba@suse.com>
[sudip: adjust context]
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/inode.c

index bf0e0e3e09c5d0d62a14d97ac1aa86c6a92b1dea..d29f4cf125d27ecfdc73448079df131bd7af0581 100644 (file)
@@ -530,7 +530,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, start, end)) {
+       if (nr_pages > 1 && inode_need_compress(inode, start, end)) {
                WARN_ON(pages);
                pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
                if (!pages) {