A way to reclaim initial thread resources
Hey, I am currently looking for a way to reclaim resources allocated by kernel for the rootserver thread, i.e. memory for CNode, TCB, BootInfo, etc. My current approach looks like this: * in rootserver instead of calling seL4_TCB_Suspend, call custom syscall seL4_ReclaimRootserverResources. This sycall as parameters takes CNode and slot no. after which kernel should be able to freely write new caps. This CNode is main CNode of some component initialized by the rootserver. * implmenetation of this syscall then suspends initial thread, schedules new thread, revokes most of rootserver's resources, notably TCB, BootInfo, IPCBuffer, VSpace and CNode. Then for those now free memory regions new untyped capabilities are created, with the same sizes as the original objects. Lastly, new capabilities are written to subsequent slots in CNode a'la boot.c, so with null MDBNode; mdbRevocable and mdbFirstBadged set to true. This solution has couple of problems. First and foremost, it requires creating additional syscall to handle this. Secondly, even though the component _technically_ has access to this newly created capabilities, it doesn't know where they are, or how big they are. This could be partially band-aided by hardcoding this information in relevant component, but that is far from elegant. This component also recives rest of the untyped memory from rootserver, including bootinfo entries about this memory specification, so that renders solution with hardcoding spec even worse. Last but not least, before the seL4_ReclaimRootserverResources is called, all the components are resumed using seL4_TCB_Resume as part of rootserver's work, so there could be race-condition between calling reclaiming syscall, and component initialization (although I am not 100% sure about that part) Is there maybe a better way to do it, and I am doing it all round? The perfect solution would be to somehow extend bootinfo and/or remaining untypeds that were given by the kernel to the rootserver.
Marcin,
I am currently looking for a way to reclaim resources allocated by kernel for the rootserver thread
I wonder, what you are trying to achieve in the end when doing this? Is this just about resources in system with very low memory? Or do you want an atomic way to do it because there is no other trusted thread can can take care of the cleanup? The root task basically has access to all it's resource, so it could either "morph" itself into something useful. Or, with a smart design, it can release most of its resources itself. Some can't be release because it would make the rootserver crash and I don't think there is a smart way out here via setting up a fault endpoint that hands over control to another thread while the last caps are removed. But another thread could release the remaining rootserver resources assuming the root server has given it access, ie. gave it a copy of the caps. I'm not sure if there is really any rootserver cap that must remain and thus blocks resources forever. Axel
I wonder, what you are trying to achieve in the end when doing this? Is this just about resources in system with very low memory? [...]
Yes, exactly -- sorry I didn't mention it earlier.
But another thread could release the remaining rootserver resources assuming the root server has given it access, i.e. gave it a copy of the caps.
Could you please briefly explain how this procedure would look like? From my understanding, while calling seL4_CNode_Delete on i.e. seL4_CapInitThreadTCB would remove this capability, the memory which was used for it wouldn't be freed as it wasn't derived from Untyped capability, but the cap was created directly using cap_cnode_cap_new, and thus there is no untyped capability I could call seL4_Untyped_Retype on to reuse this memory in another thread. Or maybe I got this completely wrong? -- Marcin
Marcin,
Could you please briefly explain how this procedure would look like? From my understanding, while calling seL4_CNode_Delete on i.e. seL4_CapInitThreadTCB would remove this capability, the memory which was used for it wouldn't be freed as it wasn't derived from Untyped capability, but the cap was created directly using cap_cnode_cap_new, and thus there is no untyped capability I could call seL4_Untyped_Retype on to reuse this memory in another thread. Or maybe I got this completely wrong?
You are right, you don't have the original untyped for the root server, and this does not exists due to the way the kernel boot allocation works. So some memory lost anyway even if you reuse the rootserver objects. The boot could be modified to create only such object directly that are not meant to be deleted (e.g. interrupt control). All other objects (e.g. TCB, pages tables, pages) are created via an untyped, where the root server gets the untyped capability also. That should allow to recover all of them via the existing cap APIs and no special syscall is needed. Axel
participants (2)
-
Axel Heider
-
Marcin Witkowski