linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zram: use writer semaphores in device attributes store
@ 2016-06-17  3:31 Geliang Tang
  2016-06-17  4:13 ` Sergey Senozhatsky
  0 siblings, 1 reply; 2+ messages in thread
From: Geliang Tang @ 2016-06-17  3:31 UTC (permalink / raw)
  To: Minchan Kim, Nitin Gupta, Sergey Senozhatsky; +Cc: Geliang Tang, linux-kernel

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().

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);
 
 	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);
 
 	return len;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] zram: use writer semaphores in device attributes store
  2016-06-17  3:31 [PATCH] zram: use writer semaphores in device attributes store Geliang Tang
@ 2016-06-17  4:13 ` Sergey Senozhatsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2016-06-17  4:13 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Minchan Kim, Nitin Gupta, Sergey Senozhatsky, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-17  4:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-17  3:31 [PATCH] zram: use writer semaphores in device attributes store Geliang Tang
2016-06-17  4:13 ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).