Stepping back slightly I am going to argue that fundamentally the issue here is that the heap is being used in a place where the stack should be. In this case due to vspace_new_pages having to allocate a reservation to do the mapping, only to immediately free the reservation in the same function. Having to allocate a reservation with malloc is in some ways an 'accident' of how the interfaces work, and not something that we actually want or need to happen in this case.
This is something that might need to be discussed internally, as it has wider reaching impacts and breakages, but I would lean towards changing the vspace API to either
* Make it possible to create reservations without involving malloc (by being able to pass a prior allocation to the reserve functions or otherwise)
* Allow for passing in 'NULL' reservations to create/map pages
Otherwise without changing the API doing 'self' allocation, i.e. your MEMPOOL_USE_VSPACE, instead of malloc seems reasonable, I just think it's not as 'clean' as removing the need for allocation altogether, and so think we should explore that avenue first.
Adrian
On Thu 27-Jul-2017 12:34 PM, Fabrizio Bertocci wrote:
Hi Kofi,
Thanks for your reply.
I have modified the vspace.c to get the area for the cached sel4utils_res_t object in a configurable way. This seems to be solve my problem, but would you mind taking a look and see if I have missed something or if I'm doing something wrong? I still don't have a full understanding of the vspace/vka and memory management, so I need a second pair of eyes here.
See attached diff.
In short, there are 3 ways to dynamically allocate memory for the cached objects, controlled by a macro defined at the beginning of the file:
- If you define MEMPOOL_USE_MALLOC will do exactly as now, it will call malloc/free to allocate the dynamic sel4utils_res_t
- If you define MEMPOOL_USE_STATIC (to a numeric value), it will simply use a static pool of sel4utils_res_t objects, falling to use malloc() if this limit is reached. This was an experimental/intermediate version before I implemented the next version.
- If you define MEMPOOL_USE_VSPACE will dynamically allocate pools of sel4utils_res_t objects as needed from vspace. Mapped pages are never freed, but only returned to the pool to be used later.
The value of MEMPOOL_SLOT_PER_PAGE is calculated to have a whole record fit a 4k page.
If the version for MEMPOOL_USE_VSPACE is correct we should probably consider integrating it.
Let me know what you think.
Regards,
Fabrizio Bertocci
Real-Time Innovations, Inc.
Sunnyvale, CA
On Wed, Jul 26, 2017 at 12:12 AM,