From patchwork Tue Sep 5 10:35:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13374421 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 897FBC83F2C for ; Tue, 5 Sep 2023 10:35:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 087A894000D; Tue, 5 Sep 2023 06:35:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 037B98E001A; Tue, 5 Sep 2023 06:35:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E68DC94000D; Tue, 5 Sep 2023 06:35:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D7BED8E001A for ; Tue, 5 Sep 2023 06:35:24 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A3D0840C09 for ; Tue, 5 Sep 2023 10:35:24 +0000 (UTC) X-FDA: 81202186968.18.3F1F716 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf10.hostedemail.com (Postfix) with ESMTP id 39017C001C for ; Tue, 5 Sep 2023 10:35:20 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693910122; 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=6GJtcOqaQ6aAoVxIz2ALggu5bdbC7/tOfEINCZV5+OI=; b=c1AgjeXNE0C0GbsTM//yz0M0MRta8TcOEPHRwxH3E+mcaagcURwpbUphFnmb2dCnA+M+hK CabbTv+HYKYQ0sOfmyOrXcmX0uSp9gIZ8IAggnfWVPawjhQg2gM/tDk3DRielMIGXfOjDO iRTzxQcW6csVRREO2IHnLxcXC+UbqCk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693910122; a=rsa-sha256; cv=none; b=UuD64hqCPucl1ZRpLsGH4UIvR3ery4TYXVhaYqN5gsbf0j0jlUJpdbyrCcY0YCg2uXCDoO WjpygDWGKMAvJKAF+RacTcX+ryjfpgxxaCDH+6O+c5mXN8nY3JYi5kHumpkWB6+ScOnPMI QnXz2PB2/tg07KhcHSsfDF6CG1bhlg0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Rg1yf1Qh5zMl6g; Tue, 5 Sep 2023 18:31:54 +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 18:35:12 +0800 From: Kefeng Wang To: Andrew Morton , Mike Kravetz , Muchun Song , CC: Kefeng Wang , Yuan Can Subject: [PATCH resend] mm: hugetlb_vmemmap: use bulk allocator in alloc_vmemmap_page_list() Date: Tue, 5 Sep 2023 18:35:08 +0800 Message-ID: <20230905103508.2996474-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: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 39017C001C X-Rspam-User: X-Stat-Signature: rkk7kdcq5qxpjmcdqdyn5ohsf57c7w9g X-Rspamd-Server: rspam03 X-HE-Tag: 1693910120-739016 X-HE-Meta: U2FsdGVkX1+6G7D+AFMgpBJrWNXoZMSmKiQtArF7AV9s75b+v34hOaqMEm7xFD2rhSmUEfhfNe6estBDTLo6CD6faKs7Gh0juPup3xQql+DTUXaQ6YBxLPo+HntQ0p6eymuvYJF2J5vApCrKvLxadNXauxjIYqgdniRIdqb0s5Ra6OdoENpjBBIudifzdSZb39aePpWY7jbzBuCLKHlC7V+7pzVx6jMJ/UgZp4VHeqXXGdOFgAuslVdttjREzrFy5hg+qb8HOlSCL8q8O5spJsCa+Y8Rd4e1MDlUR0k4yQhwP97EOpZOx2HvMID2Db47EQfLFLkTM52mVmlwlupMK12vQgODuO5EFdemo4hFk4xypJ0p1H2Hcrw9FfpzOWAjHNxthjJLSKMPaezdH9NvUa3fJoOkdkgFs5m7TaTglDJc5IBSL7aj3PEvqks/qPmyx5srRE1xNtDzEvaD64Zbw9SS4/aizD01cTD1U+PlMl76NldVC8eI/Ge8kpTPSOxOUdYqpwyZ5evLAQXfA7al5PFApkatRWwIKXy+vp6blwc51/977Cz5P7BcS65e+53VkNp+Bkh9dJ45GfW38AnT4tUuxa+nJSDy3Sigt1/I5Ta+UOVmg0a2tWGL4KZPXsEpdfl/vC/CfOCRK1fmjXw0MyjeNK762A+je1qww3F7tkI1TZfxmdErFVS+1BktLjsuN1YSmUJyS2B3lbOKkae1JiZ9xWRWUV/cA+v3kyi+Gwa3fSdhdcuu7m8ZxlaOqaZtMtx2+yZkg3D7pcXUXw++JOdI1BHE4/QP6wMbfxcQL5e30LaYh68NyYKsjyt70k5sye2+LVq0dtcs3HuEcq+7oM0w4cfHXhwnT3sSS4rZVWNvzqVloOMYfEVtylFgGPFmuk02kX8Vu1wnPV88ge15/pvODGj3J6E+WrIdhUT+nmBEyYfiR7Sd+MNaMWIV8ZmJYC4uzuzOJ3RZuUqcpZb gXgUluSg cKEi9pYmAUfgiXv/ZZUZzINqfKtHWM7VLkCkF2iLVrVLFCrxN23R9QHJRPrR5MGikAzUoRD6MmhhMGX2KRyVzfIdgsIxyyQwNpjcuKF8TBn6DbsE2/qZzw2OyFkUI6DkxPgQhd9omiwrmwMSQ+DQoB4M+arwNvlfeD4RvAM28znjzIqGW+VLnMN00lW06uC1ssDrq 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, even if there is a certain fluctuation, it is still a nice improvement. Tested-by: Yuan Can Signed-off-by: Kefeng Wang Reviewed-by: Muchun Song Signed-off-by: Mel Gorman --- resend: fix allocated spell and decrease nr_pages in fallback logical include/linux/gfp.h | 9 +++++++++ mm/hugetlb_vmemmap.c | 6 ++++++ 2 files changed, 15 insertions(+) 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..786e581703c7 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -384,7 +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_allocated; + nr_allocated = alloc_pages_bulk_list_node(gfp_mask, nid, nr_pages, list); + if (!nr_allocated) + return -ENOMEM; + + nr_pages -= nr_allocated; while (nr_pages--) { page = alloc_pages_node(nid, gfp_mask, 0); if (!page)