mystikos
mystikos copied to clipboard
Handle pages shared between processes (reference-counting)
When a process exits, all pages belonging to that process are unmapped. But if pages are inherited due to a fork, the should be reference-counted, else if the parent process disappears, it will remove the child's pages.
A reference count could be added to the fd-mappings and that reference count could be incremented during fork. Then child exit does this:
- Release all pages owned by
getpid()
- Release all pages owned by
getppid()
The parent would have to release all pages inherited by children.
This idea has not been thought through but just capturing it.
The current approach is to make sure the parent process outlives the child.
Note: as long as the parent process outlives the child, this change will be unnecessary.
Parents do wait for children. However! When a child shuts down it will take all its own memory. With fork, a child heap becomes intermixed with the fork parents and fork siblings. When the child goes away it will unmap all pages it allocated, thus destroying all fork parent and siblings heap. If we had mapping and we are in a fork tree we could share all the pages and not free the shared ones until the tree goes away, or until a child does an exec to break free from the parent and siblings heap.