Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3682104pxv; Mon, 26 Jul 2021 09:17:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAgP8zZu+zks8Y2NPVUiCkSS+0wLrYFnJRrJzN47ibWYsS0r0vciLJDRfkMKOkuay+yMiu X-Received: by 2002:a17:906:6c8f:: with SMTP id s15mr17920883ejr.498.1627316241147; Mon, 26 Jul 2021 09:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627316241; cv=none; d=google.com; s=arc-20160816; b=KrN2kYSqVkZo5HCTx1XKXBmbvCnGz2Adn4wc603aBl/1wVYkIi/9Iq6tlEAqurne7T JXuU/86yX609iWwHK28qnwaeJbIlKexkJS/K+sgW8Yc1sEd53NZtbjzWO4uDVEkWsK4X DL84GtGnEydr3NJpeF4MHpZjitkNHWIkiphA9EqJcF9koqEkNhm8ePj/OAYP2Ni7PUnV x3wuUzFKj/ZpZv1IO151M9Anu9D0uzMNMgOe6sn5u/4O/3i97ChEpcUJwdJl5yS1I3j1 fB3Bv97wx/61ZYw/Iy25+wL7P5jhe6RwIUAoH920AmKAHpvWBS9bkEkiOpLYS8V9vUc5 87Fw== 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=TRi620SaoiTeG7T+XxD9e159WkFRAHrrxpQKlbSPeTo=; b=gDvdIhvPJK0Q/mbVQ3WePMgO585iuo6qJIZEK4l7ShoyksbDSFWpmAXE7OEDhplaKd AjMGJ6c9lKW34B+UxgrwW2YksCHqJv8ARP0J+Ymf/ozGr6Yxok+qQCE8tae4/OU6k4Uo 83T5Yu/sGntowtcGfYCCBPyCesXlIagq2jTCP2VrWU6ebFvbBwJiQjhhQcMEDycw/kd8 O3rHADZvH4FSoNk5r24JP7Wwn9Gz5Aom3GjzcKcG1v0YU6Rj1VDWzoJMyzW3RCvZdXAm JesnoXcU+BokUo4OkQZG32AUGlYWrPDgo9ptb5dmWOcJ8cqqgzkO5dI06F1lGEfxJInq MZXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gc8qZGVo; 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 p31si338791edb.554.2021.07.26.09.16.58; Mon, 26 Jul 2021 09:17:21 -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=gc8qZGVo; 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 S237060AbhGZPe3 (ORCPT + 99 others); Mon, 26 Jul 2021 11:34:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:60956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236342AbhGZPTk (ORCPT ); Mon, 26 Jul 2021 11:19:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2778E60F38; Mon, 26 Jul 2021 16:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315207; bh=DyuSOriBI8G8PrvE6t1AnzJgmXGSn3r853KEj8y3Egs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gc8qZGVolsIJbyQ0ZukqMwEBXOFPyFu7mz4k10GSRmfbU4rT48VhsVqnQYNWVg+xb fHkcjdfUL7a81CvgvtXVrwRzEMSnL0Mrn1WP5TUKOv0fUu0fmwB9aVkejttZ9vkiJt 6BQv/vwqwsDpSpns5zcbdoR3rHHgMzyTFP98gH3Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Sterba , Sudip Mukherjee Subject: [PATCH 5.4 105/108] btrfs: compression: dont try to compress if we dont have enough pages Date: Mon, 26 Jul 2021 17:39:46 +0200 Message-Id: <20210726153835.041101251@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@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 @@ -543,7 +543,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) {