c - Is it possible to discard dirty pages on a shared mapping? -


the program i’m working on needs save information on every item of input. number of items processed huge, cannot keep data in memory (i iterate on input in first pass , record information).

i want place data virtual memory, go disk when memory becomes scarce (that’s /when/, not /if/. become scarce).

currently create sparse file of (hopefully) appropriate size, mmap whole thing, close , unlike file afterwards. reason unlink file don’t need information program quits.

the program can happily read , write mapped region, well.

until program exists. kernel starts write useless data disk, although file no longer open or linked. first thought kernel realize data no longer accessible, apparently not. first included call madvise mdv_remove @ end of program, , didn’t help, added mdv_dontneed well. both didn’t problem.

the worst thing blocks machine every write other program makes (like text editor) has wait long running write complete.

is there way convince kernel not write data disk?

going on comments, appears using swap fine needs alternative file storage. if that's case, think best bet use file, you've done, on tmpfs partition. best tmpfs partition use purpose @ /dev/shm.

just open file in /dev/shm, truncate size need, mmap , unlink, precisely you've done. /dev/shm uses main memory it's "backing store", swapped out if memory short.

the advantage of using swap no force flush happen pages still fit in memory @ point program exists. after, these pages recognized unneeded, , discarded. should solve problem while still allowing resize etc.

it has benefit of requiring no change current code :-)


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -