4 ms·
Idea: What if there was an OS interface to mark memory regions as "throwaway"? Throwaway in the sense that it's less costly to recalculate than to recall it fro
by leni536 10y ago
Idea: What if there was an OS interface to mark memory regions as "throwaway"? Throwaway in the sense that it's less costly to recalculate than to recall it from swap. So the OS would throw such memory regions instead of swapping out and signal the process about it to recalculate it if needed.
I don't usually bump into heavy swap usage except when I wake my laptop from hibernate. I tend to close browsers before hibernating because it's faster to just resume the last session from a cold start then load from swap.
- Kristine1975 10y agoBoth OS X and iOS have the NSPurgeableData class which implements something like this: https://developer.apple.com/library/mac/documentation/Performance/Conceptual/ManagingMemory/Articles/CachingandPurgeableMemory.html https://developer.apple.com/library/mac/documentation/Perfor... Edit: Chromium has this: https://chromium.googlesource.com/chromium/src/base/+/master/memory/discardable_memory.h https://chromium.googlesource.com/chromium/src/base/+/master...
- leni536 10y ago"Discardable memory" doesn't seem to be implemented though, however there is an implementation for "discardable shared memory" [1] which seems to offer this volatile behavior. It uses ashmem_pin_region() and ashmem_unpin_region() for Android, which seems to be the equivalent for iOS's NSPurgeableData. I wonder if it does anything useful for any other OS. [1] https://chromium.googlesource.com/chromium/src/base/+/master/memory/discardable_shared_memory.cc https://chromium.googlesource.com/chromium/src/base/+/master...
- amelius 10y ago> Throwaway in the sense that it's less costly to recalculate than to recall it from swap. Network is slower than disk (is slower than memory). So if "recalculate" means getting it from the internet, then probably getting it from disk is faster in most cases.
- daurnimator 10y agolocal network is faster than disk. The internet is rarely faster than disk unless you're in a major data centre. And then... this is assuming you're referring to spinning rust. local disks in the form of SSDs will be faster again.
- leni536 10y agoI expect that it's easy to rerender webpages but it's wasteful to swap the bitmaps and load them from disk again. I wouldn't expect the browser to throw away data retrieved via network.
- willvarfar 10y agoYour OS already has a 'file buffer cache' that keeps pages of read files in RAM and discards them only if the RAM is needed for something else. I made a neat little application-accessible key-value cache that used these pages. It means you can write keys that end up in your OS's file buffer cache, and if the OS doesn't need that RAM for anything else, you can read them back later. http://williamedwardscoder.tumblr.com/post/13363076806/buffcacher http://williamedwardscoder.tumblr.com/post/13363076806/buffc... Sadly not a mainstream thing :( ;)
- keeperofdakeys 10y agoThere has been some thoughts about implementing this for linux, but I don't think it got very far. The idea is that you mark a range of memory as "volatile", and the OS will free that when it's running low on memory. In most cases where you're running out of memory though, swapping out pages or killing a program using the memory is probably the right thing to do though. https://lwn.net/Articles/522135/ https://lwn.net/Articles/522135/
- Kristine1975 10y agoThere was also this in 2009: http://lwn.net/Articles/340080/ http://lwn.net/Articles/340080/