kernel: mmu: support for on-demand mappings

This provides memory mappings with the ability to be initialized in their
paged-out state and be paged in on demand. This is especially nice for
anonymous memory mappings as they no longer have to allocate all memory
at mem_map time. This also allows for file mappings to be implemented by
simply providing backing store location tokens.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2024-07-17 00:06:42 -04:00 committed by Anas Nashif
commit c9aa98ebc0
6 changed files with 144 additions and 13 deletions

View file

@ -344,9 +344,15 @@ ZTEST(demand_paging_stat, test_backing_store_capacity)
mem = k_mem_map(size, K_MEM_PERM_RW);
zassert_not_null(mem, "k_mem_map failed");
/* Show no memory is left */
ret = k_mem_map(CONFIG_MMU_PAGE_SIZE, K_MEM_PERM_RW);
zassert_is_null(ret, "k_mem_map shouldn't have succeeded");
if (!IS_ENABLED(CONFIG_DEMAND_MAPPING)) {
/* Show no memory is left */
ret = k_mem_map(CONFIG_MMU_PAGE_SIZE, K_MEM_PERM_RW);
zassert_is_null(ret, "k_mem_map shouldn't have succeeded");
} else {
/* Show it doesn't matter */
ret = k_mem_map(CONFIG_MMU_PAGE_SIZE, K_MEM_PERM_RW);
zassert_not_null(ret, "k_mem_map should have succeeded");
}
key = irq_lock();
faults = k_mem_num_pagefaults_get();
@ -448,6 +454,10 @@ ZTEST_USER(demand_paging_stat, test_user_get_hist)
void *demand_paging_api_setup(void)
{
arena = k_mem_map(arena_size, K_MEM_PERM_RW);
if (IS_ENABLED(CONFIG_DEMAND_MAPPING)) {
/* force pages in */
k_mem_page_in(arena, arena_size);
}
test_k_mem_page_out();
return NULL;