Skip to content

Commit e649804

Browse files
htejunH. Peter Anvin
authored andcommitted
memblock: Separate out memblock_find_in_range_node()
Node affine memblock allocation logic is currently implemented across memblock_alloc_nid() and memblock_alloc_nid_region(). This reorganizes it such that it resembles that of non-NUMA allocation API. Area finding is collected and moved into new exported function memblock_find_in_range_node() which is symmetrical to non-NUMA counterpart - it handles @start/@EnD and understands ANYWHERE and ACCESSIBLE. memblock_alloc_nid() now simply calls memblock_find_in_range_node() and reserves the returned area. This makes memblock_alloc[_try]_nid() observe ACCESSIBLE limit on node affine allocations too (again, this doesn't make any difference for the current sole user - sparc64). Signed-off-by: Tejun Heo <tj@kernel.org> Link: http://lkml.kernel.org/r/1310460395-30913-8-git-send-email-tj@kernel.org Cc: Yinghai Lu <yinghai@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent 34e1845 commit e649804

2 files changed

Lines changed: 36 additions & 25 deletions

File tree

‎include/linux/memblock.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ extern long memblock_reserve(phys_addr_t base, phys_addr_t size);
6161
/* The numa aware allocator is only available if
6262
* CONFIG_ARCH_POPULATES_NODE_MAP is set
6363
*/
64+
extern phys_addr_t memblock_find_in_range_node(phys_addr_t start,
65+
phys_addr_t end,
66+
phys_addr_t size,
67+
phys_addr_t align, int nid);
6468
extern phys_addr_t memblock_alloc_nid(phys_addr_t size, phys_addr_t align,
6569
int nid);
6670
extern phys_addr_t memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align,

‎mm/memblock.c‎

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -521,49 +521,56 @@ static phys_addr_t __init memblock_nid_range_rev(phys_addr_t start,
521521
return start;
522522
}
523523

524-
static phys_addr_t __init memblock_alloc_nid_region(struct memblock_region *mp,
524+
phys_addr_t __init memblock_find_in_range_node(phys_addr_t start,
525+
phys_addr_t end,
525526
phys_addr_t size,
526527
phys_addr_t align, int nid)
527528
{
528-
phys_addr_t start, end;
529+
struct memblock_type *mem = &memblock.memory;
530+
int i;
529531

530-
start = mp->base;
531-
end = start + mp->size;
532+
BUG_ON(0 == size);
532533

533-
while (start < end) {
534-
phys_addr_t this_start;
535-
int this_nid;
534+
/* Pump up max_addr */
535+
if (end == MEMBLOCK_ALLOC_ACCESSIBLE)
536+
end = memblock.current_limit;
536537

537-
this_start = memblock_nid_range_rev(start, end, &this_nid);
538-
if (this_nid == nid) {
539-
phys_addr_t ret = memblock_find_region(this_start, end, size, align);
540-
if (ret &&
541-
!memblock_add_region(&memblock.reserved, ret, size))
542-
return ret;
538+
for (i = mem->cnt - 1; i >= 0; i--) {
539+
struct memblock_region *r = &mem->regions[i];
540+
phys_addr_t base = max(start, r->base);
541+
phys_addr_t top = min(end, r->base + r->size);
542+
543+
while (base < top) {
544+
phys_addr_t tbase, ret;
545+
int tnid;
546+
547+
tbase = memblock_nid_range_rev(base, top, &tnid);
548+
if (nid == MAX_NUMNODES || tnid == nid) {
549+
ret = memblock_find_region(tbase, top, size, align);
550+
if (ret)
551+
return ret;
552+
}
553+
top = tbase;
543554
}
544-
end = this_start;
545555
}
556+
546557
return 0;
547558
}
548559

549560
phys_addr_t __init memblock_alloc_nid(phys_addr_t size, phys_addr_t align, int nid)
550561
{
551-
struct memblock_type *mem = &memblock.memory;
552-
int i;
553-
554-
BUG_ON(0 == size);
562+
phys_addr_t found;
555563

556-
/* We align the size to limit fragmentation. Without this, a lot of
564+
/*
565+
* We align the size to limit fragmentation. Without this, a lot of
557566
* small allocs quickly eat up the whole reserve array on sparc
558567
*/
559568
size = round_up(size, align);
560569

561-
for (i = mem->cnt - 1; i >= 0; i--) {
562-
phys_addr_t ret = memblock_alloc_nid_region(&mem->regions[i],
563-
size, align, nid);
564-
if (ret)
565-
return ret;
566-
}
570+
found = memblock_find_in_range_node(0, MEMBLOCK_ALLOC_ACCESSIBLE,
571+
size, align, nid);
572+
if (found && !memblock_add_region(&memblock.reserved, found, size))
573+
return found;
567574

568575
return 0;
569576
}

0 commit comments

Comments
 (0)