Re: [PATCH 1/5] mm/sparse: check size of struct mm_section

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

 



>> Platforms like PPC might need two level mem_section for SPARSEMEM
>> with enabled CONFIG_SPARSEMEM_EXTREME. On the other hand, the
>> memory section descriptor might be allocated from bootmem allocator
>> with PAGE_SIZE alignment. In order to fully utilize the memory chunk
>> allocated from bootmem allocator, it'd better to assure memory
>> sector descriptor won't run across the boundary (PAGE_SIZE).
>
>Why? The memory is continuous, right?
>

Yes, the memory is conginous and the capacity of specific entry
in mem_section[NR_SECTION_ROOTS] has been defined as follows:


#define SECTIONS_PER_ROOT       (PAGE_SIZE / sizeof (struct mem_section))

Also, the memory is prone to be allocated from bootmem by function
alloc_bootmem_node(), which has PAGE_SIZE alignment. So I think it's
reasonable to introduce the extra check here from my personal view :-)

Thanks,
Gavin

>> 
>> The patch introduces the check on size of "struct mm_section" to
>> assure that.
>> 
>> Signed-off-by: Gavin Shan <shangw@xxxxxxxxxxxxxxxxxx>
>> ---
>>  mm/sparse.c |    9 +++++++++
>>  1 file changed, 9 insertions(+)
>> 
>> diff --git a/mm/sparse.c b/mm/sparse.c
>> index 6a4bf91..afd0998 100644
>> --- a/mm/sparse.c
>> +++ b/mm/sparse.c
>> @@ -63,6 +63,15 @@ static struct mem_section noinline __init_refok *sparse_index_alloc(int nid)
>>  	unsigned long array_size = SECTIONS_PER_ROOT *
>>  				   sizeof(struct mem_section);
>>  
>> +	/*
>> +	 * The root memory section descriptor might be allocated
>> +	 * from bootmem, which has minimal memory chunk requirement
>> +	 * of page. In order to fully utilize the memory, the sparse
>> +	 * memory section descriptor shouldn't run across the boundary
>> +	 * that bootmem allocator has.
>> +	 */
>> +	BUILD_BUG_ON(PAGE_SIZE % sizeof(struct mem_section));
>> +
>>  	if (slab_is_available()) {
>>  		if (node_state(nid, N_HIGH_MEMORY))
>>  			section = kmalloc_node(array_size, GFP_KERNEL, nid);
>> -- 
>> 1.7.9.5
>> 
>> --
>> 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>
>
>-- 
>Michal Hocko
>SUSE Labs
>SUSE LINUX s.r.o.
>Lihovarska 1060/12
>190 00 Praha 9    
>Czech Republic
>
>--
>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>
>

--
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]