From patchwork Tue Jul 17 10:56:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10528949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9CE3600F4 for ; Tue, 17 Jul 2018 10:57:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6DF9283D1 for ; Tue, 17 Jul 2018 10:57:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAD4A28429; Tue, 17 Jul 2018 10:57:01 +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 44482283D1 for ; Tue, 17 Jul 2018 10:57:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0145F6B000D; Tue, 17 Jul 2018 06:56:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EAAC66B0266; Tue, 17 Jul 2018 06:56:56 -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 CFF0F6B0269; Tue, 17 Jul 2018 06:56:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 655CB6B000D for ; Tue, 17 Jul 2018 06:56:56 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id g9-v6so268206wrq.7 for ; Tue, 17 Jul 2018 03:56:56 -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:from:to:cc :subject:date:message-id:in-reply-to:references; bh=GRN6BVIjhi4Szt9i0nsQJEBXG+lbTWrcyANSNDxqxJY=; b=a7QDWkuvkkMDMvWofGnoPwsKNVx/ElHNUgU9EU4xOIoY+3lRNfP94bMcbqyqedqhBT X55ZpckY/lfzHFF3sQoJmdXFQm7Pjtp8S0KGm7I4YiHSJhISLnPbsY/zEd0Se9eLlIca X43wpTNXTt6257YIuHDMVt9gKAxvNFZNYs328ihbqpwxiBy4d1Eg6cJ8G1kFGu2FnmIx wDn1ufSrr6pmb56ur4ONbE43XvVhdMjGljn2EbAInaaQ9YuindVc3+MQOZO9XAjdP0n1 DNWXR7VV5pF1Pp+1sfnpTE2AWCTTNtRxb5dN3QZ32VQ+UlKlykonGjCo+WPRKzC+H8Nl L5jg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Gm-Message-State: AOUpUlEKDyAefM5FQO1R1kMfvVA7LemQEk1lt7RuFNWSMcX6WzQgFyY0 CIlyJnlHA9tyTbZUbHDa5ILDZKPevYjpzpqW07bYNbi7Ys9pH81Jsvf0Bq408ZRDTC/mHBAWjw2 YECjPZKaWbypL/XOSEtTvFw+pXZW9X3HM8lsEDqUQih86gzYFlyPUUEvwCcFuqpMx33SN3q94Ik lMjoxs+617l3qNp9E2O61w3EQkBolXfglUDkyhP/BNNNlWJhlwpG03UDgebOtNq5wBLm6GW4FHM QNnA4MJ2YBQScM0+xI9j9MJtsxbVCOQFeysEhISxt7/HF3JTd27Pe2WqTcFFPQQHElZTTih+sYa cODtEE5+NuTH8r445QiovmzsfsyO4DRVXgI28zV3a3sMnA4NNchni6nTqCkupV6nqHVc+BHKog= = X-Received: by 2002:a1c:3e8e:: with SMTP id l136-v6mr978102wma.45.1531825015892; Tue, 17 Jul 2018 03:56:55 -0700 (PDT) X-Received: by 2002:a1c:3e8e:: with SMTP id l136-v6mr978073wma.45.1531825015113; Tue, 17 Jul 2018 03:56:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531825015; cv=none; d=google.com; s=arc-20160816; b=yD9hgUiatlbJ68gL7B9nZ0PnLR1aIqoe1Gys9qKEztMOPtpeFwUlelx0zEK9+Ag0nu sHwDN9D39F06orbzNs3GY3l79f4EdUQePMDGOLY0Fq/qaCFKemDCRKSd5PTdCEI0g9tg cEkiIj4oTyVG7VIwnCP19P2W65Cm4KPVTZuScZ9dcSmJQqVbYk2i7Uxxga8Q4Xoq5fDa 1h0BkD4H5UQLRlwl0gfXpAtYGTnZQYCP9uy5FD2kZFwl2NmUinOFxbesg+ljx0kzX6kT Kjundb9lWW7RWFD58iF+56DKEWMHNshhZ1LDL3gm0UXcz9HTh9/Kv2jWK5dw0ua7MDaT 2Wpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=GRN6BVIjhi4Szt9i0nsQJEBXG+lbTWrcyANSNDxqxJY=; b=Fz1rjGkbd2RLK539kGTMW+2SixOODjpPfzF3AG7Rp/ejRrQ24m2lO7S1ecrJOvip38 dFXOi26iKxCy+zXkRweVBef17i1yRo+XQ7dAa7G1j31B8x8Mm4GkxBigtQ2FpZiVtSDn pVdAsm3pTOYcYvnfbmLnfb+GZ9hHFR6ajka5mqGkNCYYaki9nA5dAmw1pwlPPNzx5S9N 4BfHnQzCOeyFQyCwsIhWVxNvqi5txxSQw+LeeuVBL6DZhnfb++xCAsytZhp6X43CQhec rjwzxlMf9RMnGFwbPhC+KgqGRzU0bOib+G9wf+tSmJnpSSF93KgZDfhKlrEe0hxr7ZVf 7NHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@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 n15-v6sor334253wrg.22.2018.07.17.03.56.54 for (Google Transport Security); Tue, 17 Jul 2018 03:56:55 -0700 (PDT) Received-SPF: pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Google-Smtp-Source: AAOMgpfPvxzQhqIe9tUCH8KFopSdCeYkO4zUFi3ME0K5mjlQW7+HjBIVXX4D6pfcC8O5dvAbE3X4rQ== 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> 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 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); + } } }