From patchwork Mon Feb 26 09:49:27 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: 13571762 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 1865CC54E49 for ; Mon, 26 Feb 2024 09:50:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93A0094001E; Mon, 26 Feb 2024 04:50:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 899EC940014; Mon, 26 Feb 2024 04:50:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73B3494001E; Mon, 26 Feb 2024 04:50:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 61172940014 for ; Mon, 26 Feb 2024 04:50:03 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 03374C07D8 for ; Mon, 26 Feb 2024 09:50:02 +0000 (UTC) X-FDA: 81833483886.16.8F399AC Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf30.hostedemail.com (Postfix) with ESMTP id 65F4080010 for ; Mon, 26 Feb 2024 09:50:01 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="k+/Se9RL"; spf=pass (imf30.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708941001; a=rsa-sha256; cv=none; b=ub4TG9ykdwA3bWygRwdqf/JbVeEO3rFak70pkZX3RCPQ7WBAPNWFO2DoCGBccyPfBLoaM+ oYKvMxUBUy3SPq1pqiE2OPXx2jTrvSoF0yhZ4hjHY5Yw91AxJmwiRqrBG7Zk4ia/hK83K6 hqhvbbOz2gkeiWNLkVFCxBrNZNrnh38= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="k+/Se9RL"; spf=pass (imf30.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708941001; 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=dxmi9nVYwim1cNNfe2Xlh2MStfm/gxTJRd9QPZsgFwc=; b=3Dhz67jsh/UV+xE0OxhoKXO/A9HhXHgmIMSjursCFhveMoXT5j37nouAacTxMdLaU8LOU4 /N32WHduFdTs/uE1uVcQJfkgMZcfktFac2r6ohEV+2MavP0hHUbDIZdHfi4c2U15JRE6RM qAIVtJlT5WD4b6Uvwls88uhZQ0vZ8xw= Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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-101.mailbox.org (Postfix) with ESMTPS id 4Tjwny230Zz9sd7; Mon, 26 Feb 2024 10:49:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1708940998; 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=dxmi9nVYwim1cNNfe2Xlh2MStfm/gxTJRd9QPZsgFwc=; b=k+/Se9RLgvLTB8sb1uVay3Y3/zq/KKPrHWmX8ufvZwefrZwIlUZfRJ0xhs2kSLt6KkAjZ0 9MhFKa3OZzoGhJhjkXWfmOyOmF6woVxT8c4RkkyYzVoI+NsAWx9L+rFJyTV/+HVlrL7F7J Syh0kvGX8dYH758lZpESl95+fW81cGnQCMLeqVuZ5ygto6rxyq+UTXhfeGE8R8KTkQyjIg mJAkC9sTnrgntU6ZIPmJk5y6f+LDnq6nvSS1raDz9Jbn5PyL/vN7dzypafSByUv5sFm/tl 4mvQEppUs15HBHAzDg/EKxrm8u1fJ2KPfgzmxH28w64LHM1jHLhVdQWK6O39yg== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, mcgrof@kernel.org, ziy@nvidia.com, hare@suse.de, djwong@kernel.org, gost.dev@samsung.com, linux-mm@kvack.org, willy@infradead.org, Pankaj Raghav Subject: [PATCH 04/13] filemap: use mapping_min_order while allocating folios Date: Mon, 26 Feb 2024 10:49:27 +0100 Message-ID: <20240226094936.2677493-5-kernel@pankajraghav.com> In-Reply-To: <20240226094936.2677493-1-kernel@pankajraghav.com> References: <20240226094936.2677493-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 65F4080010 X-Stat-Signature: jpzkiuz7g3p64aohirmotgawtr4adb3h X-Rspam-User: X-HE-Tag: 1708941001-711518 X-HE-Meta: U2FsdGVkX18L1B5FQ1dPThC6V3y4rejuUInPRsjl6JDzf0skw99IW5y5XT50wRqlnLXV1LLcpRVBScF1i03YZHr7fl8X/LpyH2f24lbTSTXYf2I6r7EkphK8t9MUO4mnf7MSORSM0d8SPR3pR2Xmb50R3mC2zmthEDCL6olcn2WcdREDzOMS1/aXtyJqTH+WnRUQotNMD/cmMLS3CFD1lADN7hhXlExzGn/DaNrTzAcA4SJWm0ggc5VXstJX//I2O436sEdG9x2G+/ul8F1ArtQ0wB31SYBF24gFx4qwKWo1xmXoBtAl3Pmuwz3lOuR+muL6kDQuizGGh0+lCuxc5qWMUydviT4aagg00VzBtf2hWTka+nKeWqZJ/hr2+5DGOPkIAPufW3hyV+K4PuOrkvwmOWcjlNyXbczBOYD85AqUkqCpwM9DjCKXOmTE+zyaisMwaV2m+R/1eYc+9IBEd0Yc9Gkk4bxaeUBJ+q7iJPf0xNX+FBVg4B7Mgh9oPbL959O+kRKndEb0U1xMmILFI1mH0SbUlmxc0RUIvGBOXOPXhv9XHZT6a+DXcRVqyy/QCW2q9tpoRATX3bz0AMYiDfWewJuFOMLryCZgJ4iXv81+0S0llkqmbOSRIieIxOMI1dtO2el74MyzrwLzL2Aundizd5cAUccOMYzeuebUTWLjYlccBd1+d1vxP5GbWKfHamStpsd2jMDJ6OPdQPxjSgmsgKVN5hyc+n2VKCLvhAw5JXy/nSy5kJVUGRRc+DDropka+fP5rUeRJrzLymr6MpwHXzhr2SXrQsDBupYvwtPRm9TupzK5f2v4WgQOG7lk0sBa4mXLEFqWAz0EnibiXoKIOTju9g6Sc+pPDk/74ulfKzIgX3JOZj9cyx0joGVrpdk9CYDFESl1MCM5INnIUvRnUcNNYlA8KTsaBoyODCL3JyBUf+5TrEK8rJd1eAwmUoxZTOXkTJ0xKJ7/N+/ t6mL+EZE vlq/XzuKpUONZ5ViQ2yNKNG4O8YS0EcL0qIeGdMDZmcvK7npDOQGZwhTKTmEABeZU5zy0HkbBiAnZrPwx0kfo2a1vpPTb+jZa8nLd1PPokrTRDC4= 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 page_cache_delete[batch] and __filemap_add_folio to catch errors where we delete or 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 | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index bdf4f65f597c..4b144479c4cb 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -135,6 +135,8 @@ static void page_cache_delete(struct address_space *mapping, xas_set_order(&xas, folio->index, folio_order(folio)); nr = folio_nr_pages(folio); + VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping), + folio); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); xas_store(&xas, shadow); @@ -305,6 +307,8 @@ static void page_cache_delete_batch(struct address_space *mapping, WARN_ON_ONCE(!folio_test_locked(folio)); + VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping), + folio); folio->mapping = NULL; /* Leave folio->index set: truncation lookup relies on it */ @@ -896,6 +900,8 @@ noinline int __filemap_add_folio(struct address_space *mapping, } } + VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping), + folio); xas_store(&xas, folio); if (xas_error(&xas)) goto unlock; @@ -1847,6 +1853,9 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, fgf_t fgp_flags, gfp_t gfp) { struct folio *folio; + unsigned int min_order = mapping_min_folio_order(mapping); + + index = mapping_align_start_index(mapping, index); repeat: folio = filemap_get_entry(mapping, index); @@ -1886,7 +1895,7 @@ 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 order = max(min_order, FGF_GET_ORDER(fgp_flags)); int err; if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping)) @@ -1912,8 +1921,13 @@ 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; + + VM_BUG_ON(index & ((1UL << order) - 1)); + folio = filemap_alloc_folio(alloc_gfp, order); if (!folio) continue; @@ -1927,7 +1941,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; @@ -2422,7 +2436,8 @@ static int filemap_create_folio(struct file *file, struct folio *folio; int error; - folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0); + folio = filemap_alloc_folio(mapping_gfp_mask(mapping), + mapping_min_folio_order(mapping)); if (!folio) return -ENOMEM; @@ -3666,7 +3681,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);