Re: [PATCH v2] memblock: make memblock_find_in_range method private
Στις 2021-08-02 09:37, Mike Rapoport έγραψε: From: Mike Rapoport There are a lot of uses of memblock_find_in_range() along with memblock_reserve() from the times memblock allocation APIs did not exist. memblock_find_in_range() is the very core of memblock allocations, so any future changes to its internal behaviour would mandate updates of all the users outside memblock. Replace the calls to memblock_find_in_range() with an equivalent calls to memblock_phys_alloc() and memblock_phys_alloc_range() and make memblock_find_in_range() private method of memblock. This simplifies the callers, ensures that (unlikely) errors in memblock_reserve() are handled and improves maintainability of memblock_find_in_range(). Signed-off-by: Mike Rapoport --- v2: don't change error message in arm::reserve_crashkernel(), per Russell v1: https://lore.kernel.org/lkml/20210730104039.7047-1-r...@kernel.org arch/arm/kernel/setup.c | 18 + arch/arm64/kvm/hyp/reserved_mem.c | 9 +++ arch/arm64/mm/init.c | 36 - arch/mips/kernel/setup.c | 14 +- arch/riscv/mm/init.c | 44 ++- arch/s390/kernel/setup.c | 10 --- arch/x86/kernel/aperture_64.c | 5 ++-- arch/x86/mm/init.c| 21 +-- arch/x86/mm/numa.c| 5 ++-- arch/x86/mm/numa_emulation.c | 5 ++-- arch/x86/realmode/init.c | 2 +- drivers/acpi/tables.c | 5 ++-- drivers/base/arch_numa.c | 5 +--- drivers/of/of_reserved_mem.c | 12 ++--- include/linux/memblock.h | 2 -- mm/memblock.c | 2 +- 16 files changed, 78 insertions(+), 117 deletions(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index f97eb2371672..67f5421b2af7 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1012,31 +1012,25 @@ static void __init reserve_crashkernel(void) unsigned long long lowmem_max = __pa(high_memory - 1) + 1; if (crash_max > lowmem_max) crash_max = lowmem_max; - crash_base = memblock_find_in_range(CRASH_ALIGN, crash_max, - crash_size, CRASH_ALIGN); + + crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, + CRASH_ALIGN, crash_max); if (!crash_base) { pr_err("crashkernel reservation failed - No suitable area found.\n"); return; } } else { + unsigned long long crash_max = crash_base + crash_size; unsigned long long start; - start = memblock_find_in_range(crash_base, - crash_base + crash_size, - crash_size, SECTION_SIZE); + start = memblock_phys_alloc_range(crash_size, SECTION_SIZE, + crash_base, crash_max); if (start != crash_base) { pr_err("crashkernel reservation failed - memory is in use.\n"); return; } } - ret = memblock_reserve(crash_base, crash_size); - if (ret < 0) { - pr_warn("crashkernel reservation failed - memory is in use (0x%lx)\n", - (unsigned long)crash_base); - return; - } - pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", (unsigned long)(crash_size >> 20), (unsigned long)(crash_base >> 20), diff --git a/arch/arm64/kvm/hyp/reserved_mem.c b/arch/arm64/kvm/hyp/reserved_mem.c index d654921dd09b..578670e3f608 100644 --- a/arch/arm64/kvm/hyp/reserved_mem.c +++ b/arch/arm64/kvm/hyp/reserved_mem.c @@ -92,12 +92,10 @@ void __init kvm_hyp_reserve(void) * this is unmapped from the host stage-2, and fallback to PAGE_SIZE. */ hyp_mem_size = hyp_mem_pages << PAGE_SHIFT; - hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(), - ALIGN(hyp_mem_size, PMD_SIZE), - PMD_SIZE); + hyp_mem_base = memblock_phys_alloc(ALIGN(hyp_mem_size, PMD_SIZE), + PMD_SIZE); if (!hyp_mem_base) - hyp_mem_base = memblock_find_in_range(0, memblock_end_of_DRAM(), - hyp_mem_size, PAGE_SIZE); + hyp_mem_base = memblock_phys_alloc(hyp_mem_size, PAGE_SIZE); else hyp_mem_size = ALIGN(hyp_mem_size, PMD_SIZE); @@ -105,7 +103,6 @@ void __init kvm_hyp_reserve(void) kvm_err("Failed to reserve hyp memory\n"); return; } -
Re: [RFC PATCH 14/15] mm: introduce MIN_MAX_ORDER to replace MAX_ORDER as compile time constant.
On Thu, Aug 05, 2021 at 03:02:52PM -0400, Zi Yan wrote: > From: Zi Yan > > For other MAX_ORDER uses (described below), there is no need or too much > hassle to convert certain static array to dynamic ones. Add > MIN_MAX_ORDER to serve as compile time constant in place of MAX_ORDER. > > ARM64 hypervisor maintains its own free page list and does not import > any core kernel symbols, so soon-to-be runtime variable MAX_ORDER is not > accessible in ARM64 hypervisor code. Also there is no need to allocating > very large pages. > > In SLAB/SLOB/SLUB, 2-D array kmalloc_caches uses MAX_ORDER in its second > dimension. It is too much hassle to allocate memory for kmalloc_caches > before any proper memory allocator is set up. > > Signed-off-by: Zi Yan > Cc: Marc Zyngier > Cc: Catalin Marinas > Cc: Christoph Lameter > Cc: Vlastimil Babka > Cc: Quentin Perret > Cc: linux-arm-ker...@lists.infradead.org > Cc: kvmarm@lists.cs.columbia.edu > Cc: linux...@kvack.org > Cc: linux-ker...@vger.kernel.org > --- > arch/arm64/kvm/hyp/include/nvhe/gfp.h | 2 +- > arch/arm64/kvm/hyp/nvhe/page_alloc.c | 3 ++- > include/linux/mmzone.h| 3 +++ > include/linux/slab.h | 8 > mm/slab.c | 2 +- > mm/slub.c | 7 --- > 6 files changed, 15 insertions(+), 10 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/include/nvhe/gfp.h > b/arch/arm64/kvm/hyp/include/nvhe/gfp.h > index fb0f523d1492..c774b4a98336 100644 > --- a/arch/arm64/kvm/hyp/include/nvhe/gfp.h > +++ b/arch/arm64/kvm/hyp/include/nvhe/gfp.h > @@ -16,7 +16,7 @@ struct hyp_pool { >* API at EL2. >*/ > hyp_spinlock_t lock; > - struct list_head free_area[MAX_ORDER]; > + struct list_head free_area[MIN_MAX_ORDER]; > phys_addr_t range_start; > phys_addr_t range_end; > unsigned short max_order; > diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c > b/arch/arm64/kvm/hyp/nvhe/page_alloc.c > index 41fc25bdfb34..a1cc1b648de0 100644 > --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c > +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c > @@ -226,7 +226,8 @@ int hyp_pool_init(struct hyp_pool *pool, u64 pfn, > unsigned int nr_pages, > int i; > > hyp_spin_lock_init(>lock); > - pool->max_order = min(MAX_ORDER, get_order(nr_pages << PAGE_SHIFT)); > + > + pool->max_order = min(MIN_MAX_ORDER, get_order(nr_pages << PAGE_SHIFT)); > for (i = 0; i < pool->max_order; i++) > INIT_LIST_HEAD(>free_area[i]); > pool->range_start = phys; > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index 09aafc05aef4..379dada82d4b 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -27,11 +27,14 @@ > #ifndef CONFIG_ARCH_FORCE_MAX_ORDER > #ifdef CONFIG_SET_MAX_ORDER > #define MAX_ORDER CONFIG_SET_MAX_ORDER > +#define MIN_MAX_ORDER CONFIG_SET_MAX_ORDER > #else > #define MAX_ORDER 11 > +#define MIN_MAX_ORDER MAX_ORDER > #endif /* CONFIG_SET_MAX_ORDER */ > #else > #define MAX_ORDER CONFIG_ARCH_FORCE_MAX_ORDER > +#define MIN_MAX_ORDER CONFIG_ARCH_FORCE_MAX_ORDER > #endif /* CONFIG_ARCH_FORCE_MAX_ORDER */ > #define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) The end result of this #ifdef explosion looks entirely unreadable: /* Free memory management - zoned buddy allocator. */ #ifndef CONFIG_ARCH_FORCE_MAX_ORDER #ifdef CONFIG_SET_MAX_ORDER /* Defined in mm/page_alloc.c */ extern int buddy_alloc_max_order; #define MAX_ORDER buddy_alloc_max_order #define MIN_MAX_ORDER CONFIG_SET_MAX_ORDER #else #define MAX_ORDER 11 #define MIN_MAX_ORDER MAX_ORDER #endif /* CONFIG_SET_MAX_ORDER */ #else #ifdef CONFIG_SPARSEMEM_VMEMMAP /* Defined in mm/page_alloc.c */ extern int buddy_alloc_max_order; #define MAX_ORDER buddy_alloc_max_order #else #define MAX_ORDER CONFIG_ARCH_FORCE_MAX_ORDER #endif /* CONFIG_SPARSEMEM_VMEMMAP */ #define MIN_MAX_ORDER CONFIG_ARCH_FORCE_MAX_ORDER #endif /* CONFIG_ARCH_FORCE_MAX_ORDER */ > diff --git a/include/linux/slab.h b/include/linux/slab.h > index 2c0d80cca6b8..d8747c158db6 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -244,8 +244,8 @@ static inline void __check_heap_object(const void *ptr, > unsigned long n, > * to do various tricks to work around compiler limitations in order to > * ensure proper constant folding. > */ > -#define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT - 1) <= 25 ? \ > - (MAX_ORDER + PAGE_SHIFT - 1) : 25) > +#define KMALLOC_SHIFT_HIGH ((MIN_MAX_ORDER + PAGE_SHIFT - 1) <= 25 ? \ > + (MIN_MAX_ORDER + PAGE_SHIFT - 1) : 25) > #define KMALLOC_SHIFT_MAXKMALLOC_SHIFT_HIGH > #ifndef KMALLOC_SHIFT_LOW > #define KMALLOC_SHIFT_LOW5 > @@ -258,7 +258,7 @@ static inline void __check_heap_object(const void *ptr, > unsigned long n, > * (PAGE_SIZE*2). Larger requests are passed to the page allocator. > */ > #define KMALLOC_SHIFT_HIGH (PAGE_SHIFT + 1) >