3 ms·
an API for "this memory is a droppable-at-any-time cache" would be nice in OSes, but it doesn't exist at the moment Naive question: would this be any better t
by dkarl 17y ago
an API for "this memory is a droppable-at-any-time cache" would be nice in OSes, but it doesn't exist at the moment
Naive question: would this be any better than letting applications provide swapping hints to the OS? And is that any better than just letting the OS swap based on usage?
- ori_b 17y agoYes, to a certain degree. The problem is that it would be cheaper to, say, drop a decoded version of a JPEG and re-decode it, instead of having it get swapped out. In fact, I suspect that for large images, it would be cheaper to re-read the compressed jpeg and decompress it than to read back a larger swapped out decompressed version, just because hitting the disk is slow, and swap tends to get fragmented because it's usually written a few pages at a time. Swap hints probably aren't really worth the effort, although I haven't benchmarked it. The idea behind caches is to avoid doing expensive operations repeatedly, and hitting swap is about as expensive as an operation can get.
- ori_b 17y agoOh, another big problem is that you need to actually write the data you're swapping out to disk. You can't just drop it on the floor whenever memory pressure is high; You have to wait for the disk so spin up, seek, write, and so on. What you really want is to be able to tell the OS "I don't care if this data goes away. If you need space, don't bother taking time to save it, I can regenerate it quickly."