Re: [PATCHv4 01/17] zram: switch to non-atomic entry locking
From: Sebastian Andrzej Siewior
Date: Thu Feb 06 2025 - 03:13:38 EST
On 2025-02-06 16:47:02 [+0900], Sergey Senozhatsky wrote:
> zram is atomic right now, e.g.
>
> zram_read()
> lock entry by index # disables preemption
> map zsmalloc entry # possibly memcpy
> decompress
> unmap zsmalloc
> unlock entry # enables preemption
>
> That's a pretty long time to keep preemption disabled (e.g. using slow
> algorithm like zstd or deflate configured with high compression levels).
> Apart from that that, difficult to use async algorithms, which can
> e.g. wait for a H/W to become available, or algorithms that might want
> to allocate memory internally during compression/decompression, e.g.
> zstd).
>
> Entry lock is not the only lock in zram currently that makes it
> atomic, just one of.
Okay. So there are requirements for the sleeping lock. A mutex isn't
fitting the requirement because it is too large I guess.
> > > 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.
Sebastian