zephyr/doc/kernel/memory_management
Nicolas Pitre e9a47d932c kernel: mmu: shrink and align struct z_page_frame
The struct z_page_frame is marked __packed to avoid extra padding as
such padding may represent significant memory waste when lots of page
frames are used. However this is a bad strategy.

The code contained this somewhat dubious comment and code in
free_page_frame_list_put():

	/* The structure is packed, which ensures that this is true */
	void *node = pf;
	sys_slist_append(&free_page_frame_list, node);

This is bad for many reasons:

- type checking is completely bypassed;

- if the sys_snode_t node member is no longer located at the front of
  struct z_page_frame then the code will still compile and possibly run
  but be broken with memory corruption as a likely outcome;

- the sys_slist_append() code is completely unaware of the packed
  attribute which breaks architectures with alignment restrictions.

Let's improve code efficiency as well as memory usage by removing the
packed attribute and manually packing the flags in the unused virtual
address bits. This way the page frame array remains naturally aligned,
data access becomes optimal and the actual array size gets even smaller.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-05-13 16:04:40 -04:00
..
demand_paging.rst kernel: mmu: shrink and align struct z_page_frame 2024-05-13 16:04:40 -04:00
heap.rst doc: fix typo in multiple directories (build, hardware, kernel, project) 2024-01-26 13:16:18 +01:00
index.rst doc: kernel/mm: add a page about virtual memory 2023-12-08 08:31:15 -05:00
shared_multi_heap.rst shared_multi_heap: Rework framework 2022-04-21 13:15:26 +02:00
slabs.rst docs: mem: slabs: fix for mem_slab docs snippets 2023-10-17 13:17:56 +03:00
sys_mem_blocks.rst doc: memory: Fix SYS_MEM_BLOCKS_DEFINE_STATIC description 2023-11-06 19:03:29 -05:00
virtual_memory.rst doc: kernel/mm: add a page about virtual memory 2023-12-08 08:31:15 -05:00