Skip to content

Commit 474b881

Browse files
htejunH. Peter Anvin
authored andcommitted
x86: Use absent_pages_in_range() instead of memblock_x86_hole_size()
memblock_x86_hole_size() calculates the total size of holes in a given range according to memblock and is used by numa emulation code and numa_meminfo_cover_memory(). Since conversion to MEMBLOCK_NODE_MAP, absent_pages_in_range() also uses memblock and gives the same result. This patch replaces memblock_x86_hole_size() uses with absent_pages_in_range(). After the conversion the x86 function doesn't have any user left and is killed. Signed-off-by: Tejun Heo <tj@kernel.org> Link: http://lkml.kernel.org/r/1310462166-31469-12-git-send-email-tj@kernel.org Cc: Yinghai Lu <yinghai@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent 6b5d41a commit 474b881

4 files changed

Lines changed: 20 additions & 68 deletions

File tree

‎arch/x86/include/asm/memblock.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
void memblock_x86_reserve_range(u64 start, u64 end, char *name);
77
void memblock_x86_free_range(u64 start, u64 end);
88

9-
u64 memblock_x86_hole_size(u64 start, u64 end);
10-
119
#endif

‎arch/x86/mm/memblock.c‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,55 +32,3 @@ void __init memblock_x86_free_range(u64 start, u64 end)
3232

3333
memblock_free(start, end - start);
3434
}
35-
36-
/*
37-
* Finds an active region in the address range from start_pfn to last_pfn and
38-
* returns its range in ei_startpfn and ei_endpfn for the memblock entry.
39-
*/
40-
static int __init memblock_x86_find_active_region(const struct memblock_region *ei,
41-
unsigned long start_pfn,
42-
unsigned long last_pfn,
43-
unsigned long *ei_startpfn,
44-
unsigned long *ei_endpfn)
45-
{
46-
u64 align = PAGE_SIZE;
47-
48-
*ei_startpfn = round_up(ei->base, align) >> PAGE_SHIFT;
49-
*ei_endpfn = round_down(ei->base + ei->size, align) >> PAGE_SHIFT;
50-
51-
/* Skip map entries smaller than a page */
52-
if (*ei_startpfn >= *ei_endpfn)
53-
return 0;
54-
55-
/* Skip if map is outside the node */
56-
if (*ei_endpfn <= start_pfn || *ei_startpfn >= last_pfn)
57-
return 0;
58-
59-
/* Check for overlaps */
60-
if (*ei_startpfn < start_pfn)
61-
*ei_startpfn = start_pfn;
62-
if (*ei_endpfn > last_pfn)
63-
*ei_endpfn = last_pfn;
64-
65-
return 1;
66-
}
67-
68-
/*
69-
* Find the hole size (in bytes) in the memory range.
70-
* @start: starting address of the memory range to scan
71-
* @end: ending address of the memory range to scan
72-
*/
73-
u64 __init memblock_x86_hole_size(u64 start, u64 end)
74-
{
75-
unsigned long start_pfn = start >> PAGE_SHIFT;
76-
unsigned long last_pfn = end >> PAGE_SHIFT;
77-
unsigned long ei_startpfn, ei_endpfn, ram = 0;
78-
struct memblock_region *r;
79-
80-
for_each_memblock(memory, r)
81-
if (memblock_x86_find_active_region(r, start_pfn, last_pfn,
82-
&ei_startpfn, &ei_endpfn))
83-
ram += ei_endpfn - ei_startpfn;
84-
85-
return end - start - ((u64)ram << PAGE_SHIFT);
86-
}

‎arch/x86/mm/numa.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
475475
numaram = 0;
476476
}
477477

478-
e820ram = max_pfn - (memblock_x86_hole_size(0,
479-
PFN_PHYS(max_pfn)) >> PAGE_SHIFT);
478+
e820ram = max_pfn - absent_pages_in_range(0, max_pfn);
479+
480480
/* We seem to lose 3 pages somewhere. Allow 1M of slack. */
481481
if ((s64)(e820ram - numaram) >= (1 << (20 - PAGE_SHIFT))) {
482482
printk(KERN_ERR "NUMA: nodes only cover %LuMB of your %LuMB e820 RAM. Not used.\n",

‎arch/x86/mm/numa_emulation.c‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ static int __init emu_find_memblk_by_nid(int nid, const struct numa_meminfo *mi)
2828
return -ENOENT;
2929
}
3030

31+
static u64 mem_hole_size(u64 start, u64 end)
32+
{
33+
unsigned long start_pfn = PFN_UP(start);
34+
unsigned long end_pfn = PFN_DOWN(end);
35+
36+
if (start_pfn < end_pfn)
37+
return PFN_PHYS(absent_pages_in_range(start_pfn, end_pfn));
38+
return 0;
39+
}
40+
3141
/*
3242
* Sets up nid to range from @start to @end. The return value is -errno if
3343
* something went wrong, 0 otherwise.
@@ -89,7 +99,7 @@ static int __init split_nodes_interleave(struct numa_meminfo *ei,
8999
* Calculate target node size. x86_32 freaks on __udivdi3() so do
90100
* the division in ulong number of pages and convert back.
91101
*/
92-
size = max_addr - addr - memblock_x86_hole_size(addr, max_addr);
102+
size = max_addr - addr - mem_hole_size(addr, max_addr);
93103
size = PFN_PHYS((unsigned long)(size >> PAGE_SHIFT) / nr_nodes);
94104

95105
/*
@@ -135,8 +145,7 @@ static int __init split_nodes_interleave(struct numa_meminfo *ei,
135145
* Continue to add memory to this fake node if its
136146
* non-reserved memory is less than the per-node size.
137147
*/
138-
while (end - start -
139-
memblock_x86_hole_size(start, end) < size) {
148+
while (end - start - mem_hole_size(start, end) < size) {
140149
end += FAKE_NODE_MIN_SIZE;
141150
if (end > limit) {
142151
end = limit;
@@ -150,16 +159,15 @@ static int __init split_nodes_interleave(struct numa_meminfo *ei,
150159
* this one must extend to the boundary.
151160
*/
152161
if (end < dma32_end && dma32_end - end -
153-
memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
162+
mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
154163
end = dma32_end;
155164

156165
/*
157166
* If there won't be enough non-reserved memory for the
158167
* next node, this one must extend to the end of the
159168
* physical node.
160169
*/
161-
if (limit - end -
162-
memblock_x86_hole_size(end, limit) < size)
170+
if (limit - end - mem_hole_size(end, limit) < size)
163171
end = limit;
164172

165173
ret = emu_setup_memblk(ei, pi, nid++ % nr_nodes,
@@ -180,7 +188,7 @@ static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
180188
{
181189
u64 end = start + size;
182190

183-
while (end - start - memblock_x86_hole_size(start, end) < size) {
191+
while (end - start - mem_hole_size(start, end) < size) {
184192
end += FAKE_NODE_MIN_SIZE;
185193
if (end > max_addr) {
186194
end = max_addr;
@@ -211,8 +219,7 @@ static int __init split_nodes_size_interleave(struct numa_meminfo *ei,
211219
* creates a uniform distribution of node sizes across the entire
212220
* machine (but not necessarily over physical nodes).
213221
*/
214-
min_size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) /
215-
MAX_NUMNODES;
222+
min_size = (max_addr - addr - mem_hole_size(addr, max_addr)) / MAX_NUMNODES;
216223
min_size = max(min_size, FAKE_NODE_MIN_SIZE);
217224
if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
218225
min_size = (min_size + FAKE_NODE_MIN_SIZE) &
@@ -252,16 +259,15 @@ static int __init split_nodes_size_interleave(struct numa_meminfo *ei,
252259
* this one must extend to the boundary.
253260
*/
254261
if (end < dma32_end && dma32_end - end -
255-
memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
262+
mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
256263
end = dma32_end;
257264

258265
/*
259266
* If there won't be enough non-reserved memory for the
260267
* next node, this one must extend to the end of the
261268
* physical node.
262269
*/
263-
if (limit - end -
264-
memblock_x86_hole_size(end, limit) < size)
270+
if (limit - end - mem_hole_size(end, limit) < size)
265271
end = limit;
266272

267273
ret = emu_setup_memblk(ei, pi, nid++ % MAX_NUMNODES,

0 commit comments

Comments
 (0)