[lkml]   [2021]   [Jul]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 4.9 60/60] btrfs: compression: dont try to compress if we dont have enough pages
From: David Sterba <>

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: # 4.4+
Signed-off-by: David Sterba <>
[sudip: adjust context]
Signed-off-by: Sudip Mukherjee <>
Signed-off-by: Greg Kroah-Hartman <>
fs/btrfs/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- 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)) {
pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
if (!pages) {

 \ /
  Last update: 2021-07-26 17:47    [W:0.178 / U:4.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site