Re: page cache query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Immediately before and after this code execution, command "free -m"
> shows free memory decreased by 10M and cache incresed by 10M.
>
> If I delete foo.txt, then free memory increases by 10M and cache
> decreases by 10M.
>
> My question is why the cache is growing even after O_SYNC flag? Even
> fsync does not help. But deleting file freeing the cache.
>

When you do a sync, the data is written to disk from the page cache
but is not removed from memory till required. Why would it anyway? The
kernel caches everything as long as it can.

However the kernel can discard these pages easily (because they're
clean after you did a sync, unlike in the case where dirty pages have
to be written to disk before they are reclaimed) and can reuse them
for other requirements when memory is low.

About cache being free on deleting file, AFAIK, that is because every
inode has its own page cache (address_space), and when you delete the
file, its inode and associated page cache is freed.

> Is there any way to free cache?

Why do you want to do this? What is the problem you're trying to
solve? I think you can use the fadvise system call with
advice=FADV_DONTNEED to achieve this:
http://linux.die.net/man/2/fadvise

-Joel

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux