Opened 7 years ago
Last modified 6 days ago
#14332 new bug
fork() leaks (?) heap areas
Reported by: | waddlesplash | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | System/Kernel | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
- Compile attached test program.
- Run it. Observe that system memory usage climbs +200MB before the fork, as expected.
- Observe that system memory usage climbs +400MB after the second pair of memory sets.
Changing the SIZ
constant shows that the second round of sets will always consume 2x as much memory as expected.
Attachments (1)
Change History (4)
by , 7 years ago
Attachment: | forktest.cpp added |
---|
comment:1 by , 7 years ago
comment:2 by , 5 years ago
Not only is this still a bug, I now notice that swap usage increases by 470MB in addition to main memory usage increasing by 600MB at peak.
comment:3 by , 6 days ago
So here's what happens:
- The original application creates a large heap area, it gets filled with pages on memset.
- The fork occurs. The original heap area's cache becomes a source cache for two new caches, one for each of the child processes.
- The child processes copy-on-write from the parent cache.
- The source cache's pages are now fully shadowed by the child caches' pages, but the source cache is still referenced by the child caches so it isn't released.
When either of the processes exits, the caches will be merged and all the "duplicate" pages discarded, but as of now we don't do anything to detect when pages are not needed in this case. Fixing that will be quite tricky.
Note:
See TracTickets
for help on using tickets.
I note that in ProcessController, both processes are supposedly using only 200MB each, but the kernel memory usage increases 200MB. (After the process exits, all memory returns to the way it was before.) Running
listarea
at each pause point and thendiff
ing the results finds nothing of consequence in the kernel.