Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3378575imm; Tue, 17 Jul 2018 03:59:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf7tk/5GpBWxBcsUmtVWyUbH4GYs0cnYBpx4rW3R0hW4/4r+uUY7krLAH+LB7QQb42VJtB1 X-Received: by 2002:a63:2644:: with SMTP id m65-v6mr1085876pgm.371.1531825159855; Tue, 17 Jul 2018 03:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531825159; cv=none; d=google.com; s=arc-20160816; b=M6x3xNMMxMLzBz74Q0aNMZXfYwku5Ckb2t1xhn7s0VznQbngU2ja0sUmshQJiwOMsr wGp9Uc/d0n1rGmZYB/0PsPqrkOVzU4luCCGeFH54yva7Z4wvRVQ1u6Q5/O6GIHfp6R6w MZP/rmEqaUbGc/KwFOXTuMcoNR7vieNnzKvz5PEQerzScEiV3z8DKlVC3y/D9S4cYN8u qhBFlU32/C/2WiPNBN1veKnk4VkumAr7bxUdY//I5bQHGKm+fK5VoGg5qgORSmEcfkz5 e3A83L9+uOgpj1MsMtrz6w0Tqv80zfhMhULzUIizLG4kVGX8jPrAxGLSTPQtjuNcfEO4 himA== 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=GRN6BVIjhi4Szt9i0nsQJEBXG+lbTWrcyANSNDxqxJY=; b=HWX9JbGp5buOo8+GYXHNawqNV21g3YtOS84bDmcwEU2HPoshpEX3E1+46qVHUCEFXA cblhSpzdT5CX0K7fBcVjvFRlhVA/rTf2++XvBKkXkmdSMYNWxBsSyrvz1vZZ1eeYJQ7m PMJgTzIy97VoQMlwW9rcZwm1rl6+YjSTaPvH+jfzUS7Tkg6dMVVhBkLJG+CS0gIRTxWp 1vaF+6FEf0d6HSByS6tu8tMJPn+Sjlj877/mLF4a7Ni8JZmfCI1blhEWHBejVG5z1GP7 V/tbUp1CSvmkGUtFVljF/KmdxvdENpnTFxN3XUjXnCV3NrByc0fA0i0ht/Q9zY0rOn9F 5Log== 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 x130-v6si713708pgx.207.2018.07.17.03.59.04; Tue, 17 Jul 2018 03:59:19 -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 S1731205AbeGQL3A (ORCPT + 99 others); Tue, 17 Jul 2018 07:29:00 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38524 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730301AbeGQL27 (ORCPT ); Tue, 17 Jul 2018 07:28:59 -0400 Received: by mail-wr1-f67.google.com with SMTP id v14-v6so801229wro.5 for ; Tue, 17 Jul 2018 03:56:55 -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=GRN6BVIjhi4Szt9i0nsQJEBXG+lbTWrcyANSNDxqxJY=; b=TSwxCFCvYiksyxwxOuQl6kMC2Pho/cKolC79IMLp+RTOWAPL2zPVmY/ZkannE2IBLv zlxD3s+J38oQRQYzalBMjQQHHDAO+ogaX0ZpEXN+vBMAB5ZVKTTKGxqZS9nwV/pjyWVh QMq7eM9mVOhaaT8XLxs/OO1MPf++8HxSVJIchvCbeXnt1dYbe5HAoYioswH8Sxsw9o8N 7RABDhGeV9ohOs0xT4SWTi9ijRKDU/2qf/KCTgPRP2+pBPXq/FVHeuQerJFYvPjNx2lE VkOLU4SWv/3SuOPQpOM/IEcovfsC8xu0aBSiBY/cazoa6EH3od2+rVCauTWZzKVXGLo7 5M2w== X-Gm-Message-State: AOUpUlHrbn/6vcQBOjC+xbJtz/WcMlUIgyNLuce6vLYmLv81aa8A7fGw 8rEc2313uQuYPaKJ1foGI3M= X-Received: by 2002:adf:c684:: with SMTP id j4-v6mr1013222wrg.243.1531825014840; Tue, 17 Jul 2018 03:56:54 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id q140-v6sm1491748wmb.35.2018.07.17.03.56.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 03:56:54 -0700 (PDT) Received: from d104.suse.de (nat.nue.novell.com [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id C757F123FFB; Tue, 17 Jul 2018 12:56:52 +0200 (CEST) From: osalvador@techadventures.net To: linux-mm@kvack.org Cc: pasha.tatashin@oracle.com, mhocko@suse.com, vbabka@suse.cz, akpm@linux-foundation.org, aaron.lu@intel.com, iamjoonsoo.kim@lge.com, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH 2/3] mm: Refactor free_area_init_core Date: Tue, 17 Jul 2018 12:56:21 +0200 Message-Id: <20180717105622.12410-3-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180717105622.12410-1-osalvador@techadventures.net> References: <20180717105622.12410-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 do not really need to go through all memmap calculations. This structures the code a bit better. Signed-off-by: Oscar Salvador --- mm/page_alloc.c | 106 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8a73305f7c55..3bf939393ca1 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6237,6 +6237,42 @@ static void pgdat_init_kcompactd(struct pglist_data *pgdat) static void pgdat_init_kcompactd(struct pglist_data *pgdat) {} #endif +static void calculate_pages(enum zone_type type, unsigned long *freesize, + unsigned long size) +{ + /* + * 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 + */ + 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); + } + + 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; +} + /* * Set up the zone data structures: * - mark all pages reserved @@ -6267,50 +6303,7 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) 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; - - 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; - - /* - * Set an approximate value for lowmem here, it will be adjusted - * when the bootmem allocator frees pages into the buddy system. - * And all highmem pages will be managed by the buddy system. - */ - zone->managed_pages = freesize; #ifdef CONFIG_NUMA zone->node = nid; #endif @@ -6320,13 +6313,28 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) zone_seqlock_init(zone); zone_pcp_init(zone); - if (!size) - continue; + if(system_state == SYSTEM_BOOTING) { + unsigned long size, freesize; + 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); + size = zone->spanned_pages; + freesize = zone->present_pages; + calculate_pages(j, &freesize, size); + + /* + * Set an approximate value for lowmem here, it will be adjusted + * when the bootmem allocator frees pages into the buddy system. + * And all highmem pages will be managed by the buddy system. + */ + zone->managed_pages = freesize; + if (!size) + continue; + + 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