diff options
| author | Sergey Senozhatsky <sergey.senozhatsky@gmail.com> | 2014-04-07 18:38:09 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-07 19:36:00 -0400 |
| commit | b67d1ec189ffb92cdad9b2bd29475fb1e0166983 (patch) | |
| tree | 47ee59a17c86fe9e7e778eb89069178ae775f321 /drivers/block | |
| parent | 8dd1d3247e6c00b50ef83934ea8b22a1590015de (diff) | |
zram: delete zram_init_device()
allocate new `zram_meta' in disksize_store() only for uninitialised zram
device, saving a number of allocations and deallocations in case if
disksize_store() was called on currently used device. at the same time
zram_meta stack variable is not necessary, because we can set ->meta
directly. there is also no need in setting QUEUE_FLAG_NONROT queue on
every disksize_store(), set it once during device creation.
[minchan@kernel.org: handle zram->meta alloc fail case]
[minchan@kernel.org: prevent lockdep spew of init_lock]
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
Acked-by: Jerome Marchand <jmarchan@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block')
| -rw-r--r-- | drivers/block/zram/zram_drv.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 21aee3edcb25..76ba67673a90 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c | |||
| @@ -533,14 +533,6 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) | |||
| 533 | up_write(&zram->init_lock); | 533 | up_write(&zram->init_lock); |
| 534 | } | 534 | } |
| 535 | 535 | ||
| 536 | static void zram_init_device(struct zram *zram, struct zram_meta *meta) | ||
| 537 | { | ||
| 538 | /* zram devices sort of resembles non-rotational disks */ | ||
| 539 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); | ||
| 540 | zram->meta = meta; | ||
| 541 | pr_debug("Initialization done!\n"); | ||
| 542 | } | ||
| 543 | |||
| 544 | static ssize_t disksize_store(struct device *dev, | 536 | static ssize_t disksize_store(struct device *dev, |
| 545 | struct device_attribute *attr, const char *buf, size_t len) | 537 | struct device_attribute *attr, const char *buf, size_t len) |
| 546 | { | 538 | { |
| @@ -556,17 +548,18 @@ static ssize_t disksize_store(struct device *dev, | |||
| 556 | meta = zram_meta_alloc(disksize); | 548 | meta = zram_meta_alloc(disksize); |
| 557 | if (!meta) | 549 | if (!meta) |
| 558 | return -ENOMEM; | 550 | return -ENOMEM; |
| 551 | |||
| 559 | down_write(&zram->init_lock); | 552 | down_write(&zram->init_lock); |
| 560 | if (init_done(zram)) { | 553 | if (init_done(zram)) { |
| 561 | up_write(&zram->init_lock); | ||
| 562 | zram_meta_free(meta); | 554 | zram_meta_free(meta); |
| 555 | up_write(&zram->init_lock); | ||
| 563 | pr_info("Cannot change disksize for initialized device\n"); | 556 | pr_info("Cannot change disksize for initialized device\n"); |
| 564 | return -EBUSY; | 557 | return -EBUSY; |
| 565 | } | 558 | } |
| 566 | 559 | ||
| 560 | zram->meta = meta; | ||
| 567 | zram->disksize = disksize; | 561 | zram->disksize = disksize; |
| 568 | set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); | 562 | set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); |
| 569 | zram_init_device(zram, meta); | ||
| 570 | up_write(&zram->init_lock); | 563 | up_write(&zram->init_lock); |
| 571 | 564 | ||
| 572 | return len; | 565 | return len; |
| @@ -776,7 +769,8 @@ static int create_device(struct zram *zram, int device_id) | |||
| 776 | 769 | ||
| 777 | /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ | 770 | /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ |
| 778 | set_capacity(zram->disk, 0); | 771 | set_capacity(zram->disk, 0); |
| 779 | 772 | /* zram devices sort of resembles non-rotational disks */ | |
| 773 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); | ||
| 780 | /* | 774 | /* |
| 781 | * To ensure that we always get PAGE_SIZE aligned | 775 | * To ensure that we always get PAGE_SIZE aligned |
| 782 | * and n*PAGE_SIZED sized I/O requests. | 776 | * and n*PAGE_SIZED sized I/O requests. |
