From patchwork Fri Sep 15 09:51:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13386761 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 E792FEE644C for ; Fri, 15 Sep 2023 09:53:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233880AbjIOJxU (ORCPT ); Fri, 15 Sep 2023 05:53:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233966AbjIOJxQ (ORCPT ); Fri, 15 Sep 2023 05:53:16 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A44274681 for ; Fri, 15 Sep 2023 02:51:36 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230915095124euoutp02b2237e75d8dcf8e4b025e54f583da711~FCa_eVZJ71347113471euoutp02R for ; Fri, 15 Sep 2023 09:51:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230915095124euoutp02b2237e75d8dcf8e4b025e54f583da711~FCa_eVZJ71347113471euoutp02R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694771484; bh=9t9ULkMuBq/epaiWHGp5SMiuW3po0qdU7nTNfWyOmvY=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=RQwu1oOKOP/OHNYx/6DeTA5c7ndiENxNu0XN99GO9cPncv7eY9AC1RxPHE2y/6W35 tdfnjH8d+Cba1a31UkfrqxlHUNaemIKiqY0oZ75ZnWAYO2Df7GMhEx1jyIjF0sIwam b7ZpPMSXL58XOLa1lrWEu1AAJ4/ZP/KrK6BYEbnk= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230915095124eucas1p2b20cd2623e776492e070e7d7757fe49b~FCa_N49lA0862308623eucas1p2V; Fri, 15 Sep 2023 09:51:24 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id E7.E7.11320.C1924056; Fri, 15 Sep 2023 10:51:24 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230915095124eucas1p1eb0e0ef883f6316cf14c349404a51150~FCa93UCLR2203022030eucas1p1Q; Fri, 15 Sep 2023 09:51:23 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230915095123eusmtrp1c3cce7f6f7a5eb736598ffae8ecc3ca0~FCa92ilDZ1836118361eusmtrp17; Fri, 15 Sep 2023 09:51:23 +0000 (GMT) X-AuditID: cbfec7f4-97dff70000022c38-1c-6504291cfd59 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 5A.D6.14344.B1924056; Fri, 15 Sep 2023 10:51:23 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230915095123eusmtip267ceaaeebbabd3d66cf4aa80ead14236~FCa9rj4DM0935009350eusmtip2G; Fri, 15 Sep 2023 09:51:23 +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; Fri, 15 Sep 2023 10:51:23 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 15 Sep 2023 10:51:23 +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: [PATCH 1/6] filemap: make the folio order calculation shareable Thread-Topic: [PATCH 1/6] filemap: make the folio order calculation shareable Thread-Index: AQHZ57ovaMdf9q/cjECRh1BbWSoXsQ== Date: Fri, 15 Sep 2023 09:51:23 +0000 Message-ID: <20230915095042.1320180-2-da.gomez@samsung.com> In-Reply-To: <20230915095042.1320180-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+NgFjrNKsWRmVeSWpSXmKPExsWy7djP87oymiypBr+OC1vMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/MmuQCOKC6blNSczLLU In27BK6MviXLmArOK1Z8a2hmbGDcLt3FyMkhIWAisfNbA2sXIxeHkMAKRonNO3axQzhfGCWe rroD5XxmlNgztZEVpuXmwTNMEInljBKtExqY4aq69r2HajnDKDHp5wQ2CGclo8S1mc2MIP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Sws9IxNLPUNj81grI1MlfTublNSczLLUIn27BL2MviXLmArOK1Z8a2hm bGDcLt3FyMkhIWAicfPgGaYuRi4OIYGljBJH/i5lgkjISGz8cpUVwhaW+HOtiw3EFhL4yCjR tqoYouEMo0RT13VGCGclo8SMa4cZQarYBDQl9p3cxA6SEBGYzSpxeHEHWIJZoE5izbNZLCC2 sICHxLK9e8DWiQj4Smw5sYUNwtaTaG36ygxiswioSkx9d58dxOYVsJbo2d8DFOcA2mYtMWu6 F4jJKWAj8f5HOUgFo4CsxKOVv9ghNolL3HoyH+oZAYkle84zQ9iiEi8f/4N6TEfi7PUnjBC2 gcTWpftYIGwliT8dC6Eu1pO4MXUKG4StLbFs4WtmiGsEJU7OfMIygVF6FpJ1s5C0zELSMgtJ ywJGllWMIqmlxbnpucVGesWJucWleel6yfm5mxiByWnbsZ9bdjCufPVR7xAjEwfjIUYJDmYl EV42W6ZUId6UxMqq1KL8+KLSnNTiQ4ymwBCayCwlmpwPTI95JfGGZgamhiZmlgamlmbGSuK8 ngUdiUIC6YklqdmpqQWpRTB9TBycUg1MOgkHnd78zdr97NxpyRXvVsU97kpbOF1j7f/qVz6L d9rVr7+wKHxrQ2Cc8zaG75Oa6vqcf29fVn9bVEzRY+d2mytP7yaaC89eu9zRYVa497G7Xdec bNK9DnEt0XkuuGrq80O/X39QVk3/dqZpcc/Pnw+27FaKnb8+2pkl91m7uq/3/17DE4EzJ7w4 aTnre88tzirWnSYW1gtV3oY4XRUVTOZayHGlf//m8DTDdu8PWkEZfYJZ874pMrCqT5VWLlQv ntI3s++DK8/i/8Hv47bcm2l3yUlRzptPZbOqRJzpF+dNGl6l5Xe3zspKKXgVotOhdu5Nopzv 15DUy8m3XZMyX0U1MeYUnC27dKy5cCu3EktxRqKhFnNRcSIANnSnRtcDAAA= X-CMS-MailID: 20230915095124eucas1p1eb0e0ef883f6316cf14c349404a51150 X-Msg-Generator: CA X-RootMTR: 20230915095124eucas1p1eb0e0ef883f6316cf14c349404a51150 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230915095124eucas1p1eb0e0ef883f6316cf14c349404a51150 References: <20230915095042.1320180-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org To make the code that clamps the folio order in the __filemap_get_folio routine reusable to others, move and merge it to the fgf_set_order new subroutine (mapping_size_order), so when mapping the size at a given index, the order calculated is already valid and ready to be used when order is retrieved from fgp_flags with FGF_GET_ORDER. Signed-off-by: Daniel Gomez --- fs/iomap/buffered-io.c | 6 ++++-- include/linux/pagemap.h | 42 ++++++++++++++++++++++++++++++++++++----- mm/filemap.c | 8 -------- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index ae8673ce08b1..bfd9a22a9464 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -546,12 +546,14 @@ EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate); struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len) { fgf_t fgp = FGP_WRITEBEGIN | FGP_NOFS; + pgoff_t index = pos >> PAGE_SHIFT; + struct address_space *mapping = iter->inode->i_mapping; if (iter->flags & IOMAP_NOWAIT) fgp |= FGP_NOWAIT; - fgp |= fgf_set_order(len); + fgp |= fgf_set_order(mapping, index, len); - return __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, + return __filemap_get_folio(mapping, index, fgp, mapping_gfp_mask(iter->inode->i_mapping)); } EXPORT_SYMBOL_GPL(iomap_get_folio); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 351c3b7f93a1..7af5636eb32a 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -576,6 +576,39 @@ typedef unsigned int __bitwise fgf_t; #define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE) +/** + * 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. + * + * Return: The order. + */ +static inline unsigned int mapping_size_order(struct address_space *mapping, + pgoff_t index, size_t size) +{ + unsigned int order = ilog2(size); + + if ((order <= PAGE_SHIFT) || (!mapping_large_folio_support(mapping))) + return 0; + else + order = 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; +} + /** * fgf_set_order - Encode a length in the fgf_t flags. * @size: The suggested size of the folio to create. @@ -587,13 +620,12 @@ typedef unsigned int __bitwise fgf_t; * due to alignment constraints, memory pressure, or the presence of * other folios at nearby indices. */ -static inline fgf_t fgf_set_order(size_t size) +static inline fgf_t fgf_set_order(struct address_space *mapping, pgoff_t index, + size_t size) { - unsigned int shift = ilog2(size); + unsigned int order = mapping_size_order(mapping, index, size); - if (shift <= PAGE_SHIFT) - return 0; - return (__force fgf_t)((shift - PAGE_SHIFT) << 26); + return (__force fgf_t)(order << 26); } void *filemap_get_entry(struct address_space *mapping, pgoff_t index); diff --git a/mm/filemap.c b/mm/filemap.c index 582f5317ff71..e285fffa9bcf 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1917,14 +1917,6 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, if (WARN_ON_ONCE(!(fgp_flags & (FGP_LOCK | FGP_FOR_MMAP)))) fgp_flags |= FGP_LOCK; - if (!mapping_large_folio_support(mapping)) - order = 0; - if (order > MAX_PAGECACHE_ORDER) - order = MAX_PAGECACHE_ORDER; - /* If we're not aligned, allocate a smaller folio */ - if (index & ((1UL << order) - 1)) - order = __ffs(index); - do { gfp_t alloc_gfp = gfp; From patchwork Fri Sep 15 09:51:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13386762 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 DCC96EE644B for ; Fri, 15 Sep 2023 09:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233892AbjIOJx5 (ORCPT ); Fri, 15 Sep 2023 05:53:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233814AbjIOJx4 (ORCPT ); Fri, 15 Sep 2023 05:53:56 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E7E04696 for ; Fri, 15 Sep 2023 02:51:37 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230915095127euoutp02c6f13bebed01dff599b35c6a9a9d4de4~FCbAtB8rq1230712307euoutp02I for ; Fri, 15 Sep 2023 09:51:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230915095127euoutp02c6f13bebed01dff599b35c6a9a9d4de4~FCbAtB8rq1230712307euoutp02I DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694771487; bh=pQ5HIMyPnnwhcYJ76rc1mPPc+k+o81B2sKXtPyg4zdw=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=dRnQE4X3b17aD2oqDXZH5BTfLC+mfYSYB3NR2dMRflrnrl1BtrmPzKFgseY6oQpbQ ZzkRwa4nIp88Qnirv0XY2Ve9K2j2PL4EIuwJZYmEoBYkHzlKcZliBSpnqcK4cO017M XzHLOtBtiZ3MG74YPPkZIIJXV1cCDwNNHE5/9D/o= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230915095126eucas1p2632b3b07d57634dee3bc87e2526e1769~FCbAZwO811725217252eucas1p2z; Fri, 15 Sep 2023 09:51:26 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id F2.9A.42423.E1924056; Fri, 15 Sep 2023 10:51:26 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230915095126eucas1p2cf75674dab8a81228f493a7200f4a1ba~FCbACyp_W0866108661eucas1p2R; Fri, 15 Sep 2023 09:51:26 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230915095126eusmtrp29f2fa2307f1978fafd648c484cebcafa~FCa-9WV9v1712217122eusmtrp2z; Fri, 15 Sep 2023 09:51:26 +0000 (GMT) X-AuditID: cbfec7f2-a51ff7000002a5b7-f4-6504291e5557 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id B1.3B.10549.E1924056; Fri, 15 Sep 2023 10:51:26 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230915095126eusmtip299bf0302eaf2d7781e72b80611f92e41~FCa-x_3a21112711127eusmtip21; Fri, 15 Sep 2023 09:51:26 +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; Fri, 15 Sep 2023 10:51:25 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 15 Sep 2023 10:51:25 +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: [PATCH 2/6] shmem: drop BLOCKS_PER_PAGE macro Thread-Topic: [PATCH 2/6] shmem: drop BLOCKS_PER_PAGE macro Thread-Index: AQHZ57owSgjKzHCSYUqzwv9vQRCtyw== Date: Fri, 15 Sep 2023 09:51:24 +0000 Message-ID: <20230915095042.1320180-3-da.gomez@samsung.com> In-Reply-To: <20230915095042.1320180-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: H4sIAAAAAAAAA01SfVCLcRzvtz179pSbe1rRj2a0K9S06s65B7WrcPfQddd5u0OHnZ6rWMvt afJ+ORzlpLxdrVLpZSuFJpNUunV6QURRhN7GqFxEE8toPXP67/Pyffl8f/fD2PxmzlwsVpFA KRUyuQh1QvSNP5/6Cr0Ryv/ag8VE9o0ylLj29hxKtBtnEu9HUxGi9rWYqKltQYj26myUeFf2 h0NUT1Rxia6094AoHhvhEvcqrqKEZTwbDeaRWUnPEDJPpyJvaX3I9lYVqStNRknd6Hku2Zxh QchvOmEEttUpMIqSx+6jlH7SnU4xZj2y9xNnv+VYOicJmJAU4IhBfCnUlkyAFOCE8XEtgHWf h1kM+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NSmpOZllqkb5dgl7Gt20sBS9ZK343TmRt YHzO0sXIySEhYCIx/9g/MFtIYCmjROcrX4i4jMTGL1dZIWxhiT/Xuti6GLmAaj4ySqw8sh/K OcMo8eHFLhYIZyWjxIY/n5hBWtgENCX2ndzEDpIQEZjNKnF4cQcjSIJZoE5izbNZYPuEBcwk tl3qYgKxRQSsJR5svMoMYetJ3Dv1CCjOwcEioCrRsj0VJMwLVPJ9wmSwsBCQPWu6F4jJKWAj 8f5HOUgFo4CsxKOVv9ghFolL3HoynwniAQGJJXvOM0PYohIvH/+DekxH4uz1J4wQtoHE1qX7 oIGiJPGnYyHUwXoSN6ZOYYOwtSWWLXzNDHGNoMTJmU9YJjBKz0KybhaSlllIWmYhaVnAyLKK USS1tDg3PbfYUK84Mbe4NC9dLzk/dxMjMDFtO/Zz8w7Gea8+6h1iZOJgPMQowcGsJMLLZsuU KsSbklhZlVqUH19UmpNafIjRFBhAE5mlRJPzgakxryTe0MzA1NDEzNLA1NLMWEmc17OgI1FI ID2xJDU7NbUgtQimj4mDU6qBqbB6f//C1Zwhr5xnrz01bdr361KegsJSb2a9fxgxwfbigj8B k5g/cLGX8vz/cWXK7O8lYdPO77n5KOTx5AIFvp816suWr1D3YtgfEq3tLHg9wXTK9CdbAqSq o/bF2Vkyvd++v22h3qve/pKSsjdmuybrrjvQ8+Oo2dZJ2kvXC888rbH6TERFjc38gP7Qp/6z zzv1Cfq8E9vmJr8qw2HJ0gnJSSkR3HdKbXoX+XzZZ3+h+/UE1bwOzR1K/XPN/15KeRpWvcXk Wlm7tf+TD7vfnVinP/U6j+Yk8/XzHTIVnu2WU1qrmr4v8Is3++FW5VNp3a6zRepbRO/Eaa24 dPW/wVybc3lSVY65Tptmrf776qESS3FGoqEWc1FxIgB/H/s+1QMAAA== X-CMS-MailID: 20230915095126eucas1p2cf75674dab8a81228f493a7200f4a1ba X-Msg-Generator: CA X-RootMTR: 20230915095126eucas1p2cf75674dab8a81228f493a7200f4a1ba X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230915095126eucas1p2cf75674dab8a81228f493a7200f4a1ba References: <20230915095042.1320180-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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 13c27c343820..8b3823e4d344 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -84,7 +84,6 @@ static struct vfsmount *shm_mnt; #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 Fri Sep 15 09:51:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13386772 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 ED57FEE644C for ; Fri, 15 Sep 2023 09:54:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233999AbjIOJzD (ORCPT ); Fri, 15 Sep 2023 05:55:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234196AbjIOJye (ORCPT ); Fri, 15 Sep 2023 05:54:34 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A432D5B for ; Fri, 15 Sep 2023 02:53:01 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230915095129euoutp016a04b1e5f38b7c300b9cbd8ab3a7f12a~FCbChrfUf0696306963euoutp01A for ; Fri, 15 Sep 2023 09:51:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230915095129euoutp016a04b1e5f38b7c300b9cbd8ab3a7f12a~FCbChrfUf0696306963euoutp01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694771489; bh=MPvP7/bW/aMWENbqWzpXNJZ4Wgeps0pePFDrgq86iOg=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=uNcOYwD1KXFgn9ho/vmqx/GG2pljZqP4wWUJe/iAOVXSPVAgPm4bqM8VFV5ieV4ru CbC7HBFUYykz+VdcN8I3F7MfhS7wQogKmSFNon3fHPgSa+5/m0D690BwJavo6RtfUA 8Km3tK7Dl/XcLhl1Dqg+eDb/YI31C7YHaTW7Ko5k= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230915095128eucas1p1c1a3ec9f583e1c28f521e3e197036d1d~FCbCF227V1980119801eucas1p1J; Fri, 15 Sep 2023 09:51:28 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 20.BC.37758.02924056; Fri, 15 Sep 2023 10:51:28 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230915095128eucas1p2885c3add58d82413d9c1d17832d3d281~FCbBm3leg0860408604eucas1p2N; Fri, 15 Sep 2023 09:51:28 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230915095128eusmtrp2d7b39d9dd999d006e785228e6b920fbd~FCbBmNn_X1716917169eusmtrp2j; Fri, 15 Sep 2023 09:51:28 +0000 (GMT) X-AuditID: cbfec7f5-815ff7000002937e-6d-6504292037c2 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 04.3B.10549.F1924056; Fri, 15 Sep 2023 10:51:27 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230915095127eusmtip135d9c0b9a9fdcb2530a0ed2723b2c1c3~FCbBb1Xge2687926879eusmtip18; Fri, 15 Sep 2023 09:51:27 +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; Fri, 15 Sep 2023 10:51:27 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 15 Sep 2023 10:51:27 +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: [PATCH 3/6] shmem: account for large order folios Thread-Topic: [PATCH 3/6] shmem: account for large order folios Thread-Index: AQHZ57oxkDDTtuHEck+OwDgOe5Q+ig== Date: Fri, 15 Sep 2023 09:51:26 +0000 Message-ID: <20230915095042.1320180-4-da.gomez@samsung.com> In-Reply-To: <20230915095042.1320180-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+NgFjrBKsWRmVeSWpSXmKPExsWy7djP87oKmiypBtO/y1jMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/MmuQCOKC6blNSczLLU In27BK6MC+seMRe8Uqj4NHEDewPjdqkuRk4OCQETiZ/rtrN3MXJxCAmsYJQ4u/gdI4TzhVHi wp1mNpAqIYHPjBInj5rAdHz4tpMJomg5o0TP1GnMcEVHL4ZCJM4wSlzecJMVwlnJKLHj8Bcm kCo2AU2JfSc3gS0UEZjNKnF4cQcjSIJZoE5izbNZLCC2sICVRM+qOWBxEQF7iZ0X3rBB2HoS P8/PAarh4GARUJXYdzASJMwrYC2x9e9SsDCngI3E+x/lIGFGAVmJRyt/sUNMF5e49WQ+E8QH ghKLZu9hhrDFJP7tesgGYetInL3+hBHCNpDYunQfC4StJPGnYyHUlXoSN6ZOYYOwtSWWLXzN DHGCoMTJmU9YQN6SEGjiknh8ci47RLOLRP+6lVALhCVeHd8CFZeR+L9zPtMERu1ZSO6bhWTH LCQ7ZiHZsYCRZRWjeGppcW56arFxXmq5XnFibnFpXrpecn7uJkZgYjv97/jXHYwrXn3UO8TI xMF4iFGCg1lJhJfNlilViDclsbIqtSg/vqg0J7X4EKM0B4uSOK+27clkIYH0xJLU7NTUgtQi mCwTB6dUA1NjmfW+6GmVZ5mElf59tlg36eiplXFh3g2PP8yOLBCd18a6X8LjTISE5fu+JGuX 17+S/RJ2PRV+9+mq2KutVT79AdH7//KWe39xmZ4m62Hnyiy0w0y96XFg3ELLw97JItPsZsZ3 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SC1CKYPiYOTqkGpsSJaUsr/xavZjmz9+/L4t9mRTwu06YzqaUuv1vRPnvH 5Jjpy8LEF4i3Va36Ynl1gdnrg+H9fxkNtTRXm76r+D5x48G5Ta1TdG6yvPQ0YKo3z5F1vfxD 7r/+ns60g113vJPi/jkI/k7fd1t2tux9hQNczlcdvYT9pGqWXfLuOKPlPOla+pVbkcbdIgqf lt3Q8Jg8y5crY9r1x0GfnA9Z9WV9N1/BXuZ+dN51K/8di6bKrfv3+MXT3f/X31k7+Y2Bb/4u BRnRAolN3x+u7Uhe5HIm/pv4Xr1vJs6CVWLvGD1FGxj/OUQEh3xZc//M4zOX9qzv3jK3x5O/ 6ON1ld1PT//6Vz6J/e91J6kTH1OrvS4rsRRnJBpqMRcVJwIADD2h59cDAAA= X-CMS-MailID: 20230915095128eucas1p2885c3add58d82413d9c1d17832d3d281 X-Msg-Generator: CA X-RootMTR: 20230915095128eucas1p2885c3add58d82413d9c1d17832d3d281 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230915095128eucas1p2885c3add58d82413d9c1d17832d3d281 References: <20230915095042.1320180-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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 | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 8b3823e4d344..836d44584796 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -869,16 +869,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()) { @@ -1006,10 +1006,12 @@ 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; - nr_swaps_freed += !shmem_free_swap(mapping, - indices[i], folio); + swaps_freed = folio_nr_pages(folio); + if (!shmem_free_swap(mapping, indices[i], folio)) + nr_swaps_freed += swaps_freed; continue; } @@ -1075,14 +1077,16 @@ 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; + swaps_freed = folio_nr_pages(folio); if (shmem_free_swap(mapping, indices[i], folio)) { /* Swap was replaced by page: retry */ index = indices[i]; break; } - nr_swaps_freed++; + nr_swaps_freed += swaps_freed; continue; } @@ -1528,7 +1532,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)); @@ -1801,6 +1805,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, @@ -1810,13 +1815,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); } @@ -1903,7 +1909,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); @@ -2663,7 +2669,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 Fri Sep 15 09:51:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13386774 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 44E74EE644B for ; Fri, 15 Sep 2023 09:55:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233912AbjIOJzX (ORCPT ); Fri, 15 Sep 2023 05:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234045AbjIOJzF (ORCPT ); Fri, 15 Sep 2023 05:55:05 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 240D030C3 for ; Fri, 15 Sep 2023 02:53:12 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230915095130euoutp01684b8407be354eca63034f13495f0b5e~FCbDknWwa0810408104euoutp01Y for ; Fri, 15 Sep 2023 09:51:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230915095130euoutp01684b8407be354eca63034f13495f0b5e~FCbDknWwa0810408104euoutp01Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694771490; bh=N6Xp9rRcJyqLlmISFymB45Rbo8znf7lO4hyxQ746apU=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=J2oiuKF9izy/Cw4x6EnydyqbwSzsnCF2Y0XFOnQ8IlWbu28IVYZHWP6sXeY3XHfUG 193Msihdm4oTg6/gkV33eD2KXYpN7XwTFksMmuEQWDUGFpWSGXCnEyBLb6rHhGaAJB IPHcHFtFpDvNNNWfqxWRKhZ64MxGq4FRAnOOVXYc= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230915095129eucas1p185187ba8793eb2c506b0e568c0f6f608~FCbDBzwkA1980119801eucas1p1L; Fri, 15 Sep 2023 09:51:29 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 16.BC.37758.12924056; Fri, 15 Sep 2023 10:51:29 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230915095129eucas1p1383d75c6d62056afbb20b78a3ec15234~FCbCnzYvG2007620076eucas1p1P; Fri, 15 Sep 2023 09:51:29 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230915095129eusmtrp2e690b2af500d4bb298bad715c8e8eb8f~FCbCmH9Ln1712217122eusmtrp24; Fri, 15 Sep 2023 09:51:29 +0000 (GMT) X-AuditID: cbfec7f5-815ff7000002937e-7b-650429212abc Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 65.3B.10549.02924056; Fri, 15 Sep 2023 10:51:28 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230915095128eusmtip1ea983b58b5ef15df525d8a7f9a3c571b~FCbCaAFBw2687926879eusmtip19; Fri, 15 Sep 2023 09:51:28 +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; Fri, 15 Sep 2023 10:51:28 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 15 Sep 2023 10:51:28 +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: [PATCH 4/6] shmem: add order parameter support to shmem_alloc_folio Thread-Topic: [PATCH 4/6] shmem: add order parameter support to shmem_alloc_folio Thread-Index: AQHZ57oyL8hoyYlY0kqz+yQTJH6NwQ== Date: Fri, 15 Sep 2023 09:51:28 +0000 Message-ID: <20230915095042.1320180-5-da.gomez@samsung.com> In-Reply-To: <20230915095042.1320180-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+NgFjrBKsWRmVeSWpSXmKPExsWy7djPc7qKmiypBi87ZS3mrF/DZrH6bj+b xeUnfBZPP/WxWOy9pW2xZ+9JFovLu+awWdxb85/VYtefHewWNyY8ZbRY9vU9u8XujYvYLH7/ mMPmwOsxu+Eii8eCTaUem1doeVw+W+qxaVUnm8emT5PYPU7M+M3i8XmTXABHFJdNSmpOZllq kb5dAlfGkdfvGQt6ZSqmnJ3G3MD4QKyLkZNDQsBEoudyA2sXIxeHkMAKRonGjxuhnC+MEntX 3IZyPjNKvGw/xNLFyAHWsvahF0i3kMByRonVG9XgalZvu8AO4ZxhlHh9/ysjhLOSUeLUhtnM IC1sApoS+05uAqsSEZjNKnF4cQcjSIJZoE5izbNZLCC2sICPxNQ5W8HiIgLBEqd/zmCHsPUk 3u3vBBvEIqAq8XzSCzYQm1fAWuLKzfOsIOdxCthIvP9RDhJmFJCVeLTyFzvEeHGJW0/mM0E8 LSixaPYeZghbTOLfrodsELaOxNnrTxghbAOJrUv3sUDYShJ/OhZCnakncWPqFDYIW1ti2cLX zBAnCEqcnPmEBeQvCYEmLomWJyegweUiseZbBcQcYYlXx7ewQ9gyEv93zmeawKg9C8l5s5Cs mIVkxSwkKxYwsqxiFE8tLc5NTy02zkst1ytOzC0uzUvXS87P3cQITGyn/x3/uoNxxauPeocY mTgYDzFKcDArifCy2TKlCvGmJFZWpRblxxeV5qQWH2KU5mBREufVtj2ZLCSQnliSmp2aWpBa BJNl4uCUamBqvxLYGpBlG/8n+jf31Y0v/oWkfVHb+1zWLix+zt9awaJza5IunrfRa2MxOrIu NCbshnVIcopW05Mwk/ULxN8c9eaXL5/PfTG+dy8bZ+xjpqfzHq3xOcoxz8NBNGjy+ROrlYKj N3N+mPxP29BHcLd0t9nXGSdy181rnOP+9MfJjyt0hZI83h4M07qtZqvHdeMsY/Cvrl8fPDfZ 7b6+9FIoz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w/ElVd9un059l1IQF390itNZq47tnxX Uv0jM2HLD+svel6GX+9VuzbbHWwWElVjsLXgeO16PUZsl+7ZiOILsb9ur0qxsDAWqFx1Ls/D 2/pxS+HH8mMOl31dOkpX+f57b1+7pmrvZ+2TIVNVrFwfKIo8+8Vaoxu1c4Pjp2ClHae1uz2n +1XdP+KZy1scpHv5UeCeoIvBM3/t2Dbnpq7R9oOTfAUeLHe/uYbVfPoXqxObOedtv7Vi5q63 q236YpeeYLm98UbPTJUwkZ/+b8xvnJ+vxFKckWioxVxUnAgAlvTUeNUDAAA= X-CMS-MailID: 20230915095129eucas1p1383d75c6d62056afbb20b78a3ec15234 X-Msg-Generator: CA X-RootMTR: 20230915095129eucas1p1383d75c6d62056afbb20b78a3ec15234 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230915095129eucas1p1383d75c6d62056afbb20b78a3ec15234 References: <20230915095042.1320180-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org In preparation for high order folio support for the write path, add order parameter when allocating a folio. This is on the write path when huge support is not enabled or when it is but the huge page allocation fails, the fallback will take advantage of this too. Use order 0 for the non write paths such as reads or swap in as these currently lack high order folios support. Signed-off-by: Daniel Gomez --- mm/shmem.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 836d44584796..ee297d8874d3 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1669,20 +1669,21 @@ static struct folio *shmem_alloc_hugefolio(gfp_t gfp, } static struct folio *shmem_alloc_folio(gfp_t gfp, - struct shmem_inode_info *info, pgoff_t index) + struct shmem_inode_info *info, pgoff_t index, + unsigned int order) { struct vm_area_struct pvma; struct folio *folio; shmem_pseudo_vma_init(&pvma, info, index); - folio = vma_alloc_folio(gfp, 0, &pvma, 0, false); + folio = vma_alloc_folio(gfp, order, &pvma, 0, false); shmem_pseudo_vma_destroy(&pvma); return folio; } static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode, - pgoff_t index, bool huge) + pgoff_t index, bool huge, unsigned int *order) { struct shmem_inode_info *info = SHMEM_I(inode); struct folio *folio; @@ -1691,7 +1692,7 @@ static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode, if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) huge = false; - nr = huge ? HPAGE_PMD_NR : 1; + nr = huge ? HPAGE_PMD_NR : 1U << *order; err = shmem_inode_acct_block(inode, nr); if (err) @@ -1700,7 +1701,7 @@ static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode, if (huge) folio = shmem_alloc_hugefolio(gfp, info, index); else - folio = shmem_alloc_folio(gfp, info, index); + folio = shmem_alloc_folio(gfp, info, index, *order); if (folio) { __folio_set_locked(folio); __folio_set_swapbacked(folio); @@ -1750,7 +1751,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; @@ -1961,6 +1962,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, int error; int once = 0; int alloced = 0; + unsigned int order = 0; if (index > (MAX_LFS_FILESIZE >> PAGE_SHIFT)) return -EFBIG; @@ -2036,10 +2038,12 @@ 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_acct_folio(huge_gfp, inode, index, true); + folio = shmem_alloc_and_acct_folio(huge_gfp, inode, index, true, + &order); if (IS_ERR(folio)) { alloc_nohuge: - folio = shmem_alloc_and_acct_folio(gfp, inode, index, false); + folio = shmem_alloc_and_acct_folio(gfp, inode, index, false, + &order); } if (IS_ERR(folio)) { int retry = 5; @@ -2602,7 +2606,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 Fri Sep 15 09:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13386771 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 C2E4EEE644C for ; Fri, 15 Sep 2023 09:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233771AbjIOJyp (ORCPT ); Fri, 15 Sep 2023 05:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234160AbjIOJyd (ORCPT ); Fri, 15 Sep 2023 05:54:33 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53BF93596 for ; Fri, 15 Sep 2023 02:53:13 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230915095131euoutp02800dfabc6f1a8e7dfe73359b0a595cc6~FCbFStMQE1141011410euoutp02a for ; Fri, 15 Sep 2023 09:51:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230915095131euoutp02800dfabc6f1a8e7dfe73359b0a595cc6~FCbFStMQE1141011410euoutp02a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694771492; bh=KBxqvbiqwxbpjqMz9Z69KDs2z1l+Vy83NL/rF/oYkIA=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=JOehX4by5wtuX/tE/lkY/wGdcZiXjGvV+uvowvsHd2pzTMwEPs6jAg6SaKbGyeYcE iR1US6vyNvUMUR3ILaF+Pv2qAnqLxDu6BYFROC3ouKN35j27QhPrumNlIemiLqUGlG wMaSFWpsfDW+px6/1X9wAnkxvPWX6ewHOlmRMtkE= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230915095131eucas1p25cc2b04fd359369a4fc473bf907da57c~FCbFAjAMZ1349613496eucas1p21; Fri, 15 Sep 2023 09:51:31 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 2B.9A.42423.32924056; Fri, 15 Sep 2023 10:51:31 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d~FCbEmMxFv0060700607eucas1p1L; Fri, 15 Sep 2023 09:51:31 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230915095131eusmtrp24a417d7970c44623708b2e39cfebe5a0~FCbElcNAu1712217122eusmtrp27; Fri, 15 Sep 2023 09:51:31 +0000 (GMT) X-AuditID: cbfec7f2-a51ff7000002a5b7-1a-65042923bb09 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 09.3B.10549.22924056; Fri, 15 Sep 2023 10:51:31 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230915095130eusmtip22dc6e7222c8a07a587bf7bef6f55c865~FCbES6n5V0935009350eusmtip2L; Fri, 15 Sep 2023 09:51:30 +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; Fri, 15 Sep 2023 10:51:30 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 15 Sep 2023 10:51:30 +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: [PATCH 5/6] shmem: add file length in shmem_get_folio path Thread-Topic: [PATCH 5/6] shmem: add file length in shmem_get_folio path Thread-Index: AQHZ57ozxEpCdFcMBk645e2R7dVRyg== Date: Fri, 15 Sep 2023 09:51:29 +0000 Message-ID: <20230915095042.1320180-6-da.gomez@samsung.com> In-Reply-To: <20230915095042.1320180-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: H4sIAAAAAAAAA02SfVBMYRTG57179+7tjtW1Wr2EMduUsZul4Y+LUMNwfczEjDEYg2tdWX1g txX5KoNRI5K+7G6lsJS0WqXUrpJRtpSy+RhGwkY0JopY1abtLtN/v+c553nPOTMvzhNZ+ZNw ZVQ0q4piIiQYgd6pdTyZ6TsDZWdfbJ5G6Y2FGHXjzTmMstnHUh09Z1HK8kpGmS1WlLJV6DGq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p+3flzua/+XRUlluKMREMt5qLiRABLoVzZ1gMAAA== X-CMS-MailID: 20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d X-Msg-Generator: CA X-RootMTR: 20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d References: <20230915095042.1320180-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org To be able to calculate folio order based on the file size when allocation occurs on the write path. Use of length 0 for non write paths. Signed-off-by: Daniel Gomez --- include/linux/shmem_fs.h | 2 +- mm/khugepaged.c | 2 +- mm/shmem.c | 28 ++++++++++++++++------------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 6b0c626620f5..b3509e7f1054 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -133,7 +133,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 88433cc25d8a..e5d3feff6de6 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1856,7 +1856,7 @@ 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, 0)) { result = SCAN_FAIL; goto xa_unlocked; } diff --git a/mm/shmem.c b/mm/shmem.c index ee297d8874d3..adff74751065 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -969,7 +969,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, 0); return folio; } @@ -1950,7 +1950,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_area_struct *vma, struct vm_fault *vmf, - vm_fault_t *fault_type) + vm_fault_t *fault_type, size_t len) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); @@ -2164,10 +2164,11 @@ 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, NULL); + mapping_gfp_mask(inode->i_mapping), + NULL, NULL, NULL, len); } /* @@ -2251,7 +2252,7 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf) } err = shmem_get_folio_gfp(inode, vmf->pgoff, &folio, SGP_CACHE, - gfp, vma, vmf, &ret); + gfp, vma, vmf, &ret, i_size_read(inode)); if (err) return vmf_error(err); if (folio) @@ -2702,6 +2703,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))) { @@ -2711,7 +2715,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; @@ -2783,7 +2787,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, 0); if (error) { if (error == -EINVAL) error = 0; @@ -2960,7 +2964,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, 0); if (error) { if (error == -EINVAL) error = 0; @@ -3147,7 +3151,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, 0); if (error) { info->fallocend = undo_fallocend; /* Remove the !uptodate folios we added */ @@ -3502,7 +3506,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, 0); if (error) goto out_remove_offset; inode->i_mapping->a_ops = &shmem_aops; @@ -3550,7 +3554,7 @@ static const char *shmem_get_link(struct dentry *dentry, return ERR_PTR(-ECHILD); } } else { - error = shmem_get_folio(inode, 0, &folio, SGP_READ); + error = shmem_get_folio(inode, 0, &folio, SGP_READ, 0); if (error) return ERR_PTR(error); if (!folio) @@ -4923,7 +4927,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, NULL); + gfp, NULL, NULL, NULL, i_size_read(inode)); if (error) return ERR_PTR(error); From patchwork Fri Sep 15 09:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13386773 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 22C68EE644B for ; Fri, 15 Sep 2023 09:55:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234137AbjIOJzS (ORCPT ); Fri, 15 Sep 2023 05:55:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234234AbjIOJzA (ORCPT ); Fri, 15 Sep 2023 05:55:00 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E1492D42 for ; Fri, 15 Sep 2023 02:53:53 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230915095134euoutp02c44dd59be3313d9923bf782cc42bcadc~FCbHVf2q81425714257euoutp02I for ; Fri, 15 Sep 2023 09:51:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230915095134euoutp02c44dd59be3313d9923bf782cc42bcadc~FCbHVf2q81425714257euoutp02I DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694771494; bh=nTKXGiIiML3QQW/w2E+mOtcZhHyvpI4/kPyFKr8+glQ=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=KI2kOdoS2yg7Vh86md6sPK4vwrtx1rr8lkcPGelzTYN+V1wDwjhXbTPHfi1ayADmq SnuX6aSN1YRX5kU7TmhzwLcmfDlEAs/J/VhdqKM/lMU1vn2PXUcHsE0QM7qAuv739c MwIfQURAnIrUaVFqn6+icPbpvOOlVSZ/rhM39T1M= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230915095133eucas1p1fc05405567bd735c07ff213d3dff3c85~FCbG_4jQF2007620076eucas1p1T; Fri, 15 Sep 2023 09:51:33 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 63.AA.42423.52924056; Fri, 15 Sep 2023 10:51:33 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f~FCbGdpbh00862308623eucas1p2c; Fri, 15 Sep 2023 09:51:33 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230915095133eusmtrp2540609b9602d103cb0a1998aeeb2d1b1~FCbGc8gqX1712217122eusmtrp2_; Fri, 15 Sep 2023 09:51:33 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-26-65042925ea5e Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 5B.3B.10549.52924056; Fri, 15 Sep 2023 10:51:33 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230915095133eusmtip145b39d48e2d4c2b2f0f476f141a1971f~FCbGQl2U92594625946eusmtip1i; Fri, 15 Sep 2023 09:51:33 +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; Fri, 15 Sep 2023 10:51:32 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 15 Sep 2023 10:51:32 +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: [PATCH 6/6] shmem: add large folios support to the write path Thread-Topic: [PATCH 6/6] shmem: add large folios support to the write path Thread-Index: AQHZ57o0gOj42/h7V0WVSDdaHJaWqA== Date: Fri, 15 Sep 2023 09:51:31 +0000 Message-ID: <20230915095042.1320180-7-da.gomez@samsung.com> In-Reply-To: <20230915095042.1320180-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+NgFjrKKsWRmVeSWpSXmKPExsWy7djP87qqmiypBpfmq1vMWb+GzWL13X42 i8tP+Cyefupjsdh7S9tiz96TLBaXd81hs7i35j+rxa4/O9gtbkx4ymix7Ot7dovdGxexWfz+ MYfNgddjdsNFFo8Fm0o9Nq/Q8rh8ttRj06pONo9Nnyaxe5yY8ZvF4/MmuQCOKC6blNSczLLU In27BK6M/d1mBbuEKv5se8bWwHiar4uRg0NCwETia5tOFyMXh5DACkaJncsWMkM4Xxgl9t9b xgLhfGaUeNZ6mxWmY94rFYj4ckaJoy1b2eCKfmyeDeWcYZRY8vYn1KyVjBLbZr0EmsXJwSag KbHv5CZ2kISIwGxWicOLOxhBEswCdRJrns0CKmLnEBZwk1ijDxIVEfCWeLFzCRuErSfx/tAb sGoWAVWJz7t+soNcxCtgLbH+VjaIySlgI/H+RzlIBaOArMSjlb/YIWaLS9x6Mp8JxJYQEJRY NHsPM4QtJvFv10M2CFtH4uz1J4wQtoHE1qX7WCBsJYk/HQuhbtSTuDF1ChuErS2xbOFrsDm8 QDNPznwCDiwJgSYuicZ7nawQzS4S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sTnXT/ZQQ7lFbCWWH8rG8QUAjJnTfcC MTkFbCTe/ygHKWYUkJV4tPIXO8QacYlbT+YzQVwvILFkz3lmCFtU4uXjf1Bf6Uicvf6EEcI2 kNi6dB8LhK0k8adjIdS5ehI3pk5hg7C1JZYtfA02h1dAUOLkzCcsExilZyFZNwtJyywkLbOQ tCxgZFnFKJJaWpybnltsqFecmFtcmpeul5yfu4kRmJK2Hfu5eQfjvFcf9Q4xMnEwHmKU4GBW EuFls2VKFeJNSaysSi3Kjy8qzUktPsRoCgygicxSosn5wKSYVxJvaGZgamhiZmlgamlmrCTO 61nQkSgkkJ5YkpqdmlqQWgTTx8TBKdXAFGb97Euc/wHZOwe2H2d42C6wT9inRO7LFrv2jz5P F+jw6Pd+rmiR+vWiN6yJcdZj/UWebt99mZZpm3FUc8u9iHs94eG6jMblr2Q0rq9tOuBysvnq HqNDv/XmeUz9sMmm9fl6u4v7WCZt+nauo1l/yR1BpU1qlornQqTCTdjnZiWU1r2rlODnvbzW y/y5mNgqoQcvG6a8O3E48N3Ed//ZoxIdvsRvEP6t4OX9WH7C2uygo9XeTnlK3J69P5QXenPc YjKPy5Hg+z9xZ/CXbD2xu1ucfZzSnzWK+9ucKK07vLfk5Url5KaYKNUCptfdS40XvdXc07yx feHuG8fPJVYcFP399u7Tmcvfdkzx73g/VYmlOCPRUIu5qDgRACdVhs7SAwAA X-CMS-MailID: 20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f X-Msg-Generator: CA X-RootMTR: 20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f References: <20230915095042.1320180-1-da.gomez@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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(). Use the __folio_get_max_order to get a hint for the order of the folio based on 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. Signed-off-by: Daniel Gomez --- mm/shmem.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index adff74751065..26ca555b1669 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1683,13 +1683,19 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, } static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode, - pgoff_t index, bool huge, unsigned int *order) + pgoff_t index, bool huge, unsigned int *order, + struct shmem_sb_info *sbinfo) { struct shmem_inode_info *info = SHMEM_I(inode); struct folio *folio; int nr; int err; + if (!sbinfo->noswap) + *order = 0; + else + *order = (*order == 1) ? 0 : *order; + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) huge = false; nr = huge ? HPAGE_PMD_NR : 1U << *order; @@ -2032,6 +2038,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, return 0; } + order = mapping_size_order(inode->i_mapping, index, len); + if (!shmem_is_huge(inode, index, false, vma ? vma->vm_mm : NULL, vma ? vma->vm_flags : 0)) goto alloc_nohuge; @@ -2039,11 +2047,11 @@ 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_acct_folio(huge_gfp, inode, index, true, - &order); + &order, sbinfo); if (IS_ERR(folio)) { alloc_nohuge: folio = shmem_alloc_and_acct_folio(gfp, inode, index, false, - &order); + &order, sbinfo); } if (IS_ERR(folio)) { int retry = 5; @@ -2147,6 +2155,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, if (folio_test_large(folio)) { folio_unlock(folio); folio_put(folio); + if (order > 0) + order--; goto alloc_nohuge; } unlock: