From patchwork Fri Dec 7 10:08:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 10717831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDD5E13AF for ; Fri, 7 Dec 2018 10:09:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBA942D9FD for ; Fri, 7 Dec 2018 10:09:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF7BB2DEED; Fri, 7 Dec 2018 10:09:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 325A32D9FD for ; Fri, 7 Dec 2018 10:09:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36A6A8E0002; Fri, 7 Dec 2018 05:09:16 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 31BA88E0001; Fri, 7 Dec 2018 05:09:16 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20B098E0002; Fri, 7 Dec 2018 05:09:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id D7C1F8E0001 for ; Fri, 7 Dec 2018 05:09:15 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id r16so2233417pgr.15 for ; Fri, 07 Dec 2018 02:09:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=Iu8L/42Ui3DjFUMVAfwDzdJHxKSHgadmul0P2aOWrgA=; b=MEg+WkbB1K/Pm8Br04sxo5jIWixv6pI5K+3JHeRGhAEZGLJYbXAvExFrMifoHLfeEI p5IGVxtW76JHe/faL0F8Jt7rSUDSrL5JHCkG4IX5gNT+j1gSrNeLhSixzoAedzYVbu/6 9jJn1oSuTW/pthjXTKH0T1TBnfXkzd54C7LdaDdnHn6Rz9tRpYpj0zoE7iBVyMjXo0C0 weeI+lqDMAVzwlOtKuGTz736geKGX9skC1koLYt8gdzCDbBYjkjlzEpRO06jzNsRDSNn 0VY102ohWfjjAfixnUqAZ0ic8xU8krv/nIUNNgz3KrQn0fAbSI86rOvu853H/UOI/YvK EPMw== X-Gm-Message-State: AA+aEWbjHKVffTrLsM8Q5VdsHp+M6GGKrr/JM8TMCr7vqX5E6Z2yXTKL xlVsXQUarPOKW/wmwG/HtkuxnHW2NxduA2Jlg/9pSz9ZAuEQjepdc1nZgwTkxVydJxfsWHbtplh 2adXqlCVCimybIzIU1JrLW3Jxb9Y1TwqE5HsTVOqFBVdzBCMBbe5toIOic1qBU/GP7XNNk5Sbbk C0dPL48sEAUJm5yxofVFhdd3394PicfKlpg+w2pU011J3kqBVo7DkDUQmPopVv+hjEjRCw+WGKt MvGgWkQJDpyTsrTZ/54GXnMN+UV6oqwzzvXBG1pNkkiUVeIoo00zdc/qU4cRROlbi1PeapUeGQU NjgBQVfiy3vh81YrN962jq40hLfA6PfAIWaJR/gFDenYgkHpwTt+0wIs68EXdrYf1A71Lb0+4/e i X-Received: by 2002:a63:7a5b:: with SMTP id j27mr1412569pgn.112.1544177355521; Fri, 07 Dec 2018 02:09:15 -0800 (PST) X-Received: by 2002:a63:7a5b:: with SMTP id j27mr1412527pgn.112.1544177354677; Fri, 07 Dec 2018 02:09:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544177354; cv=none; d=google.com; s=arc-20160816; b=vS8FimhbuLEJBFLHcqhqCwxClyNpGmkvqk+tD9voCjRAcwzOPiFLRom51DZwsTJS4h 8VW1/VXa9+To9gDnbclIoffERyVr/5k9u8OewZtiFUakNLc1VXnT2uY0Hd5eTmA5S2md q8j3PcKKtcaaBbeQt/GX6kl0yzl8bK0Ygp4kQv2VUsuuEf0t60rMcGH8OQz+Pc7zPab1 08xNbaT4oaTWsMBSAJULGcg8/G+w0k25UrfABzVG8zfhSn+bDjWihI2JnmG3WMcp7VNk pBqeFKtjJfY8Jm7xKQsPI2eDmUkXTvTX4qAvHLpsTKSqmPV/OAxJbyRIwPiYN9/e6/dk bgbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=Iu8L/42Ui3DjFUMVAfwDzdJHxKSHgadmul0P2aOWrgA=; b=dg1yajii/VCgevI7t7AN5N25bWt66D/t72IefK2vRKfWSzS/HHIPenPqS1VZWBS1Sa uBuaqWWfigju/Mq8hdTQFBv7AiL745ll4KOFJJGAY2auFQcQASlQFLzQ/QmispyPH5XN PZfHGBou4mHVkx54JuTAOogiagucrCMZYCH/zCTHAS37huS0r8FJezS+etYSzi+KsWiT q+EPylaxM9SK1zyRt7gDW5DpSzTBHxWXNTlQw49mtgRRSYTPp+jn67h4JQEyuRt9m+bP SHmjMBocSk044YeNsrAL1DRhr7g/Kf4U36cIzFpTi6nHKYW1V1Dd6AKpkutJdk/sLTEx XraA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="qTAnii/p"; spf=pass (google.com: domain of richard.weiyang@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id j1sor4580489plk.57.2018.12.07.02.09.14 for (Google Transport Security); Fri, 07 Dec 2018 02:09:14 -0800 (PST) Received-SPF: pass (google.com: domain of richard.weiyang@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="qTAnii/p"; spf=pass (google.com: domain of richard.weiyang@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Iu8L/42Ui3DjFUMVAfwDzdJHxKSHgadmul0P2aOWrgA=; b=qTAnii/pYMsTCUOHvehEXg9+4qD2YNSRMZ6u5CQr1pajnYVF3R6nY3IwkmfdkSRKvX ucwTRmbIykNpb6gp3hsotUir7vLjYf3wOVbh1p3wxFJ1p+aBSBIBPQ18MfDavKbNb5ll kKnkTUsKmYBjsEyFet2o81YtovCEsXsTMB1QULSZKvcGYA7RxxU3zrp30n2DPXl8J0zp p8QhCKozZY+bj9uM3SYh6JFroN4hHyVj4taqPbrNnY22+Jsg75k4D/vyYj9RHlldz4CH XMwAClAidzLUT4vfpwbMpLLLHOsYQYTcCojEGr5fWd8dADUQ9MS42j1+cxjAmBgNbRx7 LIsw== X-Google-Smtp-Source: AFSGD/WvsWYFdKZjPtvytEjMgeksElIZxdlmwCVRvhZI96shpmRVsAnXvwTGUkRQSJiylSZP511dGw== X-Received: by 2002:a17:902:f24:: with SMTP id 33mr1559422ply.65.1544177353832; Fri, 07 Dec 2018 02:09:13 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id p2sm3777570pfp.125.2018.12.07.02.09.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Dec 2018 02:09:13 -0800 (PST) From: Wei Yang To: linux-mm@kvack.org Cc: pavel.tatashin@microsoft.com, akpm@linux-foundation.org, mhocko@suse.com, Wei Yang Subject: [PATCH] mm, page_alloc: calculate first_deferred_pfn directly Date: Fri, 7 Dec 2018 18:08:59 +0800 Message-Id: <20181207100859.8999-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.15.1 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: X-Virus-Scanned: ClamAV using ClamSMTP After commit c9e97a1997fb ("mm: initialize pages on demand during boot"), the behavior of DEFERRED_STRUCT_PAGE_INIT is changed to initialize first section for highest zone on each node. Instead of test each pfn during iteration, we could calculate the first_deferred_pfn directly with necessary information. By doing so, we also get some performance benefit during bootup: +----------+-----------+-----------+--------+ | |Base |Patched |Gain | +----------+-----------+-----------+--------+ | 1 Node |0.011993 |0.011459 |-4.45% | +----------+-----------+-----------+--------+ | 4 Nodes |0.006466 |0.006255 |-3.26% | +----------+-----------+-----------+--------+ Test result is retrieved from dmesg time stamp by add printk around free_area_init_nodes(). Signed-off-by: Wei Yang Signed-off-by: Wei Yang Signed-off-by: Andrew Morton --- mm/page_alloc.c | 57 +++++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index baf473f80800..5f077bf07f3e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -306,38 +306,33 @@ static inline bool __meminit early_page_uninitialised(unsigned long pfn) } /* - * Returns true when the remaining initialisation should be deferred until - * later in the boot cycle when it can be parallelised. + * Calculate first_deferred_pfn in case: + * - in MEMMAP_EARLY context + * - this is the last zone + * + * If the first aligned section doesn't exceed the end_pfn, set it to + * first_deferred_pfn and return it. */ -static bool __meminit -defer_init(int nid, unsigned long pfn, unsigned long end_pfn) +unsigned long __meminit +defer_pfn(int nid, unsigned long start_pfn, unsigned long end_pfn, + enum memmap_context context) { - static unsigned long prev_end_pfn, nr_initialised; + struct pglist_data *pgdat = NODE_DATA(nid); + unsigned long pfn; - /* - * prev_end_pfn static that contains the end of previous zone - * No need to protect because called very early in boot before smp_init. - */ - if (prev_end_pfn != end_pfn) { - prev_end_pfn = end_pfn; - nr_initialised = 0; - } + if (context != MEMMAP_EARLY) + return end_pfn; - /* Always populate low zones for address-constrained allocations */ - if (end_pfn < pgdat_end_pfn(NODE_DATA(nid))) - return false; + /* Always populate low zones */ + if (end_pfn < pgdat_end_pfn(pgdat)) + return end_pfn; - /* - * We start only with one section of pages, more pages are added as - * needed until the rest of deferred pages are initialized. - */ - nr_initialised++; - if ((nr_initialised > PAGES_PER_SECTION) && - (pfn & (PAGES_PER_SECTION - 1)) == 0) { - NODE_DATA(nid)->first_deferred_pfn = pfn; - return true; + pfn = roundup(start_pfn + PAGES_PER_SECTION - 1, PAGES_PER_SECTION); + if (end_pfn > pfn) { + pgdat->first_deferred_pfn = pfn; + end_pfn = pfn; } - return false; + return end_pfn; } #else static inline bool early_page_uninitialised(unsigned long pfn) @@ -345,9 +340,11 @@ static inline bool early_page_uninitialised(unsigned long pfn) return false; } -static inline bool defer_init(int nid, unsigned long pfn, unsigned long end_pfn) +unsigned long __meminit +defer_pfn(int nid, unsigned long start_pfn, unsigned long end_pfn, + enum memmap_context context) { - return false; + return end_pfn; } #endif @@ -5514,6 +5511,8 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, } #endif + end_pfn = defer_pfn(nid, start_pfn, end_pfn, context); + for (pfn = start_pfn; pfn < end_pfn; pfn++) { /* * There can be holes in boot-time mem_map[]s handed to this @@ -5526,8 +5525,6 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, continue; if (overlap_memmap_init(zone, &pfn)) continue; - if (defer_init(nid, pfn, end_pfn)) - break; } page = pfn_to_page(pfn);