Re: [PATCH] mm: use BITS_PER_LONG to unify the definition in page->flags

2017-03-19 Thread Wei Yang
On Sun, Mar 19, 2017 at 11:08:22AM -0400, Michal Hocko wrote:
>On Sun 19-03-17 23:03:45, Wei Yang wrote:
>> On Sun, Mar 19, 2017 at 10:30:13AM -0400, Michal Hocko wrote:
>> >On Sat 18-03-17 08:39:14, Wei Yang wrote:
>> >> The field page->flags is defined as unsigned long and is divided into
>> >> several parts to store different information of the page, like section,
>> >> node, zone. Which means all parts must sit in the one "unsigned
>> >> long".
>> >> 
>> >> BITS_PER_LONG is used in several places to ensure this applies.
>> >> 
>> >> #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - 
>> >> NR_PAGEFLAGS
>> >> #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - 
>> >> NR_PAGEFLAGS
>> >> #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT <= 
>> >> BITS_PER_LONG - NR_PAGEFLAGS
>> >> 
>> >> While we use "sizeof(unsigned long) * 8" in the definition of
>> >> SECTIONS_PGOFF
>> >> 
>> >> #define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - 
>> >> SECTIONS_WIDTH)
>> >> 
>> >> This may not be that obvious for audience to catch the point.
>> >> 
>> >> This patch replaces the "sizeof(unsigned long) * 8" with BITS_PER_LONG to
>> >> make all this consistent.
>> >
>> >I am not really sure this is an improvement. page::flags is unsigned
>> >long nad the current code reflects that type.
>> >
>> 
>> Hi, Michal
>> 
>> Glad to hear from you.
>> 
>> I think the purpose of definition BITS_PER_LONG is more easily to let 
>> audience
>> know it is the number of bits of type long. If it has no improvement, we 
>> don't
>> need to define a specific macro .
>> 
>> And as you could see, several related macros use BITS_PER_LONG in their
>> definition. After this change, all of them will have a consistent definition.
>> 
>> After this change, code looks more neat :-)
>> 
>> So it looks more reasonable to use this.
>
>I do not think that this is sufficient to justify the change.
>

Fine~ Thanks for comments~

>-- 
>Michal Hocko
>SUSE Labs

-- 
Wei Yang
Help you, Help me


signature.asc
Description: PGP signature


Re: [PATCH] mm: use BITS_PER_LONG to unify the definition in page->flags

2017-03-19 Thread Michal Hocko
On Sun 19-03-17 23:03:45, Wei Yang wrote:
> On Sun, Mar 19, 2017 at 10:30:13AM -0400, Michal Hocko wrote:
> >On Sat 18-03-17 08:39:14, Wei Yang wrote:
> >> The field page->flags is defined as unsigned long and is divided into
> >> several parts to store different information of the page, like section,
> >> node, zone. Which means all parts must sit in the one "unsigned
> >> long".
> >> 
> >> BITS_PER_LONG is used in several places to ensure this applies.
> >> 
> >> #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - 
> >> NR_PAGEFLAGS
> >> #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - 
> >> NR_PAGEFLAGS
> >> #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT <= 
> >> BITS_PER_LONG - NR_PAGEFLAGS
> >> 
> >> While we use "sizeof(unsigned long) * 8" in the definition of
> >> SECTIONS_PGOFF
> >> 
> >> #define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - 
> >> SECTIONS_WIDTH)
> >> 
> >> This may not be that obvious for audience to catch the point.
> >> 
> >> This patch replaces the "sizeof(unsigned long) * 8" with BITS_PER_LONG to
> >> make all this consistent.
> >
> >I am not really sure this is an improvement. page::flags is unsigned
> >long nad the current code reflects that type.
> >
> 
> Hi, Michal
> 
> Glad to hear from you.
> 
> I think the purpose of definition BITS_PER_LONG is more easily to let audience
> know it is the number of bits of type long. If it has no improvement, we don't
> need to define a specific macro .
> 
> And as you could see, several related macros use BITS_PER_LONG in their
> definition. After this change, all of them will have a consistent definition.
> 
> After this change, code looks more neat :-)
> 
> So it looks more reasonable to use this.

I do not think that this is sufficient to justify the change.

-- 
Michal Hocko
SUSE Labs


Re: [PATCH] mm: use BITS_PER_LONG to unify the definition in page->flags

2017-03-19 Thread Wei Yang
On Sun, Mar 19, 2017 at 10:30:13AM -0400, Michal Hocko wrote:
>On Sat 18-03-17 08:39:14, Wei Yang wrote:
>> The field page->flags is defined as unsigned long and is divided into
>> several parts to store different information of the page, like section,
>> node, zone. Which means all parts must sit in the one "unsigned
>> long".
>> 
>> BITS_PER_LONG is used in several places to ensure this applies.
>> 
>> #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS
>> #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - 
>> NR_PAGEFLAGS
>> #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT <= 
>> BITS_PER_LONG - NR_PAGEFLAGS
>> 
>> While we use "sizeof(unsigned long) * 8" in the definition of
>> SECTIONS_PGOFF
>> 
>> #define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - 
>> SECTIONS_WIDTH)
>> 
>> This may not be that obvious for audience to catch the point.
>> 
>> This patch replaces the "sizeof(unsigned long) * 8" with BITS_PER_LONG to
>> make all this consistent.
>
>I am not really sure this is an improvement. page::flags is unsigned
>long nad the current code reflects that type.
>

Hi, Michal

Glad to hear from you.

I think the purpose of definition BITS_PER_LONG is more easily to let audience
know it is the number of bits of type long. If it has no improvement, we don't
need to define a specific macro .

And as you could see, several related macros use BITS_PER_LONG in their
definition. After this change, all of them will have a consistent definition.

After this change, code looks more neat :-)

So it looks more reasonable to use this.

-- 
Wei Yang
Help you, Help me


signature.asc
Description: PGP signature


Re: [PATCH] mm: use BITS_PER_LONG to unify the definition in page->flags

2017-03-19 Thread Michal Hocko
On Sat 18-03-17 08:39:14, Wei Yang wrote:
> The field page->flags is defined as unsigned long and is divided into
> several parts to store different information of the page, like section,
> node, zone. Which means all parts must sit in the one "unsigned
> long".
> 
> BITS_PER_LONG is used in several places to ensure this applies.
> 
> #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS
> #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
> #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT <= 
> BITS_PER_LONG - NR_PAGEFLAGS
> 
> While we use "sizeof(unsigned long) * 8" in the definition of
> SECTIONS_PGOFF
> 
> #define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - 
> SECTIONS_WIDTH)
> 
> This may not be that obvious for audience to catch the point.
> 
> This patch replaces the "sizeof(unsigned long) * 8" with BITS_PER_LONG to
> make all this consistent.

I am not really sure this is an improvement. page::flags is unsigned
long nad the current code reflects that type.

> Signed-off-by: Wei Yang 
> ---
>  include/linux/mm.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index b84615b0f64c..a5d80de089ff 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -684,7 +684,7 @@ int finish_mkwrite_fault(struct vm_fault *vmf);
>   */
>  
>  /* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPUPID] | ... | FLAGS | */
> -#define SECTIONS_PGOFF   ((sizeof(unsigned long)*8) - 
> SECTIONS_WIDTH)
> +#define SECTIONS_PGOFF   (BITS_PER_LONG - SECTIONS_WIDTH)
>  #define NODES_PGOFF  (SECTIONS_PGOFF - NODES_WIDTH)
>  #define ZONES_PGOFF  (NODES_PGOFF - ZONES_WIDTH)
>  #define LAST_CPUPID_PGOFF(ZONES_PGOFF - LAST_CPUPID_WIDTH)
> -- 
> 2.11.0
> 

-- 
Michal Hocko
SUSE Labs