All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pasha Tatashin <Pavel.Tatashin@microsoft.com>
To: Oscar Salvador <osalvador@techadventures.net>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Cc: "mhocko@suse.com" <mhocko@suse.com>,
	"dan.j.williams@intel.com" <dan.j.williams@intel.com>,
	"david@redhat.com" <david@redhat.com>,
	"Jonathan.Cameron@huawei.com" <Jonathan.Cameron@huawei.com>,
	"yasu.isimatu@gmail.com" <yasu.isimatu@gmail.com>,
	"malat@debian.org" <malat@debian.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Oscar Salvador <osalvador@suse.de>
Subject: Re: [PATCH 5/5] mm/memory_hotplug: Clean up node_states_check_changes_offline
Date: Fri, 21 Sep 2018 00:38:59 +0000	[thread overview]
Message-ID: <13ceceb0-6e01-71a1-1eaf-258b9cbb9f21@microsoft.com> (raw)
In-Reply-To: <20180919100819.25518-6-osalvador@techadventures.net>

On 9/19/18 6:08 AM, Oscar Salvador wrote:
> From: Oscar Salvador <osalvador@suse.de>
> 
> 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 <osalvador@suse.de>
> ---
>  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
> 


A couple nits:

I would simplify this a little, initialize all fields at the beginning

        arg->status_change_nid_normal = -1;
        arg->status_change_nid_high = -1;
        arg->status_change_nid = -1;

And remove all the elses, including ifdef else.

And remove:
        zt = ZONE_HIGHMEM;
        zt = ZONE_MOVABLE;

Use macros directly, lines are are still going to be under 80 chars.

Otherwise looks good.

Reviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>

Pavel

      reply	other threads:[~2018-09-21  0:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-19 10:08 [PATCH 0/5] Refactor node_states_check_changes_online/offline Oscar Salvador
2018-09-19 10:08 ` [PATCH 1/5] mm/memory_hotplug: Spare unnecessary calls to node_set_state Oscar Salvador
2018-09-20 20:53   ` Pasha Tatashin
2018-09-19 10:08 ` [PATCH 2/5] mm/memory_hotplug: Avoid node_set/clear_state(N_HIGH_MEMORY) when !CONFIG_HIGHMEM Oscar Salvador
2018-09-20 20:59   ` Pasha Tatashin
2018-09-21 10:31     ` Oscar Salvador
2018-09-19 10:08 ` [PATCH 3/5] mm/memory_hotplug: Tidy up node_states_clear_node Oscar Salvador
2018-09-20 23:40   ` Pasha Tatashin
2018-09-19 10:08 ` [PATCH 4/5] mm/memory_hotplug: Simplify node_states_check_changes_online Oscar Salvador
2018-09-21  0:15   ` Pasha Tatashin
2018-09-21 10:30     ` Oscar Salvador
2018-09-19 10:08 ` [PATCH 5/5] mm/memory_hotplug: Clean up node_states_check_changes_offline Oscar Salvador
2018-09-21  0:38   ` Pasha Tatashin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=13ceceb0-6e01-71a1-1eaf-258b9cbb9f21@microsoft.com \
    --to=pavel.tatashin@microsoft.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=malat@debian.org \
    --cc=mhocko@suse.com \
    --cc=osalvador@suse.de \
    --cc=osalvador@techadventures.net \
    --cc=yasu.isimatu@gmail.com \
    --subject='Re: [PATCH 5/5] mm/memory_hotplug: Clean up node_states_check_changes_offline' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.