From patchwork Fri Jul 9 09:28:31 2021
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 12367025
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level:
X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID,
DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH,
MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham
autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
by smtp.lore.kernel.org (Postfix) with ESMTP id B010CC07E9B
for ; Fri, 9 Jul 2021 09:29:01 +0000 (UTC)
Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17])
by mail.kernel.org (Postfix) with ESMTP id 379FC61241
for ; Fri, 9 Jul 2021 09:29:01 +0000 (UTC)
DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 379FC61241
Authentication-Results: mail.kernel.org;
dmarc=fail (p=none dis=none) header.from=vivo.com
Authentication-Results: mail.kernel.org;
spf=pass smtp.mailfrom=owner-linux-mm@kvack.org
Received: by kanga.kvack.org (Postfix)
id E7F756B0071; Fri, 9 Jul 2021 05:29:00 -0400 (EDT)
Received: by kanga.kvack.org (Postfix, from userid 40)
id E2F546B0072; Fri, 9 Jul 2021 05:29:00 -0400 (EDT)
X-Delivered-To: int-list-linux-mm@kvack.org
Received: by kanga.kvack.org (Postfix, from userid 63042)
id CF71F6B0073; Fri, 9 Jul 2021 05:29:00 -0400 (EDT)
X-Delivered-To: linux-mm@kvack.org
Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com
[216.40.44.221])
by kanga.kvack.org (Postfix) with ESMTP id A7DE96B0071
for ; Fri, 9 Jul 2021 05:29:00 -0400 (EDT)
Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com
[10.5.19.251])
by forelay03.hostedemail.com (Postfix) with ESMTP id D3A0280E3AC3
for ; Fri, 9 Jul 2021 09:28:59 +0000 (UTC)
X-FDA: 78342525198.19.55A4CB2
Received: from mail-m17640.qiye.163.com (mail-m17640.qiye.163.com
[59.111.176.40])
by imf15.hostedemail.com (Postfix) with SMTP id BE7F9D0000A4
for ; Fri, 9 Jul 2021 09:28:58 +0000 (UTC)
DKIM-Signature: a=rsa-sha256;
b=XAH0IEfcRfeZE7UB/65emWi7kublQJLvo590LGrtaCreJgfQ3tfTL5KYUQbqHQpCCf7fUxNcYQWtXWumlz6991kod97e02TJnGTpkApl6ZfItpt4Z0DbmbMswYCKvN8qRy4jXtehwsoX/aB6z5UBu0CXI8+zGBpRUYB/KiZ7Lnw=;
s=default; c=relaxed/relaxed; d=vivo.com; v=1;
bh=k9wd7HqyzcT7Q175fHyVzh2jv7YkhXwVzBNioWAiaPU=;
h=date:mime-version:subject:message-id:from;
Received: from NJ-11133793.vivo.xyz (unknown [36.152.145.180])
by mail-m17640.qiye.163.com (Hmail) with ESMTPA id 5558954030E;
Fri, 9 Jul 2021 17:28:56 +0800 (CST)
From: Yang Huan
To: Andrew Morton ,
linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: kernel@vivo.com,
Yang Huan
Subject: [PATCH] mm/vmalloc: try alloc_pages_bulk first to get order 0 pages
fast
Date: Fri, 9 Jul 2021 17:28:31 +0800
Message-Id: <20210709092831.10602-1-link@vivo.com>
X-Mailer: git-send-email 2.32.0
MIME-Version: 1.0
X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR
oVCBIfWUFZQklDQ1ZPTx5JHk1KTE5NSR9VEwETFhoSFyQUDg9ZV1kWGg8SFR0UWUFZT0tIVUpKS0
hKQ1VLWQY+
X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PlE6MSo6ST9CKhIcGikOUQwL
KBwaCTxVSlVKTUlOQ0lJQkhNQ0tOVTMWGhIXVRcSFRA7DRINFFUYFBZFWVdZEgtZQVlITVVKTklV
Sk9OVUpDS1lXWQgBWUFJTENPNwY+
X-HM-Tid: 0a7a8a993d71d995kuws5558954030e
Authentication-Results: imf15.hostedemail.com;
dkim=none ("invalid DKIM record") header.d=vivo.com header.s=default
header.b=XAH0IEfc;
dmarc=pass (policy=none) header.from=vivo.com;
spf=pass (imf15.hostedemail.com: domain of link@vivo.com designates
59.111.176.40 as permitted sender) smtp.mailfrom=link@vivo.com
X-Rspamd-Server: rspam02
X-Rspamd-Queue-Id: BE7F9D0000A4
X-Stat-Signature: ayc6jfdsf1gfawi5w4zcfurkm8cncfur
X-HE-Tag: 1625822938-475080
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:
Vmalloc may offen get pages by loop invoke alloc_pags, this is
cost too much time in count watermark/cpuset or something.
Let's just try alloc by alloc_pages_bulk, if failed, fullback in
original path.
With my own test, simulate loop alloc_page and alloc_pages_bulk_array,
get this:
size 1M 10M 20M 30
normal 44 1278 3665 5581
test 34 889 2167 3300
optimize 22% 30% 40% 40%
And in my vmalloc top sort, zram/f2fs may alloc more than 20MB, so,
It's worth to use alloc_pages_bulk.
Signed-off-by: Yang Huan
---
mm/vmalloc.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index a13ac524f6ff..b5af7b4e30bc 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2791,17 +2791,23 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
}
area->pages = pages;
- area->nr_pages = nr_small_pages;
+ area->nr_pages = 0;
set_vm_area_page_order(area, page_shift - PAGE_SHIFT);
page_order = vm_area_page_order(area);
-
+ /* first try alloc in alloc bulk when order is 0*/
+ if (!page_order) {
+ area->nr_pages = alloc_pages_bulk_array(
+ gfp_mask, nr_small_pages, area->pages);
+ if (likely(area->nr_pages == nr_small_pages))
+ goto success;
+ }
/*
* Careful, we allocate and map page_order pages, but tracking is done
* per PAGE_SIZE page so as to keep the vm_struct APIs independent of
* the physical/mapped size.
*/
- for (i = 0; i < area->nr_pages; i += 1U << page_order) {
+ for (i = area->nr_pages; i < nr_small_pages; i += 1U << page_order) {
struct page *page;
int p;
@@ -2824,6 +2830,8 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
if (gfpflags_allow_blocking(gfp_mask))
cond_resched();
}
+ area->nr_pages = nr_small_pages;
+success:
atomic_long_add(area->nr_pages, &nr_vmalloc_pages);
if (vmap_pages_range(addr, addr + size, prot, pages, page_shift) < 0) {