Skip to content

Commit

Permalink
sparsemem: add BUILD_BUG_ON when sizeof mem_section is non-power-of-2
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Dave Hansen <[email protected]>
Cc: Jiang Liu <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
codyps authored and torvalds committed Jul 3, 2013
1 parent b26a3df commit 55878e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/linux/mmzone.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,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
Expand Down
3 changes: 3 additions & 0 deletions mm/sparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 55878e8

Please sign in to comment.