From patchwork Wed May 15 05:57:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13664606 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 975D4C25B75 for ; Wed, 15 May 2024 05:57:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C27A6B015D; Wed, 15 May 2024 01:57:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 025286B0165; Wed, 15 May 2024 01:57:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1F656B015D; Wed, 15 May 2024 01:57:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id ACF5D6B0153 for ; Wed, 15 May 2024 01:57:41 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6D3F3121103 for ; Wed, 15 May 2024 05:57:41 +0000 (UTC) X-FDA: 82119573522.02.8DEF214 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf29.hostedemail.com (Postfix) with ESMTP id 897CC120016 for ; Wed, 15 May 2024 05:57:38 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=XE0WeUZ4; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf29.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 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=1715752658; 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=KSFa/00drIrpTPTVaHKTJFLNN4vEYokk0j2qhn9ASTY=; b=WX5FtPAqgIlzDU4CZ5174Us6/0xwqg+HjT8lbOL42hCUOs685DbEXe7+l2Iw0T3w6dF1+f LaIa3jIEqaxl//2XjWlJJbIRWE9Jq4xr2VEjrtRSEB5oXliVZ/l4dFyt2ODCia5pnSw33Z mGhZHiza0+d8EIY8PUM90yBlq2lwHGg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=XE0WeUZ4; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf29.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715752658; a=rsa-sha256; cv=none; b=r+Tg1zrGO+T5c8+4YCIuQookVQEfZV/KaQSvbPw2n7+uBueRiHN1feaXUvGrxdWeoPCz/p y34F5PiiibkFMqAES5n0L2N/8qQa00JAusLCxTCAOVWJTDaHNHvLUAONeyJj9qPtxNu95H jcqa3VHj00akxjaCLQkUB7bp0oZWG/0= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055737euoutp01f6edc2da26c5a067c4ba60b50b5518aa~Pk-OQj1uv2237822378euoutp01B for ; Wed, 15 May 2024 05:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055737euoutp01f6edc2da26c5a067c4ba60b50b5518aa~Pk-OQj1uv2237822378euoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752657; bh=KSFa/00drIrpTPTVaHKTJFLNN4vEYokk0j2qhn9ASTY=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=XE0WeUZ4/fxHAxJkG/mIY/WGU0C4ZHUEw5qzBkuqT9YA+ux6u/VMvXpPQ5QfXZsCN RAdqw8x6EFSJ3Uy0xmtAXcHqL9FipFkZbQdC03MkUvzvsQe44ht0ez97k3oK7S9HbB ZKW8iyeunnHh5sOncAza29RBBZxrEoJLw6eIoNhE= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240515055737eucas1p2687839099f1491893036e9edf50d6776~Pk-N8z2ap0810008100eucas1p2W; Wed, 15 May 2024 05:57:37 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 58.D8.09875.0DE44466; Wed, 15 May 2024 06:57:36 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240515055736eucas1p1bfa9549398e766532d143ba9314bee18~Pk-NPUDB_1859218592eucas1p1L; Wed, 15 May 2024 05:57:36 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055736eusmtrp1cd38f7c68e33115cb0f700536a34b1e1~Pk-NOpRJH0411404114eusmtrp1C; Wed, 15 May 2024 05:57:36 +0000 (GMT) X-AuditID: cbfec7f4-11bff70000002693-f1-66444ed03f5f Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 6D.F1.09010.0DE44466; Wed, 15 May 2024 06:57:36 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240515055736eusmtip10c080390bd41a09baa29d247f828f893~Pk-NCedQq0562705627eusmtip1T; Wed, 15 May 2024 05:57:36 +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; Wed, 15 May 2024 06:57:35 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Wed, 15 May 2024 06:57:35 +0100 From: Daniel Gomez To: "hughd@google.com" , "akpm@linux-foundation.org" , "willy@infradead.org" , "jack@suse.cz" , "mcgrof@kernel.org" CC: "linux-mm@kvack.org" , "linux-xfs@vger.kernel.org" , "djwong@kernel.org" , "Pankaj Raghav" , "dagmcr@gmail.com" , "yosryahmed@google.com" , "baolin.wang@linux.alibaba.com" , "ritesh.list@gmail.com" , "lsf-pc@lists.linux-foundation.org" , "david@redhat.com" , "chandan.babu@oracle.com" , "linux-kernel@vger.kernel.org" , "brauner@kernel.org" , Daniel Gomez Subject: [PATCH 10/12] shmem: add order arg to shmem_alloc_folio() Thread-Topic: [PATCH 10/12] shmem: add order arg to shmem_alloc_folio() Thread-Index: AQHapozIzXRp8FIrX0Ow3XgDmWV32Q== Date: Wed, 15 May 2024 05:57:35 +0000 Message-ID: <20240515055719.32577-11-da.gomez@samsung.com> In-Reply-To: <20240515055719.32577-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.210.248.161] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIKsWRmVeSWpSXmKPExsWy7djP87oX/FzSDHZ9srSYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWx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bcUZCm cd5f3z2ornxusa1H1MfPUpG3J5qfbeUTO/vqgdPit1Wf+n2VN683NlI+lXLmFzPfA2uuM3Wb RN26T/LqZJQ7Xdsp75R5I+DXvy2Kf9V/LLRl9HQS6FkyYVOQ/5cEt8SoGYFT1nilvJnKs9FW P/vf0+B+vnM8SizFGYmGWsxFxYkAp8+SoAEEAAA= X-CMS-MailID: 20240515055736eucas1p1bfa9549398e766532d143ba9314bee18 X-Msg-Generator: CA X-RootMTR: 20240515055736eucas1p1bfa9549398e766532d143ba9314bee18 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055736eucas1p1bfa9549398e766532d143ba9314bee18 References: <20240515055719.32577-1-da.gomez@samsung.com> X-Rspamd-Queue-Id: 897CC120016 X-Stat-Signature: 9ejzosuzewoa4kgwfd85nxomznfeo491 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1715752658-620013 X-HE-Meta: U2FsdGVkX183rHv59NXp25EAe776fJ1fAWr6Rt47R6cUsuq3//BipNIGv88QAZ6rbJKgIVjVRM8L1zKYF0yVtOrxyX88ZA2syb/MQz6bwQchR87UA6mSM1anMgkvo/JSyuIm7L2eIemXSf8ff8txJ6nDMgq2nl+/3b1cIWvl978nonhvVgZPIkxXjOQK+DmYo0lFMxEZ41W6UeNaPR2a8iOUKLm7BxfyCdnLCqxj1anF+K+jhWCbekhjv2W7yn3FRthz5hJnIKWMspd1uW7IYly/Rk6ox3aXeCX3tLo5isKqtJ7EX+/RoBz+fLSVfJ+Tx0FUel2fUHFuvs+xgE0xKSCFyXOML/JJAurfQR6nE012E/xWEYPLIsN0Zjiv+6ZozMpv3324Ijx/DyhYbQ87wVw2RQ/3HpZFUqXs3oQUScH8oyAxcFbP5IpGtfvIXx8aSj2uOSWAY9Hp6BNxpa69Z7XYfj7TdKnTa8wA1WWKBOVC7SWpGo3cdMaX9bR/Z+KAHugRkCfZ0vadPZU0upk9J1vc5/OKljCSTVFeutEf74EZQ2kpXwdTD1KwssMVqOEbkUGjDV8Wgw5e2Kst1PXzgB/8qXTMu1ZH/1A5/nsyowNYKGH2QDpQ2igP2befms6SZQArh7R19yxf5Wd/Meig//m+zKNku1zEKcBBA9OdnIj0k4qSxICkgbqm+Mein0lHDOT0ElefQBUks82c7So4PzEhFK/taGeNGuxe4S7HA7c5tjEEfI5W80A+B5ml7IMteS9qPIPHRq5/I0f+e6EZ53tS4yIfqaL1SKCnDkUAO9jZ+G7KtSdBezHKMijadB1WVPlFVUqMzBaQCcsfh9KvgaOIWZQL6K9TF/LnEdbbm4iEfPGSsuUDM+33UW7GkdYfprVRuM/pmFA8hdV5i4wAkd8pscd2wrkLX+zcp76XuBqFAwiqKDs+MpgGVOVV2oaI99POM7r8Y6t2S5IUXEc 1fL/DB6x eON7CTqhGktf8EnALX2jjvdsfcK/qOOZ+1pHK2sYqM0U5f0Twf4+njuWOmZvFrYbOyDRiO0HU0O4xY+TElFNLGmzIW7TCjgRqOIxT4a71HjgeTEeMdmWJ1ySXm4rOw8TgDbTagRumThesIumK15R4qt9Hjqtpf9vbdO/ANJtyEk+pl9TGxd9lPfK/oDuE4OzSCfnIbeOnXP5WK6J3LKt+73M5qaGmXSSlRN0PogRc6jbCLEakibOkaB90GCzQ+0OkD+pOTKtFAoifkDCCMOszaS+rWA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add folio order argument to the shmem_alloc_folio(). Return will make use of the new page_rmappable_folio() where order-0 and high order folios are both supported. As the order requested may not match the order returned when allocating high order folios, make sure pages are calculated after getting the folio. Signed-off-by: Daniel Gomez --- mm/shmem.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 7a6ad678e2ff..d531018ffece 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1828,18 +1828,18 @@ static struct folio *shmem_alloc_hugefolio(gfp_t gfp, return page_rmappable_folio(page); } -static struct folio *shmem_alloc_folio(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, 0, &ilx); - page = alloc_pages_mpol(gfp, 0, 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 (struct folio *)page; + return page_rmappable_folio(page); } static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, @@ -1848,6 +1848,7 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, { 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; @@ -1856,7 +1857,6 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, huge = false; if (huge) { - pages = HPAGE_PMD_NR; index = round_down(index, HPAGE_PMD_NR); /* @@ -1875,12 +1875,13 @@ static struct folio *shmem_alloc_and_add_folio(gfp_t gfp, if (!folio) count_vm_event(THP_FILE_FALLBACK); } else { - pages = 1; - folio = shmem_alloc_folio(gfp, info, index); + folio = shmem_alloc_folio(gfp, info, index, order); } if (!folio) return ERR_PTR(-ENOMEM); + pages = folio_nr_pages(folio); + __folio_set_locked(folio); __folio_set_swapbacked(folio); @@ -1976,7 +1977,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, folio_order(old)); if (!new) return -ENOMEM; @@ -2855,7 +2856,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;