tools/testing/memblock/tests/alloc_nid_api.c
Source file repositories/reference/linux-study-clean/tools/testing/memblock/tests/alloc_nid_api.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/memblock/tests/alloc_nid_api.c- Extension
.c- Size
- 80875 bytes
- Lines
- 2734
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
alloc_nid_api.h
Detected Declarations
function get_memblock_alloc_nid_namefunction alloc_nid_top_down_simple_checkfunction alloc_nid_top_down_end_misaligned_checkfunction alloc_nid_exact_address_generic_checkfunction max_addrfunction alloc_nid_low_max_generic_checkfunction alloc_nid_min_reserved_generic_checkfunction alloc_nid_max_reserved_generic_checkfunction alloc_nid_top_down_reserved_with_space_checkfunction alloc_nid_reserved_full_merge_generic_checkfunction alloc_nid_top_down_reserved_no_space_checkfunction alloc_nid_reserved_all_generic_checkfunction alloc_nid_top_down_cap_max_checkfunction alloc_nid_top_down_cap_min_checkfunction alloc_nid_bottom_up_simple_checkfunction alloc_nid_bottom_up_start_misaligned_checkfunction alloc_nid_bottom_up_narrow_range_checkfunction alloc_nid_bottom_up_reserved_with_space_checkfunction alloc_nid_bottom_up_reserved_no_space_checkfunction alloc_nid_bottom_up_cap_max_checkfunction alloc_nid_bottom_up_cap_min_checkfunction alloc_nid_simple_checkfunction alloc_nid_misaligned_checkfunction alloc_nid_narrow_range_checkfunction alloc_nid_reserved_with_space_checkfunction alloc_nid_reserved_no_space_checkfunction alloc_nid_cap_max_checkfunction alloc_nid_cap_min_checkfunction alloc_nid_min_reserved_checkfunction alloc_nid_max_reserved_checkfunction alloc_nid_exact_address_checkfunction alloc_nid_reserved_full_merge_checkfunction alloc_nid_reserved_all_checkfunction alloc_nid_low_max_checkfunction memblock_alloc_nid_range_checksfunction alloc_nid_top_down_numa_simple_checkfunction memoryfunction memoryfunction alloc_nid_top_down_numa_part_reserved_checkfunction memoryfunction alloc_nid_top_down_numa_split_range_low_checkfunction alloc_nid_top_down_numa_split_range_high_checkfunction alloc_nid_top_down_numa_no_overlap_split_checkfunction alloc_nid_top_down_numa_no_overlap_low_checkfunction alloc_nid_top_down_numa_no_overlap_high_checkfunction alloc_nid_bottom_up_numa_simple_checkfunction memoryfunction memory
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
#include "alloc_nid_api.h"
static int alloc_nid_test_flags = TEST_F_NONE;
/*
* contains the fraction of MEM_SIZE contained in each node in basis point
* units (one hundredth of 1% or 1/10000)
*/
static const unsigned int node_fractions[] = {
2500, /* 1/4 */
625, /* 1/16 */
1250, /* 1/8 */
1250, /* 1/8 */
625, /* 1/16 */
625, /* 1/16 */
2500, /* 1/4 */
625, /* 1/16 */
};
static inline const char * const get_memblock_alloc_nid_name(int flags)
{
if (flags & TEST_F_EXACT)
return "memblock_alloc_exact_nid_raw";
if (flags & TEST_F_RAW)
return "memblock_alloc_try_nid_raw";
return "memblock_alloc_try_nid";
}
static inline void *run_memblock_alloc_nid(phys_addr_t size,
phys_addr_t align,
phys_addr_t min_addr,
phys_addr_t max_addr, int nid)
{
assert(!(alloc_nid_test_flags & TEST_F_EXACT) ||
(alloc_nid_test_flags & TEST_F_RAW));
/*
* TEST_F_EXACT should be checked before TEST_F_RAW since
* memblock_alloc_exact_nid_raw() performs raw allocations.
*/
if (alloc_nid_test_flags & TEST_F_EXACT)
return memblock_alloc_exact_nid_raw(size, align, min_addr,
max_addr, nid);
if (alloc_nid_test_flags & TEST_F_RAW)
return memblock_alloc_try_nid_raw(size, align, min_addr,
max_addr, nid);
return memblock_alloc_try_nid(size, align, min_addr, max_addr, nid);
}
/*
* A simple test that tries to allocate a memory region within min_addr and
* max_addr range:
*
* + +
* | + +-----------+ |
* | | | rgn | |
* +----+-------+-----------+------+
* ^ ^
* | |
* min_addr max_addr
*
* Expect to allocate a region that ends at max_addr.
*/
static int alloc_nid_top_down_simple_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
phys_addr_t size = SZ_128;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t rgn_end;
PREFIX_PUSH();
setup_memblock();
min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
max_addr = min_addr + SZ_512;
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
rgn_end = rgn->base + rgn->size;
ASSERT_NE(allocated_ptr, NULL);
assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
ASSERT_EQ(rgn->size, size);
ASSERT_EQ(rgn->base, max_addr - size);
ASSERT_EQ(rgn_end, max_addr);
Annotation
- Immediate include surface: `alloc_nid_api.h`.
- Detected declarations: `function get_memblock_alloc_nid_name`, `function alloc_nid_top_down_simple_check`, `function alloc_nid_top_down_end_misaligned_check`, `function alloc_nid_exact_address_generic_check`, `function max_addr`, `function alloc_nid_low_max_generic_check`, `function alloc_nid_min_reserved_generic_check`, `function alloc_nid_max_reserved_generic_check`, `function alloc_nid_top_down_reserved_with_space_check`, `function alloc_nid_reserved_full_merge_generic_check`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.