lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6f3mkwaehrrcpekezlryfipc7dw3vxovdlvybt4utfqpmonywl@n5vm4vnx5jrn>
Date: Tue, 28 Jan 2025 09:29:47 +0900
From: Sergey Senozhatsky <senozhatsky@...omium.org>
To: Uros Bizjak <ubizjak@...il.com>
Cc: Sergey Senozhatsky <senozhatsky@...omium.org>, 
	Andrew Morton <akpm@...ux-foundation.org>, Minchan Kim <minchan@...nel.org>, 
	Johannes Weiner <hannes@...xchg.org>, Yosry Ahmed <yosry.ahmed@...ux.dev>, 
	Nhat Pham <nphamcs@...il.com>, linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH 2/6] zsmalloc: make zspage lock preemptible

On (25/01/27 21:23), 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_cmpxchg(lock, old, old + 1) == old)
> > +			return;
> 
> You can use atomic_try_cmpxchg() here:
> 
> if (atomic_try_cmpxchg(lock, &old, old + 1))
>         return;
> 
> > +
> > +		cpu_relax();
> > +	}
> > +}
> > +
> > +static void zspage_read_unlock(struct zspage *zspage)
> > +{
> > +	atomic_dec(&zspage->lock);
> > +}
> > +
> > +static void zspage_write_lock(struct zspage *zspage)
> > +{
> > +	atomic_t *lock = &zspage->lock;
> > +	int old;
> > +
> > +	while (1) {
> > +		old = atomic_cmpxchg(lock, ZS_PAGE_UNLOCKED, ZS_PAGE_WRLOCKED);
> > +		if (old == ZS_PAGE_UNLOCKED)
> > +			return;
> 
> Also, the above code can be rewritten as:
> 
> while (1) {
>         old = ZS_PAGE_UNLOCKED;
>         if (atomic_try_cmpxchg (lock, &old, ZS_PAGE_WRLOCKED))
>                 return;	
> > +
> > +		cpu_relax();
> > +	}
> > +}
> 
> The above change will result in a slightly better generated asm.

Thanks, I'll take a look for the next version.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ