linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: sparse: use __aligned() instead of manual padding in mem_section
@ 2013-05-29 23:14 Cody P Schafer
  2013-05-30  0:54 ` Jiang Liu
  2013-05-30 17:39 ` Dave Hansen
  0 siblings, 2 replies; 6+ messages in thread
From: Cody P Schafer @ 2013-05-29 23:14 UTC (permalink / raw)
  To: Andrew Morton; +Cc: LKML, Linux MM, Cody P Schafer

Instead of leaving a trap for the next person who comes along and wants
to add something to mem_section, add an __aligned() and remove the
manual padding added for MEMCG.

Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
---
 include/linux/mmzone.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

---

Also, does anyone know what causes this alignment to be required here? I found
this was breaking things in a patchset I'm working on (WARNs in sysfs code
about duplicate filenames when initing mem_sections). Adding some documentation
for the reason would be appreciated.

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 131989a..a8e8056 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1125,9 +1125,8 @@ struct mem_section {
 	 * section. (see memcontrol.h/page_cgroup.h about this.)
 	 */
 	struct page_cgroup *page_cgroup;
-	unsigned long pad;
 #endif
-};
+} __aligned(2 * sizeof(unsigned long));
 
 #ifdef CONFIG_SPARSEMEM_EXTREME
 #define SECTIONS_PER_ROOT       (PAGE_SIZE / sizeof (struct mem_section))
-- 
1.8.3

--
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 related	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm: sparse: use __aligned() instead of manual padding in mem_section
  2013-05-29 23:14 [PATCH] mm: sparse: use __aligned() instead of manual padding in mem_section Cody P Schafer
@ 2013-05-30  0:54 ` Jiang Liu
  2013-05-30 16:36   ` Cody P Schafer
  2013-05-30 17:39 ` Dave Hansen
  1 sibling, 1 reply; 6+ messages in thread
From: Jiang Liu @ 2013-05-30  0:54 UTC (permalink / raw)
  To: Cody P Schafer; +Cc: LKML, Linux MM, Andrew Morton

On Thu 30 May 2013 07:14:39 AM CST, Cody P Schafer wrote:
> Instead of leaving a trap for the next person who comes along and wants
> to add something to mem_section, add an __aligned() and remove the
> manual padding added for MEMCG.
>
> Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
> ---
>  include/linux/mmzone.h | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> ---
>
> Also, does anyone know what causes this alignment to be required here? I found
> this was breaking things in a patchset I'm working on (WARNs in sysfs code
> about duplicate filenames when initing mem_sections). Adding some documentation
> for the reason would be appreciated.
Hi Cody,
        I think the alignment requirement is caused by the way the 
mem_section array is
organized. Basically it requires that PAGE_SIZE could be divided by 
sizeof(struct mem_section).
So your change seems risky too because it should be aligned to power of 
two instead
of 2 * sizeof(long).
Regards!
Gerry

>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 131989a..a8e8056 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -1125,9 +1125,8 @@ struct mem_section {
>  	 * section. (see memcontrol.h/page_cgroup.h about this.)
>  	 */
>  	struct page_cgroup *page_cgroup;
> -	unsigned long pad;
>  #endif
> -};
> +} __aligned(2 * sizeof(unsigned long));
>
>  #ifdef CONFIG_SPARSEMEM_EXTREME
>  #define SECTIONS_PER_ROOT       (PAGE_SIZE / sizeof (struct mem_section))


--
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] 6+ messages in thread

* Re: [PATCH] mm: sparse: use __aligned() instead of manual padding in mem_section
  2013-05-30  0:54 ` Jiang Liu
@ 2013-05-30 16:36   ` Cody P Schafer
  0 siblings, 0 replies; 6+ messages in thread
From: Cody P Schafer @ 2013-05-30 16:36 UTC (permalink / raw)
  To: Jiang Liu; +Cc: LKML, Linux MM, Andrew Morton

On 05/29/2013 05:54 PM, Jiang Liu wrote:
> On Thu 30 May 2013 07:14:39 AM CST, Cody P Schafer wrote:
>> Also, does anyone know what causes this alignment to be required here? I found
>> this was breaking things in a patchset I'm working on (WARNs in sysfs code
>> about duplicate filenames when initing mem_sections). Adding some documentation
>> for the reason would be appreciated.
> Hi Cody,
>          I think the alignment requirement is caused by the way the
> mem_section array is
> organized. Basically it requires that PAGE_SIZE could be divided by
> sizeof(struct mem_section).
> So your change seems risky too because it should be aligned to power of
> two instead
> of 2 * sizeof(long).

Well, if that's the case then this patch is wrong, and manual padding 
may be the only way to go. :(

--
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] 6+ messages in thread

* Re: [PATCH] mm: sparse: use __aligned() instead of manual padding in mem_section
  2013-05-29 23:14 [PATCH] mm: sparse: use __aligned() instead of manual padding in mem_section Cody P Schafer
  2013-05-30  0:54 ` Jiang Liu
@ 2013-05-30 17:39 ` Dave Hansen
  2013-05-30 18:40   ` [PATCH] sparsemem: BUILD_BUG_ON when sizeof mem_section is non-power-of-2 Cody P Schafer
  1 sibling, 1 reply; 6+ messages in thread
From: Dave Hansen @ 2013-05-30 17:39 UTC (permalink / raw)
  To: Cody P Schafer; +Cc: Andrew Morton, LKML, Linux MM

On 05/29/2013 04:14 PM, Cody P Schafer wrote:
> Instead of leaving a trap for the next person who comes along and wants
> to add something to mem_section, add an __aligned() and remove the
> manual padding added for MEMCG.

It doesn't need to be aligned technically.  It needs to be a power-of-2:

http://lkml.indiana.edu/hypermail/linux/kernel/1205.2/03077.html

I'd be quite happy for someone to resurrect that patch, though.  We need
a big fat comment in there.

--
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] 6+ messages in thread

* [PATCH] sparsemem: BUILD_BUG_ON when sizeof mem_section is non-power-of-2
  2013-05-30 17:39 ` Dave Hansen
@ 2013-05-30 18:40   ` Cody P Schafer
  2013-05-30 19:18     ` Dave Hansen
  0 siblings, 1 reply; 6+ messages in thread
From: Cody P Schafer @ 2013-05-30 18:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: LKML, Linux MM, David Hansen, Cody P Schafer

Instead of leaving a hidden trap for the next person who comes along and
wants to add something to mem_section, add a big fat warning about it
needing to be a power-of-2, and insert a BUILD_BUG_ON() in sparse_init()
to catch mistakes.

Right now non-power-of-2 mem_sections cause a number of WARNs at boot
(which don't clearly point to the size of mem_section as an issue), but
the system limps on (temporarily, at least).

This is based upon Dave Hansen's earlier RFC where he ran into the same
issue:
	"sparsemem: fix boot when SECTIONS_PER_ROOT is not power-of-2"
	http://lkml.indiana.edu/hypermail/linux/kernel/1205.2/03077.html

Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
---

Dave: Consider it resurrected.

---

 include/linux/mmzone.h | 4 ++++
 mm/sparse.c            | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 131989a..88e23f3 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1127,6 +1127,10 @@ struct mem_section {
 	struct page_cgroup *page_cgroup;
 	unsigned long pad;
 #endif
+	/*
+	 * WARNING: mem_section must be a power-of-2 in size for the
+	 * calculation and use of SECTION_ROOT_MASK to make sense.
+	 */
 };
 
 #ifdef CONFIG_SPARSEMEM_EXTREME
diff --git a/mm/sparse.c b/mm/sparse.c
index 1c91f0d3..3194ec4 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -481,6 +481,9 @@ void __init sparse_init(void)
 	struct page **map_map;
 #endif
 
+	/* see include/linux/mmzone.h 'struct mem_section' definition */
+	BUILD_BUG_ON(!is_power_of_2(sizeof(struct mem_section)));
+
 	/* Setup pageblock_order for HUGETLB_PAGE_SIZE_VARIABLE */
 	set_pageblock_order();
 
-- 
1.8.3

--
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 related	[flat|nested] 6+ messages in thread

* Re: [PATCH] sparsemem: BUILD_BUG_ON when sizeof mem_section is non-power-of-2
  2013-05-30 18:40   ` [PATCH] sparsemem: BUILD_BUG_ON when sizeof mem_section is non-power-of-2 Cody P Schafer
@ 2013-05-30 19:18     ` Dave Hansen
  0 siblings, 0 replies; 6+ messages in thread
From: Dave Hansen @ 2013-05-30 19:18 UTC (permalink / raw)
  To: Cody P Schafer; +Cc: Andrew Morton, LKML, Linux MM, David Hansen

On 05/30/2013 11:40 AM, Cody P Schafer wrote:
> Instead of leaving a hidden trap for the next person who comes along and
> wants to add something to mem_section, add a big fat warning about it
> needing to be a power-of-2, and insert a BUILD_BUG_ON() in sparse_init()
> to catch mistakes.
> 
> Right now non-power-of-2 mem_sections cause a number of WARNs at boot
> (which don't clearly point to the size of mem_section as an issue), but
> the system limps on (temporarily, at least).
> 
> This is based upon Dave Hansen's earlier RFC where he ran into the same
> issue:
> 	"sparsemem: fix boot when SECTIONS_PER_ROOT is not power-of-2"
> 	http://lkml.indiana.edu/hypermail/linux/kernel/1205.2/03077.html

Thanks for doing that, Cody.  At the risk of patting myself on the back:

Acked-by: Dave Hansen <dave.hansen@linux.intel.com>

--
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] 6+ messages in thread

end of thread, other threads:[~2013-05-30 19:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-29 23:14 [PATCH] mm: sparse: use __aligned() instead of manual padding in mem_section Cody P Schafer
2013-05-30  0:54 ` Jiang Liu
2013-05-30 16:36   ` Cody P Schafer
2013-05-30 17:39 ` Dave Hansen
2013-05-30 18:40   ` [PATCH] sparsemem: BUILD_BUG_ON when sizeof mem_section is non-power-of-2 Cody P Schafer
2013-05-30 19:18     ` Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).