Skip to content

app shared memory placeholders waste memory #13923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewboie opened this issue Feb 28, 2019 · 0 comments
Closed

app shared memory placeholders waste memory #13923

andrewboie opened this issue Feb 28, 2019 · 0 comments
Assignees
Labels
area: Memory Protection bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@andrewboie
Copy link
Contributor

andrewboie commented Feb 28, 2019

For application shared memory partitions declared with K_APPMEM_PARTITION_DEFINE(), we insert a placeholder char symbol in each partition.

If a partition is declared with K_APPMEM_PARTITION, but never has any
data assigned to its contents, then no symbols with its prefix will end
up in the symbol table. This prevents gen_app_partitions.py from detecting
that the partition exists, and the linker symbols which specify partition
bounds will not be generated, resulting in build errors.

However, wasting a byte like this can actually waste a great deal more memory on power-of-two systems. If I declare a buffer of some power of two size and declare a partition for it, say 256 bytes, the extra char for the placeholder will push the section to 257 bytes, and a region of 512 bytes will be created instead.

Also, empty sections can take up a lot of room on MMU-based systems, since a section of size 1 results in an entire 4k page being consumed on x86.

We need to allow zero-sized partitions without wasting memory like this, and not increase the size of partitions that do have data in them. For example, depending on the C library and kernel configuration, z_libc_partition may be empty or z_malloc_partition may be empty.

@andrewboie andrewboie added bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug area: Memory Protection labels Feb 28, 2019
@andrewboie andrewboie self-assigned this Feb 28, 2019
andrewboie pushed a commit to andrewboie/zephyr that referenced this issue Mar 2, 2019
We used to leave byte-long placeholder symbols to ensure
that empty application memory sections did not cause
build errors that were very difficult to understand.

Now we use some relatively portable inline assembly to
generate a symbol, but don't take up any extra space.

The malloc and libc partitions are now only instantiated
if there is some data to put in them.

Fixes: zephyrproject-rtos#13923

Signed-off-by: Andrew Boie <[email protected]>
andrewboie pushed a commit that referenced this issue Mar 4, 2019
We used to leave byte-long placeholder symbols to ensure
that empty application memory sections did not cause
build errors that were very difficult to understand.

Now we use some relatively portable inline assembly to
generate a symbol, but don't take up any extra space.

The malloc and libc partitions are now only instantiated
if there is some data to put in them.

Fixes: #13923

Signed-off-by: Andrew Boie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Memory Protection bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

No branches or pull requests

1 participant