Re: [PATCHv4 01/17] zram: switch to non-atomic entry locking

From: Sebastian Andrzej Siewior
Date: Thu Feb 06 2025 - 03:26:46 EST


On 2025-02-06 17:17:41 [+0900], Sergey Senozhatsky wrote:
> > Okay. So there are requirements for the sleeping lock. A mutex isn't
> > fitting the requirement because it is too large I guess.
>
> Correct.

I would nice to state this why a generic locking implementation can not
be used. From what I have seen it should play along with RT nicely.

> > > > > static void zram_slot_lock(struct zram *zram, u32 index)
> > > > > {
> > > > > unsigned long *lock = &zram->table[index].flags;
> > > > >
> > > > > WARN_ON_ONCE(!preemptible());
> > > >
> > > > you want might_sleep() here instead. preemptible() works only on
> > > > preemptible kernels. And might_sleep() is already provided by
> > > > wait_on_bit_lock(). So this can go.
> > >
> > > wait_on_bit_lock() has might_sleep().
> >
> > My point exactly. This makes the WARN_ON_ONCE() obsolete.
>
> Right, might_sleep() can be disabled, as far as I understand,
> via CONFIG_DEBUG_ATOMIC_SLEEP, unlike WARN_ON_ONCE(). But I
> can drop it and then just rely on might_sleep(), should be
> enough.

It should be enough. mutex_lock(), down() and so on relies solely on it.
As I said, preemptible() only works on preemptible kernels if it comes
to the preemption counter on and !preemptible kernels with enabled
debugging.

Sebastian