From: Jay Levitt Date: 2007-10-21T02:50:01+09:00 Subject: Re: [OT] Re: Should *most* memory be release back to the system? On Sun, 21 Oct 2007 02:31:17 +0900, Michal Suchanek wrote: >> There was a paper a few years ago on the idea of a GC that could >> communicate with the virtual memory manager, so that it could sweep pages >> when they happened to be already swapped in, rather than intentionally >> pulling them in purely to do the sweep. Or something along those lines; >> the key is that right now, you have no way to know if accessing an address >> will produce a page fault. > > You could probably see your memory map and your pagefaults, after all > it's your memory. I am not sure it would buy you anything, though. You > have to visit all pages to perform the garbage collection. You could > possibly optimize the order a bit but the pages will be probably > interlinked in weird ways and unless you do something very clever you > can easily get lost. Right - I think the idea was, in fact, to do something clever. I'm also not sure that there's a good UI available on most (or any?) to see your memory map, but I admit I haven't dug into it. On the only OS I know cold, there's no way to see which pages of yours are currently swapped in, but that OS is ancient and irrelevant and doen't run VMs anyway. I also imagine that if you're truly clever, you could store data in such a way that you might be able to know that "nothing in that swapped-out page is referenced anymore", and thus be able to free it without paging it in. Certainly if the system page size is 4K and I'm freeing a 32K object, I know that the inner 24-28K doesn't need swapping in; I don't know if it ends up being swapped in today's VMs. As for smaller objects, I suppose you'd need to store the metadata in its own page, so that you could sweep through object references without sweeping through objects. Again, dunno if that's already being done. In general, the impression I got from the paper was that today's VMs don't spend a lot of time thinking about how their memory usage is physically mapped, and that's partly because there's no good way to communicate with the OS about that. An API that would allow a VM to hint the OS, and find out if pages are swapped in, would seem to help there. Here's the paper I think I was looking at; it's dated 2004, and I don't know if changes in Linux and/or HotSpot have surpassed it: http://www.cs.umass.edu/~emery/pubs/04-16.pdf -- Jay Levitt | Boston, MA | My character doesn't like it when they Faster: jay at jay dot fm | cry or shout or hit. http://www.jay.fm | - Kristoffer