RE: [PATCH] f2fs: change to use rwsem for cp_mutex

From: David Laight
Date: Tue Nov 24 2020 - 04:12:39 EST


From: Chao Yu
> Sent: 24 November 2020 03:12
>
> On 2020/11/24 1:05, David Laight wrote:
> > From: Sahitya Tummala
> >> Sent: 23 November 2020 05:29
> >>
> >> Use rwsem to ensure serialization of the callers and to avoid
> >> starvation of high priority tasks, when the system is under
> >> heavy IO workload.
> >
> > I can't see any read lock requests.
> >
> > So why the change?
>
> Hi David,
>
> You can check the context of this patch in below link:
>
> https://lore.kernel.org/linux-f2fs-devel/8e094021b958f9fe01df1183a2677882@xxxxxxxxxxxxxx/T/#t
>
> BTW, the root cause here is that mutex lock won't serialize callers, so there
> could be potential starvation problem when this lock is always grabbed by high
> priority tasks.

That doesn't seem right.

If I read the above correctly it was high priority tasks that were
being 'starved' precisely because mutex lock serializes wakers.

If you have a lock that is contended so much that it is held 100%
of the time you need a different locking strategy.

IIRC mutex locks are 'ticket' locks so that only one thread is woken
each time the mutex is released, and they are woken in the order
they went to sleep.

While this behaviour might not be the one you want, relying on
rwsem (which might happen currently to work differently) doesn't
seem the correct long term fix.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)