Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

About linux v5.4 kernel arm64_memblock_init() / fdt_enforce_memory_region()

$
0
0

Q: What is the use of linux,usable-memory-range property?

Background:

Recently I am analyzing how Linux kernel initializes memory. When I go to arm64_memblock_init function in arch/arm64/mm/init.c, I meet a function called fdt_enforce_memory_region().The function handles linux,usable-memory-range property of chosen node in device tree.

The function call chain is: arm64_memblock_init() -> fdt_enforce_memory_region() -> memblock_cap_memory_range().

void __init arm64_memblock_init(void)
{
    const s64 linear_region_size = BIT(vabits_actual - 1);

    /* Handle linux,usable-memory-range property */
    fdt_enforce_memory_region();
    ...
}
static void __init fdt_enforce_memory_region(void)
{
    struct memblock_region reg = {
        .size = 0,
    };

    of_scan_flat_dt(early_init_dt_scan_usablemem, &reg);

    if (reg.size)
        memblock_cap_memory_range(reg.base, reg.size);
}
void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size)
{
    int start_rgn, end_rgn;
    int i, ret;

    if (!size)
        return;

    ret = memblock_isolate_range(&memblock.memory, base, size,
                        &start_rgn, &end_rgn);
    if (ret)
        return;
    /* codes below this line make me confused */
    /* remove all the MAP regions */
    for (i = memblock.memory.cnt - 1; i >= end_rgn; i--)  /*-- 1 --*/
        if (!memblock_is_nomap(&memblock.memory.regions[i]))
            memblock_remove_region(&memblock.memory, i);

    for (i = start_rgn - 1; i >= 0; i--)                 /*-- 2 --*/
        if (!memblock_is_nomap(&memblock.memory.regions[i]))
            memblock_remove_region(&memblock.memory, i);

    /* truncate the reserved regions */
    memblock_remove_range(&memblock.reserved, 0, base); /*-- 3 --*/
    memblock_remove_range(&memblock.reserved,          /*-- 4 --*/
            base + size, PHYS_ADDR_MAX);
}

After reading some patches and /Documentation/devicetree/bindings/chosen.txt,I have learned linux,usable-memory-range property is related with crash dump kernel. It should have some relationship with kdump. But why memblock_cap_memory_range() remove 'memory' and 'reserved' type memory which are marked above the function from 1 to 4, and it only reserves memory from [base, base + size]? I can't understand this.

But from some books, they say "linux,usable-memory-range" prop is the usable range of memory, and memblock_cap_memory_range() remove memory beyond this range. If this saying is true,I can understand this. However, as I show above, some patches and this article as well as /Documentation/devicetree/bindings/chosen.txt said the prop is related with kdump.

So, What is the use of linux,usable-memory-range property?


Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>