Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp487643imm; Wed, 18 Jul 2018 05:49:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcQeIZXM4dD8UICQmXmMsP1/F+cxjytLXe0qMTLgPck8mRWcosYmI/vVZPmswuR1VP2ZeqO X-Received: by 2002:a17:902:be0d:: with SMTP id r13-v6mr5750283pls.299.1531918185392; Wed, 18 Jul 2018 05:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531918185; cv=none; d=google.com; s=arc-20160816; b=F6INVhfIkPx02K8WVkK8PISr8k9GUPMQYBoDul+8CT+8NibdzQYeRKKmXGgtznAQ5T 0GDnplBwNLVyuUVdjF3Xo04EF00S4ukkxtT7/eggV4JR3BHgmki8azsJfZZcV8+E9G/P EsoMstfOeztx8A1nhuKKGQ01YJvFugxnNycOcqd06RAm2OKvGFkfJRdXBWunBZjA3EBl 83BpU1xdtZfu9hef1TU03Rvhcq9MHIxZ/+/ZmimnsBGmEYDOULpwIvkaQJDa3BwR5nLY Jba6qP2/nS/2qw2FQW7V1NP+M2xIaoiOI2HAsOo4LF17/0rvnbsM9DnklRQ7BARAAZuB 3wqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=G/5O9NHC2sSQXY1D1Puqte8VarWZHIWWUCI1iuNEE64=; b=uYd8JGQgAPdyzJRUfeOk/DSpsfaN/AJI9PIefs7LKlvJMi/Bda/YjeDKYpN7BQLk7F wOVBxCt+b1Nxk1FPd7BrtvO/VAq7er69CwqZpiWzYE8dqriAKYwMZeqhqPov2fp75Gcl /tc6oO2eRAa8uwPsyWt38g7R7ETMF4CZD0BV6TLAzRCJFGR592B9wLlK3Za4Ijq3IsEn 31mZ6ab6AFBOwwMp7DDDPDVN75vVVavk35EhoMAKgln8dXSXh47Iia0UPzIWrZyfH0AC 8ev1z3M74z+yfJ+kB2g8pykbe5LCxor6UnHS2aorMdFmOZTKmvorOMm4HaoxhA3WO7eW 5sOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s1-v6si3331994pfi.369.2018.07.18.05.49.30; Wed, 18 Jul 2018 05:49:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731175AbeGRNZ2 (ORCPT + 99 others); Wed, 18 Jul 2018 09:25:28 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:51303 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729263AbeGRNZ1 (ORCPT ); Wed, 18 Jul 2018 09:25:27 -0400 Received: by mail-wm0-f67.google.com with SMTP id h3-v6so2259326wmb.1 for ; Wed, 18 Jul 2018 05:47:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G/5O9NHC2sSQXY1D1Puqte8VarWZHIWWUCI1iuNEE64=; b=nhfRo4lgUxhqzgCv6KLtOcOCbyjPl3qu7fqxlXcoS7E7nee/JLp9JMKORC1onM4XSy scfmRJu4L1pijjKpN61A4D9Tle8bsES+Lok7v9lYTwLsxIP8cvn6GObuM0Fbw2927kAg 2huVJ8xwdjON+HVDt1RLv/rPQ/dmiy+PfNm5M48Z9AxVqkjZbhJ9sUvRaSOVhP5hAjIw OZzkMT1wnLcwqXvex3Dkl9+8mmFC6LO62sOUsVWoesSUuTYblzTQqppMi+VH2Zj3+ifs Wyxm/K9cFpM/1wb/iDy21vYhROsRShtyQbfk+pfWif9oKjXZFkX1/m4BNkosEgFmZYOR NDuQ== X-Gm-Message-State: AOUpUlEatCDS0lt2cCyq2z26fsdLpjmrg1VRM/QF2E0cXYxt9AmuYfvp qDZQZflkt9l7+H1jfdlT6Wk= X-Received: by 2002:a1c:69d2:: with SMTP id z79-v6mr1597964wmh.92.1531918058691; Wed, 18 Jul 2018 05:47:38 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id g10-v6sm4754781wru.43.2018.07.18.05.47.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 05:47:37 -0700 (PDT) Received: from d104.suse.de (nat.nue.novell.com [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 676C21240C6; Wed, 18 Jul 2018 14:47:36 +0200 (CEST) From: osalvador@techadventures.net To: akpm@linux-foundation.org Cc: pasha.tatashin@oracle.com, mhocko@suse.com, vbabka@suse.cz, iamjoonsoo.kim@lge.com, aaron.lu@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Oscar Salvador Subject: [PATCH 2/3] mm/page_alloc: Refactor free_area_init_core Date: Wed, 18 Jul 2018 14:47:21 +0200 Message-Id: <20180718124722.9872-3-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180718124722.9872-1-osalvador@techadventures.net> References: <20180718124722.9872-1-osalvador@techadventures.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oscar Salvador When free_area_init_core gets called from the memhotplug code, we only need to perform some of the operations in there. Since memhotplug code is the only place where free_area_init_core gets called while node being still offline, we can better separate the context from where it is called. This patch re-structures the code for that purpose. Signed-off-by: Oscar Salvador --- mm/page_alloc.c | 94 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 42 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8a73305f7c55..d652a3ad720c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6237,6 +6237,40 @@ static void pgdat_init_kcompactd(struct pglist_data *pgdat) static void pgdat_init_kcompactd(struct pglist_data *pgdat) {} #endif +static unsigned long calc_remaining_pages(enum zone_type type, unsigned long freesize, + unsigned long size) +{ + unsigned long memmap_pages = calc_memmap_size(size, freesize); + + if(!is_highmem_idx(type)) { + if (freesize >= memmap_pages) { + freesize -= memmap_pages; + if (memmap_pages) + printk(KERN_DEBUG + " %s zone: %lu pages used for memmap\n", + zone_names[type], memmap_pages); + } else + pr_warn(" %s zone: %lu pages exceeds freesize %lu\n", + zone_names[type], memmap_pages, freesize); + } + + /* Account for reserved pages */ + if (type == 0 && freesize > dma_reserve) { + freesize -= dma_reserve; + printk(KERN_DEBUG " %s zone: %lu pages reserved\n", + zone_names[0], dma_reserve); + } + + if (!is_highmem_idx(type)) + nr_kernel_pages += freesize; + /* Charge for highmem memmap if there are enough kernel pages */ + else if (nr_kernel_pages > memmap_pages * 2) + nr_kernel_pages -= memmap_pages; + nr_all_pages += freesize; + + return freesize; +} + /* * Set up the zone data structures: * - mark all pages reserved @@ -6249,6 +6283,7 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) { enum zone_type j; int nid = pgdat->node_id; + bool no_hotplug_context; pgdat_resize_init(pgdat); @@ -6265,45 +6300,18 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) pgdat->per_cpu_nodestats = &boot_nodestats; + /* Memhotplug is the only place where free_area_init_node gets called + * with the node being still offline. + */ + no_hotplug_context = node_online(nid); + for (j = 0; j < MAX_NR_ZONES; j++) { struct zone *zone = pgdat->node_zones + j; - unsigned long size, freesize, memmap_pages; - unsigned long zone_start_pfn = zone->zone_start_pfn; + unsigned long size = zone->spanned_pages; + unsigned long freesize = zone->present_pages; - size = zone->spanned_pages; - freesize = zone->present_pages; - - /* - * Adjust freesize so that it accounts for how much memory - * is used by this zone for memmap. This affects the watermark - * and per-cpu initialisations - */ - memmap_pages = calc_memmap_size(size, freesize); - if (!is_highmem_idx(j)) { - if (freesize >= memmap_pages) { - freesize -= memmap_pages; - if (memmap_pages) - printk(KERN_DEBUG - " %s zone: %lu pages used for memmap\n", - zone_names[j], memmap_pages); - } else - pr_warn(" %s zone: %lu pages exceeds freesize %lu\n", - zone_names[j], memmap_pages, freesize); - } - - /* Account for reserved pages */ - if (j == 0 && freesize > dma_reserve) { - freesize -= dma_reserve; - printk(KERN_DEBUG " %s zone: %lu pages reserved\n", - zone_names[0], dma_reserve); - } - - if (!is_highmem_idx(j)) - nr_kernel_pages += freesize; - /* Charge for highmem memmap if there are enough kernel pages */ - else if (nr_kernel_pages > memmap_pages * 2) - nr_kernel_pages -= memmap_pages; - nr_all_pages += freesize; + if (no_hotplug_context) + freesize = calc_remaining_pages(j, freesize, size); /* * Set an approximate value for lowmem here, it will be adjusted @@ -6311,6 +6319,7 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) * And all highmem pages will be managed by the buddy system. */ zone->managed_pages = freesize; + #ifdef CONFIG_NUMA zone->node = nid; #endif @@ -6320,13 +6329,14 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) zone_seqlock_init(zone); zone_pcp_init(zone); - if (!size) - continue; + if (size && no_hotplug_context) { + unsigned long zone_start_pfn = zone->zone_start_pfn; - set_pageblock_order(); - setup_usemap(pgdat, zone, zone_start_pfn, size); - init_currently_empty_zone(zone, zone_start_pfn, size); - memmap_init(size, nid, j, zone_start_pfn); + set_pageblock_order(); + setup_usemap(pgdat, zone, zone_start_pfn, size); + init_currently_empty_zone(zone, zone_start_pfn, size); + memmap_init(size, nid, j, zone_start_pfn); + } } } -- 2.13.6