2017-03-16 09:17:24

by Michal Hocko

[permalink] [raw]
Subject: Re: + mm-sparse-refine-usemap_size-a-little.patch added to -mm tree

[CC Mel]

On Fri 10-03-17 14:41:22, Andrew Morton wrote:
> From: Wei Yang <[email protected]>
> Subject: mm/sparse: refine usemap_size() a little
>
> Current implementation calculates usemap_size in two steps:
> * calculate number of bytes to cover these bits
> * calculate number of "unsigned long" to cover these bytes
>
> It would be more clear by:
> * calculate number of "unsigned long" to cover these bits
> * multiple it with sizeof(unsigned long)
>
> This patch refine usemap_size() a little to make it more easy to
> understand.

I haven't checked deeply yet but reading through 5c0e3066474b ("Fix
corruption of memmap on IA64 SPARSEMEM when mem_section is not a power
of 2") made me ask whether the case described in the commit message
still applies after this change or whether it has been considered at
all.

> Link: http://lkml.kernel.org/r/[email protected]
> Signed-off-by: Wei Yang <[email protected]>
> Cc: Tejun Heo <[email protected]>
> Signed-off-by: Andrew Morton <[email protected]>
> ---
>
> mm/sparse.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff -puN mm/sparse.c~mm-sparse-refine-usemap_size-a-little mm/sparse.c
> --- a/mm/sparse.c~mm-sparse-refine-usemap_size-a-little
> +++ a/mm/sparse.c
> @@ -248,10 +248,7 @@ static int __meminit sparse_init_one_sec
>
> unsigned long usemap_size(void)
> {
> - unsigned long size_bytes;
> - size_bytes = roundup(SECTION_BLOCKFLAGS_BITS, 8) / 8;
> - size_bytes = roundup(size_bytes, sizeof(unsigned long));
> - return size_bytes;
> + return BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS) * sizeof(unsigned long);
> }
>
> #ifdef CONFIG_MEMORY_HOTPLUG
> _
>
> Patches currently in -mm which might be from [email protected] are
>
> mm-sparse-refine-usemap_size-a-little.patch
> mm-page_alloc-return-0-in-case-this-node-has-no-page-within-the-zone.patch
>
> --
> To unsubscribe from this list: send the line "unsubscribe mm-commits" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Michal Hocko
SUSE Labs


2017-03-17 01:47:49

by Wei Yang

[permalink] [raw]
Subject: Re: + mm-sparse-refine-usemap_size-a-little.patch added to -mm tree

On Thu, Mar 16, 2017 at 10:17:18AM +0100, Michal Hocko wrote:
>[CC Mel]
>
>On Fri 10-03-17 14:41:22, Andrew Morton wrote:
>> From: Wei Yang <[email protected]>
>> Subject: mm/sparse: refine usemap_size() a little
>>
>> Current implementation calculates usemap_size in two steps:
>> * calculate number of bytes to cover these bits
>> * calculate number of "unsigned long" to cover these bytes
>>
>> It would be more clear by:
>> * calculate number of "unsigned long" to cover these bits
>> * multiple it with sizeof(unsigned long)
>>
>> This patch refine usemap_size() a little to make it more easy to
>> understand.
>
>I haven't checked deeply yet but reading through 5c0e3066474b ("Fix
>corruption of memmap on IA64 SPARSEMEM when mem_section is not a power
>of 2") made me ask whether the case described in the commit message
>still applies after this change or whether it has been considered at
>all.
>

Hi, Michal

Thanks for your comment.

By looking into the commit 5c0e3066474b, I think it does two things:
1. Recalculate the SECTION_BLOCKFLAGS_BITS
2. Move pageblock_flags out mem_section to make the structure power of 2 in
size.

When we look at the original data structure, pageblock_flags originally is
defined as a bitmap:

DECLARE_BITMAP(pageblock_flags, SECTION_BLOCKFLAGS_BITS);

Which in turn is:

#define DECLARE_BITMAP(pageblock_flags,SECTION_BLOCKFLAGS_BITS) \
unsigned long pageblock_flags[BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS)]

My patch is using BITS_TO_LONGS() to simplify the code and obviously has the
same effect.

Does this resolve your concern?

--
Wei Yang
Help you, Help me


Attachments:
(No filename) (1.61 kB)
signature.asc (819.00 B)
Download all attachments