Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3654058pxv; Mon, 26 Jul 2021 08:48:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsdeC+YL44G7BVvEr5cj+HAnXU9p2TTLwJymp2C6A7+zYalWrzdrXFXsfpYoSPfIh2haL4 X-Received: by 2002:a05:6e02:d09:: with SMTP id g9mr8495582ilj.153.1627314510009; Mon, 26 Jul 2021 08:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627314509; cv=none; d=google.com; s=arc-20160816; b=Yi8FrL5P0KQjBt96gIrtPYkPLDnNOKK1elTJXu8fZp+NOf5eaLTxeWhZsjKmfEEKBr BXcJ0oHX/FoN/gyq/LBIVwUueacdTJYexvyLIXPN7ypuV4GepMnCcpIRVKGci+/hrvM6 QEIBFX8Ujd8oBntyBgQw89Jwu6hqIyRq0igWaEI02A/QdT19N+Z4eCUyHY8dVh8W9feu d3FjV3r9/1R+dh4Qw5ba9LL1FqPVgMZlStRyq9HyZMdoM1tzf53sjH4JPhHqhRTCJF9U KhnHI4Q/Qzs3SVzTdCIXl/+asYyFgk/J/eFxfiLJ1fys1rxd9sBddZrxGo1P+SkRGpkQ T6iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7jUSAL52C+fa4qxt2ublJbPK45eqZGO6UciNJDsKNzE=; b=WmwURHFXk4OJg74h1G/CjRGDcybYs8QsZSNb1xeb5sK5a7pQH/fhLqFCRV0FCydE4R pqwWTyHLIOjfXaZjHDZFGKP1uiDxQEhoUecI5NLv3/dnP7CYhr84xuTta2eciS5v/UhT NC15zTx2C15E/5PjfIvz4VfQ70ZMiEAbEbFxkyXy78CfFaTgdTwmiCx/L4GKRN1JFsPb iMakV4Cv5lxz2mUNgSEcSO0RPAo/1x28KARJh+4FhlbcNNuM0TApwQjBoU8tvCwCPKI2 CpvOp6llP1k1ZLuqXeK48g9h7Q6+TLi4TORa5PuaPAkzgN4X7wSSTjljYUIxprE+tauq HeaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o6Av7cJs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si272654ilf.57.2021.07.26.08.48.17; Mon, 26 Jul 2021 08:48:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o6Av7cJs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235988AbhGZPGC (ORCPT + 99 others); Mon, 26 Jul 2021 11:06:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:45372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235725AbhGZPFA (ORCPT ); Mon, 26 Jul 2021 11:05:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AAF3760F5B; Mon, 26 Jul 2021 15:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627314328; bh=9g1soENvLV8l1xZaSZUxicGcQuXbmy3p2Xn1klrf4NE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o6Av7cJsDHyE8wcxmY0o6wtEZ8ZLGdDlG4yW8xA2xVoKE/w9jJEzHlu3qysNniU8O gaZLRMj3caVBUOQKNUA+kaAeCxPjBTMT3wGpowUYgLW1eynHepJAv5LyPtESvPYqcx cnG4uXXopFc0B0VbfWU0SWcH/R56Xzo5/k7XEhyo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Sterba , Sudip Mukherjee Subject: [PATCH 4.9 60/60] btrfs: compression: dont try to compress if we dont have enough pages Date: Mon, 26 Jul 2021 17:39:14 +0200 Message-Id: <20210726153826.754545251@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153824.868160836@linuxfoundation.org> References: <20210726153824.868160836@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 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 --- 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)) { WARN_ON(pages); pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); if (!pages) {