From patchwork Fri Mar 1 16:44:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13578742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9FF6C5475B for ; Fri, 1 Mar 2024 16:45:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77D8B6B0089; Fri, 1 Mar 2024 11:45:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 72DEB6B008A; Fri, 1 Mar 2024 11:45:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 580406B008C; Fri, 1 Mar 2024 11:45:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 470A86B0089 for ; Fri, 1 Mar 2024 11:45:08 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F033741367 for ; Fri, 1 Mar 2024 16:45:07 +0000 (UTC) X-FDA: 81849045054.26.9084575 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 1108A18001D for ; Fri, 1 Mar 2024 16:45:05 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=gLQIhxE+; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf06.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311506; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TofXuty2ThUTVbSRpvzx3fKuxbhJgVt2hgC/1tt8iys=; b=QpxXqEddiXAax0gU9eZQNKKfORDGW7bczSLisS50S8ZUgAi9lZpVwpacoNdGdhVooQL8Iw QXwN05teapwtAiOc8mPjQtRAbtq5x1HHJIPOnqyhrix4in/cj2BJQ1QEeyal757VCmkzrr 0Er+GDEyZq7++ZDwCb+/zlW/IQGWjCg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=gLQIhxE+; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf06.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311506; a=rsa-sha256; cv=none; b=aGSBQ3CpBV2ruWrK94pbx01e/gX6XjmX3hrU7wc1IG4FTMHx13Q8Q1iDQZmPUV5JTh16/F BJWA91fVZI7IWtf4JvbBcdWRT9y0xPwG+6tKnsRHXnXH4Jp8MTKGdV/xR3/91aL59qVvyx LDhOspSwgpQ26sKZbNOn03XCU22yixI= Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TmYq26jcYz9tWM; Fri, 1 Mar 2024 17:45:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TofXuty2ThUTVbSRpvzx3fKuxbhJgVt2hgC/1tt8iys=; b=gLQIhxE+TRtwfuu+rkDGqXs9WJziHw+JgFYbs09TJNFTQr/gW51opLqv2FzJyRdjGXp4D+ ne65X9oZMlHrjtB7n2NoVfWLB7HRk8vf4R2509Dwyk0M0ewQllhPja9qtmtoL4b8sPFTQ+ nkXNSyx3ulIxKLLguMd3aSVWP1dyntFOl0MdffdljoNDzvM11kcYKpKwACEbRaRp/XCnWk 3OVsBFM2dylNmecH3BKcdEkp8R+JtceQH/tuSiOi2Mxn50YFHT3Dhlceayzt6YF/1p9wYQ 959x+3MJa2eWXaXbDEZx1+NDiBkzsl0pBsLvjOU/sWouTcpNx5vpkjIcz7zGbA== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 04/13] filemap: use mapping_min_order while allocating folios Date: Fri, 1 Mar 2024 17:44:35 +0100 Message-ID: <20240301164444.3799288-5-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: r8deoyq8ho7nokkxfhogerwmtzwd6tjg X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1108A18001D X-HE-Tag: 1709311505-179235 X-HE-Meta: U2FsdGVkX1+XGM22g/8CavEA6aQsjeqzAXRQXRpg0sEoPytbHNCk06EFJmdPnTMiVildGPNoLJGafGw+NFI2/AbZ7xPCztgqntFiWXxaeu/B6QQYoKfvVJ6RWXLwu/5t8JNl0uwM6NdFsshHdA5ji3uuGQomiFOVwzXNxf1HbWTaY9+kkGN0FTHfnmpcXXEMDynf1IoOgFNM/kRmAVMLQOKFNjyCyMaGWkNe2hKzOfN7EVgoevxDSK+kvN1d97Z2iV5TRjQoB2OrTiAfdTVADEJ23El4A/NyOdsFPCZwBX86aAdiw+1PpjfGxQR0mkRgEBREvFV3klqFkZcatlfe8fxZQiaXmdcfcQzWEPpaV0Fy0h0tf6GhKu5kwV/zQxmPx5QfwpEqKW6I88b1pWQDHNtz1PpD5aR3GeJE3EFhgydZAr8caWShCQLGgaWRbzjTpdx4MYTtQbx4htcG8SvWD8ecIOC4HtNVGZUibxKTPQzDN1XCpynh+wxDhrjlSJO9+de3BGHMNrAErvaFk1omflqo9MHtUyoY7cN9UZKD48b2TjN2nzLb624Ogzx5AmhFMPjx7623WKhAcvxdKV5gMgdmGqE0wgQD3QRjIVu5XlfPwkCu43FTUxIehrkt/fazQXaK5LGgGi4SFfcybRRldAy8gG9fgX2FOkMUl6Vtn+tzbtsXe0s9ZQwLpfPnCEQWHitSkRh6xuVGPAEg1kL70Tit2auNBA8mqMhLCv66qGgcd9BiANrwXKTTVRZ0ZIfz9zzog7wIyhe2A5uw4/vH4mhJWncrtq+MAhQ/XBvMzaqhZhDnlTlRi0MQTcvBJheTxGJTjx+eznzknfCWvk8LZqVEDX5yvk3EvdFbKffMeK8GwNf3E3DgayWLs/g/bd9E+h1r6AwhhSHpGzmWh3eSV+NaxCtKcISUTxQvJGdn+JBWCTEmY826LEU5Pr8n2a138ImRXU0a2mCFlS7smAX 3MK8HGwv sWFQUOg9FrIxq6owBbf4idqF3jqmxgLnJym+WJGccYeCuvB4yJVqz+mdi8+dN9XVZGn93WkT0Modi+L+wtfCnxd6XYvrEjqS/xUspPOXn6zu8QKKxFXcSeTgNYTsuLOLLWMFqgONCzNE2jhw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav filemap_create_folio() and do_read_cache_folio() were always allocating folio of order 0. __filemap_get_folio was trying to allocate higher order folios when fgp_flags had higher order hint set but it will default to order 0 folio if higher order memory allocation fails. As we bring the notion of mapping_min_order, make sure these functions allocate at least folio of mapping_min_order as we need to guarantee it in the page cache. Add some additional VM_BUG_ON() in __filemap_add_folio to catch errors where we add folios that has order less than min_order. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- mm/filemap.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 96fe5c7fe094..3e621c6344f7 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -849,6 +849,8 @@ noinline int __filemap_add_folio(struct address_space *mapping, VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapbacked(folio), folio); + VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping), + folio); mapping_set_update(&xas, mapping); if (!huge) { @@ -1886,8 +1888,10 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, folio_wait_stable(folio); no_page: if (!folio && (fgp_flags & FGP_CREAT)) { - unsigned order = FGF_GET_ORDER(fgp_flags); + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int order = max(min_order, FGF_GET_ORDER(fgp_flags)); int err; + index = mapping_align_start_index(mapping, index); if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping)) gfp |= __GFP_WRITE; @@ -1912,8 +1916,11 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, gfp_t alloc_gfp = gfp; err = -ENOMEM; + if (order < min_order) + order = min_order; if (order > 0) alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN; + folio = filemap_alloc_folio(alloc_gfp, order); if (!folio) continue; @@ -1927,7 +1934,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, break; folio_put(folio); folio = NULL; - } while (order-- > 0); + } while (order-- > min_order); if (err == -EEXIST) goto repeat; @@ -2424,7 +2431,8 @@ static int filemap_create_folio(struct file *file, unsigned int min_order = mapping_min_folio_order(mapping); pgoff_t index; - folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0); + folio = filemap_alloc_folio(mapping_gfp_mask(mapping), + min_order); if (!folio) return -ENOMEM; @@ -3666,7 +3674,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, repeat: folio = filemap_get_folio(mapping, index); if (IS_ERR(folio)) { - folio = filemap_alloc_folio(gfp, 0); + folio = filemap_alloc_folio(gfp, + mapping_min_folio_order(mapping)); if (!folio) return ERR_PTR(-ENOMEM); err = filemap_add_folio(mapping, folio, index, gfp);