Re: [PATCHv1 3/6] zsmalloc: make zspage lock preemptible
From: Sergey Senozhatsky
Date: Wed Jan 29 2025 - 22:22:24 EST
On (25/01/29 16:22), Uros Bizjak wrote:
> > +static void zspage_read_lock(struct zspage *zspage)
> > +{
> > + atomic_t *lock = &zspage->lock;
> > + int old;
> > +
> > + while (1) {
> > + old = atomic_read(lock);
> > + if (old == ZS_PAGE_WRLOCKED) {
> > + cpu_relax();
> > + continue;
> > + }
> > +
> > + if (atomic_try_cmpxchg(lock, &old, old + 1))
> > + return;
> > +
> > + cpu_relax();
> > + }
> > +}
[..]
> Based on the above, cpu_relax() should be removed from the loop, which
> becomes:
>
> {
> atomic_t *lock = &zspage->lock;
> int old = atomic_read(lock);
>
> do {
> if (old == ZS_PAGE_WRLOCKED) {
> cpu_relax();
> old = atomic_read(lock);
> continue;
> }
>
> } while (!atomic_try_cmpxchg(lock, &old, old + 1));
> }
Ack.
> > +static int zspage_try_write_lock(struct zspage *zspage)
>
> This function can be declared as bool, returning true/false.
Ack. Thank you.