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>
This commit is contained in:
parent
57305971d1
commit
e9a47d932c
3 changed files with 84 additions and 53 deletions
|
@ -53,6 +53,10 @@ Page Frame
|
|||
addresses. For every page frame, a ``struct z_page_frame`` is instantiated to
|
||||
store metadata. Flags for each page frame:
|
||||
|
||||
* ``Z_PAGE_FRAME_FREE`` indicates a page frame is unused and on the list of
|
||||
free page frames. When this flag is set, none of the other flags are
|
||||
meaningful and they must not be modified.
|
||||
|
||||
* ``Z_PAGE_FRAME_PINNED`` indicates a page frame is pinned in memory
|
||||
and should never be paged out.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue