Re: [PATCH] memory hotplug: update the variables after memory removed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]