From patchwork Tue Sep 19 13:55: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: 13391493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4A72CD5BBD for ; Tue, 19 Sep 2023 13:56:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42CD06B052E; Tue, 19 Sep 2023 09:55:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DBE66B0531; Tue, 19 Sep 2023 09:55:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BEFF6B0533; Tue, 19 Sep 2023 09:55:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E36606B052E for ; Tue, 19 Sep 2023 09:55:57 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9A00B1404DD for ; Tue, 19 Sep 2023 13:55:57 +0000 (UTC) X-FDA: 81253495554.05.A7F7DA4 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by imf27.hostedemail.com (Postfix) with ESMTP id 86E774002B for ; Tue, 19 Sep 2023 13:55:54 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=Nuk+vBjm; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf27.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695131754; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j5/WuYRozdtOAgqCuDPHuq7YO9f8GU76Eza03ZT/hH0=; b=wh+kpbSolxVut42NOW8B7QRwRc3DRa0dFV5UBmS6EJHs/rDAe7yCmIbGyFuq0jNqJH+yUp CpjayyoXIDPPnJooszlP+EcsiBuaJq7mdcbofE4mWyUMReJVC3Dcy+H7A2onsTRcZNzDsW dwstqRbgcObwE+r8LjMo0htHDGE5Ek4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=Nuk+vBjm; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf27.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695131754; a=rsa-sha256; cv=none; b=CD7bfArCNpQ0UG/7rjfemcU7nTMfwKWp4Iw5Lg3I8TGDYSC5Am3+3IuzuhOyUA5gb5AHT+ ttGwRQ/dTOdrUbm4gvAxdMq3nqiTgTz4nybNBDgt+wKfqgm7V++h8CBKj2L23MA5u9Ej/C xiB2+ScMmS9bYVAVqEgXrjC9dMzcZj0= Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230919135553euoutp02329f264fe0c275fad9eadd8a6c53c251~GUVkxhfYt1585515855euoutp02U for ; Tue, 19 Sep 2023 13:55:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230919135553euoutp02329f264fe0c275fad9eadd8a6c53c251~GUVkxhfYt1585515855euoutp02U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1695131753; bh=j5/WuYRozdtOAgqCuDPHuq7YO9f8GU76Eza03ZT/hH0=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=Nuk+vBjmOh37sbt6+cadKZVS5pDdzpixYn6VfaHIUcxAPCiEoA5HyMHU16U4AXzlS uAY13cUs5iF3t9vzP0Wwptp6v7rcHcS1QS4p2z9CuSenJGbi8FP5xvy52tPDOa5C+A HquMNJPl6Mp5dXIMgriwdNYppSWors5aDVdkPq2A= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230919135552eucas1p24dc412b1eadbba23c9d14f70df03b1ac~GUVkXHo8C1636016360eucas1p2s; Tue, 19 Sep 2023 13:55:52 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id C5.8E.11320.868A9056; Tue, 19 Sep 2023 14:55:52 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230919135552eucas1p11e19cd339078c2e0b788b52fae46e7c9~GUVj9gkvl1092210922eucas1p1Q; Tue, 19 Sep 2023 13:55:52 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230919135552eusmtrp1594d9a0d3fd5111d702d62a93bc6f02d~GUVj8zkSl2614026140eusmtrp1G; Tue, 19 Sep 2023 13:55:52 +0000 (GMT) X-AuditID: cbfec7f4-97dff70000022c38-ca-6509a868e751 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 9C.C9.10549.868A9056; Tue, 19 Sep 2023 14:55:52 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230919135552eusmtip105fc41d27402e30d4f75b71c970cf4f9~GUVjooqQg1607416074eusmtip1K; Tue, 19 Sep 2023 13:55:52 +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; Tue, 19 Sep 2023 14:55: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; Tue, 19 Sep 2023 14:55: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: [PATCH v2 4/6] shmem: add order parameter support to shmem_alloc_folio Thread-Topic: [PATCH v2 4/6] shmem: add order parameter support to shmem_alloc_folio Thread-Index: AQHZ6wD/X9RVQ39BEEGXAtoeSmDJSA== Date: Tue, 19 Sep 2023 13:55:50 +0000 Message-ID: <20230919135536.2165715-5-da.gomez@samsung.com> In-Reply-To: <20230919135536.2165715-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+NgFjrOKsWRmVeSWpSXmKPExsWy7djPc7oZKzhTDSZu1rWYs34Nm8Xqu/1s Fpef8Fk8/dTHYrH3lrbFnr0nWSwu75rDZnFvzX9Wi11/drBb3JjwlNFi2df37Ba7Ny5is/j9 Yw6bA6/H7IaLLB4LNpV6bF6h5XH5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/jfztEKC pTOr/XjCIhRMHzHeWNQ2+cEUSY7oXY+UWIozEg21mIuKEwFsJZsF2QMAAA== X-CMS-MailID: 20230919135552eucas1p11e19cd339078c2e0b788b52fae46e7c9 X-Msg-Generator: CA X-RootMTR: 20230919135552eucas1p11e19cd339078c2e0b788b52fae46e7c9 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230919135552eucas1p11e19cd339078c2e0b788b52fae46e7c9 References: <20230919135536.2165715-1-da.gomez@samsung.com> X-Rspamd-Queue-Id: 86E774002B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ps5596pzzz7kpuiyyajrk4z7bz7qa637 X-HE-Tag: 1695131754-554904 X-HE-Meta: U2FsdGVkX1+6lpma34XzTh22H2Mt74MHwxVEYWQoEcJHxOX4UgD7uDOQJW1QhA2HJ0idrVJDX9sYfdFsEOQTF83uhGdc/UwG9iVHgfJQ6j4c+L5hQ9O+x41k2zFoFY1DwxERQ8vklryw7tB1UadGN1/zFZdqGTKmbsVULvUBoIhiwTq5dcGGg91e92GrBcXVypRkc8eMIKNX9g/tjTJLzjj34YJ1HYqFm9s2WjWZ5ZzdANRrCAaar+9xUNx+bBUccz/GqwNF3TJtOyBiLqk6Er0ubMsuW2p/0nsWr5cOmNdbWaL4S8gCAXaUVJF6lKw+4S4YMJ0mnORUis0EaWmkW91cR79El3CBqDsS5txif2o6MC/I0I3ktemC4wSk79XBluXrPACfuy3fzSnJMXwSK89lvm8oZKwPwehxcvojmsgfKkshEfi0c+hZF9zjNDD6/92l8YPn+aLoSS/sJUJ3gRravepzEf3weUw/GNL8Dy26D9zFjMn2RYzhAQrDK8WlXXPHb4fYrFDDIjCt5fNNPL3hgTFftSwC+QUgAYhVveg5CjwfZP+UAgGkSDTruUAZu/U8PoEFPi4zp09mfEoBYpztlV9XyofTdEE1Cb15PXhyuuQoTWJ8i0u4TabPPWV/XwkLfzHD0MvSwMRNPyGRYGosFplmi8xKSPBMMbayHudh1SRr5Ht5UvtuyfHxU78dFXaKlv3kmjFldFk7NG298XaexyHBtZ6KcGlY+fKcz6PmkQk1UcmsCJQTrKvcvbeXOCkBpZlIKALcoyiyHhSWQlpo6iwBNjPoGCoLWJrtOH2H8kIAY/reiM4pbn5fwqPuUgLIx1ILY73Q2BVdNBoWYt6zDfpeQE1TB9ouxt1G78LHcevZwErYuUyDEPTS1RKVwb1eVqyCaSI8oJMr7DgUBXLU9vfCunMto7Vzi8Z0ImKI3nhIOfBPHUt3liIoiudxQUszrVOAdBkLnfGRxLm 4Hf44vJN m+sBVyCG/fcdtQsWucjUyxlM9cTOtJM6RlWcYpjhYaVN3GcoSWWLzGl5ilNFqRh/SLk4VyTqQfQmjpAn0drMJ3hzeMZPl5WkkYZ81eyAlpiVsVf+hV/4eY4bVcqf7QOSLNgQWenB+CWYev/FRfp/WpIpEYIPGKRERkUd9ekO1qQhRRmTwOyFCDbej46QKGqcSMiJap/RZb9PsN125XfOzR6Jdfg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 d41ee5983fd4..66d94207b40c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1667,20 +1667,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; @@ -1689,7 +1690,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) @@ -1698,7 +1699,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); @@ -1748,7 +1749,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; @@ -1959,6 +1960,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; @@ -2034,10 +2036,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; @@ -2600,7 +2604,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;