From patchwork Wed Jul 18 12:47: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: 10532425 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 2A2EE601D2 for ; Wed, 18 Jul 2018 12:47:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CFAF2915C for ; Wed, 18 Jul 2018 12:47:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10E1029162; Wed, 18 Jul 2018 12:47:48 +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 8935A2915C for ; Wed, 18 Jul 2018 12:47:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95B7F6B000E; Wed, 18 Jul 2018 08:47:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 90D4B6B0266; Wed, 18 Jul 2018 08:47:40 -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 8001E6B0010; Wed, 18 Jul 2018 08:47:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f69.google.com (mail-wm0-f69.google.com [74.125.82.69]) by kanga.kvack.org (Postfix) with ESMTP id 2063F6B000E for ; Wed, 18 Jul 2018 08:47:40 -0400 (EDT) Received: by mail-wm0-f69.google.com with SMTP id q8-v6so1023235wmc.2 for ; Wed, 18 Jul 2018 05:47:40 -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=G/5O9NHC2sSQXY1D1Puqte8VarWZHIWWUCI1iuNEE64=; b=Z2O93lPHqIQrSskSxf9TzOw6X5b9sCkKYaVaoNYlEdqpMoKGz4J8OrsDNVD6xouLqv 8VO6O3e529dVcPi68jlBQNWQAZZkbG2OOfrUD5kFT9kgiwF5oM+/X1UDEZYLgtEqF2MR eTw5nOy6CU059I9Se8L7dG04es1YWJHDNF7ZTA7p0qw8Eq7VnLYjFusbXKKoHTXG+Z2R XAkFHantcvbOfhej3fB3FGQ4f/HlAxFzlJL2rz0UGKNkW0ZGJi0tjA/WG7qCDJn6Bb6k W9M3NWX+vHHWHE7T0Xs8071jFfbSneY9YS9aVGb+DsgxStnr4cEUuhWiVCBwXJLSeXt8 cKkA== 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: AOUpUlFDRTRKKNhONR8jEUXLP+Y+VqmvpA7b+1HitAhEh/UQ9uM93K5l dJZ0BlrFCvkTTBhbBL5GcCWeGKDawAqA2YaDSWM/oRSUAfa2BFuPXMT2zqhqSUnytrsV2FmZna0 rYT3bKzJ4p7OLTCjjYvpHKLcoLXb3MNS2EybYJhBVekjbn7z2FmIDKI7BvKzkfAkngMEvzf6vCX YjKiYJXFd5gqz197LNtoZK6ff55nqJTIYEPQY6IfBzXybVqEXzlBYYTGPPljydvO9xmjvL7Xa1C 49A/3p2BHA7s2XyKzfjZEX/pqyedRDBwseYg2DaRcBN4Z1r/3+wPRCG/NOT/YNXgxnLxzRpKigk 1LlfV39ZYoZIns/4ypT5Ed2/ctde9MVMQNeXJ+1dwonkcnGPnFnnG7doWkn/IWvfl7/nBjw9EA= = X-Received: by 2002:adf:9bc9:: with SMTP id e9-v6mr4609325wrc.240.1531918059695; Wed, 18 Jul 2018 05:47:39 -0700 (PDT) X-Received: by 2002:adf:9bc9:: with SMTP id e9-v6mr4609290wrc.240.1531918058986; Wed, 18 Jul 2018 05:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531918058; cv=none; d=google.com; s=arc-20160816; b=imvPX2Twsaw1yP4ctJeBNyv+4zwNLuCznDTwmiHg4xC6ZfykprLikppJlNZilS+oLq EiQnMGgamCd9qwQVf4NviB1a55zegedbgOR5B0WK7kuUoJVD74DA0ssDqbmlnA/4xiHd hiWGXQd79efcb9nXs1sXc8ur3lC3SarcknTOTiTVAEhR1+ySYOdaoAtwPY/WhtN5mevK h5Ref/KSQoRT30ZIvEIkZGtVY8Bzu4gDWOYZwuEAldl5LYXYXBe0WYWAH3VYKFGnfUBV R5ujGh4DiDXgZU2nwTOw+s7qEhutCCHWVP7ZVC9m0+DT03OwvbWSewCvafwMEFNu3mmO yayw== 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=G/5O9NHC2sSQXY1D1Puqte8VarWZHIWWUCI1iuNEE64=; b=dhMfaVMP9zc9gaFsAGPbjqeSsr9MU3cAugC6eVy3unwkbqAyrDWVOlz7y65NeA7tJG MtuR/WG3j+xj4P1672TPoiZS4VeflcTaXDenAK0jBGehsekEE/WzPoPHopTyVWnP5Suo rN9IekRIuKmt+TUcFS0d+vrPQCPFGrOtK0BlHEzeJnZhbzMD+el3bt2i6aozDiLSn1C2 X0UCURfsxAA2UOHGSgNrapYlnrBVxS3rUSYYeTqKgVgiDo0y319wcysxk+wiN3miriFG zlQu61x+qrU7VO8EldRuV9mZs7AOsWyZS72F/FxcEEtE/XFxEJPZowlDwNGgOxabVPAf kQmQ== 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 o189-v6sor562889wmd.69.2018.07.18.05.47.38 for (Google Transport Security); Wed, 18 Jul 2018 05:47:38 -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: AAOMgpfEKhJpaMt+4ScWPfF0nWep86UdOglR3jUw7t40Hj2jb/yfMBtJjnN6ug6FRfnuFfl0NVBJOQ== 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> 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 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); + } } }