Re: Moving /tmp to tmpfs makes it useless
Uoti Urpala <firstname.lastname@example.org> writes:
> Goswin von Brederlow wrote:
>> > Le vendredi 25 mai 2012 Ã? 16:01 +0300, Uoti Urpala a Ã?Â©crit :
>> >> There is one significant difference though. When you read data back to
>> >> memory from swap, the kernel does not remember that it already exists on
>> >> disk; when the data is evicted from memory again, it is unnecessarily
>> >> rewritten to disk rather than just dropped. Thus, if you do multiple
>> >> read iterations through a large set of data (which does not fit in
>> >> memory) on tmpfs, each iteration does disk read AND write rather than
>> >> just read.
>> Linux certainly has a notion of cached swap, i.e. pages from swap that
>> are also unmodified in memory. As long as you have enough swap the
>> kernel should not reap the swapped data and know that it is already on
>> disk when it wants to evict the page.
> I haven't read the relevant kernel code, but that doesn't match the
> behavior I see. Reading a large file from tmpfs and then allocating
> memory results in large swap writes every time, even if the newly
> allocated memory is not itself immediately swapped out and the file
> should already be in swap from before.
But does it rewrite the pages it has just read back? Or does it swap out
some other pages it didn't have swapped out before?
It might consider a page it just had to swap in to be more valuable than
a page it had lying around for a long time and rather swap out the old
page than forget the just read page. So this doesn't proof that data in
tmpfs is rewritten again and again.
> The script below can be used to test the behavior. It creates a file,
> then loops alternatively reading the file and allocating+freeing memory.
> It's noteworthy that sometimes the read performance also drops over
> iterations (maybe the swap layout becomes more fragmented?). I used the
> given sizes for testing on a machine with 8 GiB memory. This load does
> run faster on ext4 than tmpfs.