On (25/02/06 09:13), Sebastian Andrzej Siewior wrote: > 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. Correct. > > > > 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.