linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage (v2)
@ 2013-09-06 15:12 Sergey Senozhatsky
  2013-09-09 12:33 ` Dan Carpenter
  0 siblings, 1 reply; 21+ messages in thread
From: Sergey Senozhatsky @ 2013-09-06 15:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Minchan Kim, Jerome Marchand, devel, linux-kernel

Calling handle_pending_slot_free() for every RW operation may
cause unneccessary slot_free_lock locking, because most likely
process will see NULL slot_free_rq. handle_pending_slot_free()
only when current detects that slot_free_rq is not NULL.

v2: protect handle_pending_slot_free() with zram rw_lock.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

---

 drivers/staging/zram/zram_drv.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index 91d94b5..5bfbe0e 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -517,6 +517,7 @@ static void handle_pending_slot_free(struct zram *zram)
 {
 	struct zram_slot_free *free_rq;
 
+	down_write(&zram->lock);
 	spin_lock(&zram->slot_free_lock);
 	while (zram->slot_free_rq) {
 		free_rq = zram->slot_free_rq;
@@ -525,6 +526,7 @@ static void handle_pending_slot_free(struct zram *zram)
 		kfree(free_rq);
 	}
 	spin_unlock(&zram->slot_free_lock);
+	up_write(&zram->lock);
 }
 
 static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
@@ -532,14 +534,15 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
 {
 	int ret;
 
+	if (zram->slot_free_rq)
+		handle_pending_slot_free(zram);
+
 	if (rw == READ) {
 		down_read(&zram->lock);
-		handle_pending_slot_free(zram);
 		ret = zram_bvec_read(zram, bvec, index, offset, bio);
 		up_read(&zram->lock);
 	} else {
 		down_write(&zram->lock);
-		handle_pending_slot_free(zram);
 		ret = zram_bvec_write(zram, bvec, index, offset);
 		up_write(&zram->lock);
 	}


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

end of thread, other threads:[~2013-09-23  8:44 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-06 15:12 [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage (v2) Sergey Senozhatsky
2013-09-09 12:33 ` Dan Carpenter
2013-09-09 12:49   ` Sergey Senozhatsky
2013-09-09 13:21     ` Dan Carpenter
2013-09-09 13:46       ` Jerome Marchand
2013-09-09 16:10         ` Jerome Marchand
2013-09-10 14:34           ` Sergey Senozhatsky
2013-09-10 14:58             ` Dan Carpenter
2013-09-10 15:15               ` Greg Kroah-Hartman
2013-09-10 23:12               ` [PATCH 1/2] staging: zram: fix handle_pending_slot_free() and zram_reset_device() race Sergey Senozhatsky
2013-09-12 22:12                 ` Greg KH
2013-09-13  9:17                   ` Sergey Senozhatsky
2013-09-16  0:02                 ` Minchan Kim
2013-09-17 17:24                   ` Sergey Senozhatsky
2013-09-23  4:24                     ` Minchan Kim
2013-09-23  8:42                       ` Sergey Senozhatsky
2013-09-10 23:19               ` [PATCH 2/2] staging: zram: remove init_done from zram struct (v3) Sergey Senozhatsky
2013-09-10 23:27             ` [PATCH 1/2] staging: zram: minimize `slot_free_lock' usage (v2) Sergey Senozhatsky
2013-09-09 14:42       ` Sergey Senozhatsky
2013-09-09 14:52         ` Dan Carpenter
2013-09-09 15:09           ` 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).