From patchwork Wed Sep 19 10:08:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10605587 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 6E6C1112B for ; Wed, 19 Sep 2018 10:08:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 607272B59D for ; Wed, 19 Sep 2018 10:08:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54C5B2B5F2; Wed, 19 Sep 2018 10:08:56 +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 A92732B59D for ; Wed, 19 Sep 2018 10:08:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9B698E0007; 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 9D8A68E0001; Wed, 19 Sep 2018 06:08:43 -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 7668F8E0007; Wed, 19 Sep 2018 06:08:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 092EB8E0001 for ; Wed, 19 Sep 2018 06:08:43 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id g3-v6so2826680wrr.11 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=CPZ3SLz+vsImuE3JcnMjrOKHwubgJYYNz5KpnVll+6g=; b=Iwh3XdXTD1VMCyoBSXwH2ihuEXHzyAxaog69YsP71BaAFt6a+7cY/Alwv9R+HeIomg B4ssrnjI9p0m48bJjCRpQD2SnPAXU180D2Nmv6HgvJHmkKIq25Kf3QV4+is1G0L+bQQ7 ccL+ObTJxxUDvNEkKTF5HdSM9Mjz6NCWfnKMCY20cZJSugccRkIJLof8znNV1F9kuTiY oqttKHzvNodzsJkv1KqaOofC9cYU4XmK7jkHGtF9NAFjh+crksGrrvJKF6tcta6CFV6O PBu8faAwLtEJN4Yi1FXbHSbWwp1URVLZ9aT8OG//KtMo3Drf0EpJsr9396Hsfyc+4vou xKTg== 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: APzg51CmB4fA3zgoeNcoL2XiFBOiQmAWCVgDsgbrVd6E5c5Nh9RkJgI2 6WQ0RKoLVkF1ZsWz+dl7Qqv4DdvXodqTNh0InThiyzGdy3gKayonQ1a8zPO5axoyi2sUjwGWJix fvcRzRj5bk5tHGi2Oxsfy5bqIDAF6jqyQTjReLEPfgRSC3DV0bfc52qsW6W+ttwzMF8uIOeBcyL okVE8q7UuMN41ySkH1rLazrK7ZB9GQm6JUI3uzIyGlFxHVmznuof3t1vMZJEPAxvhekywlB/+TQ J+Votq7IYTJHEv54odM1FiLP5Bz46Lb6eqDU0wKb5XMnv37dB7SOppRusJGJoLGOC9Yg9isPtiy 9kxCoM49qN7K5EbN3fT69mug0oquiWuASdv/lh5fbyh49vGuEYrosVRKNHkry1NmsQVc1ecpyg= = X-Received: by 2002:a1c:d141:: with SMTP id i62-v6mr18508054wmg.113.1537351722549; Wed, 19 Sep 2018 03:08:42 -0700 (PDT) X-Received: by 2002:a1c:d141:: with SMTP id i62-v6mr18507980wmg.113.1537351721583; 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=hWB8mWPPP1lYbrlVpFsa5b7QUL3mx9gHuaHAp+zMuzjCDW0hN/3TFhLdjpfkrzGyMc hP4Shy+Dx8bNclSf1qhArNMtfPZRDF5YzQjK2nTC0uqjXs+6u96KiI9ygO7SdCQItDey FadxJGEt2L0AA1KEjGcRfz60gK7VQR1BYqHeRm6sQjD6bfurKDef4usANFMiHKaiCQzh FyIOXSIVK6Z8kekfSBYwUg1o2o5vcvHRB26rRTVmw41wf4bz5Fz7rOjPtZTtz14xnBTg IjsW0Qixj0wPKS8zqzftWruw3hofw5QitW85jTBZrSsPYH3umTWomjnC0afs0ndjRkPm GDKg== 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=CPZ3SLz+vsImuE3JcnMjrOKHwubgJYYNz5KpnVll+6g=; b=lqQDzmm0JmPwlTvria3gsA4AxnLtN8v5oqesYB1aUMyzCXSa9ddPueoYh14xLT2GyV QsrhaZ5/eW6a6co9mVHY0HS0KELD3+5L0gIX+4JPJjxmh8se7MsU72AYRVqilUklJ09s INRVADdwOZ0oXMDML0B/bji3rB3BRB+DvT0y/dGgUHoK7nVwzFSR9bUk6N0CqESeA3hZ dySexzCDosLWycarzo40+LhxKqY8tTg/+c0+UzHsmDso7C2RzCYWN04fSVmdrsRxXqMB Yu/LWrkN8JEPOzhezfvmruSa4fsLTWbOCCGglYEjVcX1TZsKpYpd5eEdQYeh68q83bX0 UrCQ== 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 g11-v6sor9504931wmg.19.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: ANB0VdZgJPGYpBQq2OBEkD7jNE2m2NRfhTGmiHgajHXDJ9aUNSIUIjDVoWBGrl/chuyhC9EF/bEBTw== X-Received: by 2002:a1c:9290:: with SMTP id u138-v6mr19088034wmd.52.1537351721295; Wed, 19 Sep 2018 03:08:41 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id v2-v6sm18364035wrs.54.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 ACD641253C6; 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 5/5] mm/memory_hotplug: Clean up node_states_check_changes_offline Date: Wed, 19 Sep 2018 12:08:19 +0200 Message-Id: <20180919100819.25518-6-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 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: Reviewed-by: Pavel Tatashin --- zone_last = ZONE_MOVABLE; /* * 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; --- In case the node gets empry, it must be removed from N_MEMORY. We already check N_HIGH_MEMORY a bit above within the CONFIG_HIGHMEM ifdef code. Not to say that status_change_nid is for N_MEMORY, and not for N_HIGH_MEMORY. So I re-wrote some of the comments to what I think is better. Signed-off-by: Oscar Salvador --- mm/memory_hotplug.c | 71 +++++++++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index ab3c1de18c5d..15ecf3d7a554 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1485,51 +1485,36 @@ 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. + * 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]. */ - if (N_MEMORY == N_NORMAL_MEMORY) - zone_last = ZONE_MOVABLE; - - /* - * 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]. - */ - 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; + zt = ZONE_HIGHMEM; + present_pages += pgdat->node_zones[zt].present_pages; - for (; zt <= zone_last; zt++) - present_pages += pgdat->node_zones[zt].present_pages; - if (zone_idx(zone) <= zone_last && nr_pages >= present_pages) + if (zone_idx(zone) <= zt && nr_pages >= present_pages) arg->status_change_nid_high = zone_to_nid(zone); else arg->status_change_nid_high = -1; @@ -1542,18 +1527,18 @@ static void node_states_check_changes_offline(unsigned long nr_pages, #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; + zt = ZONE_MOVABLE; + present_pages += pgdat->node_zones[zt].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