All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Zhang Zhen <zhenzhang.zhang@huawei.com>,
	shaohui.zheng@intel.com, mgorman@suse.de, mingo@redhat.com,
	Linux MM <linux-mm@kvack.org>,
	linux-kernel@vger.kernel.org
Cc: wangnan0@huawei.com, akpm@linux-foundation.org
Subject: Re: [PATCH] memory hotplug: update the variables after memory removed
Date: Mon, 28 Jul 2014 08:12:28 -0700	[thread overview]
Message-ID: <53D6685C.1060509@intel.com> (raw)
In-Reply-To: <53D642E5.2010305@huawei.com>

On 07/28/2014 05:32 AM, Zhang Zhen wrote:
> -static void  update_end_of_memory_vars(u64 start, u64 size)
> +static void  update_end_of_memory_vars(u64 start, u64 size, bool flag)
>  {
> -	unsigned long end_pfn = PFN_UP(start + size);
> -
> -	if (end_pfn > max_pfn) {
> -		max_pfn = end_pfn;
> -		max_low_pfn = end_pfn;
> -		high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
> +	unsigned long end_pfn;
> +
> +	if (flag) {
> +		end_pfn = PFN_UP(start + size);
> +		if (end_pfn > max_pfn) {
> +			max_pfn = end_pfn;
> +			max_low_pfn = end_pfn;
> +			high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
> +		}
> +	} else {
> +		end_pfn = PFN_UP(start);
> +		if (end_pfn < max_pfn) {
> +			max_pfn = end_pfn;
> +			max_low_pfn = end_pfn;
> +			high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
> +		}
>  	}
>  }

I would really prefer not to see code like this.

This patch takes a small function that did one thing, copies-and-pastes
its code 100%, subtly changes it, and makes it do two things.  The only
thing to tell us what the difference between these two subtly different
things is a variable called 'flag'.  So the variable is useless in
trying to figure out what each version is supposed to do.

But, this fixes a pretty glaring deficiency in the memory remove code.

I would suggest making two functions.  Make it clear that one is to be
used at remove time and the other at add time.  Maybe

	move_end_of_memory_vars_down()
and
	move_end_of_memory_vars_up()

?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Dave Hansen <dave.hansen@intel.com>
To: Zhang Zhen <zhenzhang.zhang@huawei.com>,
	shaohui.zheng@intel.com, mgorman@suse.de, mingo@redhat.com,
	Linux MM <linux-mm@kvack.org>,
	linux-kernel@vger.kernel.org
Cc: wangnan0@huawei.com, akpm@linux-foundation.org
Subject: Re: [PATCH] memory hotplug: update the variables after memory removed
Date: Mon, 28 Jul 2014 08:12:28 -0700	[thread overview]
Message-ID: <53D6685C.1060509@intel.com> (raw)
In-Reply-To: <53D642E5.2010305@huawei.com>

On 07/28/2014 05:32 AM, Zhang Zhen wrote:
> -static void  update_end_of_memory_vars(u64 start, u64 size)
> +static void  update_end_of_memory_vars(u64 start, u64 size, bool flag)
>  {
> -	unsigned long end_pfn = PFN_UP(start + size);
> -
> -	if (end_pfn > max_pfn) {
> -		max_pfn = end_pfn;
> -		max_low_pfn = end_pfn;
> -		high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
> +	unsigned long end_pfn;
> +
> +	if (flag) {
> +		end_pfn = PFN_UP(start + size);
> +		if (end_pfn > max_pfn) {
> +			max_pfn = end_pfn;
> +			max_low_pfn = end_pfn;
> +			high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
> +		}
> +	} else {
> +		end_pfn = PFN_UP(start);
> +		if (end_pfn < max_pfn) {
> +			max_pfn = end_pfn;
> +			max_low_pfn = end_pfn;
> +			high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
> +		}
>  	}
>  }

I would really prefer not to see code like this.

This patch takes a small function that did one thing, copies-and-pastes
its code 100%, subtly changes it, and makes it do two things.  The only
thing to tell us what the difference between these two subtly different
things is a variable called 'flag'.  So the variable is useless in
trying to figure out what each version is supposed to do.

But, this fixes a pretty glaring deficiency in the memory remove code.

I would suggest making two functions.  Make it clear that one is to be
used at remove time and the other at add time.  Maybe

	move_end_of_memory_vars_down()
and
	move_end_of_memory_vars_up()

?

  reply	other threads:[~2014-07-28 15:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1406550617-19556-1-git-send-email-zhenzhang.zhang@huawei.com>
2014-07-28 12:32 ` [PATCH] memory hotplug: update the variables after memory removed Zhang Zhen
2014-07-28 12:32   ` Zhang Zhen
2014-07-28 15:12   ` Dave Hansen [this message]
2014-07-28 15:12     ` Dave Hansen
2014-07-28 23:12     ` David Rientjes
2014-07-28 23:12       ` David Rientjes
2014-07-28 23:24       ` Dave Hansen
2014-07-28 23:24         ` Dave Hansen
2014-07-29  6:55         ` Zhang Zhen
2014-07-29  6:55           ` Zhang Zhen

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=53D6685C.1060509@intel.com \
    --to=dave.hansen@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=shaohui.zheng@intel.com \
    --cc=wangnan0@huawei.com \
    --cc=zhenzhang.zhang@huawei.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.