From patchwork Tue Sep 5 07:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13374357 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 0615DC83F2C for ; Tue, 5 Sep 2023 07:10:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E121940007; Tue, 5 Sep 2023 03:10:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78F3B8E001A; Tue, 5 Sep 2023 03:10:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A6A3940007; Tue, 5 Sep 2023 03:10:33 -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 5A3518E001A for ; Tue, 5 Sep 2023 03:10:33 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 30B121A0A92 for ; Tue, 5 Sep 2023 07:10:33 +0000 (UTC) X-FDA: 81201670746.09.6CF2FE1 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf17.hostedemail.com (Postfix) with ESMTP id 4256A40018 for ; Tue, 5 Sep 2023 07:10:29 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693897831; 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: references; bh=qjyyjOOufbvezh5liNFbyGhCMBi9joiE7vSbEVJXjNs=; b=8K/gCczEnMdT64+GBsWJcDDBDOqzif/U4DPk0yZ8y/diUSPrxj+C83pl9xtCa6YjlTHUY+ ds6CllcBpcyDiTRH9LxT6FWgdj2w11Ja8zVWGuL+Ch0d1qOoFkqmQLwTuTN/QOLUi62d40 EHkCskKEFRW55h8oHvV7iTe2L6sv0qc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693897831; a=rsa-sha256; cv=none; b=zkBsBF8ux9GmHuCSncFp1Bc3A/QAAjTTq6B2ZeZLRhAYHJfgDmCHI4bdEMHGpVUriyY1QZ YNVE9qgNggf1D/2gnfwXzpGkwRPj8yzSFxdXUbq0wiUci1qXP4TmKDuOBlGqs3mUa4LP/b kJEmvhuL++JnB3P9NeEdPKY00lemyIE= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RfxQG290fzMl5s; Tue, 5 Sep 2023 15:07:02 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 5 Sep 2023 15:10:20 +0800 From: Kefeng Wang To: Andrew Morton , Mike Kravetz , Muchun Song , CC: Kefeng Wang , Yuan Can Subject: [PATCH] mm: hugetlb_vmemmap: use bulk allocator in alloc_vmemmap_page_list() Date: Tue, 5 Sep 2023 15:10:16 +0800 Message-ID: <20230905071016.2818810-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 4256A40018 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: g3y9nc5p77uf7wj7edk1rh9rnzhtwngb X-HE-Tag: 1693897829-741746 X-HE-Meta: U2FsdGVkX19zOcR5zZYhr0PF+/+Rh/6fzrl/GN4WcxP1bB+acPjLzQrrFrJXf24TaiP+aC91rbLajDBAb68cdjx9qR6puWAWmwbuS/tdf9DMEEjYoCMCc+K0j8p1aR247415PpKbPkMDHOTJ/Ry7m5qdp6JI4ePT6OJxArH/BUAZc863aHrZXBghd12y51GkOZkqHG2u7PcCVk4Cl1h7izijcG1fOqyLWR94B8tr9Y01cqVtYvYYGP7kgc4y1c1SrcGawZIALf4RsVcPLysLI6CtiynpFRz5xorI5M76CyuWNKKEScpQ8x2no4/OFbqWUrHEi9g+QCVr01vdXmHCnolJqHk/uTcZeWCTdBaVjdsH7USGKzYgC928ZofYve6r4TA1VfAobksStJ+Lqpl2RBwCFIuhn7fq3VZpi3Nsz975BzkP20SCF4o7QDOgORn0eUOu9Z+AjyXGrDKe4P/fN0gH9vDeorHj+D9II5HMnCqUhR8/1gzFNg+tG7UXFWrHXfG7gu9RN4GPzKXOFmUPmbtzLqFfNYW14WQBCjUsVXuwlgzycoAeTL7S3oRp/NuuQ9pMuxDrMo/m1YW8TkvEF5UGSoMR1S/s4CDNYrqH1ikaMVrOqxTg4VdDXrkqH7FKf7Ei1Eu11j94KK5rIxH5iBk5rMDXj54LUv45F0kJZASkOoAfz9mMc2LB24S/Zk0LDnQnyAUbSBhI6tMzEgRPDVgjARzUcXnyqcvLQ8V33LubimniBqIX/Iy8rDXZ/OB2MIxwvD/Pn+lWGKPcmpKUsWRWSw+avv1E5i69IdsOGA+zC4XKbfavK+yOFZ874FDQb7falKvDjAeiW997C13XtycaABDYTBcLaYlW9hg69rjQvpe37KQFqTLYAvZYdgGWvk3H9Yvf1rThgiWbzneGZV4RPijNSqmts9RiLMJDe732oX0k7/YQBJ9OXkioA97AEx5F1eqGMpri1gdqYCx ClNDM4QA XJF01kpcKZwLUtxklnDamsghU15sa5Ufp8X6R+jvHfEBP+c4yhLzB1Qna22uPRq8p2joRXK/eaDBN59BGZRIC/9apqDcc2nqX23VueeEpWKfhsSr+oFFeP4gv9l28haLkLInD9ssUSrcANdjc5hl1i4nqi49hgbWwbL2lmWwpaPCyvKKXD5WiCxhjMBJHL0ndjY/9 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: It is needed 4095 pages(1G) or 7 pages(2M) to be allocated once in alloc_vmemmap_page_list(), so let's add a bulk allocator varietas alloc_pages_bulk_list_node() and switch alloc_vmemmap_page_list() to use it to accelerate page allocation. Simple test on arm64's qemu with 1G Hugetlb, 870,842ns vs 3,845,252ns despite the fluctuations, it is still a nice improvement. Tested-by: Yuan Can Signed-off-by: Kefeng Wang --- include/linux/gfp.h | 9 +++++++++ mm/hugetlb_vmemmap.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 665f06675c83..d6e82f15b61f 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -195,6 +195,15 @@ alloc_pages_bulk_list(gfp_t gfp, unsigned long nr_pages, struct list_head *list) return __alloc_pages_bulk(gfp, numa_mem_id(), NULL, nr_pages, list, NULL); } +static inline unsigned long +alloc_pages_bulk_list_node(gfp_t gfp, int nid, unsigned long nr_pages, struct list_head *list) +{ + if (nid == NUMA_NO_NODE) + nid = numa_mem_id(); + + return __alloc_pages_bulk(gfp, nid, NULL, nr_pages, list, NULL); +} + static inline unsigned long alloc_pages_bulk_array(gfp_t gfp, unsigned long nr_pages, struct page **page_array) { diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 4b9734777f69..699c4fea6b9f 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -384,8 +384,13 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end, unsigned long nr_pages = (end - start) >> PAGE_SHIFT; int nid = page_to_nid((struct page *)start); struct page *page, *next; + unsigned long nr_alloced; - while (nr_pages--) { + nr_alloced = alloc_pages_bulk_list_node(gfp_mask, nid, nr_pages, list); + if (!nr_alloced) + return -ENOMEM; + + while (nr_alloced < nr_pages) { page = alloc_pages_node(nid, gfp_mask, 0); if (!page) goto out;