Re: [PATCH RFC 02/10] mm: Make shrink_slab() lockless

From: Kirill Tkhai
Date: Wed Aug 08 2018 - 08:51:38 EST

On 08.08.2018 15:36, Tetsuo Handa wrote:
> On 2018/08/08 20:51, Kirill Tkhai wrote:
>> @@ -192,7 +193,6 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker)
>> int id, ret = -ENOMEM;
>> down_write(&shrinker_rwsem);
>> - /* This may call shrinker, so it must use down_read_trylock() */
>> id = idr_alloc(&shrinker_idr, SHRINKER_REGISTERING, 0, 0, GFP_KERNEL);
>> if (id < 0)
>> goto unlock;
> I don't know why perf reports down_read_trylock(&shrinker_rwsem).

This happens in the case of many cgroups and mounts on node. This
is often happen on the big machines with containers.

> But above code is already bad. GFP_KERNEL allocation involves shrinkers and
> the OOM killer would be invoked because shrinkers are defunctional due to
> this down_write(&shrinker_rwsem). Please avoid blocking memory allocation
> with shrinker_rwsem held.

There was non-blocking allocation in first versions of the patchset,
but it's gone away in the process of the review (CC Vladimir).

There are still pages lists shrinkers in case of shrink_slab() is
not available, while additional locks makes the code more difficult
and not worth this difficulties.