Re: Page cache and swapping

Bernd Schmidt (crux@Pool.Informatik.RWTH-Aachen.DE)
Thu, 26 Jun 1997 10:23:15 +0200 (MET DST)

> Looking at shrink_mmap in mm/filemap.c I found, that shared pages (page->count
> > 1) are inviolable. Additionally, the referenced bit is set, so next time
> the page is not freed again, even if it was _not_ used. In other parts of the
> kernel I found that page->count is increased on purpose to lock the page
> in memory. On the other hand, page->count is for page cache pages (with no buffers
> attached to it) the number of processes "seeing" the page. So, I supposed that
> removing a shared, but unused page from page cache should not be disasterous.
> The patch allows removing shared pages from page cache and removes setting
> of the referenced bit for all shared pages.

I'm sorry, but this can't work. There is no such thing as a "shared unused"
page. I suppose you mean "not referenced" by "unused".
Still, your patch doesn't work. You need to guarantee that the page you
are freeing is not in any process page tables. Otherwise, a process could
reference the page after you have freed it. This is usually done by
try_to_swap_out which will in turn remove the page from the memory map of
every process that contains it. After that, it can be freed.