diff options
-rw-r--r-- | drivers/block/zram/zram_drv.c | 17 | ||||
-rw-r--r-- | drivers/block/zram/zram_drv.h | 4 |
2 files changed, 9 insertions, 12 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index f1a3c958d84b..011e55d820b1 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c | |||
@@ -230,6 +230,7 @@ static struct zram_meta *zram_meta_alloc(u64 disksize) | |||
230 | } | 230 | } |
231 | 231 | ||
232 | rwlock_init(&meta->tb_lock); | 232 | rwlock_init(&meta->tb_lock); |
233 | mutex_init(&meta->buffer_lock); | ||
233 | return meta; | 234 | return meta; |
234 | 235 | ||
235 | free_table: | 236 | free_table: |
@@ -412,6 +413,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, | |||
412 | struct page *page; | 413 | struct page *page; |
413 | unsigned char *user_mem, *cmem, *src, *uncmem = NULL; | 414 | unsigned char *user_mem, *cmem, *src, *uncmem = NULL; |
414 | struct zram_meta *meta = zram->meta; | 415 | struct zram_meta *meta = zram->meta; |
416 | bool locked = false; | ||
415 | 417 | ||
416 | page = bvec->bv_page; | 418 | page = bvec->bv_page; |
417 | src = meta->compress_buffer; | 419 | src = meta->compress_buffer; |
@@ -431,6 +433,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, | |||
431 | goto out; | 433 | goto out; |
432 | } | 434 | } |
433 | 435 | ||
436 | mutex_lock(&meta->buffer_lock); | ||
437 | locked = true; | ||
434 | user_mem = kmap_atomic(page); | 438 | user_mem = kmap_atomic(page); |
435 | 439 | ||
436 | if (is_partial_io(bvec)) { | 440 | if (is_partial_io(bvec)) { |
@@ -457,7 +461,6 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, | |||
457 | 461 | ||
458 | ret = lzo1x_1_compress(uncmem, PAGE_SIZE, src, &clen, | 462 | ret = lzo1x_1_compress(uncmem, PAGE_SIZE, src, &clen, |
459 | meta->compress_workmem); | 463 | meta->compress_workmem); |
460 | |||
461 | if (!is_partial_io(bvec)) { | 464 | if (!is_partial_io(bvec)) { |
462 | kunmap_atomic(user_mem); | 465 | kunmap_atomic(user_mem); |
463 | user_mem = NULL; | 466 | user_mem = NULL; |
@@ -514,6 +517,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, | |||
514 | atomic_inc(&zram->stats.good_compress); | 517 | atomic_inc(&zram->stats.good_compress); |
515 | 518 | ||
516 | out: | 519 | out: |
520 | if (locked) | ||
521 | mutex_unlock(&meta->buffer_lock); | ||
517 | if (is_partial_io(bvec)) | 522 | if (is_partial_io(bvec)) |
518 | kfree(uncmem); | 523 | kfree(uncmem); |
519 | 524 | ||
@@ -527,15 +532,10 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index, | |||
527 | { | 532 | { |
528 | int ret; | 533 | int ret; |
529 | 534 | ||
530 | if (rw == READ) { | 535 | if (rw == READ) |
531 | down_read(&zram->lock); | ||
532 | ret = zram_bvec_read(zram, bvec, index, offset, bio); | 536 | ret = zram_bvec_read(zram, bvec, index, offset, bio); |
533 | up_read(&zram->lock); | 537 | else |
534 | } else { | ||
535 | down_write(&zram->lock); | ||
536 | ret = zram_bvec_write(zram, bvec, index, offset); | 538 | ret = zram_bvec_write(zram, bvec, index, offset); |
537 | up_write(&zram->lock); | ||
538 | } | ||
539 | 539 | ||
540 | return ret; | 540 | return ret; |
541 | } | 541 | } |
@@ -808,7 +808,6 @@ static int create_device(struct zram *zram, int device_id) | |||
808 | { | 808 | { |
809 | int ret = -ENOMEM; | 809 | int ret = -ENOMEM; |
810 | 810 | ||
811 | init_rwsem(&zram->lock); | ||
812 | init_rwsem(&zram->init_lock); | 811 | init_rwsem(&zram->init_lock); |
813 | 812 | ||
814 | zram->queue = blk_alloc_queue(GFP_KERNEL); | 813 | zram->queue = blk_alloc_queue(GFP_KERNEL); |
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index d876300da6c9..ad8aa35bae00 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h | |||
@@ -88,13 +88,11 @@ struct zram_meta { | |||
88 | void *compress_buffer; | 88 | void *compress_buffer; |
89 | struct table *table; | 89 | struct table *table; |
90 | struct zs_pool *mem_pool; | 90 | struct zs_pool *mem_pool; |
91 | struct mutex buffer_lock; /* protect compress buffers */ | ||
91 | }; | 92 | }; |
92 | 93 | ||
93 | struct zram { | 94 | struct zram { |
94 | struct zram_meta *meta; | 95 | struct zram_meta *meta; |
95 | struct rw_semaphore lock; /* protect compression buffers, | ||
96 | * reads and writes | ||
97 | */ | ||
98 | struct request_queue *queue; | 96 | struct request_queue *queue; |
99 | struct gendisk *disk; | 97 | struct gendisk *disk; |
100 | int init_done; | 98 | int init_done; |