Skip to content

Commit f216562

Browse files
committed
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>
1 parent 4436582 commit f216562

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
629629
* inode has not been flagged as nocompress. This flag can
630630
* change at any time if we discover bad compression ratios.
631631
*/
632-
if (inode_need_compress(BTRFS_I(inode), start, end)) {
632+
if (nr_pages > 1 && inode_need_compress(BTRFS_I(inode), start, end)) {
633633
WARN_ON(pages);
634634
pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
635635
if (!pages) {

0 commit comments

Comments
 (0)