Re: [PATCH v2] locking/rwbase: Prevent indefinite writer starvation

From: Ingo Molnar
Date: Wed Jan 18 2023 - 06:28:07 EST



* Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> wrote:

> > > dio_truncate is not a realtime application but indefinite writer
> > > starvation
> >
> > If so then the PI boosting would not work if we would have it ;)
> >
>
> True, but it's still undesirable for a basic functional test using normal
> tasks with no prioritisation to stall forever.

Agreed.

> +/*
> + * Allow reader bias with a pending writer for a minimum of 4ms or 1 tick.
> + * This matches RWSEM_WAIT_TIMEOUT for the generic RWSEM implementation.
> + * The granularity is not exact as the lowest bit in rwbase_rt->waiter_timeout
> + * is used to detect recent DL / RT tasks taking a read lock.
> + */
> +#define RWBASE_RT_WAIT_TIMEOUT DIV_ROUND_UP(HZ, 250)
> +
> +static void __sched update_dlrt_reader(struct rwbase_rt *rwb)
> +{
> + /* No update required if DL / RT tasks already identified. */
> + if (rwb->waiter_timeout & 1)
> + return;
> +
> + /*
> + * Record a DL / RT task acquiring the lock for read. This may result
> + * in indefinite writer starvation but DL / RT tasks should avoid such
> + * behaviour.
> + */
> + if (rt_task(current)) {
> + struct rt_mutex_base *rtm = &rwb->rtmutex;
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&rtm->wait_lock, flags);
> + rwb->waiter_timeout |= 1;
> + raw_spin_unlock_irqrestore(&rtm->wait_lock, flags);
> + }
> +}

So I'm not sure this should be dependent on the task being an RT task.

Starvation scenarios are bad no matter what scheduling policy is used.

Should be unconditional - and all workloads should live with the new
behavior.

Thanks,

Ingo