Skip to content
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

mempool based on bget #5066

Merged
merged 2 commits into from
Jan 3, 2022
Merged

mempool based on bget #5066

merged 2 commits into from
Jan 3, 2022

Conversation

jenswi-linaro
Copy link
Contributor

This relates to the issue #5022 and the recently merged PR #5065

Reply to #5022 (comment)

Interesting, I wonder how much it can increase. Perhaps it's time to start looking for a alternative implementation to the mempool. I have an idea where bget could actually be reused with this.

Yes, we should look for some other mempool implementation as it hogs memory which is already free in some cases. It would be great if we can improve this implementation with bget.

This PR attempts to do this. Note that I haven't tried to tune MPI_MEMPOOL_SIZE.

The purpose of mempool is to be able to guarantee that temporary memory allocations will succeed during asymmetric cipher operations. As long as we return the memory allocated with mempool_alloc() we can use it in other functions too. There's a couple of examples of that in the code already. So the rule is: if you allocate memory with mempool_alloc() you should free it again before returning.

lib/libutils/isoc/bget_malloc.c Show resolved Hide resolved
DMSG("Max memory usage increased to %zu",
(size_t)pool->max_last_offset);
}
struct malloc_stats stats = { };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block should also be in CFG_WITH_STATS along with CFG_MEMPOOL_REPORT_LAST_OFFSET

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll enable CFG_WITH_STATS from mk/config.mk when CFG_MEMPOOL_REPORT_LAST_OFFSET=y.

@jenswi-linaro
Copy link
Contributor Author

It seems I've mixed up which change should go into which commit. I'll fix that and force push. This needs to be rebased so I'll do that too.

@jenswi-linaro
Copy link
Contributor Author

Updated

@sahilnxp
Copy link
Contributor

Acked-by: Sahil Malhotra <sahil.malhotra@nxp.com>

Exports raw_{memalign,malloc,free,calloc,realloc}() and also adds
raw_malloc_get_ctx_size(), raw_malloc_init_ctx(),
raw_malloc_add_pool() and raw_malloc_get_stats().

This allows using the malloc functions to allocate with a independent
memory pool.

Acked-by: Sahil Malhotra <sahil.malhotra@nxp.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Instead of the old stack like internal memory allocator, use the raw
malloc functions instead for more efficient memory usage.

CFG_WITH_STATS is enabled automatically if
CFG_MEMPOOL_REPORT_LAST_OFFSET is enabled to secure a new dependency in
the code.

Acked-by: Sahil Malhotra <sahil.malhotra@nxp.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
@jenswi-linaro
Copy link
Contributor Author

Tags applied. Rebased on master to resolve a conflict.

@jforissier jforissier merged commit a51d45b into OP-TEE:master Jan 3, 2022
@jenswi-linaro jenswi-linaro deleted the mpool branch January 10, 2022 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants