Re: [RFC PATCH] mm: don't reclaim inodes with many attached pages

From: Roman Gushchin
Date: Wed Oct 24 2018 - 19:49:54 EST


On Wed, Oct 24, 2018 at 03:18:53PM -0700, Andrew Morton wrote:
> On Tue, 23 Oct 2018 16:43:29 +0000 Roman Gushchin <guro@xxxxxx> wrote:
>
> > Spock reported that the commit 172b06c32b94 ("mm: slowly shrink slabs
> > with a relatively small number of objects") leads to a regression on
> > his setup: periodically the majority of the pagecache is evicted
> > without an obvious reason, while before the change the amount of free
> > memory was balancing around the watermark.
> >
> > The reason behind is that the mentioned above change created some
> > minimal background pressure on the inode cache. The problem is that
> > if an inode is considered to be reclaimed, all belonging pagecache
> > page are stripped, no matter how many of them are there. So, if a huge
> > multi-gigabyte file is cached in the memory, and the goal is to
> > reclaim only few slab objects (unused inodes), we still can eventually
> > evict all gigabytes of the pagecache at once.
> >
> > The workload described by Spock has few large non-mapped files in the
> > pagecache, so it's especially noticeable.
> >
> > To solve the problem let's postpone the reclaim of inodes, which have
> > more than 1 attached page. Let's wait until the pagecache pages will
> > be evicted naturally by scanning the corresponding LRU lists, and only
> > then reclaim the inode structure.
> >
> > ...
> >
> > --- a/fs/inode.c
> > +++ b/fs/inode.c
> > @@ -730,8 +730,11 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
> > return LRU_REMOVED;
> > }
> >
> > - /* recently referenced inodes get one more pass */
> > - if (inode->i_state & I_REFERENCED) {
> > + /*
> > + * Recently referenced inodes and inodes with many attached pages
> > + * get one more pass.
> > + */
> > + if (inode->i_state & I_REFERENCED || inode->i_data.nrpages > 1) {
> > inode->i_state &= ~I_REFERENCED;
> > spin_unlock(&inode->i_lock);
> > return LRU_ROTATE;
>
> hm, why "1"?
>
> I guess one could argue that this will encompass long symlinks, but I
> just made that up to make "1" appear more justifiable ;)
>

Well, I'm slightly aware of introducing an inode leak here, so I was thinking
about some small number of pages. It's definitely makes no sense to reclaim
several Gb of pagecache, however throwing away a couple of pages to speed up
inode reuse is totally fine.
But then I realized that I don't have any justification for a number like
4 or 32, so I ended up with 1. I'm pretty open here, but not sure that switching
to 0 is much better.

Thanks!