From patchwork Wed Sep 26 23:28:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10617041 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 63BD1175A for ; Wed, 26 Sep 2018 23:29:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 501872B1E5 for ; Wed, 26 Sep 2018 23:29:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 415582B1EB; Wed, 26 Sep 2018 23:29:55 +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=-2.9 required=2.0 tests=BAYES_00,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 8C5942B1E5 for ; Wed, 26 Sep 2018 23:29:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DF338E0008; Wed, 26 Sep 2018 19:29:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 98E468E0001; Wed, 26 Sep 2018 19:29:53 -0400 (EDT) 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 8A4FE8E0008; Wed, 26 Sep 2018 19:29:53 -0400 (EDT) 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 4BA9F8E0001 for ; Wed, 26 Sep 2018 19:29:53 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id 77-v6so772741pgg.0 for ; Wed, 26 Sep 2018 16:29:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=VbI0oypiNuBd2J+fDxXjgmQgjmKW+0JuD3bnq1+BaS4=; b=BDM2+S3KgxUMYYLuHjaFwxAJSlziiuWOx5PghthSAyp5X5E9FLJx02NiTtQLT121xD /YMKwmOu0oixq6FmaSv5+9sIvmJyI4yENAu+ZAYBqfPaFuw3uHWnSY0QSnEpvEQE0q7V CnJR1XN9L4WhJXwwmrUnJ7fYDtXCcDLF0jvSZXPQ5THojiaPZ3Lc5Tjw6M8gknK9jVDD wpN45F+6CyTpxb3c3ado0YHaHtmdgSfEEstkcEnEagZXrNdgzmE6kZGIh29orRKL8SKm gfSRJEraUm/hJReYCrMRI5K7ywkfNrL1IuSX2CB7eZgUb6iHh8ylplIeo2Dmg1xkT8p/ d48Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ABuFfoiK8vThnaI/o5MPh3hHO9doKjNdfdSCJD4PX2GLVFptksbcMNmV 6XmBq0sa3hSi3bUhK1cpaeEYbrCSFJx8r/kzMyxVbb6A0map0ffN61E0XzF0WTraxyNmvKa7gdY /l+e9KSkrrXpHnlKDLd4+tvE4tCZIsFtjiEPEKmxTAXHutG+hCjuwh7vct55bEK3vlw== X-Received: by 2002:a63:1e19:: with SMTP id e25-v6mr7605396pge.44.1538004592963; Wed, 26 Sep 2018 16:29:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV60aqsGtCcPXUrTvytCqjBUZRZI9wa2sI0Cfw/fDPHSuRgQzFVMR+LxYzv0iwhqZCFW9siYT X-Received: by 2002:a63:1e19:: with SMTP id e25-v6mr7605357pge.44.1538004591952; Wed, 26 Sep 2018 16:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538004591; cv=none; d=google.com; s=arc-20160816; b=h06n2dArTa8vz5Fvdxu4o3Yk6TtWFQmvOyR5T2MZhvqoOZb3btDkrPhUO8+wexMGJj OwMFxNi9nNeLT2Jc0f9SgQg5QXitvZYPeeg+yEB410jjNZMi8RNLvOiJ9YrehIBCXXUx dKBcFZXbontfhxBuGh99lEdPRkJ85ki2oeA2eAY5jzj9P6ItYRt7FaGVvhcgQ+kJZtov 2Hu3IGmI5GMBueS8pRXND4A+lAH/k/9DoJtjhZuAwvlCTUStOjdPOWTnia6R6K1K6ufx uYCiqaw7yqCbGw/MD50/9b6qIllKkyiXaoAAhzpVUZSDpc9IDno09upPxjvf1wNRX7x/ YXOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject; bh=VbI0oypiNuBd2J+fDxXjgmQgjmKW+0JuD3bnq1+BaS4=; b=lzsmLINOEXArBbC3B84TL+64ieBQBC4V+4My007e0vgNAXDi5mKeEUftm8K92T0fzZ +B+i/qH7CEI0RMYqEAtN/ks1kb8FGTcNZJbaG03CmLUj8r9CqgraWKJzzEsaMr8TMjfo vApz6f/slKOhcTQwCxONAepoPAFZ2sqLKDE1SSYGHYk5rvpgDrVFIRa2WwO9y2td2SB+ yJPls/smyLuKULex2a8i2uP8C79bPDgv0JGIZJosxW2lQw9raqPKMmIK5gevPf72wwgb hkGtzM1G0tsXMLFmd/pyij1u6zGgRC9ZNYeId5BYNMw3Hz8uNq+rrqD6uNPjsDejczLE ccJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga12.intel.com (mga12.intel.com. [192.55.52.136]) by mx.google.com with ESMTPS id j9-v6si280914pll.407.2018.09.26.16.29.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Sep 2018 16:29:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.136 as permitted sender) client-ip=192.55.52.136; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of alexander.h.duyck@linux.intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=alexander.h.duyck@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Sep 2018 16:29:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,308,1534834800"; d="scan'208";a="86873237" Received: from ahduyck-mobl.amr.corp.intel.com (HELO localhost.localdomain) ([10.7.198.154]) by orsmga003.jf.intel.com with ESMTP; 26 Sep 2018 16:28:49 -0700 Subject: [RFC mm PATCH 5/5] mm: Use common iterator for deferred_init_pages and deferred_free_pages From: Alexander Duyck To: sparclinux@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: pavel.tatashin@microsoft.com, mhocko@suse.com, dave.jiang@intel.com, alexander.h.duyck@linux.intel.com, dan.j.williams@intel.com, willy@infradead.org, mingo@kernel.org, khalid.aziz@oracle.com, rppt@linux.vnet.ibm.com, vbabka@suse.cz, akpm@linux-foundation.org, ldufour@linux.vnet.ibm.com, davem@davemloft.net, kirill.shutemov@linux.intel.com Date: Wed, 26 Sep 2018 16:28:49 -0700 Message-ID: <20180926232849.17365.28850.stgit@localhost.localdomain> In-Reply-To: <20180926232117.17365.72207.stgit@localhost.localdomain> References: <20180926232117.17365.72207.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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 This patch creates a common iterator to be used by both deferred_init_pages and deferred_free_pages. By doing this we can cut down a bit on code overhead as they will likely both be inlined into the same function anyway. This new approach allows deferred_init_pages to make use of __init_pageblock. By doing this we can cut down on the code size by sharing code between both the hotplug and deferred memory init code paths. An additional benefit to this approach is that we improve in cache locality of the memory init as we can focus on the memory areas related to identifying if a given PFN is valid and keep that warm in the cache until we transition to a region of a different type. So we will stream through a chunk of valid blocks before we turn to initializing page structs. Signed-off-by: Alexander Duyck --- mm/page_alloc.c | 134 +++++++++++++++++++++++++++---------------------------- 1 file changed, 65 insertions(+), 69 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 1baea475f296..815ce793c73d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1480,32 +1480,6 @@ void clear_zone_contiguous(struct zone *zone) } #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT -static void __init deferred_free_range(unsigned long pfn, - unsigned long nr_pages) -{ - struct page *page; - unsigned long i; - - if (!nr_pages) - return; - - page = pfn_to_page(pfn); - - /* Free a large naturally-aligned chunk if possible */ - if (nr_pages == pageblock_nr_pages && - (pfn & (pageblock_nr_pages - 1)) == 0) { - set_pageblock_migratetype(page, MIGRATE_MOVABLE); - __free_pages_boot_core(page, pageblock_order); - return; - } - - for (i = 0; i < nr_pages; i++, page++, pfn++) { - if ((pfn & (pageblock_nr_pages - 1)) == 0) - set_pageblock_migratetype(page, MIGRATE_MOVABLE); - __free_pages_boot_core(page, 0); - } -} - /* Completion tracking for deferred_init_memmap() threads */ static atomic_t pgdat_init_n_undone __initdata; static __initdata DECLARE_COMPLETION(pgdat_init_all_done_comp); @@ -1517,48 +1491,77 @@ static inline void __init pgdat_init_report_one_done(void) } /* - * Returns true if page needs to be initialized or freed to buddy allocator. + * Returns count if page range needs to be initialized or freed * - * First we check if pfn is valid on architectures where it is possible to have - * holes within pageblock_nr_pages. On systems where it is not possible, this - * function is optimized out. + * First, we check if a current large page is valid by only checking the + * validity of the head pfn. * - * Then, we check if a current large page is valid by only checking the validity - * of the head pfn. + * Then we check if the contiguous pfns are valid on architectures where it + * is possible to have holes within pageblock_nr_pages. On systems where it + * is not possible, this function is optimized out. */ -static inline bool __init deferred_pfn_valid(unsigned long pfn) +static unsigned long __next_pfn_valid_range(unsigned long *i, + unsigned long end_pfn) { - if (!pfn_valid_within(pfn)) - return false; - if (!(pfn & (pageblock_nr_pages - 1)) && !pfn_valid(pfn)) - return false; - return true; + unsigned long pfn = *i; + unsigned long count; + + while (pfn < end_pfn) { + unsigned long t = ALIGN(pfn + 1, pageblock_nr_pages); + unsigned long pageblock_pfn = min(t, end_pfn); + +#ifndef CONFIG_HOLES_IN_ZONE + count = pageblock_pfn - pfn; + pfn = pageblock_pfn; + if (!pfn_valid(pfn)) + continue; +#else + for (count = 0; pfn < pageblock_pfn; pfn++) { + if (pfn_valid_within(pfn)) { + count++; + continue; + } + + if (count) + break; + } + + if (!count) + continue; +#endif + *i = pfn; + return count; + } + + return 0; } +#define for_each_deferred_pfn_valid_range(i, start_pfn, end_pfn, pfn, count) \ + for (i = (start_pfn), \ + count = __next_pfn_valid_range(&i, (end_pfn)); \ + count && ({ pfn = i - count; 1; }); \ + count = __next_pfn_valid_range(&i, (end_pfn))) /* * Free pages to buddy allocator. Try to free aligned pages in * pageblock_nr_pages sizes. */ -static void __init deferred_free_pages(unsigned long pfn, +static void __init deferred_free_pages(unsigned long start_pfn, unsigned long end_pfn) { - unsigned long nr_pgmask = pageblock_nr_pages - 1; - unsigned long nr_free = 0; - - for (; pfn < end_pfn; pfn++) { - if (!deferred_pfn_valid(pfn)) { - deferred_free_range(pfn - nr_free, nr_free); - nr_free = 0; - } else if (!(pfn & nr_pgmask)) { - deferred_free_range(pfn - nr_free, nr_free); - nr_free = 1; - touch_nmi_watchdog(); + unsigned long i, pfn, count; + + for_each_deferred_pfn_valid_range(i, start_pfn, end_pfn, pfn, count) { + struct page *page = pfn_to_page(pfn); + + if (count == pageblock_nr_pages) { + __free_pages_boot_core(page, pageblock_order); } else { - nr_free++; + while (count--) + __free_pages_boot_core(page++, 0); } + + touch_nmi_watchdog(); } - /* Free the last block of pages to allocator */ - deferred_free_range(pfn - nr_free, nr_free); } /* @@ -1567,29 +1570,22 @@ static void __init deferred_free_pages(unsigned long pfn, * Return number of pages initialized. */ static unsigned long __init deferred_init_pages(struct zone *zone, - unsigned long pfn, + unsigned long start_pfn, unsigned long end_pfn) { - unsigned long nr_pgmask = pageblock_nr_pages - 1; + unsigned long i, pfn, count; int nid = zone_to_nid(zone); unsigned long nr_pages = 0; int zid = zone_idx(zone); - struct page *page = NULL; - for (; pfn < end_pfn; pfn++) { - if (!deferred_pfn_valid(pfn)) { - page = NULL; - continue; - } else if (!page || !(pfn & nr_pgmask)) { - page = pfn_to_page(pfn); - touch_nmi_watchdog(); - } else { - page++; - } - __init_single_page(page, pfn, zid, nid); - nr_pages++; + for_each_deferred_pfn_valid_range(i, start_pfn, end_pfn, pfn, count) { + nr_pages += count; + __init_pageblock(pfn, count, zid, nid, NULL, false); + + touch_nmi_watchdog(); } - return (nr_pages); + + return nr_pages; } /*