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


Groups > linux.kernel > #1424639

Re: [PATCH] zram: use writer semaphores in device attributes store

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] zram: use writer semaphores in device attributes store
Date Fri, 17 Jun 2016 06:20:01 +0200
Message-ID <rKTq9-1Ds-3@gated-at.bofh.it> (permalink)
References <rKSNr-19K-11@gated-at.bofh.it>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=njKZvgvShu46fbCw+ehO2KcsCsqqmet5aDL2ZhwjqSU=; b=rNZDGseOr2/fFFQgCOinUD9BIbOBsaB4wx6VEHGyn4ZdLBip7xIxec34zQ4omgTlmp XiJtbcQ1cvt37Bc5TDgRco6nOWbqwOGJrncldZAohB0n4io3dpQZtg7xxQofDyHH+INm Z2yZ/NJsTaL1GQRKfTrH15XMhTrvKI+mfvjwdepmt2Czsle0Uo/47HsiGRrk8D9FDg09 8SR3ymy1AJl7kfaZDkcxQdX+dR1F2+7HSERkYlZQYMl0llJnp8juXtrl5ZbfbNeB6qG/ ofCKjQdWeUKPMetJVfXuxeeAiJY/Ua29zmdMpDlUFjLREUe2V2PO/j1Ej0JOfz6W0aES 1bsg==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=njKZvgvShu46fbCw+ehO2KcsCsqqmet5aDL2ZhwjqSU=; b=EiOgbkykWPM1W9isXv9eUoeQ2blbLUEdnVwDqU7wHir9j0S4KzQNkVh628vMwH6MPd 1IeQpmhK2Gs0smq6uROUW+RJ4tqe4t1zbwhwFCjIkj16NHgqda4Ky1cPTuNQct2BPw9s QQ6TuoWWA6Q/qG3rjM+yL1WcTo6qBYVjua7bjpz5o74Ew3BUfmOJakDfGDYvGe61eE8l 1X1633Aiwf5IAen54bNx1fQ2yqczMS63w5vpGjS7zWwmWKWdf10w9/VGX6zuUZzN4KW9 OLkOZKAdIS4mzzavkdJ9Axrox9fSzeNyOM9EqIj7zC+A4GpbiVUbA+Vx/S8PYMfn3dBh ugkA==
X-Gm-Message-State ALyK8tLWteP6z5TgdfojXeeR8ch6iMX2ElC96hJqK7SKxXovcGz8O43mm+qeZIJ//KcX2w==
X-Received by 10.98.207.132 with SMTP id b126mr67165pfg.20.1466136797529; Thu, 16 Jun 2016 21:13:17 -0700 (PDT)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.6.1 (2016-04-27)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 63
Organization linux.* mail to news gateway
X-Original-Cc Minchan Kim <minchan@kernel.org>, Nitin Gupta <ngupta@vflare.org>, Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, linux-kernel@vger.kernel.org
X-Original-Date Fri, 17 Jun 2016 13:13:01 +0900
X-Original-Message-ID <20160617041301.GA490@swordfish>
X-Original-References <8f203f0623625f4c2065557c7bc8f3b6fd8b6ed2.1466134116.git.geliangtang@gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1424639

Show key headers only | View raw


Hello,

On (06/17/16 11:31), Geliang Tang wrote:
[..]
> Since the device attributes store provides write access. This patch uses
> down_write()/up_write() instead of down_read()/up_read() in
> mem_used_max_store() and compact_store().

we use ->init_lock not to make attrs exclusive, but to prevent
concurrent reset/etc.

> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
> ---
>  drivers/block/zram/zram_drv.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 7454cf1..cfed743 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -293,13 +293,13 @@ static ssize_t mem_used_max_store(struct device *dev,
>  	if (err || val != 0)
>  		return -EINVAL;
>  
> -	down_read(&zram->init_lock);
> +	down_write(&zram->init_lock);
>  	if (init_done(zram)) {
>  		struct zram_meta *meta = zram->meta;
>  		atomic_long_set(&zram->stats.max_used_pages,
>  				zs_get_total_pages(meta->mem_pool));
>  	}
> -	up_read(&zram->init_lock);
> +	up_write(&zram->init_lock);

not critical. can work.


>  	return len;
>  }
> @@ -372,15 +372,15 @@ static ssize_t compact_store(struct device *dev,
>  	struct zram *zram = dev_to_zram(dev);
>  	struct zram_meta *meta;
>  
> -	down_read(&zram->init_lock);
> +	down_write(&zram->init_lock);
>  	if (!init_done(zram)) {
> -		up_read(&zram->init_lock);
> +		up_write(&zram->init_lock);
>  		return -EINVAL;
>  	}
>  
>  	meta = zram->meta;
>  	zs_compact(meta->mem_pool);
> -	up_read(&zram->init_lock);
> +	up_write(&zram->init_lock);

pool compaction can take some time. *probably* seconds in the worst
case, when the device is under IO pressure and class' locks are heavily
contended and every class has a considerable number of objects to move.
so I think we don't want to block other attrs while we compact the pool,
compaction takes care of the concurrency internally.

	-ss

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


Thread

[PATCH] zram: use writer semaphores in device attributes store Geliang Tang <geliangtang@gmail.com> - 2016-06-17 05:40 +0200
  Re: [PATCH] zram: use writer semaphores in device attributes store Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-17 06:20 +0200

csiph-web