Skip to content

Commit 4ca644d

Browse files
hansendcLinus Torvalds
authored andcommitted
[PATCH] memory hotplug prep: __section_nr helper
A little helper that we use in the hotplug code. Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ed8ece2 commit 4ca644d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/linux/mmzone.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ static inline struct mem_section *__nr_to_section(unsigned long nr)
509509
return NULL;
510510
return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
511511
}
512+
extern int __section_nr(struct mem_section* ms);
512513

513514
/*
514515
* We use the lower bits of the mem_map pointer to store

mm/sparse.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ static inline int sparse_index_init(unsigned long section_nr, int nid)
7272
}
7373
#endif
7474

75+
/*
76+
* Although written for the SPARSEMEM_EXTREME case, this happens
77+
* to also work for the flat array case becase
78+
* NR_SECTION_ROOTS==NR_MEM_SECTIONS.
79+
*/
80+
int __section_nr(struct mem_section* ms)
81+
{
82+
unsigned long root_nr;
83+
struct mem_section* root;
84+
85+
for (root_nr = 0;
86+
root_nr < NR_MEM_SECTIONS;
87+
root_nr += SECTIONS_PER_ROOT) {
88+
root = __nr_to_section(root_nr);
89+
90+
if (!root)
91+
continue;
92+
93+
if ((ms >= root) && (ms < (root + SECTIONS_PER_ROOT)))
94+
break;
95+
}
96+
97+
return (root_nr * SECTIONS_PER_ROOT) + (ms - root);
98+
}
99+
75100
/* Record a memory area against a node. */
76101
void memory_present(int nid, unsigned long start, unsigned long end)
77102
{

0 commit comments

Comments
 (0)