From patchwork Wed Sep 19 10:08:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10605585 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 E5A18161F for ; Wed, 19 Sep 2018 10:08:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA8C72B59D for ; Wed, 19 Sep 2018 10:08:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE3562B5F2; Wed, 19 Sep 2018 10:08:52 +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 488832B59D for ; Wed, 19 Sep 2018 10:08:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DB148E0009; Wed, 19 Sep 2018 06:08:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 066EE8E0007; Wed, 19 Sep 2018 06:08:42 -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 BFBDF8E0001; Wed, 19 Sep 2018 06:08:42 -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 584538E0007 for ; Wed, 19 Sep 2018 06:08:42 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id i11-v6so5195676wrr.10 for ; Wed, 19 Sep 2018 03:08:42 -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=mb6vYlvIYmKOjWLuG2K0eChvByDfjqgy7Ys9RpY0B4o=; b=Ai+GCeUSD8gJkUzvhUhwCts3dCU81E+0ALwx6JPwVQNddMAAts6X4tCqadP49mJZiS jPnD9GjH/jk2hHnLg4Je7fE5GUFvhxHq+eTUlqsYA7E5zIqaDkN221FT636jC0OClZux GedZ0JB0irp8WCqNs3NhwsU1sYYgd9e4PRkHfxIgWVmTcwnakyGVxmWd21D1Mydc6Epx vZVDZH8Ovhzqm/ccm7Sa5BPfc2NW7XxISQYP3qU+tYb1Cxv3aQRZ1zCNaoiPR7T+zg4y e+iWEAV0L7+oXIRBx8P0l2Ppa7FRhmu/DwMYPJ6nx4oZ9hLF2Xqu+r/T4hu1gu16MeK0 HdKQ== 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: APzg51AYiJvV3Qz8aotEDkKgdEbKcHLTqXuVa30VM0RS+OGSmhquB2IE vqlKAaqI/kU08Eo+GadD3sE/PmCYZFhN1hOAJWhkkH4tjjeSkgjekuZauZyBPFXfWuvBvs8n1hU ODt3lb1u8MDxFUmHdgIw5aNxzQMMvCH9vj87UAKApMpYbRNriH1QE+3lJxwEnz58O5mWnM8id3r kSuDc4XBbLhZaBLaDGj9XIrOTK6v7gs7ERA/Xd5k84dWQ5gKi+AcgWRJsI1vOmN1XaKgbPn75Tc f1nYS1+79uJbiUYPJsn1bIvVfahJT7I2iHEywf9PAniQG68ssUkdq6J+CHPoxTeyBfTo42qlXQM Ggwv+j7+xNO4cSiQGT4PSrOgESUxOr1njFhoLwSIRgE9OGW5RzlTk/JbzjBJbRHj4vAx+4hxDg= = X-Received: by 2002:a1c:a401:: with SMTP id n1-v6mr20229974wme.125.1537351721872; Wed, 19 Sep 2018 03:08:41 -0700 (PDT) X-Received: by 2002:a1c:a401:: with SMTP id n1-v6mr20229923wme.125.1537351721173; Wed, 19 Sep 2018 03:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537351721; cv=none; d=google.com; s=arc-20160816; b=DZWMbD2DuMl7oMLQJEIY8QDM4B/98Dgz6+Az8SOidSGLfy2/qgJYSxYOU9vAxK67Go Fe5+2Lv6/dL5UtmA7A7Cj708gAo8u32pUjOTGZ9UJQtv42EKvKWXPjQwflB41Dcy6KUf 9VlL/z/saBnvg283n1+kkeZzT+jttswmXsWwvQHpbgjPTAq+VTi7Fo/rjBGGwpbh9UYx gWu51wLw7gWqcMryScZW5V/9xyHKScE0w2HocxltqTEKSG0LrbVMSgoENYZIgPYSb9K5 f0RCnfK5d3NOmiPGL18ftRaZn3lIXNfyHVqtiPpQbVNmdAHTIe9Lw4NrM8iiJuzh1/uh 6rmw== 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; bh=mb6vYlvIYmKOjWLuG2K0eChvByDfjqgy7Ys9RpY0B4o=; b=ukd7cP/cwO/tIwVyzmNnn0O9z9+LfvNlQpAMspKqzBjJ5Toer8F8nv0f0q6+OlBUtr oQ4sRvQu5dk2nq95op0yksMIKvEsKR1NQGKJIBAQyCTjNAr1QqMgj5aIrRpRiRpD3So9 qREY2w4NlTLWzhNCVTaxEgtmTBA38MZnJSsO9zLKB9ASr6ss4mlA3BMgkPDPOH8eLPmA RGc32ocO/b6cJPftiIos8CI8NbYYnRvgRxGGcuFAk0vJlMkMikyVYdl97G5yY4Q6Hosh u1Clw/aX79vwn4JhMkXQY0NJfxjFFSD9PZ9U6Y3/S5j3IVlLg+aA11vqNPees8nm8oXE PVbA== 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 42-v6sor15010060wrb.38.2018.09.19.03.08.41 for (Google Transport Security); Wed, 19 Sep 2018 03:08:41 -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: ANB0VdbHMUJFArsNd47dTIQSFcl+G6iSMJHasnwRtwV47Aiviqp45n5HWV7nKvoty7ZUX62TWeFkoA== X-Received: by 2002:adf:b3d7:: with SMTP id x23-v6mr26796918wrd.253.1537351720869; Wed, 19 Sep 2018 03:08:40 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id b10-v6sm16530345wrr.88.2018.09.19.03.08.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Sep 2018 03:08:39 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 70E981253C5; Wed, 19 Sep 2018 12:08:38 +0200 (CEST) From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, david@redhat.com, Pavel.Tatashin@microsoft.com, Jonathan.Cameron@huawei.com, yasu.isimatu@gmail.com, malat@debian.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH 4/5] mm/memory_hotplug: Simplify node_states_check_changes_online Date: Wed, 19 Sep 2018 12:08:18 +0200 Message-Id: <20180919100819.25518-5-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180919100819.25518-1-osalvador@techadventures.net> References: <20180919100819.25518-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 While looking at node_states_check_changes_online, I stumbled upon some confusing things. Right after entering the function, we find this: if (N_MEMORY == N_NORMAL_MEMORY) zone_last = ZONE_MOVABLE; This is wrong. N_MEMORY cannot really be equal to N_NORMAL_MEMORY. My guess is that this wanted to be something like: if (N_NORMAL_MEMORY == N_HIGH_MEMORY) to check if we have CONFIG_HIGHMEM. Later on, in the CONFIG_HIGHMEM block, we have: if (N_MEMORY == N_HIGH_MEMORY) zone_last = ZONE_MOVABLE; Again, this is wrong, and will never be evaluated to true. Besides removing these wrong if statements, I simplified the function a bit. Signed-off-by: Oscar Salvador --- mm/memory_hotplug.c | 71 +++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 131c08106d54..ab3c1de18c5d 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -687,61 +687,36 @@ static void node_states_check_changes_online(unsigned long nr_pages, struct zone *zone, struct memory_notify *arg) { int nid = zone_to_nid(zone); - enum zone_type zone_last = ZONE_NORMAL; /* - * If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY] - * contains nodes which have zones of 0...ZONE_NORMAL, - * set zone_last to ZONE_NORMAL. - * - * If we don't have HIGHMEM nor movable node, - * node_states[N_NORMAL_MEMORY] contains nodes which have zones of - * 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE. + * zone_for_pfn_range() can only return a zone within + * (0..ZONE_NORMAL] or ZONE_MOVABLE. + * If the zone is within the range (0..ZONE_NORMAL], + * we need to check if: + * 1) We need to set the node for N_NORMAL_MEMORY + * 2) On CONFIG_HIGHMEM systems, we need to also set + * the node for N_HIGH_MEMORY. + * 3) On !CONFIG_HIGHMEM, we can disregard N_HIGH_MEMORY, + * as N_HIGH_MEMORY falls back to N_NORMAL_MEMORY. */ - if (N_MEMORY == N_NORMAL_MEMORY) - zone_last = ZONE_MOVABLE; - /* - * if the memory to be online is in a zone of 0...zone_last, and - * the zones of 0...zone_last don't have memory before online, we will - * need to set the node to node_states[N_NORMAL_MEMORY] after - * the memory is online. - */ - if (zone_idx(zone) <= zone_last && !node_state(nid, N_NORMAL_MEMORY)) - arg->status_change_nid_normal = nid; - else - arg->status_change_nid_normal = -1; - -#ifdef CONFIG_HIGHMEM - /* - * If we have movable node, node_states[N_HIGH_MEMORY] - * contains nodes which have zones of 0...ZONE_HIGHMEM, - * set zone_last to ZONE_HIGHMEM. - * - * If we don't have movable node, node_states[N_NORMAL_MEMORY] - * contains nodes which have zones of 0...ZONE_MOVABLE, - * set zone_last to ZONE_MOVABLE. - */ - zone_last = ZONE_HIGHMEM; - if (N_MEMORY == N_HIGH_MEMORY) - zone_last = ZONE_MOVABLE; + if (zone_idx(zone) <= ZONE_NORMAL) { + if (!node_state(nid, N_NORMAL_MEMORY)) + arg->status_change_nid_normal = nid; + else + arg->status_change_nid_normal = -1; - if (zone_idx(zone) <= zone_last && !node_state(nid, N_HIGH_MEMORY)) - arg->status_change_nid_high = nid; - else - arg->status_change_nid_high = -1; -#else - /* - * When !CONFIG_HIGHMEM, N_HIGH_MEMORY equals N_NORMAL_MEMORY - * so setting the node for N_NORMAL_MEMORY is enough. - */ - arg->status_change_nid_high = -1; -#endif + if (IS_ENABLED(CONFIG_HIGHMEM)) { + if (!node_state(nid, N_HIGH_MEMORY)) + arg->status_change_nid_high = nid; + } else + arg->status_change_nid_high = -1; + } /* - * if the node don't have memory befor online, we will need to - * set the node to node_states[N_MEMORY] after the memory - * is online. + * if the node doesn't have memory before onlining it, we will need + * to set the node to node_states[N_MEMORY] after the memory + * gets onlined. */ if (!node_state(nid, N_MEMORY)) arg->status_change_nid = nid;