Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp670373imm; Fri, 21 Sep 2018 06:28:58 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZNj7KdGDkJIXz9lytKSpEtvznIfFUAFbmOWKdD3JPLpeDApbQJJJKgSiRF4PBdeLt+wtWR X-Received: by 2002:a63:77ce:: with SMTP id s197-v6mr42016445pgc.172.1537536538225; Fri, 21 Sep 2018 06:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537536538; cv=none; d=google.com; s=arc-20160816; b=qd8OSf/V3UlxetQH+JfuvbeKfbqjJuqHGSsZ20feO9h0kKa6Zo4oQFbdfc3wSVk7Dt 2zxybkTPVRDIJM6XaQiXeXPzoJD3V0yI1MIRNeZTCFCOVRND1GHKAgxK+sZ8mZ0TF8hz VQ+QGX7c+7shOgPrkpU21CXf3YU0r2+LLthGO1E/zdi/bZoSwDOfDmbVZG7iPEWeVum4 5Igq9gHAzvqQFHm4UxyIHcygQPrsHtJHivkCxO8lpkSVZjg63RVln2i3V8GFiejAY5y+ Fn1LZ46+G1tnDaC4jH/z775EOqFRoCdyqsJpGhxHcjJVPs2JNqaYKnIzoIx5ZCwdpa/V QNVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=o52x8tjPTmNioW0bBVA6BC8kUEvUd+5T8EUKIIECF/I=; b=WV9OF62GOi8W+myR5xIyyWQ8rAo9B4zZSRY3d6fp9D0p6H9p/ABBwvuGcSdkmS8EA1 tNmsN/BOZGf1/WAF0qTw0GNIaRvtxhGwQMLzOH0RiR68YE4g3482A1HRgRYDC/SKO5Cx 72hsMaA6GS4Oj2ltSX3uElaG7p8ExH6k2zvHoFqNsPeK1mxikjgzxlRYjifXqRVuSs/Z +EpsH8seh4xzevR5AsWL966ITdlERS1jCaUv/j8AnXXwfHFRj/2ZYoZr8xOm23ZIQFgB wkhcP2suXR1FNqGOpsT1xXvlSEa4IKovd7hBQEEgWl8H2R5pj9dz0sEB4hy1rHORxHnj Bikw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3-v6si27526066pld.146.2018.09.21.06.28.27; Fri, 21 Sep 2018 06:28:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390162AbeIUTPt (ORCPT + 99 others); Fri, 21 Sep 2018 15:15:49 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37194 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390100AbeIUTPh (ORCPT ); Fri, 21 Sep 2018 15:15:37 -0400 Received: by mail-wm1-f68.google.com with SMTP id n11-v6so3270626wmc.2 for ; Fri, 21 Sep 2018 06:26:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=o52x8tjPTmNioW0bBVA6BC8kUEvUd+5T8EUKIIECF/I=; b=pHRJ9HSp97MpKi5tVCar/D7uzpRpj5oZYpsxd1oFIFfjuGKoGMC+P4IEc6dDX7t2cp p9HdTOWlroDT9XwfzY4H0sPpDmqF33Q9JeLXdL+Tm5DT6XEyGS8Grt/7Aod1JieAN/2L cDrOi/80Nl5Vfq9n65esXzg4/UDSAu9JBHtD44ZJ8LmKZJ/rHuIu+MN2FzIcK+AJRcRM fafnXtUni+NRg9hzsm9M56hd8iCtyek8o+QE4kgmavLaNI3GC3n5+1/+jX/fJzwZta/I dtlVZ5OT/vFuYppL9iNjhyb5WDuQ8vE4rn8HfdvGsSwSpV11uU7SXGU7TFprrW8p8b26 dvPQ== X-Gm-Message-State: ABuFfogrgUsVP8EpI86i5rZF585enYQTylVRkvNAnmQX44R+GUHOUAOo CIPPHwCi627b43VjUu0Lg4k= 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: ___ 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 Reviewed-by: Pavel Tatashin --- mm/memory_hotplug.c | 80 +++++++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 51 deletions(-) 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) -- 2.13.6