linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC] mm: memblock: change default cnt for regions from 1 to 0
@ 2014-10-23 16:56 Zubair Lutfullah Kakakhel
  2014-10-23 19:18 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Zubair Lutfullah Kakakhel @ 2014-10-23 16:56 UTC (permalink / raw)
  To: akpm, Zubair.Kakakhel; +Cc: linux-mm, linux-kernel

The default region counts are set to 1 with a comment saying empty
dummy entry.

If this is a dummy entry, should this be changed to 0?

We have faced this in mips/kernel/setup.c arch_mem_init.

cma uses memblock. But even with cma disabled.
The for_each_memblock(reserved, reg) goes inside the loop.
Even without any reserved regions.

Traced it to the following, when the macro
for_each_memblock(memblock_type, region) is used.

It expands to add the cnt variable.

for (region = memblock.memblock_type.regions; 		\
	region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
	region++)

In the corner case, that there are no reserved regions.
Due to the default 1 value of cnt.
The loop under for_each_memblock still runs once.

Even when there is no reserved region.

Is this by design? or unintentional?
It might be that this loop runs an extra time every instance out there?
---
 mm/memblock.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 6d2f219..b91301c 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -33,16 +33,16 @@ static struct memblock_region memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS
 
 struct memblock memblock __initdata_memblock = {
 	.memory.regions		= memblock_memory_init_regions,
-	.memory.cnt		= 1,	/* empty dummy entry */
+	.memory.cnt		= 0,	/* empty dummy entry */
 	.memory.max		= INIT_MEMBLOCK_REGIONS,
 
 	.reserved.regions	= memblock_reserved_init_regions,
-	.reserved.cnt		= 1,	/* empty dummy entry */
+	.reserved.cnt		= 0,	/* empty dummy entry */
 	.reserved.max		= INIT_MEMBLOCK_REGIONS,
 
 #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
 	.physmem.regions	= memblock_physmem_init_regions,
-	.physmem.cnt		= 1,	/* empty dummy entry */
+	.physmem.cnt		= 0,	/* empty dummy entry */
 	.physmem.max		= INIT_PHYSMEM_REGIONS,
 #endif
 
-- 
1.9.1

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] mm: memblock: change default cnt for regions from 1 to 0
  2014-10-23 16:56 [RFC] mm: memblock: change default cnt for regions from 1 to 0 Zubair Lutfullah Kakakhel
@ 2014-10-23 19:18 ` Andrew Morton
  2014-10-27 14:17   ` Tejun Heo
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2014-10-23 19:18 UTC (permalink / raw)
  To: Zubair Lutfullah Kakakhel
  Cc: linux-mm, linux-kernel, Tejun Heo, Tang Chen, Yinghai Lu

(cc's added)

On Thu, 23 Oct 2014 17:56:53 +0100 Zubair Lutfullah Kakakhel <Zubair.Kakakhel@imgtec.com> wrote:

> The default region counts are set to 1 with a comment saying empty
> dummy entry.
> 
> If this is a dummy entry, should this be changed to 0?
> 
> We have faced this in mips/kernel/setup.c arch_mem_init.
> 
> cma uses memblock. But even with cma disabled.
> The for_each_memblock(reserved, reg) goes inside the loop.
> Even without any reserved regions.
> 
> Traced it to the following, when the macro
> for_each_memblock(memblock_type, region) is used.
> 
> It expands to add the cnt variable.
> 
> for (region = memblock.memblock_type.regions; 		\
> 	region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
> 	region++)
> 
> In the corner case, that there are no reserved regions.
> Due to the default 1 value of cnt.
> The loop under for_each_memblock still runs once.
> 
> Even when there is no reserved region.
> 
> Is this by design? or unintentional?
> It might be that this loop runs an extra time every instance out there?
> ---
>  mm/memblock.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 6d2f219..b91301c 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -33,16 +33,16 @@ static struct memblock_region memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS
>  
>  struct memblock memblock __initdata_memblock = {
>  	.memory.regions		= memblock_memory_init_regions,
> -	.memory.cnt		= 1,	/* empty dummy entry */
> +	.memory.cnt		= 0,	/* empty dummy entry */
>  	.memory.max		= INIT_MEMBLOCK_REGIONS,
>  
>  	.reserved.regions	= memblock_reserved_init_regions,
> -	.reserved.cnt		= 1,	/* empty dummy entry */
> +	.reserved.cnt		= 0,	/* empty dummy entry */
>  	.reserved.max		= INIT_MEMBLOCK_REGIONS,
>  
>  #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
>  	.physmem.regions	= memblock_physmem_init_regions,
> -	.physmem.cnt		= 1,	/* empty dummy entry */
> +	.physmem.cnt		= 0,	/* empty dummy entry */
>  	.physmem.max		= INIT_PHYSMEM_REGIONS,
>  #endif
>  
> -- 
> 1.9.1

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] mm: memblock: change default cnt for regions from 1 to 0
  2014-10-23 19:18 ` Andrew Morton
@ 2014-10-27 14:17   ` Tejun Heo
  2014-10-27 14:38     ` Zubair Lutfullah Kakakhel
  0 siblings, 1 reply; 4+ messages in thread
From: Tejun Heo @ 2014-10-27 14:17 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Zubair Lutfullah Kakakhel, linux-mm, linux-kernel, Tang Chen, Yinghai Lu

Hello,

On Thu, Oct 23, 2014 at 12:18:40PM -0700, Andrew Morton wrote:
> On Thu, 23 Oct 2014 17:56:53 +0100 Zubair Lutfullah Kakakhel <Zubair.Kakakhel@imgtec.com> wrote:
> 
> > The default region counts are set to 1 with a comment saying empty
> > dummy entry.
> > 
> > If this is a dummy entry, should this be changed to 0?

My memory is hazy now but I'm pretty sure there's a bunch of stuff
assuming that the array is never empty.

> > We have faced this in mips/kernel/setup.c arch_mem_init.
> > 
> > cma uses memblock. But even with cma disabled.
> > The for_each_memblock(reserved, reg) goes inside the loop.
> > Even without any reserved regions.

Does that matter?  It's a zero-length reservation.

> > Traced it to the following, when the macro
> > for_each_memblock(memblock_type, region) is used.
> > 
> > It expands to add the cnt variable.
> > 
> > for (region = memblock.memblock_type.regions; 		\
> > 	region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
> > 	region++)
> > 
> > In the corner case, that there are no reserved regions.
> > Due to the default 1 value of cnt.
> > The loop under for_each_memblock still runs once.
> > 
> > Even when there is no reserved region.
> > 
> > Is this by design? or unintentional?

It's by design.

> > It might be that this loop runs an extra time every instance out there?

The first actual entry replaces the dummy one and the last removal
makes the entry dummy again, so the dummy one exists iff that's the
only entry.  I don't recall the exact details right now but the choice
was an intentional one.

Thanks.

-- 
tejun

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] mm: memblock: change default cnt for regions from 1 to 0
  2014-10-27 14:17   ` Tejun Heo
@ 2014-10-27 14:38     ` Zubair Lutfullah Kakakhel
  0 siblings, 0 replies; 4+ messages in thread
From: Zubair Lutfullah Kakakhel @ 2014-10-27 14:38 UTC (permalink / raw)
  To: Tejun Heo, Andrew Morton; +Cc: linux-mm, linux-kernel, Tang Chen, Yinghai Lu


On 27/10/14 14:17, Tejun Heo wrote:
> Hello,
> 
> On Thu, Oct 23, 2014 at 12:18:40PM -0700, Andrew Morton wrote:
>> On Thu, 23 Oct 2014 17:56:53 +0100 Zubair Lutfullah Kakakhel <Zubair.Kakakhel@imgtec.com> wrote:
>>
>>> The default region counts are set to 1 with a comment saying empty
>>> dummy entry.
>>>
>>> If this is a dummy entry, should this be changed to 0?
> 
> My memory is hazy now but I'm pretty sure there's a bunch of stuff
> assuming that the array is never empty.
> 
>>> We have faced this in mips/kernel/setup.c arch_mem_init.
>>>
>>> cma uses memblock. But even with cma disabled.
>>> The for_each_memblock(reserved, reg) goes inside the loop.
>>> Even without any reserved regions.
> 
> Does that matter?  It's a zero-length reservation.
> 
>>> Traced it to the following, when the macro
>>> for_each_memblock(memblock_type, region) is used.
>>>
>>> It expands to add the cnt variable.
>>>
>>> for (region = memblock.memblock_type.regions; 		\
>>> 	region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
>>> 	region++)
>>>
>>> In the corner case, that there are no reserved regions.
>>> Due to the default 1 value of cnt.
>>> The loop under for_each_memblock still runs once.
>>>
>>> Even when there is no reserved region.
>>>
>>> Is this by design? or unintentional?
> 
> It's by design.
> 
>>> It might be that this loop runs an extra time every instance out there?
> 
> The first actual entry replaces the dummy one and the last removal
> makes the entry dummy again, so the dummy one exists iff that's the
> only entry.  I don't recall the exact details right now but the choice
> was an intentional one.
> 
> Thanks.
> 

Thank-you for clarifying.

Regards
ZubairLK

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-27 14:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-23 16:56 [RFC] mm: memblock: change default cnt for regions from 1 to 0 Zubair Lutfullah Kakakhel
2014-10-23 19:18 ` Andrew Morton
2014-10-27 14:17   ` Tejun Heo
2014-10-27 14:38     ` Zubair Lutfullah Kakakhel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox