mmu: add k_mem_free_get()
Return the amount of physical anonymous memory remaining. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
8ccec8eba6
commit
5db615bb38
2 changed files with 27 additions and 0 deletions
|
@ -138,6 +138,19 @@ void z_phys_map(uint8_t **virt_ptr, uintptr_t phys, size_t size,
|
||||||
*/
|
*/
|
||||||
#define K_MEM_MAP_GUARD BIT(18)
|
#define K_MEM_MAP_GUARD BIT(18)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the amount of free memory available
|
||||||
|
*
|
||||||
|
* The returned value will reflect how many free RAM page frames are available.
|
||||||
|
* If demand paging is enabled, it may still be possible to allocate more.
|
||||||
|
*
|
||||||
|
* The information reported by this function may go stale immediately if
|
||||||
|
* concurrent memory mappings or page-ins take place.
|
||||||
|
*
|
||||||
|
* @return Free physical RAM, in bytes
|
||||||
|
*/
|
||||||
|
size_t k_mem_free_get(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map anonymous memory into Zephyr's address space
|
* Map anonymous memory into Zephyr's address space
|
||||||
*
|
*
|
||||||
|
|
14
kernel/mmu.c
14
kernel/mmu.c
|
@ -363,6 +363,20 @@ out:
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t k_mem_free_get(void)
|
||||||
|
{
|
||||||
|
size_t ret;
|
||||||
|
k_spinlock_key_t key;
|
||||||
|
|
||||||
|
__ASSERT(page_frames_initialized, "%s called too early", __func__);
|
||||||
|
|
||||||
|
key = k_spin_lock(&z_mm_lock);
|
||||||
|
ret = z_free_page_count;
|
||||||
|
k_spin_unlock(&z_mm_lock, key);
|
||||||
|
|
||||||
|
return ret * CONFIG_MMU_PAGE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
/* This may be called from arch early boot code before z_cstart() is invoked.
|
/* This may be called from arch early boot code before z_cstart() is invoked.
|
||||||
* Data will be copied and BSS zeroed, but this must not rely on any
|
* Data will be copied and BSS zeroed, but this must not rely on any
|
||||||
* initialization functions being called prior to work correctly.
|
* initialization functions being called prior to work correctly.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue