2019-12-06 17:12:14

by Shakeel Butt

[permalink] [raw]
Subject: Re: [PATCH] mm: fix hanging shrinker management on long do_shrink_slab

On Thu, Dec 5, 2019 at 6:10 PM Dave Chinner <[email protected]> wrote:
>
> [please cc me on future shrinker infrastructure modifications]
>
> On Mon, Dec 02, 2019 at 07:36:03PM +0300, Andrey Ryabinin wrote:
> >
> > On 11/30/19 12:45 AM, Pavel Tikhomirov wrote:
> > > We have a problem that shrinker_rwsem can be held for a long time for
> > > read in shrink_slab, at the same time any process which is trying to
> > > manage shrinkers hangs.
> > >
> > > The shrinker_rwsem is taken in shrink_slab while traversing shrinker_list.
> > > It tries to shrink something on nfs (hard) but nfs server is dead at
> > > these moment already and rpc will never succeed. Generally any shrinker
> > > can take significant time to do_shrink_slab, so it's a bad idea to hold
> > > the list lock here.
>
> registering/unregistering a shrinker is not a performance critical
> task.

Yes, not performance critical but it can cause isolation issues.

> If a shrinker is blocking for a long time, then we need to
> work to fix the shrinker implementation because blocking is a much
> bigger problem than just register/unregister.
>

Yes, we should be fixing the implementations of all shrinkers and yes
it is bigger issue but we can also fix register/unregister isolation
issue in parallel. Fixing all shrinkers would a tedious and long task
and we should not block fixing isolation issue on it.

> > > The idea of the patch is to inc a refcount to the chosen shrinker so it
> > > won't disappear and release shrinker_rwsem while we are in
> > > do_shrink_slab, after that we will reacquire shrinker_rwsem, dec
> > > the refcount and continue the traversal.
>
> This is going to cause a *lot* of traffic on the shrinker rwsem.
> It's already a pretty hot lock on large machines under memory
> pressure (think thousands of tasks all doing direct reclaim across
> hundreds of CPUs), and so changing them to cycle the rwsem on every
> shrinker that will only make this worse. Esepcially when we consider
> that there may be hundreds to thousands of registered shrinker
> instances on large machines.
>
> As an example of how frequent cycling of a global lock in shrinker
> instances causes issues, we used to take references to superblock
> shrinker count invocations to guarantee existence. This was found to
> be a scalability limitation when lots of near-empty superblocks were
> present in a system (see commit d23da150a37c ("fs/superblock: avoid
> locking counting inodes and dentries before reclaiming them")).
>
> This alleviated the problem for a while, but soon we had problems
> with just taking a reference to the superblock in the callbacks that
> did actual work. Hence we changed it to just take a per-superblock
> rwsem to get rid of the global sb_lock spinlock in this path. See
> commit eb6ef3df4faa ("trylock_super(): replacement for
> grab_super_passive()". Now we don't have a scalability problem.
>
> IOWs, we already know that cycling a global rwsem on every
> individual shrinker invocation is going to cause noticable
> scalability problems. Hence I don't think that this sort of "cycle
> the global rwsem faster to reduce [un]register latency" solution is
> going to fly because of the runtime performance regressions it will
> introduce....
>

I agree with your scalability concern (though others would argue to
first demonstrate the issue before adding more sophisticated scalable
code). Most memory reclaim code is written without the performance or
scalability concern, maybe we should switch our thinking.

> > I don't think this patch solves the problem, it only fixes one minor symptom of it.
> > The actual problem here the reclaim hang in the nfs.
>
> The nfs client is waiting on the NFS server to respond. It may
> actually be that the server has hung, not the client...
>
> > It means that any process, including kswapd, may go into nfs inode reclaim and stuck there.
>
> *nod*
>
> > I think this should be handled on nfs/vfs level by making inode eviction during reclaim more asynchronous.
>
> That's what we are trying to do with similar blocking based issues
> in XFS inode reclaim. It's not simple, though, because these days
> memory reclaim is like a bowl full of spaghetti covered with a
> delicious sauce of non-obvious heuristics and broken
> functionality....
>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> [email protected]


2019-12-10 01:21:16

by Dave Chinner

[permalink] [raw]
Subject: Re: [PATCH] mm: fix hanging shrinker management on long do_shrink_slab

On Fri, Dec 06, 2019 at 09:11:25AM -0800, Shakeel Butt wrote:
> On Thu, Dec 5, 2019 at 6:10 PM Dave Chinner <[email protected]> wrote:
> > If a shrinker is blocking for a long time, then we need to
> > work to fix the shrinker implementation because blocking is a much
> > bigger problem than just register/unregister.
> >
>
> Yes, we should be fixing the implementations of all shrinkers and yes
> it is bigger issue but we can also fix register/unregister isolation
> issue in parallel. Fixing all shrinkers would a tedious and long task
> and we should not block fixing isolation issue on it.

"fixing all shrinkers" is a bit of hyperbole - you've identified
only one instance where blocking is causing you problems. Indeed,
most shrinkers are already non-blocking and won't cause you any
problems at all.

> > IOWs, we already know that cycling a global rwsem on every
> > individual shrinker invocation is going to cause noticable
> > scalability problems. Hence I don't think that this sort of "cycle
> > the global rwsem faster to reduce [un]register latency" solution is
> > going to fly because of the runtime performance regressions it will
> > introduce....
> >
>
> I agree with your scalability concern (though others would argue to
> first demonstrate the issue before adding more sophisticated scalable
> code).

Look at the git history. We *know* this is a problem, so anyone
arguing that we have to prove it can go take a long walk of a short
plank....

> Most memory reclaim code is written without the performance or
> scalability concern, maybe we should switch our thinking.

I think there's a lot of core mm and other developers that would
disagree with you there. With respect to shrinkers, we've been
directly concerned about performance and scalability of the
individual instances as well as the infrastructure for at least the
last decade....

Cheers,

Dave.
--
Dave Chinner
[email protected]

2019-12-19 10:36:18

by Pavel Tikhomirov

[permalink] [raw]
Subject: Re: [PATCH] mm: fix hanging shrinker management on long do_shrink_slab

On 12/10/19 4:20 AM, Dave Chinner wrote:
> On Fri, Dec 06, 2019 at 09:11:25AM -0800, Shakeel Butt wrote:
>> On Thu, Dec 5, 2019 at 6:10 PM Dave Chinner <[email protected]> wrote:
>>> If a shrinker is blocking for a long time, then we need to
>>> work to fix the shrinker implementation because blocking is a much
>>> bigger problem than just register/unregister.
>>>
>>
>> Yes, we should be fixing the implementations of all shrinkers and yes
>> it is bigger issue but we can also fix register/unregister isolation
>> issue in parallel. Fixing all shrinkers would a tedious and long task
>> and we should not block fixing isolation issue on it.
>
> "fixing all shrinkers" is a bit of hyperbole - you've identified
> only one instance where blocking is causing you problems. Indeed,
> most shrinkers are already non-blocking and won't cause you any
> problems at all.
>
>>> IOWs, we already know that cycling a global rwsem on every
>>> individual shrinker invocation is going to cause noticable
>>> scalability problems. Hence I don't think that this sort of "cycle
>>> the global rwsem faster to reduce [un]register latency" solution is
>>> going to fly because of the runtime performance regressions it will
>>> introduce....
>>>
>>
>> I agree with your scalability concern (though others would argue to
>> first demonstrate the issue before adding more sophisticated scalable
>> code).
>
> Look at the git history. We *know* this is a problem, so anyone
> arguing that we have to prove it can go take a long walk of a short
> plank....
>
>> Most memory reclaim code is written without the performance or
>> scalability concern, maybe we should switch our thinking.
>
> I think there's a lot of core mm and other developers that would
> disagree with you there. With respect to shrinkers, we've been
> directly concerned about performance and scalability of the
> individual instances as well as the infrastructure for at least the
> last decade....
>
> Cheers,
>
> Dave.
>

Thanks a lot for your replies, now I see that the core of the problem is
in nfs hang, before that I was unsure if it's OK to have such a hang in
do_shrink_slab.

I have a possibly bad idea on how my patch can still work. What if we
use unlock/refcount way only for nfs-shrinkers? It will still give a
performance penalty if one has many nfs mounts, but for those who has
little number of nfs mounts the penalty would be less. And this would be
a small isolation improvement for nfs users.

--
Best regards, Tikhomirov Pavel
Software Developer, Virtuozzo.