From patchwork Tue Aug 7 13:37:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10558723 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 15042139A for ; Tue, 7 Aug 2018 13:38:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01C2029E12 for ; Tue, 7 Aug 2018 13:38:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E963E29E24; Tue, 7 Aug 2018 13:38:29 +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 4DEBA29E12 for ; Tue, 7 Aug 2018 13:38:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F02636B000C; Tue, 7 Aug 2018 09:38:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EB11F6B000D; Tue, 7 Aug 2018 09:38:24 -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 D2E666B000E; Tue, 7 Aug 2018 09:38:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 7603E6B000C for ; Tue, 7 Aug 2018 09:38:24 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id j6-v6so13774783wrr.15 for ; Tue, 07 Aug 2018 06:38:24 -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=UGHDYi1fGTGsyDr5+uGpoPTBhMkqCLpSGvH1cSTmmy8=; b=a3N6SH+pUdkjoBDeF93Grrp6RQF7xVpesI7VmA7xAuvfxPYhDZ3P11vnUREpcRTyt6 3FEjVNkndeQTMv6dSZKJrwWHbMs5IS2F7jvGsyDNWAnmakL750VKeILa7TetvwjO/fWE QXvxi4Rzvs62pfZ7PQF4S2QuOLe9nIifV782CO5AyS5dG2pwciMAeSvs1evgoyMAInQQ ndRM76NiKF31dHRt+IiJA0dq6bhqk5Pv+6uN4+2z8k/sS0Ljpdvq0j6DO7qyh0ADv00k ypcxzV71kK70l3uIc9fbfGhXuYQMLbprGLXEd4Wh57aVEXUYw0pYXfe58TeAQniW3Q+D fpVA== 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: AOUpUlGYhB1esw+OZpyM6A8E42KLM0kexGpzMvL4Rn+1LZ7TJtq7RyQq s+aSkUYr/gUeS0nH4UuFOsG1pRPtCRFv+143W6DoGa52Bi5VFz2bmBozPDf3tXlqUK9xO+Tmcso 3lV3RNuaYTarsZOsI6qlQrW6GWd3CsBS31fcllfJqG785x/Va4UoOO8NMo4RvcXIa+XDmmW/tEl HZLHIZDZ81NUskkEvJcNd03rbcd/CX8iiiY70kuXlAxc8lnURwRWcEp7jcKMulN4cV1IZFipsxO qw1BoSKkzD3Cf54vYRycgpG1QyZdUu0XAwHQ0K7mpg13gea0oW5js//h+sceMYCtZibFjLpfNN/ 7uv/Pj3EFFjDNcaXOa2O/ql8yaIBum0y/eMEgbVUnhjvarSVE0UtEOq9rNrAwOR8xoIl7pvjFg= = X-Received: by 2002:a1c:ce0b:: with SMTP id e11-v6mr1666966wmg.47.1533649104023; Tue, 07 Aug 2018 06:38:24 -0700 (PDT) X-Received: by 2002:a1c:ce0b:: with SMTP id e11-v6mr1666929wmg.47.1533649103134; Tue, 07 Aug 2018 06:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533649103; cv=none; d=google.com; s=arc-20160816; b=QCEU//+B6F5L+2hV4bd4aCR9GYwWb4VUEDbjnSo4yoh1LZhz2Ejxrq04Yj632/Xtqu 8dY1dSEmdRduhcJfF3IbQ+TKCykL+OoNakCRbnzDH96w9BQ05Y0i6XYmXSfQ5+RxzOzb dw4t09xYcJuQ0YaxC8kGXeLYJ111a8ERfKu/NpE6cHr+EpiWy99Kl+AQVYxT2ANWzAJf eymhRZNVMtglRsAPbDDcKTKKvCtVmNRhD2N5baCYkwpbSM8QdKPiiiPu5Rg5ixS5y51c 0izqsMQmzzVlQdFibNJAGdrsr2YmF8VOA+bdVf6IrasqVXuRrX5+R9wQhDmmXHLSF+nV 87Kw== 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=UGHDYi1fGTGsyDr5+uGpoPTBhMkqCLpSGvH1cSTmmy8=; b=RFaM+ArAs4iy3UgLLIIK00YANlBTKi8gLdbZ9+ifIpmh4lP4LHZwMv4/2AEa7LarIa 8hjrJt7xkC3xE53eNU67c8Lx/gwBI69HAe8Xkn3vzWRQwV5x+sYadXw6kftGxNFsA89g M6ZODnpLbNvOmRANroVVKNUTGYrMaCm0ZgxejTdIfbYi5sVyFy8no9W/n29vcOm/dWGr QDuDseTNQYzXvZsyKE0KzzQ9c97Pis57JZxr6WWF8ie1mVz3njNhq8Vdh2BadyM81c/I ZYIOfrHQyH8loaSqkp+thLQJcTbrhe9YqTE+m+tEbNrbU4wCR4fG+p8GzOnD+TcAlC7W 2OTA== 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 b139-v6sor400451wmd.16.2018.08.07.06.38.22 for (Google Transport Security); Tue, 07 Aug 2018 06:38:23 -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: AA+uWPwnROE4sZZPs3TVKL+ZZ0tZRrl+xz1jyG/Gf6Z16dml6uomWbV2cXWSY5kTkoPCwGLdcvPGeA== X-Received: by 2002:a1c:c95:: with SMTP id 143-v6mr1878759wmm.50.1533649102756; Tue, 07 Aug 2018 06:38:22 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id y128-v6sm2564657wmy.26.2018.08.07.06.38.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Aug 2018 06:38:21 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 71CE91246FD; Tue, 7 Aug 2018 15:38:20 +0200 (CEST) From: osalvador@techadventures.net To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, pasha.tatashin@oracle.com, jglisse@redhat.com, david@redhat.com, yasu.isimatu@gmail.com, logang@deltatee.com, dave.jiang@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH 3/3] mm/memory_hotplug: Refactor shrink_zone/pgdat_span Date: Tue, 7 Aug 2018 15:37:57 +0200 Message-Id: <20180807133757.18352-4-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180807133757.18352-1-osalvador@techadventures.net> References: <20180807133757.18352-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 This patch refactors shrink_zone_span and shrink_pgdat_span functions. In case that find_smallest/biggest_section do not return any pfn, it means that the zone/pgdat has no online sections left, so we can set the respective values to 0: zone case: zone->zone_start_pfn = 0; zone->spanned_pages = 0; pgdat case: pgdat->node_start_pfn = 0; pgdat->node_spanned_pages = 0; Also, the check that loops over all sections to see if we have something left is moved to an own function, and so the code can be shared by shrink_zone_span and shrink_pgdat_span. Signed-off-by: Oscar Salvador --- mm/memory_hotplug.c | 127 +++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index e33555651e46..ccac36eaac05 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -365,6 +365,29 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone, return 0; } +static bool has_only_holes(struct zone *zone, int nid, unsigned long zone_start_pfn, + unsigned long zone_end_pfn) +{ + unsigned long pfn; + + pfn = zone_start_pfn; + for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) { + struct mem_section *ms = __pfn_to_section(pfn); + + if (unlikely(!online_section(ms))) + continue; + if (zone && page_zone(pfn_to_page(pfn)) != zone) + continue; + + if (pfn_to_nid(pfn) != nid) + continue; + + return false; + } + + return true; +} + static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) { @@ -372,7 +395,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long z = zone_end_pfn(zone); /* zone_end_pfn namespace clash */ unsigned long zone_end_pfn = z; unsigned long pfn; - struct mem_section *ms; int nid = zone_to_nid(zone); zone_span_writelock(zone); @@ -385,10 +407,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, */ pfn = find_smallest_section_pfn(nid, zone, end_pfn, zone_end_pfn); - if (pfn) { - zone->zone_start_pfn = pfn; - zone->spanned_pages = zone_end_pfn - pfn; - } + if (!pfn) + goto only_holes; + + zone->zone_start_pfn = pfn; + zone->spanned_pages = zone_end_pfn - pfn; } else if (zone_end_pfn == end_pfn) { /* * If the section is biggest section in the zone, it need @@ -398,38 +421,28 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, */ pfn = find_biggest_section_pfn(nid, zone, zone_start_pfn, start_pfn); - if (pfn) - zone->spanned_pages = pfn - zone_start_pfn + 1; - } - - /* - * The section is not biggest or smallest mem_section in the zone, it - * only creates a hole in the zone. So in this case, we need not - * change the zone. But perhaps, the zone has only hole data. Thus - * it check the zone has only hole or not. - */ - pfn = zone_start_pfn; - for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) { - ms = __pfn_to_section(pfn); - - if (unlikely(!online_section(ms))) - continue; + if (!pfn) + goto only_holes; - if (page_zone(pfn_to_page(pfn)) != zone) - continue; - - /* If the section is current section, it continues the loop */ - if (start_pfn == pfn) - continue; - - /* If we find valid section, we have nothing to do */ - zone_span_writeunlock(zone); - return; + zone->spanned_pages = pfn - zone_start_pfn + 1; + } else { + /* + * The section is not biggest or smallest mem_section in the zone, it + * only creates a hole in the zone. So in this case, we need not + * change the zone. But perhaps, the zone has only hole data. Thus + * it check the zone has only hole or not. + */ + if (has_only_holes(zone, nid, zone_start_pfn, zone_end_pfn)) + goto only_holes; } + goto out; + +only_holes: /* The zone has no valid section */ zone->zone_start_pfn = 0; zone->spanned_pages = 0; +out: zone_span_writeunlock(zone); } @@ -440,7 +453,6 @@ static void shrink_pgdat_span(struct pglist_data *pgdat, unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */ unsigned long pgdat_end_pfn = p; unsigned long pfn; - struct mem_section *ms; int nid = pgdat->node_id; if (pgdat_start_pfn == start_pfn) { @@ -452,10 +464,11 @@ static void shrink_pgdat_span(struct pglist_data *pgdat, */ pfn = find_smallest_section_pfn(nid, NULL, end_pfn, pgdat_end_pfn); - if (pfn) { - pgdat->node_start_pfn = pfn; - pgdat->node_spanned_pages = pgdat_end_pfn - pfn; - } + if (!pfn) + goto only_holes; + + pgdat->node_start_pfn = pfn; + pgdat->node_spanned_pages = pgdat_end_pfn - pfn; } else if (pgdat_end_pfn == end_pfn) { /* * If the section is biggest section in the pgdat, it need @@ -465,35 +478,25 @@ static void shrink_pgdat_span(struct pglist_data *pgdat, */ pfn = find_biggest_section_pfn(nid, NULL, pgdat_start_pfn, start_pfn); - if (pfn) - pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1; - } - - /* - * If the section is not biggest or smallest mem_section in the pgdat, - * it only creates a hole in the pgdat. So in this case, we need not - * change the pgdat. - * But perhaps, the pgdat has only hole data. Thus it check the pgdat - * has only hole or not. - */ - pfn = pgdat_start_pfn; - for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SECTION) { - ms = __pfn_to_section(pfn); - - if (unlikely(!online_section(ms))) - continue; - - if (pfn_to_nid(pfn) != nid) - continue; + if (!pfn) + goto only_holes; - /* If the section is current section, it continues the loop */ - if (start_pfn == pfn) - continue; - - /* If we find valid section, we have nothing to do */ - return; + pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1; + } else { + /* + * If the section is not biggest or smallest mem_section in the pgdat, + * it only creates a hole in the pgdat. So in this case, we need not + * change the pgdat. + * But perhaps, the pgdat has only hole data. Thus it check the pgdat + * has only hole or not. + */ + if (has_only_holes(NULL, nid, pgdat_start_pfn, pgdat_end_pfn)) + goto only_holes; } + return; + +only_holes: /* The pgdat has no valid section */ pgdat->node_start_pfn = 0; pgdat->node_spanned_pages = 0;