diff options
author | Minchan Kim <minchan@kernel.org> | 2014-01-30 18:46:04 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-30 19:56:55 -0500 |
commit | f614a9f48dedd2b80d1dc8bae8094842fcdb39dd (patch) | |
tree | 411b14762df0f6ad7261b5d6f6ad7c9bc28a2204 | |
parent | 92967471b67163bb1654e9b7fe99449ab70a4aaa (diff) |
zram: remove workqueue for freeing removed pending slot
Commit a0c516cbfc74 ("zram: don't grab mutex in zram_slot_free_noity")
introduced free request pending code to avoid scheduling by mutex under
spinlock and it was a mess which made code lenghty and increased
overhead.
Now, we don't need zram->lock any more to free slot so this patch
reverts it and then, tb_lock should protect it.
Signed-off-by: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Tested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/block/zram/zram_drv.c | 54 | ||||
-rw-r--r-- | drivers/block/zram/zram_drv.h | 10 |
2 files changed, 6 insertions, 58 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 24e6426cf258..f1a3c958d84b 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c | |||
@@ -522,20 +522,6 @@ out: | |||
522 | return ret; | 522 | return ret; |
523 | } | 523 | } |
524 | 524 | ||
525 | static void handle_pending_slot_free(struct zram *zram) | ||
526 | { | ||
527 | struct zram_slot_free *free_rq; | ||
528 | |||
529 | spin_lock(&zram->slot_free_lock); | ||
530 | while (zram->slot_free_rq) { | ||
531 | free_rq = zram->slot_free_rq; | ||
532 | zram->slot_free_rq = free_rq->next; | ||
533 | zram_free_page(zram, free_rq->index); | ||
534 | kfree(free_rq); | ||
535 | } | ||
536 | spin_unlock(&zram->slot_free_lock); | ||
537 | } | ||
538 | |||
539 | static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index, | 525 | static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index, |
540 | int offset, struct bio *bio, int rw) | 526 | int offset, struct bio *bio, int rw) |
541 | { | 527 | { |
@@ -547,7 +533,6 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index, | |||
547 | up_read(&zram->lock); | 533 | up_read(&zram->lock); |
548 | } else { | 534 | } else { |
549 | down_write(&zram->lock); | 535 | down_write(&zram->lock); |
550 | handle_pending_slot_free(zram); | ||
551 | ret = zram_bvec_write(zram, bvec, index, offset); | 536 | ret = zram_bvec_write(zram, bvec, index, offset); |
552 | up_write(&zram->lock); | 537 | up_write(&zram->lock); |
553 | } | 538 | } |
@@ -566,8 +551,6 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) | |||
566 | return; | 551 | return; |
567 | } | 552 | } |
568 | 553 | ||
569 | flush_work(&zram->free_work); | ||
570 | |||
571 | meta = zram->meta; | 554 | meta = zram->meta; |
572 | zram->init_done = 0; | 555 | zram->init_done = 0; |
573 | 556 | ||
@@ -769,40 +752,19 @@ error: | |||
769 | bio_io_error(bio); | 752 | bio_io_error(bio); |
770 | } | 753 | } |
771 | 754 | ||
772 | static void zram_slot_free(struct work_struct *work) | ||
773 | { | ||
774 | struct zram *zram; | ||
775 | |||
776 | zram = container_of(work, struct zram, free_work); | ||
777 | down_write(&zram->lock); | ||
778 | handle_pending_slot_free(zram); | ||
779 | up_write(&zram->lock); | ||
780 | } | ||
781 | |||
782 | static void add_slot_free(struct zram *zram, struct zram_slot_free *free_rq) | ||
783 | { | ||
784 | spin_lock(&zram->slot_free_lock); | ||
785 | free_rq->next = zram->slot_free_rq; | ||
786 | zram->slot_free_rq = free_rq; | ||
787 | spin_unlock(&zram->slot_free_lock); | ||
788 | } | ||
789 | |||
790 | static void zram_slot_free_notify(struct block_device *bdev, | 755 | static void zram_slot_free_notify(struct block_device *bdev, |
791 | unsigned long index) | 756 | unsigned long index) |
792 | { | 757 | { |
793 | struct zram *zram; | 758 | struct zram *zram; |
794 | struct zram_slot_free *free_rq; | 759 | struct zram_meta *meta; |
795 | 760 | ||
796 | zram = bdev->bd_disk->private_data; | 761 | zram = bdev->bd_disk->private_data; |
797 | atomic64_inc(&zram->stats.notify_free); | 762 | meta = zram->meta; |
798 | |||
799 | free_rq = kmalloc(sizeof(struct zram_slot_free), GFP_ATOMIC); | ||
800 | if (!free_rq) | ||
801 | return; | ||
802 | 763 | ||
803 | free_rq->index = index; | 764 | write_lock(&meta->tb_lock); |
804 | add_slot_free(zram, free_rq); | 765 | zram_free_page(zram, index); |
805 | schedule_work(&zram->free_work); | 766 | write_unlock(&meta->tb_lock); |
767 | atomic64_inc(&zram->stats.notify_free); | ||
806 | } | 768 | } |
807 | 769 | ||
808 | static const struct block_device_operations zram_devops = { | 770 | static const struct block_device_operations zram_devops = { |
@@ -849,10 +811,6 @@ static int create_device(struct zram *zram, int device_id) | |||
849 | init_rwsem(&zram->lock); | 811 | init_rwsem(&zram->lock); |
850 | init_rwsem(&zram->init_lock); | 812 | init_rwsem(&zram->init_lock); |
851 | 813 | ||
852 | INIT_WORK(&zram->free_work, zram_slot_free); | ||
853 | spin_lock_init(&zram->slot_free_lock); | ||
854 | zram->slot_free_rq = NULL; | ||
855 | |||
856 | zram->queue = blk_alloc_queue(GFP_KERNEL); | 814 | zram->queue = blk_alloc_queue(GFP_KERNEL); |
857 | if (!zram->queue) { | 815 | if (!zram->queue) { |
858 | pr_err("Error allocating disk queue for device %d\n", | 816 | pr_err("Error allocating disk queue for device %d\n", |
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index c3f453f04974..d876300da6c9 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h | |||
@@ -90,20 +90,11 @@ struct zram_meta { | |||
90 | struct zs_pool *mem_pool; | 90 | struct zs_pool *mem_pool; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | struct zram_slot_free { | ||
94 | unsigned long index; | ||
95 | struct zram_slot_free *next; | ||
96 | }; | ||
97 | |||
98 | struct zram { | 93 | struct zram { |
99 | struct zram_meta *meta; | 94 | struct zram_meta *meta; |
100 | struct rw_semaphore lock; /* protect compression buffers, | 95 | struct rw_semaphore lock; /* protect compression buffers, |
101 | * reads and writes | 96 | * reads and writes |
102 | */ | 97 | */ |
103 | |||
104 | struct work_struct free_work; /* handle pending free request */ | ||
105 | struct zram_slot_free *slot_free_rq; /* list head of free request */ | ||
106 | |||
107 | struct request_queue *queue; | 98 | struct request_queue *queue; |
108 | struct gendisk *disk; | 99 | struct gendisk *disk; |
109 | int init_done; | 100 | int init_done; |
@@ -114,7 +105,6 @@ struct zram { | |||
114 | * we can store in a disk. | 105 | * we can store in a disk. |
115 | */ | 106 | */ |
116 | u64 disksize; /* bytes */ | 107 | u64 disksize; /* bytes */ |
117 | spinlock_t slot_free_lock; | ||
118 | 108 | ||
119 | struct zram_stats stats; | 109 | struct zram_stats stats; |
120 | }; | 110 | }; |