Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sergey Senozhatsky and committed by
Linus Torvalds
b67d1ec1 8dd1d324

+5 -11
+5 -11
drivers/block/zram/zram_drv.c
··· 533 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 536 static ssize_t disksize_store(struct device *dev, 545 537 struct device_attribute *attr, const char *buf, size_t len) 546 538 { ··· 548 556 meta = zram_meta_alloc(disksize); 549 557 if (!meta) 550 558 return -ENOMEM; 559 + 551 560 down_write(&zram->init_lock); 552 561 if (init_done(zram)) { 553 - up_write(&zram->init_lock); 554 562 zram_meta_free(meta); 563 + up_write(&zram->init_lock); 555 564 pr_info("Cannot change disksize for initialized device\n"); 556 565 return -EBUSY; 557 566 } 558 567 568 + zram->meta = meta; 559 569 zram->disksize = disksize; 560 570 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); 561 - zram_init_device(zram, meta); 562 571 up_write(&zram->init_lock); 563 572 564 573 return len; ··· 769 776 770 777 /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ 771 778 set_capacity(zram->disk, 0); 772 - 779 + /* zram devices sort of resembles non-rotational disks */ 780 + queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); 773 781 /* 774 782 * To ensure that we always get PAGE_SIZE aligned 775 783 * and n*PAGE_SIZED sized I/O requests.