From patchwork Wed Jul 25 22:01:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10544867 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 67FA4180E for ; Wed, 25 Jul 2018 22:02:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56A832A88B for ; Wed, 25 Jul 2018 22:02:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B2FA2A8A1; Wed, 25 Jul 2018 22:02:08 +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 A9A562A891 for ; Wed, 25 Jul 2018 22:02:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 479F36B0008; Wed, 25 Jul 2018 18:01:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 400E66B000D; Wed, 25 Jul 2018 18:01: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 2C8576B000E; Wed, 25 Jul 2018 18:01:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id AEF8B6B0008 for ; Wed, 25 Jul 2018 18:01:55 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id d1-v6so5162339wrr.4 for ; Wed, 25 Jul 2018 15:01:55 -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=rskVcuLW5mTCFv880bF+K7VIucHqpnfomG/ohSkecG0=; b=VGGYpxWvsq5gZ9qjjMEc4ngvlHXbEGK/YBZjuv1STvf5TQ2YfoIERrirdqdvWTQw9T kD25rX0/jSjOCUQmVg8Y6+coCyVi2t5WUvnacDycDrJWArz6S+3XIcX0zCAgHf4gN5sH OzauSBZinRjJfmmNS45+DW3WtirigspVY/dDK8qZKKwV+gTz9i96UVpHAlT2DirIHENP os8WMWK3cYwLgwti6mzJgPl3oDabLtIfcTPo7cBG9xLIiaS/b072YSchpneqDqJgzLpd bF+8AR6TFkOY3LhCaH3aiiuwuoHLjt2h3RopB9+Imno5PkyOxJOTcU5ZqnJIEsoV6056 u2pA== 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: AOUpUlEEyM0F+qBrc1uGJ27AMz8MVxvRf17xe3xa/ps1t4oePguV2DuW k9YSBNlBmrqeCkDfUFBfh7CVCYcL0QkR5vvay76a+xTC3FMegbozHC926i/crPjRbCYYsBvxIvQ +khrltzP14e4QLObp9EhCXwAgmRpk/y1/l1IiflkxHcRt1YzQ6RLSGjw9wQxFbhbePRmfQPMvAv YtTH/AGWfLlAO2RUy6O5iP3ZcZMWLiD0Yy85RTHWTug58YZ6hQIsJ45JT5s675WuBaRtgwPLMm1 xfFgsuGbEUc5WwjyXcvqmRkGJ+QJo6nAKRUT9/QvWYhq51w7v48aYXnw14H9AMXK/oFXWAdHhKp XQsGYyNZ9xmQb9XuHdVfxq7Km1xFxaBPT73VyOMaukGMhJK63MBBC/Ivxyovg/vA4lJITOxd9Q= = X-Received: by 2002:adf:9303:: with SMTP id 3-v6mr15853335wro.197.1532556115279; Wed, 25 Jul 2018 15:01:55 -0700 (PDT) X-Received: by 2002:adf:9303:: with SMTP id 3-v6mr15853313wro.197.1532556114622; Wed, 25 Jul 2018 15:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532556114; cv=none; d=google.com; s=arc-20160816; b=HvQGZFUSfxUmBDRrtxJlgtQIh+k5Ao1Cx+fEc53QP85JtFx3kdVdV9dh1TVInTG0Hu OTKszKAqeHXSECjJDj+QhEGRuHAUYtvQQgZZaciaOSy9dnDCs47o+u5JHGKPN+ZGvjjp 6Hjxk2mWK5Uq6i4wu/IP753p0X924qFGAnQ4rFXfcMY/6UHfXsJ4xL0UMozjQcXfk2Ll GaY1Z8+aGeK3UGPlRwg/b5KHQ6l3cw1XnwGmKytTwRW5lufMG5c+7nVd5ismLxUENNnq qTCLaK5EjChA+bLcC/UzcvW7B8jMS+JwF0EJ23ReOD5T00Gu/Yrty1j2ba0X/kk/qGPk xbbg== 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=rskVcuLW5mTCFv880bF+K7VIucHqpnfomG/ohSkecG0=; b=BK6Ci+2KONMWJkH3aoBhkNq3KkB4HHa52VFjciIj9HB9fxgp2E5NPr768P9cEoXJbW kRDRkXEQeDrdJuFUOsCbTRb1LqoSChlwEoBVNeKmH+TWp7APS2OnM5qYdbxkcMpaqeDf c+qdZlDYr84wtf43PmBYvqMZc3t8SGV9D1ziftJDppUo8fPTBapHg6Fq7CtZABjbR+tX V9MFXGeUTHqvqfSZw5eg8vTOerm8jKsH94abCc6h7bIeCNF+tihegzBLEiBPuHybgimk rumVvtHzqyjvwm7DpODY2GWdiJX9AOcfP64t331Hmu9v63SyOOg86jNJdKXuQAxfUryL lK9g== 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 s4-v6sor6194264wrp.65.2018.07.25.15.01.54 for (Google Transport Security); Wed, 25 Jul 2018 15:01:54 -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: AAOMgpfDY8YVBm0vBDEeDHjQVFUDCMNZsVqHRinE5AeLSxniHw/159rWqT+u6KglbXJodd3YHqaNyw== X-Received: by 2002:adf:fac1:: with SMTP id a1-v6mr14978854wrs.74.1532556114299; Wed, 25 Jul 2018 15:01:54 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id d14-v6sm20991515wrr.12.2018.07.25.15.01.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 15:01:53 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 6E8C6124368; Thu, 26 Jul 2018 00:01:51 +0200 (CEST) From: osalvador@techadventures.net To: akpm@linux-foundation.org Cc: mhocko@suse.com, vbabka@suse.cz, pasha.tatashin@oracle.com, mgorman@techsingularity.net, aaron.lu@intel.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dan.j.williams@intel.com, Oscar Salvador Subject: [PATCH v3 5/5] mm/page_alloc: Introduce memhotplug version of free_area_init_core Date: Thu, 26 Jul 2018 00:01:44 +0200 Message-Id: <20180725220144.11531-6-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180725220144.11531-1-osalvador@techadventures.net> References: <20180725220144.11531-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 Currently, we call free_area_init_node() from the memhotplug path. In there, we set some pgdat's fields, and call calculate_node_totalpages(). calculate_node_totalpages() calculates the # of pages the node has. Since the node is either new, or we are re-using it, the zones belonging to this node should not have any pages, so there is no point to calculate this now. Actually, we set the values to 0 later on with the calls to: reset_node_managed_pages() reset_node_present_pages() The # of pages per zone and the # of pages per zone will be calculated later on when onlining the pages: online_pages()->move_pfn_range()->move_pfn_range_to_zone()->resize_zone_range() online_pages()->move_pfn_range()->move_pfn_range_to_zone()->resize_pgdat_range() This introduces the memhotplug version of free_area_init_core and makes hotadd_new_pgdat use it. This function will only be called from memhotplug path: hotadd_new_pgdat()->free_area_init_core_hotplug(). free_area_init_core_hotplug() performs only a subset of the actions that free_area_init_core_hotplug() does. Signed-off-by: Oscar Salvador --- include/linux/mm.h | 1 + mm/memory_hotplug.c | 23 +++++++++-------------- mm/page_alloc.c | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 6954ad183159..20430becd908 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2001,6 +2001,7 @@ extern void free_area_init(unsigned long * zones_size); extern void free_area_init_node(int nid, unsigned long * zones_size, unsigned long zone_start_pfn, unsigned long *zholes_size); extern void free_initmem(void); +extern void free_area_init_core_hotplug(int nid); /* * Free reserved pages within range [PAGE_ALIGN(start), end & PAGE_MASK) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 4eb6e824a80c..bef8a3f7a760 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -978,12 +978,11 @@ static void reset_node_present_pages(pg_data_t *pgdat) pgdat->node_present_pages = 0; } + /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start) { struct pglist_data *pgdat; - unsigned long zones_size[MAX_NR_ZONES] = {0}; - unsigned long zholes_size[MAX_NR_ZONES] = {0}; unsigned long start_pfn = PFN_DOWN(start); pgdat = NODE_DATA(nid); @@ -1006,8 +1005,11 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start) /* we can use NODE_DATA(nid) from here */ + pgdat->node_id = nid; + pgdat->node_start_pfn = start_pfn; + /* init node's zones as empty zones, we don't have any present pages.*/ - free_area_init_node(nid, zones_size, start_pfn, zholes_size); + free_area_init_core_hotplug(nid); pgdat->per_cpu_nodestats = alloc_percpu(struct per_cpu_nodestat); /* @@ -1017,18 +1019,11 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start) build_all_zonelists(pgdat); /* - * zone->managed_pages is set to an approximate value in - * free_area_init_core(), which will cause - * /sys/device/system/node/nodeX/meminfo has wrong data. - * So reset it to 0 before any memory is onlined. - */ + * When memory is hot-added, all the memory is in offline state. So + * clear all zones' present_pages because they will be updated in + * online_pages() and offline_pages(). + */ reset_node_managed_pages(pgdat); - - /* - * When memory is hot-added, all the memory is in offline state. So - * clear all zones' present_pages because they will be updated in - * online_pages() and offline_pages(). - */ reset_node_present_pages(pgdat); return pgdat; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a455dc85da19..a36b4db26b50 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6265,6 +6265,25 @@ static void zone_init_internals(struct zone *zone, enum zone_type idx, int nid, } /* + * Set up the zone data structures + * - init pgdat internals + * - init all zones belonging to this node + * + * NOTE: this function is only called during memory hotplug + */ +void __paginginit free_area_init_core_hotplug(int nid) +{ + enum zone_type j; + pg_data_t *pgdat = NODE_DATA(nid); + + pgdat_init_internals(pgdat); + for(j = 0; j < MAX_NR_ZONES; j++) { + struct zone *zone = pgdat->node_zones + j; + zone_init_internals(zone, j, nid, 0); + } +} + +/* * Set up the zone data structures: * - mark all pages reserved * - mark all memory queues empty