From patchwork Fri Sep 21 13:26:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10610033 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 3D591157B for ; Fri, 21 Sep 2018 13:26:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B0142DB18 for ; Fri, 21 Sep 2018 13:26:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F4D42DB1A; Fri, 21 Sep 2018 13:26:53 +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 7EB362DB18 for ; Fri, 21 Sep 2018 13:26:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAC8B8E0005; Fri, 21 Sep 2018 09:26:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CE2F48E0001; Fri, 21 Sep 2018 09:26:46 -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 B176D8E0005; Fri, 21 Sep 2018 09:26:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by kanga.kvack.org (Postfix) with ESMTP id 492B08E0001 for ; Fri, 21 Sep 2018 09:26:46 -0400 (EDT) Received: by mail-wm1-f71.google.com with SMTP id z11-v6so2454891wma.4 for ; Fri, 21 Sep 2018 06:26:46 -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=o52x8tjPTmNioW0bBVA6BC8kUEvUd+5T8EUKIIECF/I=; b=caDBhDlqXa5tsVEApJHt/8JLmg/iXxYwjBxp9TPaYpgUqM8XfMR0fG+EsHstWmIwkK FfM6xj/cg7+wau+8gqE1D6G8zqLwcM8XW7DwPMI0vlxgcVvylbTemNyWaUooodcgN1R/ sFgCe7q4HboN9B8N0DKV7hzcFFZrI3c/MTHrAOEJNHFYBCr/g7rMrlMlKLtEpGMTLwib zubVMFdI22z20EQNGVCwyXVBrJ/y4Tq1//K4rVJZj1PjYjxNAX0a311wTgZzhS+sEOwH jYYggZwRcZOD4dYc8q5Hka/Msj7LEzNrmwRctMCMbae4l7Zhp6nE8LbTCkYo61XZvpg6 O8sw== 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: APzg51DpJrAafEcL512hVZDk47/dIY27lI7kLA6Ek/0LZCH0//86+pl7 PE9PkiHWI6rYrChlZs4tna6AVK3z9t3jQ8Y5nyFG6SdSf4JNZGGDMw9RshE+9AdMBmIIHvLd3z8 I8Y9P2xG91Dy/qC0eDbAFKVKOokZ2dU96FDCK62QHdj2bHqCjvF+NWxbrdywQtJyLuL1pIg7RBT 7D0jhKf7KLui1EDxD/pAzNfYTURskBJJ81/thYC6wUT82spGKlpLT1ZeMUD7/PTBIqNwOd7I10p 4GUeiciTcNhGaNzBmuhRGWxwsUTo9iSmumWbZkqJxcvraQohddk4MS2a5QQO5NH/NJcHkQgsoXY wlFbzM4IyYnNT4sQ5VTRKodr8NEEaToxHFNQVmpXhk9aRR2PT+tW8bV9gUuXSFslq1icSAI/6w= = X-Received: by 2002:adf:9ae5:: with SMTP id a92-v6mr40064674wrc.125.1537536405730; Fri, 21 Sep 2018 06:26:45 -0700 (PDT) X-Received: by 2002:adf:9ae5:: with SMTP id a92-v6mr40064590wrc.125.1537536404477; Fri, 21 Sep 2018 06:26:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537536404; cv=none; d=google.com; s=arc-20160816; b=uMZ0brLMKTnGmsR/U9eMmnqXZW79HqOhInzvrHzzbLVxm/aEUrQAjp75uUlE/h5Mor Vu+bIDc96+wZW5XYNKBrNaHKBw43alEzJ/esTg746E5cQ9rEPBXTHwU8ePyHKRt51SVx jEFSaoeXohnEt7loyx5AM3LixNVkW+fBeM+iDwSkydZEv9rvwzY0fQf86d5/ZG1tV+Ze pZ5vTOf40+TDehu0/4lG+km9tnVY0eS7/FNqd3hi0CNXyCR489eHfDy/SwymvDlj0gFP WmSQt7RnDOTz5aAJoxkbAeEJK7EzZ7+cKkIVFiu9nkBKrXHURoQhb5AvjU+aUsllwi3c MQhQ== 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=o52x8tjPTmNioW0bBVA6BC8kUEvUd+5T8EUKIIECF/I=; b=bj3pykzZaoC4oM2YpCldAX9UT27Pb8VwP9ynNmDxh7gtXN3jdsDOjdy5cA5PzjC6nD XXE80okO4YQWO28iDGQvWc5pK8GiA95Y5MqOtr8RvljyNMT24ZIL/6dsp9kpePcdUICM nrWIRhIyqLQVKzwbY1MiiEjKyaMt7ulbYTTAFtgOq2JDs0mQjhs8DNJaYWAeOACbLRQo WJBp0J4odyTnxdoch5yA4dxEcXiyTgMD4yytYOC0nviMgoP49XrBnRIkhnrIkmWUMMLK nMgbjJvZLN8eJqfk+9R/sPdsC3wLb0kSH5j9qbw1asnLIomfdhm+U92BKMeDOpHj/AyC kPIQ== 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 z10-v6sor4152858wmb.1.2018.09.21.06.26.44 for (Google Transport Security); Fri, 21 Sep 2018 06:26:44 -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: ACcGV60CN8yYgQgtMyKP5pJBF54wt/SEU1TVEMerZNaayS+2J2mGov6d4qsltfjXR0n9cwwo49tWAw== X-Received: by 2002:a1c:501:: with SMTP id 1-v6mr7033567wmf.140.1537536403982; Fri, 21 Sep 2018 06:26:43 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id u1-v6sm19805759wrt.59.2018.09.21.06.26.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 06:26:42 -0700 (PDT) Received: from d104.suse.de (nat.nue.novell.com [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 0C50E125344; Fri, 21 Sep 2018 15:26:41 +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 v2 4/4] mm/memory_hotplug: Clean up node_states_check_changes_offline Date: Fri, 21 Sep 2018 15:26:34 +0200 Message-Id: <20180921132634.10103-5-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180921132634.10103-1-osalvador@techadventures.net> References: <20180921132634.10103-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, as the previous one, gets rid of the wrong if statements. While at it, I realized that the comments are sometimes very confusing, to say the least, and wrong. For example: diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index eadd149eb7bc..f19b63f024c9 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1463,75 +1463,53 @@ static void node_states_check_changes_offline(unsigned long nr_pages, { struct pglist_data *pgdat = zone->zone_pgdat; unsigned long present_pages = 0; - enum zone_type zt, zone_last = ZONE_NORMAL; + enum zone_type zt; - /* - * 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. - */ - if (N_MEMORY == N_NORMAL_MEMORY) - zone_last = ZONE_MOVABLE; + arg->status_change_nid = -1; + arg->status_change_nid_normal = -1; + arg->status_change_nid_high = -1; /* - * check whether node_states[N_NORMAL_MEMORY] will be changed. - * If the memory to be offline is in a zone of 0...zone_last, - * and it is the last present memory, 0...zone_last will - * become empty after offline , thus we can determind we will - * need to clear the node from node_states[N_NORMAL_MEMORY]. + * Check whether node_states[N_NORMAL_MEMORY] will be changed. + * If the memory to be offline is within the range + * [0..ZONE_NORMAL], and it is the last present memory there, + * the zones in that range will become empty after the offlining, + * thus we can determine that we need to clear the node from + * node_states[N_NORMAL_MEMORY]. */ - for (zt = 0; zt <= zone_last; zt++) + for (zt = 0; zt <= ZONE_NORMAL; zt++) present_pages += pgdat->node_zones[zt].present_pages; - if (zone_idx(zone) <= zone_last && nr_pages >= present_pages) + if (zone_idx(zone) <= ZONE_NORMAL && nr_pages >= present_pages) arg->status_change_nid_normal = zone_to_nid(zone); - 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. + * node_states[N_HIGH_MEMORY] contains nodes which + * have normal memory or high memory. + * Here we add the present_pages belonging to ZONE_HIGHMEM. + * If the zone is within the range of [0..ZONE_HIGHMEM), and + * we determine that the zones in that range become empty, + * we need to clear the node for N_HIGH_MEMORY. */ - zone_last = ZONE_HIGHMEM; - if (N_MEMORY == N_HIGH_MEMORY) - zone_last = ZONE_MOVABLE; - - for (; zt <= zone_last; zt++) - present_pages += pgdat->node_zones[zt].present_pages; - if (zone_idx(zone) <= zone_last && nr_pages >= present_pages) + present_pages += pgdat->node_zones[ZONE_HIGHMEM].present_pages; + if (zone_idx(zone) <= ZONE_HIGHMEM && nr_pages >= present_pages) arg->status_change_nid_high = zone_to_nid(zone); - else - arg->status_change_nid_high = -1; -#else - arg->status_change_nid_high = arg->status_change_nid_normal; #endif /* - * node_states[N_HIGH_MEMORY] contains nodes which have 0...ZONE_MOVABLE + * We have accounted the pages from [0..ZONE_NORMAL), and + * in case of CONFIG_HIGHMEM the pages from ZONE_HIGHMEM + * as well. + * Here we count the possible pages from ZONE_MOVABLE. + * If after having accounted all the pages, we see that the nr_pages + * to be offlined is over or equal to the accounted pages, + * we know that the node will become empty, and so, we can clear + * it for N_MEMORY as well. */ - zone_last = ZONE_MOVABLE; + present_pages += pgdat->node_zones[ZONE_MOVABLE].present_pages; - /* - * check whether node_states[N_HIGH_MEMORY] will be changed - * If we try to offline the last present @nr_pages from the node, - * we can determind we will need to clear the node from - * node_states[N_HIGH_MEMORY]. - */ - for (; zt <= zone_last; zt++) - present_pages += pgdat->node_zones[zt].present_pages; if (nr_pages >= present_pages) arg->status_change_nid = zone_to_nid(zone); - else - arg->status_change_nid = -1; } static void node_states_clear_node(int node, struct memory_notify *arg)