From patchwork Sat Oct 28 21:15:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439584 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B443C4167B for ; Sat, 28 Oct 2023 21:15:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229870AbjJ1VPp (ORCPT ); Sat, 28 Oct 2023 17:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjJ1VPo (ORCPT ); Sat, 28 Oct 2023 17:15:44 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A3AE1 for ; Sat, 28 Oct 2023 14:15:41 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211539euoutp028ebaf1ab72968557b223d727f9a207bb~SYfrudE6K0879208792euoutp02E for ; Sat, 28 Oct 2023 21:15:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231028211539euoutp028ebaf1ab72968557b223d727f9a207bb~SYfrudE6K0879208792euoutp02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527739; bh=eR4ECi1C+RsYauRNG0Oa6wKRBmELNPkutLhe+B7jobc=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=jjaWoMKmpeL2sLoVtVIJ4rBEKLLd2KsJYQnpEHdBiXJriXoTywXG7JA0og2/7E9L4 nh3HhyRmF4s0KfRNL2fV8cM/ugVIvmzKE6VHyE/hZDSmpARN7AkVO0+/3hrdTuAeGS B39ZTQ5pTxSF7SBjTBKGSvpsliXmO/RVLKc4DdkQ= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211538eucas1p2c2a45a33072dae2e110eb46cac041cea~SYfq672AJ1087910879eucas1p2A; Sat, 28 Oct 2023 21:15:38 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id DA.57.37758.AF97D356; Sat, 28 Oct 2023 22:15:38 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231028211538eucas1p186e33f92dbea7030f14f7f79aa1b8d54~SYfqiRzRj2326023260eucas1p1N; Sat, 28 Oct 2023 21:15:38 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211538eusmtrp26da1062912af33695c737ab5cb5b69ed~SYfqhpNZo1141411414eusmtrp2Y; Sat, 28 Oct 2023 21:15:38 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-f7-653d79fa5a08 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 2B.F0.25043.AF97D356; Sat, 28 Oct 2023 22:15:38 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211538eusmtip1dbcf26df78fa637ec241be47c974aeb8~SYfqUnhnc0467404674eusmtip1G; Sat, 28 Oct 2023 21:15:38 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:37 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:36 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 01/11] XArray: add cmpxchg order test Thread-Topic: [RFC PATCH 01/11] XArray: add cmpxchg order test Thread-Index: AQHaCePk2/Onfe3eA0ia1dQGCoKrAw== Date: Sat, 28 Oct 2023 21:15:35 +0000 Message-ID: <20231028211518.3424020-2-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNKsWRmVeSWpSXmKPExsWy7djP87q/Km1TDS60mFvMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/MmuQCOKC6blNSczLLU In27BK6MV8/WsRU08lVMWbqLqYHxPXcXIyeHhICJxLkp75i6GLk4hARWMEq83rOKEcL5wigx Z+M5ZpAqIYHPjBLr//HCdJzp+AbVsZxR4unkncwQDlDRlx3P2SGcM4wSR57tYoFw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fnFJbZK0YYWRnqGlhZ6RiaWeobG5rFWRqZK+nY2Kak5mWWpRfp2CXoZr56tYyto5KuYsnQX UwPje+4uRk4OCQETiTMd35i6GLk4hASWMkqcO7WZDSIhI7Hxy1VWCFtY4s+1LjaIoo+MEl0d q6CcM4wSrxb9h3JWMkrMuvqRHaSFTUBTYt/JTewgCRGB2awShxd3MIIkmAXqJNY8m8UCYgsL WErcWHUJbIeIgJ3Ew1sv2SFsPYlz11+B3cEioCrxZPsGsBpeAWuJlaf2MHcxcgBty5Xob8sE CXMK2Ejc/7YdrJxRQFbi0cpf7BCrxCVuPZnPBPGCgMSSPeeZIWxRiZeP/0G9piNx9voTRgjb QGLr0n0sELaSxJ+OhVAn60ncmDqFDcLWlli28DUzxDmCEidnPmGZwCg9C8m6WUhaZiFpmYWk ZQEjyypGkdTS4tz03GIjveLE3OLSvHS95PzcTYzABLXt2M8tOxhXvvqod4iRiYPxEKMEB7OS CC+zo02qEG9KYmVValF+fFFpTmrxIUZTYBBNZJYSTc4Hpsi8knhDMwNTQxMzSwNTSzNjJXFe z4KORCGB9MSS1OzU1ILUIpg+Jg5OqQamtVN4di4qPqJW9uUiy9JTR6OSr77+oZN58HBy0mlj rV2/wkqcnLi/Hmj1VTzpycA2fRuHyt1LNnszbn2vFJ8bua0+pNPuTkzxli/OPRdfr5O/Zr9u 4bfNfZ58P5nt92YmyEsFH3/sNP2aiJC23dSJnoa/W9+ryPQa+ixZMWVjxofg/+83lyowMH29 fFbh9dyvPAd4dnM67THTdqvzipjd8sfUpmPqg4vNn92ZS1iuJion6zwJPOIQksO5fJnqn7Zw kVcx3Mvu7H/8/f2ErochM97c/v6E9eWUHOkY1k3uv+XuL1Z0CHta+1oldMaK+gfeAkqFCz+W BJhWPH6WrvJD2nztj0ARLbfcNVZfC3pllViKMxINtZiLihMBJkEZzNkDAAA= X-CMS-MailID: 20231028211538eucas1p186e33f92dbea7030f14f7f79aa1b8d54 X-Msg-Generator: CA X-RootMTR: 20231028211538eucas1p186e33f92dbea7030f14f7f79aa1b8d54 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211538eucas1p186e33f92dbea7030f14f7f79aa1b8d54 References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org XArray multi-index entries do not keep track of the order stored once the entry is being marked as used (replaced with NULL). Add a test to check the order is actually lost. Signed-off-by: Daniel Gomez Reviewed-by: Luis Chamberlain --- lib/test_xarray.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/test_xarray.c b/lib/test_xarray.c index e77d4856442c..6c22588963bc 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -423,6 +423,26 @@ static noinline void check_cmpxchg(struct xarray *xa) XA_BUG_ON(xa, !xa_empty(xa)); } +static noinline void check_cmpxchg_order(struct xarray *xa) +{ + void *FIVE = xa_mk_value(5); + unsigned int order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 15 : 1; + void *old; + + XA_BUG_ON(xa, !xa_empty(xa)); + XA_BUG_ON(xa, xa_store_index(xa, 5, GFP_KERNEL) != NULL); + XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY); + XA_BUG_ON(xa, xa_store_order(xa, 5, order, FIVE, GFP_KERNEL)); + XA_BUG_ON(xa, xa_get_order(xa, 5) != order); + XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(FIVE)) != order); + old = xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL); + XA_BUG_ON(xa, old != FIVE); + XA_BUG_ON(xa, xa_get_order(xa, 5) != 0); + XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(FIVE)) != 0); + XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(old)) != 0); + XA_BUG_ON(xa, !xa_empty(xa)); +} + static noinline void check_reserve(struct xarray *xa) { void *entry; @@ -1801,6 +1821,7 @@ static int xarray_checks(void) check_xas_erase(&array); check_insert(&array); check_cmpxchg(&array); + check_cmpxchg_order(&array); check_reserve(&array); check_reserve(&xa0); check_multi_store(&array); From patchwork Sat Oct 28 21:15:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439585 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFB1AC0018C for ; Sat, 28 Oct 2023 21:15:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbjJ1VPs (ORCPT ); Sat, 28 Oct 2023 17:15:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229908AbjJ1VPq (ORCPT ); Sat, 28 Oct 2023 17:15:46 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3F59EB for ; Sat, 28 Oct 2023 14:15:41 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211540euoutp0127043e7b69cd7dd3c2c1bc557f4ce7d8~SYfsE6asm2659126591euoutp01B for ; Sat, 28 Oct 2023 21:15:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231028211540euoutp0127043e7b69cd7dd3c2c1bc557f4ce7d8~SYfsE6asm2659126591euoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527740; bh=JNoJR/Xq7klfzP9hsOQ2xMnfdiLvLMoR5LEBEoVDOGw=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=Mm7/kBdisYvKed+Ygjkzhy9JoYAi4fful3cwN1vo9Q93LupZh5jo6Qx+rmZQKHVPd DyzqzIDTQ4ta+ecdzC7gF4ZhT3ywHxbN9VgChrJTvJA8ynYNXCPcGdwAnG6/90wRR5 OB4t5WBqrOK4IkC+G7LWapdYxKCBFI2bfx6akZgc= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211539eucas1p244eaee8bc62c90f79ee02e581ed59c80~SYfrfIuDH1224812248eucas1p22; Sat, 28 Oct 2023 21:15:39 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id C0.20.11320.BF97D356; Sat, 28 Oct 2023 22:15:39 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231028211538eucas1p1456b4c759a9fed51a6a77fbf2c946011~SYfqobMTB1181011810eucas1p1C; Sat, 28 Oct 2023 21:15:38 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211538eusmtrp241d650d122083e72da8aaaa16e6632fb~SYfqnuS2Q1141411414eusmtrp2Z; Sat, 28 Oct 2023 21:15:38 +0000 (GMT) X-AuditID: cbfec7f4-993ff70000022c38-82-653d79fb8a21 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 0C.F0.25043.AF97D356; Sat, 28 Oct 2023 22:15:38 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211538eusmtip1460431297fe820fa6ae8f8fd8d552ed5~SYfqdcDZX0467404674eusmtip1I; Sat, 28 Oct 2023 21:15:38 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:38 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:37 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 02/11] test_xarray: add tests for advanced multi-index use Thread-Topic: [RFC PATCH 02/11] test_xarray: add tests for advanced multi-index use Thread-Index: AQHaCePl1pHcrPV2xkWSZMmpwVjy+w== Date: Sat, 28 Oct 2023 21:15:37 +0000 Message-ID: <20231028211518.3424020-3-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SbUxSYRTHe+By75Wi3cTyKTUbWS0sspZ1IzPbWvGl5Zq9zLUZixs5ERlI 7y9mNdMPVlamQKFmmkU5yJQUXMNZovbinNNMJZLMwZqZZC+aFlxrfvudc57z///P9uDMQDtr AZ4sT6eUcrGMh7KR6uc/X60cO76JiqrvDyd1lQaUfNB7GSXbXbPJj19zEdLaHUlarHaEbK/V oWSfYZJF1o6bMbLrykdAln0b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3t8SXDefKNJSizFGYmGWsxFxYkAFE7R3dYDAAA= X-CMS-MailID: 20231028211538eucas1p1456b4c759a9fed51a6a77fbf2c946011 X-Msg-Generator: CA X-RootMTR: 20231028211538eucas1p1456b4c759a9fed51a6a77fbf2c946011 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211538eucas1p1456b4c759a9fed51a6a77fbf2c946011 References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Luis Chamberlain The multi index selftests are great but they don't replicate how we deal with the page cache exactly, which makes it a bit hard to follow as the page cache uses the advanced API. Add tests which use the advanced API, mimicking what we do in the page cache, while at it, extend the example to do what is needed for min order support. Signed-off-by: Luis Chamberlain Tested-by: Daniel Gomez --- lib/test_xarray.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/lib/test_xarray.c b/lib/test_xarray.c index 6c22588963bc..22a687e33dc5 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -694,6 +694,139 @@ static noinline void check_multi_store(struct xarray *xa) #endif } +#ifdef CONFIG_XARRAY_MULTI +static noinline void check_xa_multi_store_adv_add(struct xarray *xa, + unsigned long index, + unsigned int order, + void *p) +{ + XA_STATE(xas, xa, index); + + xas_set_order(&xas, index, order); + + do { + xas_lock_irq(&xas); + + xas_store(&xas, p); + XA_BUG_ON(xa, xas_error(&xas)); + XA_BUG_ON(xa, xa_load(xa, index) != p); + + xas_unlock_irq(&xas); + } while (xas_nomem(&xas, GFP_KERNEL)); + + XA_BUG_ON(xa, xas_error(&xas)); +} + +static noinline void check_xa_multi_store_adv_delete(struct xarray *xa, + unsigned long index, + unsigned int order) +{ + unsigned int nrpages = 1UL << order; + unsigned long base = round_down(index, nrpages); + XA_STATE(xas, xa, base); + + xas_set_order(&xas, base, order); + xas_store(&xas, NULL); + xas_init_marks(&xas); +} + +static unsigned long some_val = 0xdeadbeef; +static unsigned long some_val_2 = 0xdeaddead; + +/* mimics the page cache */ +static noinline void check_xa_multi_store_adv(struct xarray *xa, + unsigned long pos, + unsigned int order) +{ + unsigned int nrpages = 1UL << order; + unsigned long index, base, next_index, next_next_index; + unsigned int i; + + index = pos >> PAGE_SHIFT; + base = round_down(index, nrpages); + next_index = round_down(base + nrpages, nrpages); + next_next_index = round_down(next_index + nrpages, nrpages); + + check_xa_multi_store_adv_add(xa, base, order, &some_val); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, base + i) != &some_val); + + XA_BUG_ON(xa, xa_load(xa, next_index) != NULL); + + /* Use order 0 for the next item */ + check_xa_multi_store_adv_add(xa, next_index, 0, &some_val_2); + XA_BUG_ON(xa, xa_load(xa, next_index) != &some_val_2); + + /* Remove the next item */ + check_xa_multi_store_adv_delete(xa, next_index, 0); + + /* Now use order for a new pointer */ + check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, next_index + i) != &some_val_2); + + check_xa_multi_store_adv_delete(xa, next_index, order); + check_xa_multi_store_adv_delete(xa, base, order); + XA_BUG_ON(xa, !xa_empty(xa)); + + /* starting fresh again */ + + /* let's test some holes now */ + + /* hole at base and next_next */ + check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, base + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, next_index + i) != &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, next_next_index + i) != NULL); + + check_xa_multi_store_adv_delete(xa, next_index, order); + XA_BUG_ON(xa, !xa_empty(xa)); + + /* hole at base and next */ + + check_xa_multi_store_adv_add(xa, next_next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, base + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, next_index + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, next_next_index + i) != &some_val_2); + + check_xa_multi_store_adv_delete(xa, next_next_index, order); + XA_BUG_ON(xa, !xa_empty(xa)); +} +#endif + +static noinline void check_multi_store_advanced(struct xarray *xa) +{ +#ifdef CONFIG_XARRAY_MULTI + unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; + unsigned long end = ULONG_MAX/2; + unsigned long pos, i; + + /* + * About 117 million tests below. + */ + for (pos = 7; pos < end; pos = (pos * pos) + 564) { + for (i = 0; i < max_order; i++) { + check_xa_multi_store_adv(xa, pos, i); + check_xa_multi_store_adv(xa, pos + 157, i); + } + } +#endif +} + static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base) { int i; @@ -1825,6 +1958,7 @@ static int xarray_checks(void) check_reserve(&array); check_reserve(&xa0); check_multi_store(&array); + check_multi_store_advanced(&array); check_get_order(&array); check_xa_alloc(); check_find(&array); From patchwork Sat Oct 28 21:15:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439587 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E389C4708E for ; Sat, 28 Oct 2023 21:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbjJ1VPt (ORCPT ); Sat, 28 Oct 2023 17:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbjJ1VPq (ORCPT ); Sat, 28 Oct 2023 17:15:46 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1895DE1 for ; Sat, 28 Oct 2023 14:15:44 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211541euoutp02025f680e851b1238223542a801e51913~SYftrQ7hC0331103311euoutp02b for ; Sat, 28 Oct 2023 21:15:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231028211541euoutp02025f680e851b1238223542a801e51913~SYftrQ7hC0331103311euoutp02b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527741; bh=KNdASYDMYBghyPawUeQa4sXu1VB/4Vbh5nAWx6WaBVc=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=p25vRFikG8/u08B+ePf6VvgHwV8NxkrJZH/Gsn8m+A4lT/HMsDTVuZiosdX3Q/nYP 4pTukVv2uwz4EsY7oichDyeSqZ7xpFNFT2zF1JcaGs7iKcTK7FxWMMW++fF5boQcA6 LYREJzDKHJlJFelI5RdkTvhHCEVS+bsyGNhQaI6M= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211541eucas1p2956f217a1965e3854c430386af01e412~SYfs9xZLz1224812248eucas1p24; Sat, 28 Oct 2023 21:15:41 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 2B.81.42423.DF97D356; Sat, 28 Oct 2023 22:15:41 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231028211540eucas1p1fe328f4dadd3645c2c086055efc872ad~SYfslkcX60616106161eucas1p1P; Sat, 28 Oct 2023 21:15:40 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211540eusmtrp2885c51cf5903a19a29a6bef124f4dabc~SYfslCIHP1141411414eusmtrp2a; Sat, 28 Oct 2023 21:15:40 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-be-653d79fdc682 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EC.F0.25043.CF97D356; Sat, 28 Oct 2023 22:15:40 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231028211540eusmtip266e8e32a92786e265d14e5903bc6464c~SYfsYR64B1182011820eusmtip2o; Sat, 28 Oct 2023 21:15:40 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:40 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:39 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 03/11] shmem: drop BLOCKS_PER_PAGE macro Thread-Topic: [RFC PATCH 03/11] shmem: drop BLOCKS_PER_PAGE macro Thread-Index: AQHaCePme5B6ldUfmUi6e3JGjkM9rA== Date: Sat, 28 Oct 2023 21:15:39 +0000 Message-ID: <20231028211518.3424020-4-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrOKsWRmVeSWpSXmKPExsWy7djP87p/K21TDU7tYLeYs34Nm8Xqu/1s Fpef8Fk8/dTHYrH3lrbFnr0nWSwu75rDZnFvzX9Wi11/gEpvTHjKaLHs63t2i90bF7FZ/P4x h82B12N2w0UWjwWbSj02r9DyuHy21GPTqk42j02fJrF7nJjxm8Xj8ya5AI4oLpuU1JzMstQi fbsErowT+zkLfrJWnJw+kamB8RtLFyMnh4SAicSLF4/YQWwhgRWMEvuOpXYxcgHZXxglrh6Z xwbhfGaUWPPoGzNMR8uvfVCJ5YwSNxa1s8JVNRyYwQ7hnGGUuPLxKNTglYwS8x5EgNhsApoS +05uAisSEZjNKnF4cQcjSIJZoE5izbNZQFdxcAgL2Egc3GYGEhYRcJR4en4RO4StJ/H15A8m EJtFQFXi99yVTCDlvALWEpPXSoCEOYE673/bzgZiMwrISjxa+YsdYrq4xK0n85kgPhCUWDR7 D9Q3YhL/dj1kg7B1JM5ef8IIYRtIbF26DxpGShJ/OhZCXakncWPqFDYIW1ti2cLXYHN4gWae nPmEBeQtCYF/nBINa+9CNbtIXFn1BMoWlnh1fAs7hC0j8X/nfKYJjNqzkNw3C8mOWUh2zEKy YwEjyypG8dTS4tz01GLDvNRyveLE3OLSvHS95PzcTYzAtHb63/FPOxjnvvqod4iRiYPxEKME B7OSCC+zo02qEG9KYmVValF+fFFpTmrxIUZpDhYlcV7VFPlUIYH0xJLU7NTUgtQimCwTB6dU A5P9jDmlq4+837ha/eB1m4PF6iKbuHkWFNexrXP3Z8wtsTeSKZ+/zU5SSqfFdu7q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Eoi vMyONqlCvCmJlVWpRfnxRaU5qcWHGE2BITSRWUo0OR+YHPNK4g3NDEwNTcwsDUwtzYyVxHk9 CzoShQTSE0tSs1NTC1KLYPqYODilGpjanh3aXWR/1vyIa8aCFQWvODaEeT03c1qTtiH4vPMW rjtHjl1Q/ldeGmXc+3enwCFH38jZUfM1BFJvejecLP7woI+FWZqjMCH1S2PZNlZpL7c+jud+ JpW+vdveB4S7Np4tauIp40kpZJocnR/Gd8laT2itR6Ob/UEtgcveSV2LTmd9MM4NMOJ2DwnN CZ6dPVFXbMEp9RmvhGKCPBu6/0x0Dc80TdZPbXiqGbJ7vc5bG5/nMfr6+7vfZzYs9xIwFAxQ nbFtc85Mw6+Hbl4W5G8oXPxrfvDhreF1/oFnfod13DmZuW+l5Ld57JW6OnOOvPvWppnGlhvA HRHjuCWzvHsOR/6/1p1RUSnmO3cosRRnJBpqMRcVJwIAW8mX/9YDAAA= X-CMS-MailID: 20231028211540eucas1p1fe328f4dadd3645c2c086055efc872ad X-Msg-Generator: CA X-RootMTR: 20231028211540eucas1p1fe328f4dadd3645c2c086055efc872ad X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211540eucas1p1fe328f4dadd3645c2c086055efc872ad References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The commit [1] replaced all BLOCKS_PER_PAGE in favor of the generic PAGE_SECTORS but definition was not removed. Drop it as unused macro. [1] e09764cff44b5 ("shmem: quota support"). Signed-off-by: Daniel Gomez Reviewed-by: Luis Chamberlain --- mm/shmem.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 0d1ce70bce38..a2ac425b97ea 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -84,7 +84,6 @@ static struct vfsmount *shm_mnt __ro_after_init; #include "internal.h" -#define BLOCKS_PER_PAGE (PAGE_SIZE/512) #define VM_ACCT(size) (PAGE_ALIGN(size) >> PAGE_SHIFT) /* Pretend that each entry is of this size in directory's i_size */ From patchwork Sat Oct 28 21:15:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439586 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 489E7C001DD for ; Sat, 28 Oct 2023 21:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229985AbjJ1VPu (ORCPT ); Sat, 28 Oct 2023 17:15:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbjJ1VPs (ORCPT ); Sat, 28 Oct 2023 17:15:48 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B25F1F4 for ; Sat, 28 Oct 2023 14:15:45 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211543euoutp017869d28617519b102c127ac01c226ca6~SYfu8lJeD3100431004euoutp01Q for ; Sat, 28 Oct 2023 21:15:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231028211543euoutp017869d28617519b102c127ac01c226ca6~SYfu8lJeD3100431004euoutp01Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527743; bh=8ofABjUQrTp1kzdTCcGf7BUaZhuxx/1pi/TdtpYF5D0=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=VYigV6I+Xlg2f6kz+xnces7qO2f0nE5tR01Ol4rTD112qHEJhBXjL2IHc3c+wZLc0 4J5CPLxTCXq6Ef4vaHJ1aZ336J5ZiBJuzTVHj3DUHIMh8LafS+j7OlzIeMZQm0qVAT WE449o7Hrm2ASSKGptRHfU9DYe+D1wjPkqA1i5Rs= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211542eucas1p241e7ab5f2da4fdfc2cba9e250271dcbc~SYfuALImE1087910879eucas1p2E; Sat, 28 Oct 2023 21:15:42 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A1.20.11320.EF97D356; Sat, 28 Oct 2023 22:15:42 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231028211541eucas1p26663bd957cb449c7346b9dd00e33a20f~SYftgbGJH1224812248eucas1p26; Sat, 28 Oct 2023 21:15:41 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231028211541eusmtrp14898d07da8c7cf9ca684d016181d49c0~SYftf57WW0755507555eusmtrp1Z; Sat, 28 Oct 2023 21:15:41 +0000 (GMT) X-AuditID: cbfec7f4-97dff70000022c38-85-653d79fec53a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D1.52.10549.DF97D356; Sat, 28 Oct 2023 22:15:41 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211541eusmtip17d9fe4ecde792d45fb6ab59803d2f652~SYftVSUg60467404674eusmtip1K; Sat, 28 Oct 2023 21:15:41 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:41 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:40 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 04/11] shmem: return number of pages beeing freed in shmem_free_swap Thread-Topic: [RFC PATCH 04/11] shmem: return number of pages beeing freed in shmem_free_swap Thread-Index: AQHaCePnyXBbRf49wEefJYEMRSVIWA== Date: Sat, 28 Oct 2023 21:15:40 +0000 Message-ID: <20231028211518.3424020-5-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFKsWRmVeSWpSXmKPExsWy7djPc7r/Km1TDU6/4LCYs34Nm8Xqu/1s Fpef8Fk8/dTHYrH3lrbFnr0nWSwu75rDZnFvzX9Wi11/drBb3JjwlNFi2df37Ba7Ny5is/j9 Yw6bA6/H7IaLLB4LNpV6bF6h5XH5bKnHplWdbB6bPk1i9zgx4zeLx+dNcgEcUVw2Kak5mWWp Rfp2CVwZmze/Zir4K1xxbvFp1gbGh/xdjJwcEgImEjNnnmTtYuTiEBJY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AAYunQX1gMAAA== X-CMS-MailID: 20231028211541eucas1p26663bd957cb449c7346b9dd00e33a20f X-Msg-Generator: CA X-RootMTR: 20231028211541eucas1p26663bd957cb449c7346b9dd00e33a20f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211541eucas1p26663bd957cb449c7346b9dd00e33a20f References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Both shmem_free_swap callers expect the number of pages being freed. In the large folios context, this needs to support larger values other than 0 (used as 1 page being freed) and -ENOENT (used as 0 pages being freed). In preparation for large folios adoption, make shmem_free_swap routine return the number of pages being freed. So, returning 0 in this context, means 0 pages being freed. Suggested-by: Matthew Wilcox Signed-off-by: Daniel Gomez Reviewed-by: Luis Chamberlain --- mm/shmem.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index a2ac425b97ea..9f4c9b9286e5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -827,18 +827,22 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap) } /* - * Remove swap entry from page cache, free the swap and its page cache. + * Remove swap entry from page cache, free the swap and its page cache. Returns + * the number of pages being freed. 0 means entry not found in XArray (0 pages + * being freed). */ -static int shmem_free_swap(struct address_space *mapping, +static long shmem_free_swap(struct address_space *mapping, pgoff_t index, void *radswap) { void *old; + long swaps_freed = 1UL << xa_get_order(&mapping->i_pages, index); old = xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0); if (old != radswap) - return -ENOENT; + return 0; free_swap_and_cache(radix_to_swp_entry(radswap)); - return 0; + + return swaps_freed; } /* @@ -990,7 +994,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, if (xa_is_value(folio)) { if (unfalloc) continue; - nr_swaps_freed += !shmem_free_swap(mapping, + nr_swaps_freed += shmem_free_swap(mapping, indices[i], folio); continue; } @@ -1057,14 +1061,17 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio = fbatch.folios[i]; if (xa_is_value(folio)) { + long swaps_freed; + if (unfalloc) continue; - if (shmem_free_swap(mapping, indices[i], folio)) { + swaps_freed = shmem_free_swap(mapping, indices[i], folio); + if (!swaps_freed) { /* Swap was replaced by page: retry */ index = indices[i]; break; } - nr_swaps_freed++; + nr_swaps_freed += swaps_freed; continue; } From patchwork Sat Oct 28 21:15:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439588 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19C70C04A68 for ; Sat, 28 Oct 2023 21:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbjJ1VPv (ORCPT ); Sat, 28 Oct 2023 17:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbjJ1VPt (ORCPT ); Sat, 28 Oct 2023 17:15:49 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6209ECA for ; Sat, 28 Oct 2023 14:15:46 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211545euoutp026e7a184f0c6db3944c953d8a9d3480e2~SYfwvkgHc0331103311euoutp02f for ; Sat, 28 Oct 2023 21:15:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231028211545euoutp026e7a184f0c6db3944c953d8a9d3480e2~SYfwvkgHc0331103311euoutp02f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527745; bh=/CvASZfCabc/Ew9WG/OE+/8Wt2GCjn+VDx2yMe2ZiFk=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=d0BEWt0NRJ+q9fKwIT9WCJmLwnptxbJk8cHMt4E1+uBYIQAsZ8HmB0fV81C9HGMNh eplHCmHGAfK9UKuEM3ZkMU9SC9sskXWwIUvxl9OaeWtjnzZO7Uztce5QNGgW6Ll1S3 V0XCcJJ7oPcp//iGDSuKTptzJTpA26oYwVacTJPc= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211544eucas1p2dd80d12755f4916b3ddb921b0f269b68~SYfwUtLgi1224812248eucas1p27; Sat, 28 Oct 2023 21:15:44 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id FB.57.37758.00A7D356; Sat, 28 Oct 2023 22:15:44 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231028211543eucas1p2c980dda91fdccaa0b5af3734c357b2f7~SYfvYfPTw1090610906eucas1p2I; Sat, 28 Oct 2023 21:15:43 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211543eusmtrp23d56e547237e332334313cc821183188~SYfvX96w-1141411414eusmtrp2c; Sat, 28 Oct 2023 21:15:43 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-ff-653d7a00f0a9 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DD.F0.25043.FF97D356; Sat, 28 Oct 2023 22:15:43 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211543eusmtip1c2729878b21b7ae72b87f193ecb7dc7d~SYfvKXDWf0467404674eusmtip1M; Sat, 28 Oct 2023 21:15:43 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:42 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:42 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 05/11] shmem: account for large order folios Thread-Topic: [RFC PATCH 05/11] shmem: account for large order folios Thread-Index: AQHaCePog3tlS7SbBUi1hq/vgcoYwQ== Date: Sat, 28 Oct 2023 21:15:42 +0000 Message-ID: <20231028211518.3424020-6-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrOKsWRmVeSWpSXmKPExsWy7djPc7oMVbapBvtfaVrMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7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yx/27I3um6p1d8OMm7uM5QVbmrjm8Ly82mo8v+Ha0XdXDzNHHJ3SlnJWf0 4+OxtbGiwvlzZ7w5dtrzZ8sr973zpa8d+sIVfqbj6/QTS+Lzf2kG89xbIbi/VvGGbLfajIem O2xv3Pd+fUjos8EHluizHJv9WW7Mkbp08RhbgLUSS3FGoqEWc1FxIgDmdKNI1gMAAA== X-CMS-MailID: 20231028211543eucas1p2c980dda91fdccaa0b5af3734c357b2f7 X-Msg-Generator: CA X-RootMTR: 20231028211543eucas1p2c980dda91fdccaa0b5af3734c357b2f7 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211543eucas1p2c980dda91fdccaa0b5af3734c357b2f7 References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Luis Chamberlain shmem uses the shem_info_inode alloced, swapped to account for allocated pages and swapped pages. In preparation for large order folios adjust the accounting to use folio_nr_pages(). This should produce no functional changes yet as larger order folios are not yet used or supported in shmem. Signed-off-by: Luis Chamberlain Signed-off-by: Daniel Gomez --- mm/shmem.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 9f4c9b9286e5..ab31d2880e5d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -856,16 +856,16 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping, pgoff_t start, pgoff_t end) { XA_STATE(xas, &mapping->i_pages, start); - struct page *page; + struct folio *folio; unsigned long swapped = 0; unsigned long max = end - 1; rcu_read_lock(); - xas_for_each(&xas, page, max) { - if (xas_retry(&xas, page)) + xas_for_each(&xas, folio, max) { + if (xas_retry(&xas, folio)) continue; - if (xa_is_value(page)) - swapped++; + if (xa_is_value(folio)) + swapped += folio_nr_pages(folio); if (xas.xa_index == max) break; if (need_resched()) { @@ -1514,7 +1514,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (add_to_swap_cache(folio, swap, __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN, NULL) == 0) { - shmem_recalc_inode(inode, 0, 1); + shmem_recalc_inode(inode, 0, folio_nr_pages(folio)); swap_shmem_alloc(swap); shmem_delete_from_page_cache(folio, swp_to_radix_entry(swap)); @@ -1828,6 +1828,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, struct address_space *mapping = inode->i_mapping; swp_entry_t swapin_error; void *old; + long num_swap_pages; swapin_error = make_poisoned_swp_entry(); old = xa_cmpxchg_irq(&mapping->i_pages, index, @@ -1837,13 +1838,14 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, return; folio_wait_writeback(folio); + num_swap_pages = folio_nr_pages(folio); delete_from_swap_cache(folio); /* * Don't treat swapin error folio as alloced. Otherwise inode->i_blocks * won't be 0 when inode is released and thus trigger WARN_ON(i_blocks) * in shmem_evict_inode(). */ - shmem_recalc_inode(inode, -1, -1); + shmem_recalc_inode(inode, -num_swap_pages, -num_swap_pages); swap_free(swap); } @@ -1928,7 +1930,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, if (error) goto failed; - shmem_recalc_inode(inode, 0, -1); + shmem_recalc_inode(inode, 0, -folio_nr_pages(folio)); if (sgp == SGP_WRITE) folio_mark_accessed(folio); @@ -2684,7 +2686,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, if (ret) goto out_delete_from_cache; - shmem_recalc_inode(inode, 1, 0); + shmem_recalc_inode(inode, folio_nr_pages(folio), 0); folio_unlock(folio); return 0; out_delete_from_cache: From patchwork Sat Oct 28 21:15:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439589 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFD66C00A5A for ; Sat, 28 Oct 2023 21:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229994AbjJ1VPw (ORCPT ); Sat, 28 Oct 2023 17:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbjJ1VPu (ORCPT ); Sat, 28 Oct 2023 17:15:50 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16D30D3 for ; Sat, 28 Oct 2023 14:15:48 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211546euoutp02bfecc4b7c5077391c28a57811d4b865b~SYfyWKH4I0890208902euoutp02E for ; Sat, 28 Oct 2023 21:15:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231028211546euoutp02bfecc4b7c5077391c28a57811d4b865b~SYfyWKH4I0890208902euoutp02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527746; bh=cqTk9J1wmzoKfcE/fbVQ1ZhNe/efGCweXy90QEX86kQ=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=bjGf4PuODXvBE+WtcNSzL/CGuJ1b5AEEdHtQz7pHlVmrkuMHVuyweXzVQWgG/atL9 wzuPX6jt6lRIWbVhOuxYDQbOfoD02yu1xpSqLVgyQWBUoXM5O3wVGJbtK4WAyHIQxa Hv407t/IChRH42DXr+FKGurxlj6OzW9hDC5hL9E0= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211546eucas1p2d9c87ac5195deeb424c6db2ee6b4bba0~SYfyAl9sB1224812248eucas1p2_; Sat, 28 Oct 2023 21:15:46 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A2.20.11320.20A7D356; Sat, 28 Oct 2023 22:15:46 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231028211545eucas1p2da564864423007a5ab006cdd1ab4d4a1~SYfxbyUZ41087910879eucas1p2I; Sat, 28 Oct 2023 21:15:45 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211545eusmtrp27f616722d703e49e984feaa6bd1f86ae~SYfxbQh_i1141411414eusmtrp2d; Sat, 28 Oct 2023 21:15:45 +0000 (GMT) X-AuditID: cbfec7f4-97dff70000022c38-8b-653d7a029922 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id CE.F0.25043.10A7D356; Sat, 28 Oct 2023 22:15:45 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211545eusmtip1ecd5e3b6d81770cd6ea6596dd01bf8b4~SYfxRlEbt0467404674eusmtip1O; Sat, 28 Oct 2023 21:15:45 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:45 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:44 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 06/11] shmem: trace shmem_add_to_page_cache folio order Thread-Topic: [RFC PATCH 06/11] shmem: trace shmem_add_to_page_cache folio order Thread-Index: AQHaCePpKnL5pBbYgEe8tpnCRhW3OA== Date: Sat, 28 Oct 2023 21:15:44 +0000 Message-ID: <20231028211518.3424020-7-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJKsWRmVeSWpSXmKPExsWy7djPc7pMVbapBrMfSFnMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/MmuQCOKC6blNSczLLU In27BK6MK9tmsxSsFq9Y+vE0ewPjJuEuRk4OCQETifavp1i6GLk4hARWMEpMaP3OBJIQEvjC KPF9ggtE4jOjxJHm/8wwHV0v77FCJJYzSrRt+MsMV9W4eRUbhHOGUWLytqOsELNWMkqs3uMO YrMJaErsO7mJHaRIRGA2q8ThxR2MIAlmgTqJNc9msYDYwgLeErcWX2cDsUUEgiSmr7rJBGHr STxvvQdUw8HBIqAqMf2TJkiYV8BaovvoZbBWTgEbifvftoO1MgrISjxa+YsdYry4xK0n85kg XhCUWDR7D9Q7YhL/dj1kg7B1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BKHF3cwgiSYBeok1jybBVYk LOAtcWvxdTYQW0QgSOL4x6nMELaexPPWe0A1HBwsAqoS0z9pgoR5Bawluo9eBgsLCeRK9Ldl goQ5BWwk7n/bDjaFUUBW4tHKX+wQm8Qlbj2ZzwTxgYDEkj3noT4TlXj5+B/UZzoSZ68/YYSw DSS2Lt3HAmErSfzpWAh1sZ7EjalT2CBsbYllC18zQ5wjKHFy5hOWCYzSs5Csm4WkZRaSlllI WhYwsqxiFEktLc5Nzy020itOzC0uzUvXS87P3cQITE/bjv3csoNx5auPeocYmTgYDzFKcDAr ifAyO9qkCvGmJFZWpRblxxeV5qQWH2I0BYbQRGYp0eR8YILMK4k3NDMwNTQxszQwtTQzVhLn 9SzoSBQSSE8sSc1OTS1ILYLpY+LglGpgSr2q7VV9+HT5lx2zTu/N97C6+Fyy1nnjz6eXPux6 ulttHZMtu1hh07z2JXLt157P7kioUk349e5HHNPijbLsYg0zz37KLHQMWdrxs6JZOvbC4w3P pzX9XfdEf/H29MXMot/OBwpOvhC1MHv2UcXPeT9WTRBMflCbwniooNU1VE9/UxpbQ86h+Rv3 qx8XyPFbeF3Er+VCdWuMe13prGtiea8MHz3fzV0z54TW74MiFoc0mC+ZtPBNkd18lnuG1DUp BqO1ilVMy+rdFuasESy6IvFD/1ti0/tMv/V3+TZfW1F71Ipp1Sq/DJO1/zVmtl9K2Xtz3qZL XQE+PnGGYTsqdtZ8TOw13tibOzWSefOJQCWW4oxEQy3mouJEAMITPVjYAwAA X-CMS-MailID: 20231028211545eucas1p2da564864423007a5ab006cdd1ab4d4a1 X-Msg-Generator: CA X-RootMTR: 20231028211545eucas1p2da564864423007a5ab006cdd1ab4d4a1 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211545eucas1p2da564864423007a5ab006cdd1ab4d4a1 References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org To be able to trace and account for order of the folio. Based on include/trace/filemap.h. Update MAINTAINERS file list for SHMEM. Signed-off-by: Daniel Gomez --- MAINTAINERS | 1 + include/trace/events/shmem.h | 52 ++++++++++++++++++++++++++++++++++++ mm/shmem.c | 4 +++ 3 files changed, 57 insertions(+) create mode 100644 include/trace/events/shmem.h diff --git a/MAINTAINERS b/MAINTAINERS index bdc4638b2df5..befa63e7cb28 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21923,6 +21923,7 @@ M: Hugh Dickins L: linux-mm@kvack.org S: Maintained F: include/linux/shmem_fs.h +F: include/trace/events/shmem.h F: mm/shmem.c TOMOYO SECURITY MODULE diff --git a/include/trace/events/shmem.h b/include/trace/events/shmem.h new file mode 100644 index 000000000000..223f78f11457 --- /dev/null +++ b/include/trace/events/shmem.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM shmem + +#if !defined(_TRACE_SHMEM_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_SHMEM_H + +#include +#include + +DECLARE_EVENT_CLASS(mm_shmem_op_page_cache, + + TP_PROTO(struct folio *folio), + + TP_ARGS(folio), + + TP_STRUCT__entry( + __field(unsigned long, pfn) + __field(unsigned long, i_ino) + __field(unsigned long, index) + __field(dev_t, s_dev) + __field(unsigned char, order) + ), + + TP_fast_assign( + __entry->pfn = folio_pfn(folio); + __entry->i_ino = folio->mapping->host->i_ino; + __entry->index = folio->index; + if (folio->mapping->host->i_sb) + __entry->s_dev = folio->mapping->host->i_sb->s_dev; + else + __entry->s_dev = folio->mapping->host->i_rdev; + __entry->order = folio_order(folio); + ), + + TP_printk("dev %d:%d ino %lx pfn=0x%lx ofs=%lu order=%u", + MAJOR(__entry->s_dev), MINOR(__entry->s_dev), + __entry->i_ino, + __entry->pfn, + __entry->index << PAGE_SHIFT, + __entry->order) +); + +DEFINE_EVENT(mm_shmem_op_page_cache, mm_shmem_add_to_page_cache, + TP_PROTO(struct folio *folio), + TP_ARGS(folio) + ); + +#endif /* _TRACE_SHMEM_H */ + +/* This part must be outside protection */ +#include diff --git a/mm/shmem.c b/mm/shmem.c index ab31d2880e5d..e2893cf2287f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -84,6 +84,9 @@ static struct vfsmount *shm_mnt __ro_after_init; #include "internal.h" +#define CREATE_TRACE_POINTS +#include + #define VM_ACCT(size) (PAGE_ALIGN(size) >> PAGE_SHIFT) /* Pretend that each entry is of this size in directory's i_size */ @@ -1726,6 +1729,7 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, } } + trace_mm_shmem_add_to_page_cache(folio); shmem_recalc_inode(inode, pages, 0); folio_add_lru(folio); return folio; From patchwork Sat Oct 28 21:15:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439590 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0258EC4167B for ; Sat, 28 Oct 2023 21:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbjJ1VQM (ORCPT ); Sat, 28 Oct 2023 17:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbjJ1VPx (ORCPT ); Sat, 28 Oct 2023 17:15:53 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 995EEE6 for ; Sat, 28 Oct 2023 14:15:50 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211549euoutp01940c9a2b6744c13624c870e641f21c74~SYf0t9uhy2659126591euoutp01K for ; Sat, 28 Oct 2023 21:15:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231028211549euoutp01940c9a2b6744c13624c870e641f21c74~SYf0t9uhy2659126591euoutp01K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527749; bh=KMahjoHxxEGT5gaBZBeFILgQTlTnM1MpN5QmTOlrbgg=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=NpS6/cZUu5469ui0A5b4Affrh1LC9nZowLTonIS7cPKyDXrNdXVKaiyGJ1TnafE5y 4LZwZlvKcCw+9knXLxqd9tEsMBJwbMd4urVuLB7SzQre8J+EYyRm/gtGPXy8T2oiHE yjjkGvf2Jw+yP7iqeks84/0G685vWSuoHbxoybrU= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211549eucas1p2fc824cd9bc602e094c2b9bc40e72187b~SYf0VLXIT1087910879eucas1p2M; Sat, 28 Oct 2023 21:15:49 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id FC.57.37758.40A7D356; Sat, 28 Oct 2023 22:15:48 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231028211546eucas1p2147a423b26a6fa92be7e6c20df429da5~SYfyRbpOf1224812248eucas1p2A; Sat, 28 Oct 2023 21:15:46 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211546eusmtrp2c9f70e6608c90b52dc9e964b9cdca2d6~SYfyQ6t5Z1141411414eusmtrp2e; Sat, 28 Oct 2023 21:15:46 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-05-653d7a045348 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id AF.F0.25043.20A7D356; Sat, 28 Oct 2023 22:15:46 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211546eusmtip1b8f4d77fa5acb0d4af2695620577282c~SYfyEc2tN0467404674eusmtip1Q; Sat, 28 Oct 2023 21:15:46 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:46 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:45 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 07/11] shmem: remove huge arg from shmem_alloc_and_add_folio() Thread-Topic: [RFC PATCH 07/11] shmem: remove huge arg from shmem_alloc_and_add_folio() Thread-Index: AQHaCePqWfxF+qVFe0qg34umJ1pkKA== Date: Sat, 28 Oct 2023 21:15:45 +0000 Message-ID: <20231028211518.3424020-8-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKKsWRmVeSWpSXmKPExsWy7djPc7osVbapBoenWlrMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/MmuQCOKC6blNSczLLU In27BK6Mh5N2sxcsEqo4/ES4gfENXxcjJ4eEgInE2n3fWEBsIYEVjBKPJ8Z1MXIB2V8YJVbt Oc4I4XxmlHi9qgvI4QDruPuFEyK+nFHi1tclbBDdQEVfFnJBJM4wSlxf844FwlnJKLFp4kQm kCo2AU2JfSc3sYMkRARms0ocXtzBCJJgFqiTWPNsFgvICmGBEIk3TUEgpohApMTc2WALRAT0 JG78nccMEmYRUJXY1FUIEuYVsJb413OOFcTmFLCRuP9tO1g5o4CsxKOVv9ghhotL3Hoynwni Y0GJRbP3MEPYYhL/dj1kg7B1JM5ef8IIYRtIbF26jwXCVpL407EQ6kigE6ZOYYOwtSWWLXzN DHGDoMTJmU/A3pUQaOKSOPX6A9QCF4kz0xvZIWxhiVfHt0DZMhL/d85nmsCoPQvJfbOQ7JiF ZMcsJDsWMLKsYhRPLS3OTU8tNs5LLdcrTswtLs1L10vOz93ECExpp/8d/7qDccWrj3qHGJk4 GA8xSnAwK4nwMjvapArxpiRWVqUW5ccXleakFh9ilOZgURLnVU2RTxUSSE8sSc1OTS1ILYLJ MnFwSjUwzT56fvrH+S5Jb2ueTORgXruvRnfy3kX/47Nceh5cKwhaK+F/w/v8FYfY3Wm9yzYc uxozN3BCgRyPf0HqehHJYk8n72sSdVOrdng+5HMomH8raHUaj/S8GVdChRZmz91xeorGy9bW v3EsKtsu3tJVuVNqGvk1dFPtH5WdkeZp88ONLxxmVkt99+HISSE+Bp26vUcXx7rd9Vz/8jzT Z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WVWedtuOyEdi7rogBLmfxbM196sM01a8GzajgsT3yv6 FC7w2KWf+uDmF2OWsP/lfQ+fJgXn2XS05d/aVZtWf/K8URvX5vuSoa+3ngtZd+oQ66+Enfu0 /B5VqRjJrDnWedNwyRG9CCvWh+EHn39XfmolML3Inff9tR8xW7R0nIOVhc3v7Rf4WVJfrLx1 MeN0dv4Lsda2kc9qzxwN/bTdusf+hZea09sjL2WYNp9vX6PEG6cvt9P5QV//a66Yuc/O/Utm d03/XTU72TEo9pztvSbThUm9S+Yqf01TYinOSDTUYi4qTgQA2WR+ZdQDAAA= X-CMS-MailID: 20231028211546eucas1p2147a423b26a6fa92be7e6c20df429da5 X-Msg-Generator: CA X-RootMTR: 20231028211546eucas1p2147a423b26a6fa92be7e6c20df429da5 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211546eucas1p2147a423b26a6fa92be7e6c20df429da5 References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The huge flag is already part of of the memory allocation flag (gfp_t). Make use of the VM_HUGEPAGE bit set by vma_thp_gfp_mask() to know if the allocation must be a huge page. Drop CONFIG_TRANSPARENT_HUGEPAGE check in shmem_alloc_and_add_folio() as VM_HUGEPAGE won't be set unless THP config is enabled. Signed-off-by: Daniel Gomez --- mm/shmem.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index e2893cf2287f..9d68211373c4 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1644,7 +1644,7 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, struct inode *inode, pgoff_t index, - struct mm_struct *fault_mm, bool huge) + struct mm_struct *fault_mm) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); @@ -1652,10 +1652,7 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, long pages; int error; - if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) - huge = false; - - if (huge) { + if (gfp & VM_HUGEPAGE) { pages = HPAGE_PMD_NR; index = round_down(index, HPAGE_PMD_NR); @@ -1690,7 +1687,7 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, if (xa_find(&mapping->i_pages, &index, index + pages - 1, XA_PRESENT)) { error = -EEXIST; - } else if (huge) { + } else if (gfp & VM_HUGEPAGE) { count_vm_event(THP_FILE_FALLBACK); count_vm_event(THP_FILE_FALLBACK_CHARGE); } @@ -2054,7 +2051,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, huge_gfp = vma_thp_gfp_mask(vma); huge_gfp = limit_gfp_mask(huge_gfp, gfp); folio = shmem_alloc_and_add_folio(huge_gfp, - inode, index, fault_mm, true); + inode, index, fault_mm); if (!IS_ERR(folio)) { count_vm_event(THP_FILE_ALLOC); goto alloced; @@ -2063,7 +2060,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, goto repeat; } - folio = shmem_alloc_and_add_folio(gfp, inode, index, fault_mm, false); + folio = shmem_alloc_and_add_folio(gfp, inode, index, fault_mm); if (IS_ERR(folio)) { error = PTR_ERR(folio); if (error == -EEXIST) From patchwork Sat Oct 28 21:15:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439592 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA297C41535 for ; Sat, 28 Oct 2023 21:16:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbjJ1VQa (ORCPT ); Sat, 28 Oct 2023 17:16:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbjJ1VQ0 (ORCPT ); Sat, 28 Oct 2023 17:16:26 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37495100 for ; Sat, 28 Oct 2023 14:15:51 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211550euoutp0118aa5f59ae9130ebd5a84d9388de63b3~SYf1mP5d02663226632euoutp01G for ; Sat, 28 Oct 2023 21:15:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231028211550euoutp0118aa5f59ae9130ebd5a84d9388de63b3~SYf1mP5d02663226632euoutp01G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527750; bh=gxd/EGAczS5Sd2rHF+B8nzW13spueLXcZPpoB3AlPYI=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=HvgVsjl64HvJ64ot77kmzDje+uQuxtA7zifALFjBJvDoDR4pE12gHKnQopPb9Q1Ki JcsOmoG3yxeNnMF8nPokyO29MmGgAeRqQa/qZXip9wn/92O8bamlvsBdGOhyhREkOW bBBKJ419K6MQ52U10yhCjUxALGKOW1hVkwIgykE8= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211549eucas1p239234b06d304c44bb785b810de7b1834~SYf0zFEUx1087910879eucas1p2O; Sat, 28 Oct 2023 21:15:49 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id DD.57.37758.50A7D356; Sat, 28 Oct 2023 22:15:49 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231028211548eucas1p18d34af3d578966ba6778d4e60751789d~SYf0Hvnnc0616106161eucas1p1U; Sat, 28 Oct 2023 21:15:48 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231028211548eusmtrp167fbd68caf98448438c2e2eab8a99c2b~SYf0HNAVQ0755507555eusmtrp1c; Sat, 28 Oct 2023 21:15:48 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-07-653d7a050245 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 03.52.10549.40A7D356; Sat, 28 Oct 2023 22:15:48 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211548eusmtip138c1e7e6b533f290bc0b98246a985425~SYfz7zIWw0467404674eusmtip1S; Sat, 28 Oct 2023 21:15:48 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:48 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:48 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 08/11] shmem: add file length arg in shmem_get_folio() path Thread-Topic: [RFC PATCH 08/11] shmem: add file length arg in shmem_get_folio() path Thread-Index: AQHaCePr7bvMjV6bP0CdFgNDCwhrFA== Date: Sat, 28 Oct 2023 21:15:47 +0000 Message-ID: <20231028211518.3424020-9-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJKsWRmVeSWpSXmKPExsWy7djPc7qsVbapBqdbpSzmrF/DZrH6bj+b xeUnfBZPP/WxWOy9pW2xZ+9JFovLu+awWdxb85/VYtefHewWNyY8ZbRY9vU9u8XujYvYLH7/ mMPmwOsxu+Eii8eCTaUem1doeVw+W+qxaVUnm8emT5PYPU7M+M3i8XmTXABHFJdNSmpOZllq kb5dAldG69KJbAWfrSomTH3I1sDYpd/FyMkhIWAicbf9I1MXIxeHkMAKRom1J34wQjhfGCUu fNsK5XxmlLh99QkjTMupR1tYIRLLGSUeX57IBJIAq9r0LQ8icYZRYtK2L6wQiZWMEvNnBYDY bAKaEvtObmIHKRIRmM0qcXhxB9hYZoE6iTXPZrF0MXJwCAsESvy/nQYSFhEIk/h0fCMThK0n 0X7+CFg5i4CqxIVfU8Hm8wpYSyw7vpYdxOYUsJG4/207G4jNKCAr8WjlL3aI8eISt57MZ4L4 QFBi0ew9zBC2mMS/XQ/ZIGwdibPXYb40kNi6dB8LhK0k8adjIdSZehI3pk5hg7C1JZYtfM0M cYOgxMmZT1hA/pIQaOKSOHT/C9RQF4nrVxqghgpLvDq+hR3ClpE4PbmHZQKj9iwk981CsmMW kh2zkOxYwMiyilE8tbQ4Nz212DgvtVyvODG3uDQvXS85P3cTIzC1nf53/OsOxhWvPuodYmTi YDzEKMHBr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T2CBsbYllC18zQ5wjKHFy5hOWCYzSs5Csm4WkZRaSlllI WhYwsqxiFEktLc5Nzy021CtOzC0uzUvXS87P3cQITE7bjv3cvINx3quPeocYmTgYDzFKcDAr ifAyO9qkCvGmJFZWpRblxxeV5qQWH2I0BQbRRGYp0eR8YHrMK4k3NDMwNTQxszQwtTQzVhLn 9SzoSBQSSE8sSc1OTS1ILYLpY+LglGpgYlcX/fQuqjyj5O0+T1Ff6ztTeKQ4ZwnMrTtQeyF+ 44ESE+nld02Wec2Nu6F7TCt7h1Q2Y0qXppNDvFL8Rl8F/ZlhitwCvyPY18g7HvJsK19we693 1cXVLuLvebqnxVt1nKjbLvlD+OFHlpVCKmZ9a5ovLJryhjE3j0tkxvI/B6+bi76z5eSX7Wo8 UZtmIVIkej99j4nQsSmW9zcUXHFe2LzHavHXeyczNgt9+7m5KPRS49K5h+Zs1fz1Qri98lDi /KnyFzyUz6nxP6i68O9DXJXIt0/+NTsZTNaI7Eu9s9pe5FNafWHz8WWlXae65Wbzq3YYfQ31 PX1AWLXE+ZfzwTs2ecWmtzKfJOfsKp+pxFKckWioxVxUnAgAN/NqXtcDAAA= X-CMS-MailID: 20231028211548eucas1p18d34af3d578966ba6778d4e60751789d X-Msg-Generator: CA X-RootMTR: 20231028211548eucas1p18d34af3d578966ba6778d4e60751789d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211548eucas1p18d34af3d578966ba6778d4e60751789d References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org In preparation for large folio in the write path, add file length argument in shmem_get_folio() path to be able to calculate the folio order based on the file size. Use of order-0 (PAGE_SIZE) for non write paths such as read, page cache read, and vm fault. This enables high order folios in the write and fallocate paths once the folio order is calculated based on the length. Signed-off-by: Daniel Gomez --- include/linux/shmem_fs.h | 2 +- mm/khugepaged.c | 3 ++- mm/shmem.c | 33 ++++++++++++++++++--------------- mm/userfaultfd.c | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) -- 2.39.2 diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 2caa6b86106a..7138ea980884 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -137,7 +137,7 @@ enum sgp_type { }; int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, - enum sgp_type sgp); + enum sgp_type sgp, size_t len); struct folio *shmem_read_folio_gfp(struct address_space *mapping, pgoff_t index, gfp_t gfp); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 064654717843..fcde8223b507 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1855,7 +1855,8 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, xas_unlock_irq(&xas); /* swap in or instantiate fallocated page */ if (shmem_get_folio(mapping->host, index, - &folio, SGP_NOALLOC)) { + &folio, SGP_NOALLOC, + PAGE_SIZE)) { result = SCAN_FAIL; goto xa_unlocked; } diff --git a/mm/shmem.c b/mm/shmem.c index 9d68211373c4..d8dc2ceaba18 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -958,7 +958,7 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) * (although in some cases this is just a waste of time). */ folio = NULL; - shmem_get_folio(inode, index, &folio, SGP_READ); + shmem_get_folio(inode, index, &folio, SGP_READ, PAGE_SIZE); return folio; } @@ -1644,7 +1644,7 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, struct inode *inode, pgoff_t index, - struct mm_struct *fault_mm) + struct mm_struct *fault_mm, size_t len) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); @@ -1969,7 +1969,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, */ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, struct folio **foliop, enum sgp_type sgp, gfp_t gfp, - struct vm_fault *vmf, vm_fault_t *fault_type) + struct vm_fault *vmf, vm_fault_t *fault_type, size_t len) { struct vm_area_struct *vma = vmf ? vmf->vma : NULL; struct mm_struct *fault_mm; @@ -2051,7 +2051,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, huge_gfp = vma_thp_gfp_mask(vma); huge_gfp = limit_gfp_mask(huge_gfp, gfp); folio = shmem_alloc_and_add_folio(huge_gfp, - inode, index, fault_mm); + inode, index, fault_mm, len); if (!IS_ERR(folio)) { count_vm_event(THP_FILE_ALLOC); goto alloced; @@ -2060,7 +2060,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, goto repeat; } - folio = shmem_alloc_and_add_folio(gfp, inode, index, fault_mm); + folio = shmem_alloc_and_add_folio(gfp, inode, index, fault_mm, len); if (IS_ERR(folio)) { error = PTR_ERR(folio); if (error == -EEXIST) @@ -2140,10 +2140,10 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, } int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, - enum sgp_type sgp) + enum sgp_type sgp, size_t len) { return shmem_get_folio_gfp(inode, index, foliop, sgp, - mapping_gfp_mask(inode->i_mapping), NULL, NULL); + mapping_gfp_mask(inode->i_mapping), NULL, NULL, len); } /* @@ -2237,7 +2237,7 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf) WARN_ON_ONCE(vmf->page != NULL); err = shmem_get_folio_gfp(inode, vmf->pgoff, &folio, SGP_CACHE, - gfp, vmf, &ret); + gfp, vmf, &ret, PAGE_SIZE); if (err) return vmf_error(err); if (folio) { @@ -2716,6 +2716,9 @@ shmem_write_begin(struct file *file, struct address_space *mapping, struct folio *folio; int ret = 0; + if (!mapping_large_folio_support(mapping)) + len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos)); + /* i_rwsem is held by caller */ if (unlikely(info->seals & (F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_FUTURE_WRITE))) { @@ -2725,7 +2728,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping, return -EPERM; } - ret = shmem_get_folio(inode, index, &folio, SGP_WRITE); + ret = shmem_get_folio(inode, index, &folio, SGP_WRITE, len); if (ret) return ret; @@ -2796,7 +2799,7 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) break; } - error = shmem_get_folio(inode, index, &folio, SGP_READ); + error = shmem_get_folio(inode, index, &folio, SGP_READ, PAGE_SIZE); if (error) { if (error == -EINVAL) error = 0; @@ -2973,7 +2976,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, break; error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio, - SGP_READ); + SGP_READ, PAGE_SIZE); if (error) { if (error == -EINVAL) error = 0; @@ -3160,7 +3163,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, error = -ENOMEM; else error = shmem_get_folio(inode, index, &folio, - SGP_FALLOC); + SGP_FALLOC, (end - index) << PAGE_SHIFT); if (error) { info->fallocend = undo_fallocend; /* Remove the !uptodate folios we added */ @@ -3511,7 +3514,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, inode->i_op = &shmem_short_symlink_operations; } else { inode_nohighmem(inode); - error = shmem_get_folio(inode, 0, &folio, SGP_WRITE); + error = shmem_get_folio(inode, 0, &folio, SGP_WRITE, PAGE_SIZE); if (error) goto out_remove_offset; inode->i_mapping->a_ops = &shmem_aops; @@ -3558,7 +3561,7 @@ static const char *shmem_get_link(struct dentry *dentry, struct inode *inode, return ERR_PTR(-ECHILD); } } else { - error = shmem_get_folio(inode, 0, &folio, SGP_READ); + error = shmem_get_folio(inode, 0, &folio, SGP_READ, PAGE_SIZE); if (error) return ERR_PTR(error); if (!folio) @@ -4923,7 +4926,7 @@ struct folio *shmem_read_folio_gfp(struct address_space *mapping, BUG_ON(!shmem_mapping(mapping)); error = shmem_get_folio_gfp(inode, index, &folio, SGP_CACHE, - gfp, NULL, NULL); + gfp, NULL, NULL, PAGE_SIZE); if (error) return ERR_PTR(error); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 96d9eae5c7cc..aab8679b322a 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -256,7 +256,7 @@ static int mfill_atomic_pte_continue(pmd_t *dst_pmd, struct page *page; int ret; - ret = shmem_get_folio(inode, pgoff, &folio, SGP_NOALLOC); + ret = shmem_get_folio(inode, pgoff, &folio, SGP_NOALLOC, PAGE_SIZE); /* Our caller expects us to return -EFAULT if we failed to find folio */ if (ret == -ENOENT) ret = -EFAULT; From patchwork Sat Oct 28 21:15:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439591 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CDD9C4167B for ; Sat, 28 Oct 2023 21:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbjJ1VQb (ORCPT ); Sat, 28 Oct 2023 17:16:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjJ1VQ0 (ORCPT ); Sat, 28 Oct 2023 17:16:26 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68E40129 for ; Sat, 28 Oct 2023 14:15:54 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211552euoutp02759c53faf763d4a23c26db86c5878de6~SYf3uABwO0899008990euoutp02G for ; Sat, 28 Oct 2023 21:15:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231028211552euoutp02759c53faf763d4a23c26db86c5878de6~SYf3uABwO0899008990euoutp02G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527752; bh=MryWcICdLJnJIpSQ//VC4hAIbMIw5xNwvvS8lnrY/z4=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=ePBvv+WznISzR3zoq3qsBn2CBSEJB2wrKIglDYakrXINkRy/NEALAyS/D37Ds0sMW CBZwq1VbMuGTaOih6ybrOyNMlVtrlV0vm2iC1UWGc9UPbkUW/xZJlH7xcOZokOfpAz CCUnB7AMfrF+6pejFOr/f+mUZSEJSVinapl2Zh0g= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211551eucas1p2e50b635ba8eae30317009299b0be2ea3~SYf2kdVsc1224812248eucas1p2E; Sat, 28 Oct 2023 21:15:51 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id BE.57.37758.70A7D356; Sat, 28 Oct 2023 22:15:51 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231028211550eucas1p1dc1d47e413de350deda962c3df5111ef~SYf2GDan11181011810eucas1p1I; Sat, 28 Oct 2023 21:15:50 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211550eusmtrp2373a802e94a6ccdb4bd44f64388a442f~SYf2FekMo1141411414eusmtrp2g; Sat, 28 Oct 2023 21:15:50 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-0b-653d7a071720 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A0.01.25043.60A7D356; Sat, 28 Oct 2023 22:15:50 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231028211550eusmtip29b55570e519e6390a3d01dce2b0ec14a~SYf120roh1182011820eusmtip2p; Sat, 28 Oct 2023 21:15:50 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:50 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:50 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 09/11] shmem: add order arg to shmem_alloc_folio() Thread-Topic: [RFC PATCH 09/11] shmem: add order arg to shmem_alloc_folio() Thread-Index: AQHaCePsz4j06UKTKkuVsaJRZMX8Ng== Date: Sat, 28 Oct 2023 21:15:49 +0000 Message-ID: <20231028211518.3424020-10-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFKsWRmVeSWpSXmKPExsWy7djPc7rsVbapBj/nSVjMWb+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Rf9h0yP2q7/z zqoaFWq9v2pgsJpjd6Ym83e//rS6uwHm6+SPB855Upmfnum7PGERq/6yRxeaY09N9Lr+c0dU cL8WA8/crQfv3/u1jMnRapOW6PtIncf6O2u5GLZLOXpeO14crbpwV1rUrMlqjBXbGJpXxjmX 8xhfWDfzoWvY5CNaKUeDnaT8lR2VWIozEg21mIuKEwHPwMUl1wMAAA== X-CMS-MailID: 20231028211550eucas1p1dc1d47e413de350deda962c3df5111ef X-Msg-Generator: CA X-RootMTR: 20231028211550eucas1p1dc1d47e413de350deda962c3df5111ef X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211550eucas1p1dc1d47e413de350deda962c3df5111ef References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add folio order argument to the shmem_alloc_folio() and merge it with the shmem_alloc_folio_huge(). Return will make use of the new page_rmappable_folio() where order-0 and high order folios are both supported. Signed-off-by: Daniel Gomez --- mm/shmem.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index d8dc2ceaba18..fc7605da4316 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1614,40 +1614,27 @@ static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp) return result; } -static struct folio *shmem_alloc_hugefolio(gfp_t gfp, - struct shmem_inode_info *info, pgoff_t index) +static struct folio *shmem_alloc_folio(gfp_t gfp, struct shmem_inode_info *info, + pgoff_t index, unsigned int order) { struct mempolicy *mpol; pgoff_t ilx; struct page *page; - mpol = shmem_get_pgoff_policy(info, index, HPAGE_PMD_ORDER, &ilx); - page = alloc_pages_mpol(gfp, HPAGE_PMD_ORDER, mpol, ilx, numa_node_id()); + mpol = shmem_get_pgoff_policy(info, index, order, &ilx); + page = alloc_pages_mpol(gfp, order, mpol, ilx, numa_node_id()); mpol_cond_put(mpol); return page_rmappable_folio(page); } -static struct folio *shmem_alloc_folio(gfp_t gfp, - struct shmem_inode_info *info, pgoff_t index) -{ - struct mempolicy *mpol; - pgoff_t ilx; - struct page *page; - - mpol = shmem_get_pgoff_policy(info, index, 0, &ilx); - page = alloc_pages_mpol(gfp, 0, mpol, ilx, numa_node_id()); - mpol_cond_put(mpol); - - return (struct folio *)page; -} - static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, struct inode *inode, pgoff_t index, struct mm_struct *fault_mm, size_t len) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); + unsigned int order = 0; struct folio *folio; long pages; int error; @@ -1668,12 +1655,12 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, index + HPAGE_PMD_NR - 1, XA_PRESENT)) return ERR_PTR(-E2BIG); - folio = shmem_alloc_hugefolio(gfp, info, index); + folio = shmem_alloc_folio(gfp, info, index, HPAGE_PMD_ORDER); if (!folio) count_vm_event(THP_FILE_FALLBACK); } else { - pages = 1; - folio = shmem_alloc_folio(gfp, info, index); + pages = 1UL << order; + folio = shmem_alloc_folio(gfp, info, index, order); } if (!folio) return ERR_PTR(-ENOMEM); @@ -1774,7 +1761,7 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, */ gfp &= ~GFP_CONSTRAINT_MASK; VM_BUG_ON_FOLIO(folio_test_large(old), old); - new = shmem_alloc_folio(gfp, info, index); + new = shmem_alloc_folio(gfp, info, index, 0); if (!new) return -ENOMEM; @@ -2618,7 +2605,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, if (!*foliop) { ret = -ENOMEM; - folio = shmem_alloc_folio(gfp, info, pgoff); + folio = shmem_alloc_folio(gfp, info, pgoff, 0); if (!folio) goto out_unacct_blocks; From patchwork Sat Oct 28 21:15:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439594 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69095C4167D for ; Sat, 28 Oct 2023 21:16:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbjJ1VQl (ORCPT ); Sat, 28 Oct 2023 17:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbjJ1VQ0 (ORCPT ); Sat, 28 Oct 2023 17:16:26 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9E6F191 for ; Sat, 28 Oct 2023 14:15:54 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211553euoutp024837e8ddc8c974fcfe80d6318a075991~SYf4KysBl0331103311euoutp02n for ; Sat, 28 Oct 2023 21:15:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231028211553euoutp024837e8ddc8c974fcfe80d6318a075991~SYf4KysBl0331103311euoutp02n DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527753; bh=V58CpUMglUVRv2d2n4PjwOPxGbR6MAVB1lgi43BKbik=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=Ug90+BkEzSkTyQzxO6IX69s40XfH1kin4j5qyV0qRip82QwCoST7VXdZhGtirfp/C eCUwW7HRdmW9RoJGBubVMRkje6dh2LhFr2aY5RD5wPKF7i+0tilH+Z95hxaUGhQlqG PwLLloFWfV3YsuaTmdl68/3RahrJys8XbK1q3o3E= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211552eucas1p2368f287afd825b44877b59399542f661~SYf3yR5P21087910879eucas1p2Q; Sat, 28 Oct 2023 21:15:52 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A3.20.11320.80A7D356; Sat, 28 Oct 2023 22:15:52 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231028211551eucas1p1552b7695f12c27f4ea1b92ecb6259b31~SYf3Amogw0616106161eucas1p1Y; Sat, 28 Oct 2023 21:15:51 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231028211551eusmtrp166725da83a27a1657bdc91947630f5f0~SYf3AFyW50755507555eusmtrp1e; Sat, 28 Oct 2023 21:15:51 +0000 (GMT) X-AuditID: cbfec7f4-993ff70000022c38-94-653d7a08c743 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 04.52.10549.70A7D356; Sat, 28 Oct 2023 22:15:51 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231028211551eusmtip146fad08e90fd824bcd219c14210d9955~SYf206cR30467404674eusmtip1U; Sat, 28 Oct 2023 21:15:51 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:51 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:51 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 10/11] shmem: add large folio support to the write path Thread-Topic: [RFC PATCH 10/11] shmem: add large folio support to the write path Thread-Index: AQHaCePt75l+dUBUfkS9wehNfGwv9w== Date: Sat, 28 Oct 2023 21:15:50 +0000 Message-ID: <20231028211518.3424020-11-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa0hTYRjmOzs7O65WpyntU7uuJHK6mRWcwCIp8FAQXcio6LLypJWaba2L Rs0wbEMsNaFdKi95aS2mq0zMGc1srSlltrSFhjYtjFLTynRYm2eF/573ed7nfd7348NZfDs7 BD+ceoKWpUqThRgXrXn2+2Uknr6ajrrTE07qTUaMvNN5GSPb3DPI3u+5KGlxich6ix0l2+r0 GNll/MMm6zy1HLLjSi8gy38McMhH1SUYOT6qx9byKJ2yFaWKzArqXmU41daioMwGFUaZv+dz qOfXxlFq2DxvM76LG5NAJx8+Scska/Zzk765+pC0/tDTqjdsJbg7Ww0CcEisgJ5uD1sNuDif qARwqETvL0YAbHmRgzLFMIBV7V3oP0tldpu/qwJAzS8j539XzjeVX2n2KtlWFlPcBnBU7eT4 /BixFDbYzZOWIELHho2ll4BPYBHnoLFPOxkSSGyEat1LxIeDiK1QVTXsnYR7sRjmmfg+GiXC oNPowXw0j4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MBsVonDizvAEswCdRJrns0C2yEs4C3R Nfs8E4gtIhAkcXjpUqBJHEC2nsTE9UIgYRYBVYmra/6wgYR5BWwk9l4NBzGFBHIl+tsyQSo4 gaL3v21nA7EZBWQlHq38xQ6xSFzi1pP5TBAPCEgs2XOeGcIWlXj5+B/UYzoSZ68/YYSwDSS2 Lt0H9bySxJ+OhVAH60ncmDqFDcLWlli28DXYHF4BQYmTM5+wTGCUnoVk3SwkLbOQtMxC0rKA kWUVo0hqaXFuem6xoV5xYm5xaV66XnJ+7iZGYGraduzn5h2M81591DvEyMTBeIhRgoNZSYSX 2dEmVYg3JbGyKrUoP76oNCe1+BCjKTCEJjJLiSbnA5NjXkm8oZmBqaGJmaWBqaWZsZI4r2dB R6KQQHpiSWp2ampBahFMHxMHp1QDU0CAsoTS1hAGmS/nH3i36u929eEWimr/tZDT+c+W9zdk +j7s2BBvKC2z605S8rkvx6zP7W76dXdpiD1nSUCCzzKz5+//acvJXYzLU9dRFOwRv7rpzSVr prif27hWlFeseN8dwbHrtGKr7et7BevnuVody/ztGbJti0zUyv+27/oS65/7LOU+3VBofMyU ba9bTIDa0tPsS0+auyyOkO79Fc3ie2qNyC/p6H9n7FOfzFvkdt3+P+uf9zcMHmnJeP6yecp3 L4fX6NlNa4Z0JrPtjH7Mn3uDbx282qlQsc/b0zl292vXxYLP/rz7eylyVlNTK091Z+fPjF6e pqvmcyRzN6l/04ttmFnDl7CJ8zeDEktxRqKhFnNRcSIABtzmANYDAAA= X-CMS-MailID: 20231028211551eucas1p1552b7695f12c27f4ea1b92ecb6259b31 X-Msg-Generator: CA X-RootMTR: 20231028211551eucas1p1552b7695f12c27f4ea1b92ecb6259b31 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211551eucas1p1552b7695f12c27f4ea1b92ecb6259b31 References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Current work in progress. Large folios in the fallocate path makes regress fstests generic/285 and generic/436. Add large folio support for shmem write path matching the same high order preference mechanism used for iomap buffered IO path as used in __filemap_get_folio(). Add shmem_mapping_size_order to get a hint for the order of the folio based on the file size which takes care of the mapping requirements. Swap does not support high order folios for now, so make it order 0 in case swap is enabled. Add the __GFP_COMP flag for high order folios except when huge is enabled. This fixes a memory leak when allocating high order folios. Signed-off-by: Daniel Gomez --- mm/shmem.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index fc7605da4316..eb314927be78 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1621,6 +1621,9 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, struct shmem_inode_info *info, pgoff_t ilx; struct page *page; + if ((order != 0) && !(gfp & VM_HUGEPAGE)) + gfp |= __GFP_COMP; + mpol = shmem_get_pgoff_policy(info, index, order, &ilx); page = alloc_pages_mpol(gfp, order, mpol, ilx, numa_node_id()); mpol_cond_put(mpol); @@ -1628,17 +1631,56 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, struct shmem_inode_info *info, return page_rmappable_folio(page); } +/** + * shmem_mapping_size_order - Get maximum folio order for the given file size. + * @mapping: Target address_space. + * @index: The page index. + * @size: The suggested size of the folio to create. + * + * This returns a high order for folios (when supported) based on the file size + * which the mapping currently allows at the given index. The index is relevant + * due to alignment considerations the mapping might have. The returned order + * may be less than the size passed. + * + * Like __filemap_get_folio order calculation. + * + * Return: The order. + */ +static inline unsigned int +shmem_mapping_size_order(struct address_space *mapping, pgoff_t index, + size_t size, struct shmem_sb_info *sbinfo) +{ + unsigned int order = ilog2(size); + + if ((order <= PAGE_SHIFT) || + (!mapping_large_folio_support(mapping) || !sbinfo->noswap)) + return 0; + + order -= PAGE_SHIFT; + + /* If we're not aligned, allocate a smaller folio */ + if (index & ((1UL << order) - 1)) + order = __ffs(index); + + order = min_t(size_t, order, MAX_PAGECACHE_ORDER); + + /* Order-1 not supported due to THP dependency */ + return (order == 1) ? 0 : order; +} + static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, struct inode *inode, pgoff_t index, struct mm_struct *fault_mm, size_t len) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); - unsigned int order = 0; + unsigned int order = shmem_mapping_size_order(mapping, index, len, + SHMEM_SB(inode->i_sb)); struct folio *folio; long pages; int error; +neworder: if (gfp & VM_HUGEPAGE) { pages = HPAGE_PMD_NR; index = round_down(index, HPAGE_PMD_NR); @@ -1721,6 +1763,11 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, unlock: folio_unlock(folio); folio_put(folio); + if (order != 0) { + if (--order == 1) + order = 0; + goto neworder; + } return ERR_PTR(error); } From patchwork Sat Oct 28 21:15:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13439593 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70785C4332F for ; Sat, 28 Oct 2023 21:16:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229597AbjJ1VQj (ORCPT ); Sat, 28 Oct 2023 17:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbjJ1VQ3 (ORCPT ); Sat, 28 Oct 2023 17:16:29 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21E84D50 for ; Sat, 28 Oct 2023 14:15:57 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231028211555euoutp01608d1cef8b062c16860503ae7aca1bf6~SYf6bHnHq3100431004euoutp01c for ; Sat, 28 Oct 2023 21:15:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231028211555euoutp01608d1cef8b062c16860503ae7aca1bf6~SYf6bHnHq3100431004euoutp01c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698527755; bh=vhkx9nEW1P7cUV8Zzx9SlNlxAL82sC2JgyqBVsGy9MY=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=Hmi+lFYmkHisLsZG4VbgvaPvoiedms0z5nZdt23VzeCaQ4zTch+cDcnZoKOkjZexm /vTxBQ0PS0S7S/vCmV+ontWsu8i0kpVGRzZBNKgTjMHBvhGggt2MHcoh0c1JqnGkqq ARbkmZY90/TNfseuHtaw6TXdEUBbIaXDncT5gR60= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231028211555eucas1p2394b404cd93491ee5bf44a270047b733~SYf6NFJBV1224812248eucas1p2I; Sat, 28 Oct 2023 21:15:55 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 9F.57.37758.B0A7D356; Sat, 28 Oct 2023 22:15:55 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231028211553eucas1p1a93637df6c46692531894e26023920d5~SYf441zj70616106161eucas1p1Z; Sat, 28 Oct 2023 21:15:53 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231028211553eusmtrp28117a3ed7ca27591a873d3f9be3ed510~SYf44SkDt1141411414eusmtrp2i; Sat, 28 Oct 2023 21:15:53 +0000 (GMT) X-AuditID: cbfec7f5-815ff7000002937e-10-653d7a0b230b Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A1.01.25043.90A7D356; Sat, 28 Oct 2023 22:15:53 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231028211553eusmtip2ab1bab33fda116438d8bc7115d2b0f8e~SYf4oIwLJ1182011820eusmtip2q; Sat, 28 Oct 2023 21:15:53 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 28 Oct 2023 22:15:53 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 28 Oct 2023 22:15:53 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [RFC PATCH 11/11] shmem: add per-block uptodate tracking Thread-Topic: [RFC PATCH 11/11] shmem: add per-block uptodate tracking Thread-Index: AQHaCePuWb31sxRneEm07VKavHLDZg== Date: Sat, 28 Oct 2023 21:15:52 +0000 Message-ID: <20231028211518.3424020-12-da.gomez@samsung.com> In-Reply-To: <20231028211518.3424020-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNKsWRmVeSWpSXmKPExsWy7djP87rcVbapBmfWC1nMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/MmuQCOKC6blNSczLLU In27BK6Mw3f6mAtOelQ86drA0sB4zLqLkZNDQsBE4ury1exdjFwcQgIrGCUerZrOBOF8YZTY sH8NG4TzmVGibfUpZpiWZ7vfMEMkljNKbG9qYYKrOnXzEdSwM4wST/ddZgdpERJYySjRsVoR xGYT0JTYd3ITWJGIwGxWicOLOxhBEswCdRJrns1iAbGFBRwljj95BRYXEXCTmN3Sxgph60lc XrkdbCiLgKrEyw872UBsXgEbiW1/D4PFOYHs+9+2g8UZBWQlHq38xQ4xX1zi1pP5TBA/CEos mr0H6h8xiX+7HrJB2DoSZ68/YYSwDSS2Lt3HAmErSfzpWAh1p57EjalT2CBsbYllC18zQ9wg KHFy5hMWkMckBP5xSrz4cBNqgYvEqs87oAYJS7w6voUdwpaR+L9zPtMERu1ZSO6bhWTHLCQ7 ZiHZsYCRZRWjeGppcW56arFxXmq5XnFibnFpXrpecn7uJkZgejv97/jXHYwrXn3UO8TIxMF4 iFGCg1lJhJfZ0SZViDclsbIqtSg/vqg0J7X4EKM0B4uSOK9qinyqkEB6YklqdmpqQWoRTJaJ g1OqgUng8j/lnYXZ1UWJa+zn628q6ZS49+Y+y9T5ySabLx7Q2Zm2n39u0uuHi7Yf+m25qy3w 6l1D1Xvtj3Scef2zBTUkduoJ21zbXfP5D/903RUNvu/fhjEbus8QlfU+f+J/gqiJ7ZaA5j1P PaIi3HcZSxwpujP18NwVPVfqPZY+3bHk9DTn3mJZUbsduSeKXx1w88lZJ/zCyVScv+Cm4Lk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V59ZpHhI5PKzex/s4N2LgzfKCTwtXmeu++O+NKS+rTs/xNe fCx2vZt1/MbtC/dVzD/KHvzYxihx+XiuvkDISXWGvHjGd8fP++3pealQ5nbry3GpXIHmBQVb +e28FPN3Trm8YXJg2PpLr+aKvHbbLndBrS7/WkzNr0O3q1d1XrFQPPBX4vJEEYlrSQ8XyXk6 S7/ftyamem7b6TStFa02djtyb7rxKfxm8HzxRVFVPkG7be/Odbq3ZjPveaGa/uKs8j3FkxP3 mN+alyPDVFdftLSha/eDRJOLy8uUWIozEg21mIuKEwGITef91wMAAA== X-CMS-MailID: 20231028211553eucas1p1a93637df6c46692531894e26023920d5 X-Msg-Generator: CA X-RootMTR: 20231028211553eucas1p1a93637df6c46692531894e26023920d5 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231028211553eucas1p1a93637df6c46692531894e26023920d5 References: <20230919135536.2165715-1-da.gomez@samsung.com> <20231028211518.3424020-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Current work in progress due to fsx regression (check below). Based on iomap per-block dirty and uptodate state track, add support for shmem_folio_state struct to track uptodate per-block when a folio is larger than a block. In shmem, this is when large folios is used, as one block is equal to one page in this context. Add support for invalidate_folio, release_folio and is_partially_uptodate address space operations. The first two are needed to be able to free the new shmem_folio_state struct. The last callback is required for large folios when enabling per-block tracking. This was spotted when running fstests for tmpfs and regress on generic/285 and generic/436 tests [1] with large folios support in the fallocate path without having per-block uptodate tracking. [1] tests: generic/285: src/seek_sanity_test/test09() generic/436: src/seek_sanity_test/test13() How to reproduce: ```sh mkdir -p /mnt/test-tmpfs ./src/seek_sanity_test -s 9 -e 9 /mnt/test-tmpfs/file ./src/seek_sanity_test -s 13 -e 13 /mnt/test-tmpfs/file umount /mnt/test-tmpfs ``` After per-block uptodate support is added, fsx regresion is found when running the following: ```sh mkdir -p /mnt/test-tmpfs mount -t tmpfs -o size=1G -o noswap tmpfs /mnt/test-tmpfs /root/xfstests-dev/ltp/fsx /mnt/test-tmpfs/file -d -N 1200 -X umount /mnt/test-tmpfs ``` Signed-off-by: Daniel Gomez --- mm/shmem.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 159 insertions(+), 10 deletions(-) -- 2.39.2 diff --git a/mm/shmem.c b/mm/shmem.c index eb314927be78..fa67594495d5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -132,6 +132,94 @@ struct shmem_options { #define SHMEM_SEEN_QUOTA 32 }; +/* + * Structure allocated for each folio to track per-block uptodate state. + * + * Like buffered-io shmem_folio_state struct but only for uptodate. + */ +struct shmem_folio_state { + spinlock_t state_lock; + unsigned long state[]; +}; + +static inline bool sfs_is_fully_uptodate(struct folio *folio, + struct shmem_folio_state *sfs) +{ + struct inode *inode = folio->mapping->host; + + return bitmap_full(sfs->state, i_blocks_per_folio(inode, folio)); +} + +static inline bool sfs_block_is_uptodate(struct shmem_folio_state *sfs, + unsigned int block) +{ + return test_bit(block, sfs->state); +} + +static void sfs_set_range_uptodate(struct folio *folio, + struct shmem_folio_state *sfs, size_t off, + size_t len) +{ + struct inode *inode = folio->mapping->host; + unsigned int first_blk = off >> inode->i_blkbits; + unsigned int last_blk = (off + len - 1) >> inode->i_blkbits; + unsigned int nr_blks = last_blk - first_blk + 1; + unsigned long flags; + + spin_lock_irqsave(&sfs->state_lock, flags); + bitmap_set(sfs->state, first_blk, nr_blks); + if (sfs_is_fully_uptodate(folio, sfs)) + folio_mark_uptodate(folio); + spin_unlock_irqrestore(&sfs->state_lock, flags); +} + +static void shmem_set_range_uptodate(struct folio *folio, size_t off, + size_t len) +{ + struct shmem_folio_state *sfs = folio->private; + + if (sfs) + sfs_set_range_uptodate(folio, sfs, off, len); + else + folio_mark_uptodate(folio); +} + +static struct shmem_folio_state *sfs_alloc(struct inode *inode, + struct folio *folio, gfp_t gfp) +{ + struct shmem_folio_state *sfs = folio->private; + unsigned int nr_blocks = i_blocks_per_folio(inode, folio); + + if (sfs || nr_blocks <= 1) + return sfs; + + /* + * sfs->state tracks uptodate flag when the block size is smaller + * than the folio size. + */ + sfs = kzalloc(struct_size(sfs, state, BITS_TO_LONGS(nr_blocks)), gfp); + if (!sfs) + return sfs; + + spin_lock_init(&sfs->state_lock); + if (folio_test_uptodate(folio)) + bitmap_set(sfs->state, 0, nr_blocks); + folio_attach_private(folio, sfs); + + return sfs; +} + +static void sfs_free(struct folio *folio) +{ + struct shmem_folio_state *sfs = folio_detach_private(folio); + + if (!sfs) + return; + WARN_ON_ONCE(sfs_is_fully_uptodate(folio, sfs) != + folio_test_uptodate(folio)); + kfree(sfs); +} + #ifdef CONFIG_TMPFS static unsigned long shmem_default_max_blocks(void) { @@ -1495,7 +1583,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) } folio_zero_range(folio, 0, folio_size(folio)); flush_dcache_folio(folio); - folio_mark_uptodate(folio); + shmem_set_range_uptodate(folio, 0, folio_size(folio)); } swap = folio_alloc_swap(folio); @@ -1676,6 +1764,7 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, struct shmem_inode_info *info = SHMEM_I(inode); unsigned int order = shmem_mapping_size_order(mapping, index, len, SHMEM_SB(inode->i_sb)); + struct shmem_folio_state *sfs; struct folio *folio; long pages; int error; @@ -1755,6 +1844,10 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, } } + sfs = sfs_alloc(inode, folio, gfp); + if (!sfs && i_blocks_per_folio(inode, folio) > 1) + goto unlock; + trace_mm_shmem_add_to_page_cache(folio); shmem_recalc_inode(inode, pages, 0); folio_add_lru(folio); @@ -1818,7 +1911,7 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, __folio_set_locked(new); __folio_set_swapbacked(new); - folio_mark_uptodate(new); + shmem_set_range_uptodate(new, 0, folio_size(new)); new->swap = entry; folio_set_swapcache(new); @@ -2146,7 +2239,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, for (i = 0; i < n; i++) clear_highpage(folio_page(folio, i)); flush_dcache_folio(folio); - folio_mark_uptodate(folio); + shmem_set_range_uptodate(folio, 0, folio_size(folio)); } /* Perhaps the file has been truncated since we checked */ @@ -2788,13 +2881,18 @@ shmem_write_end(struct file *file, struct address_space *mapping, if (pos + copied > inode->i_size) i_size_write(inode, pos + copied); + if (unlikely(copied < len && !folio_test_uptodate(folio))) + return 0; + if (!folio_test_uptodate(folio)) { - if (copied < folio_size(folio)) { - size_t from = offset_in_folio(folio, pos); - folio_zero_segments(folio, 0, from, - from + copied, folio_size(folio)); - } - folio_mark_uptodate(folio); + size_t from = offset_in_folio(folio, pos); + if (!folio_test_large(folio) && copied < folio_size(folio)) + folio_zero_segments(folio, 0, from, from + copied, + folio_size(folio)); + if (folio_test_large(folio) && copied < PAGE_SIZE) + folio_zero_segments(folio, from, from, from + copied, + folio_size(folio)); + shmem_set_range_uptodate(folio, from, len); } folio_mark_dirty(folio); folio_unlock(folio); @@ -2803,6 +2901,54 @@ shmem_write_end(struct file *file, struct address_space *mapping, return copied; } +void shmem_invalidate_folio(struct folio *folio, size_t offset, size_t len) +{ + /* + * If we're invalidating the entire folio, clear the dirty state + * from it and release it to avoid unnecessary buildup of the LRU. + */ + if (offset == 0 && len == folio_size(folio)) { + WARN_ON_ONCE(folio_test_writeback(folio)); + folio_cancel_dirty(folio); + sfs_free(folio); + } +} + +bool shmem_release_folio(struct folio *folio, gfp_t gfp_flags) +{ + sfs_free(folio); + return true; +} + +/* + * shmem_is_partially_uptodate checks whether blocks within a folio are + * uptodate or not. + * + * Returns true if all blocks which correspond to the specified part + * of the folio are uptodate. + */ +bool shmem_is_partially_uptodate(struct folio *folio, size_t from, size_t count) +{ + struct shmem_folio_state *sfs = folio->private; + struct inode *inode = folio->mapping->host; + unsigned first, last, i; + + if (!sfs) + return false; + + /* Caller's range may extend past the end of this folio */ + count = min(folio_size(folio) - from, count); + + /* First and last blocks in range within folio */ + first = from >> inode->i_blkbits; + last = (from + count - 1) >> inode->i_blkbits; + + for (i = first; i <= last; i++) + if (!sfs_block_is_uptodate(sfs, i)) + return false; + return true; +} + static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) { struct file *file = iocb->ki_filp; @@ -3554,7 +3700,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, inode->i_mapping->a_ops = &shmem_aops; inode->i_op = &shmem_symlink_inode_operations; memcpy(folio_address(folio), symname, len); - folio_mark_uptodate(folio); + shmem_set_range_uptodate(folio, 0, folio_size(folio)); folio_mark_dirty(folio); folio_unlock(folio); folio_put(folio); @@ -4524,6 +4670,9 @@ const struct address_space_operations shmem_aops = { #ifdef CONFIG_MIGRATION .migrate_folio = migrate_folio, #endif + .invalidate_folio = shmem_invalidate_folio, + .release_folio = shmem_release_folio, + .is_partially_uptodate = shmem_is_partially_uptodate, .error_remove_page = shmem_error_remove_page, }; EXPORT_SYMBOL(shmem_aops);