Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1519318

Re: [PATCH/RFC] z3fold: use per-page read/write lock

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH/RFC] z3fold: use per-page read/write lock
Date 2016-11-10 20:40 +0100
Message-ID <sC3mx-29W-9@gated-at.bofh.it> (permalink)
References <sA9FL-6I-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat, Nov 05, 2016 at 02:49:46PM +0100, Vitaly Wool wrote:
> +/* Read-lock a z3fold page */
> +static void z3fold_page_rlock(struct z3fold_header *zhdr)
> +{
> +	while (!atomic_add_unless(&zhdr->page_lock, 1, Z3FOLD_PAGE_WRITE_FLAG))
> +		cpu_relax();
> +	smp_mb();
> +}
> +
> +/* Read-unlock a z3fold page */
> +static void z3fold_page_runlock(struct z3fold_header *zhdr)
> +{
> +	atomic_dec(&zhdr->page_lock);
> +	smp_mb();
> +}
> +
> +/* Write-lock a z3fold page */
> +static void z3fold_page_wlock(struct z3fold_header *zhdr)
> +{
> +	while (atomic_cmpxchg(&zhdr->page_lock, 0, Z3FOLD_PAGE_WRITE_FLAG) != 0)
> +		cpu_relax();
> +	smp_mb();
> +}
> +
> +/* Write-unlock a z3fold page */
> +static void z3fold_page_wunlock(struct z3fold_header *zhdr)
> +{
> +	atomic_sub(Z3FOLD_PAGE_WRITE_FLAG, &zhdr->page_lock);
> +	smp_mb();
> +}

This is trivially broken. What Andi said, don't roll your own locks.


The unlocks want: smp_mb__before_atomic() _before_ the atomic for
'obvious' reasons.

Also, this lock has serious starvation issues and is reader biased.

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH/RFC] z3fold: use per-page read/write lock Vitaly Wool <vitalywool@gmail.com> - 2016-11-05 15:00 +0100
  Re: [PATCH/RFC] z3fold: use per-page read/write lock Andi Kleen <andi@firstfloor.org> - 2016-11-06 00:40 +0100
    Re: [PATCH/RFC] z3fold: use per-page read/write lock Vitaly Wool <vitalywool@gmail.com> - 2016-11-06 10:50 +0100
      Re: [PATCH/RFC] z3fold: use per-page read/write lock Andi Kleen <andi@firstfloor.org> - 2016-11-07 17:10 +0100
  Re: [PATCH/RFC] z3fold: use per-page read/write lock Peter Zijlstra <peterz@infradead.org> - 2016-11-10 20:40 +0100

csiph-web