Commit b67d1ec1 authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Linus Torvalds

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: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: default avatarMinchan Kim <minchan@kernel.org>
Acked-by: default avatarJerome Marchand <jmarchan@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8dd1d324
...@@ -533,14 +533,6 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) ...@@ -533,14 +533,6 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
up_write(&zram->init_lock); up_write(&zram->init_lock);
} }
static void zram_init_device(struct zram *zram, struct zram_meta *meta)
{
/* zram devices sort of resembles non-rotational disks */
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
zram->meta = meta;
pr_debug("Initialization done!\n");
}
static ssize_t disksize_store(struct device *dev, static ssize_t disksize_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len) struct device_attribute *attr, const char *buf, size_t len)
{ {
...@@ -556,17 +548,18 @@ static ssize_t disksize_store(struct device *dev, ...@@ -556,17 +548,18 @@ static ssize_t disksize_store(struct device *dev,
meta = zram_meta_alloc(disksize); meta = zram_meta_alloc(disksize);
if (!meta) if (!meta)
return -ENOMEM; return -ENOMEM;
down_write(&zram->init_lock); down_write(&zram->init_lock);
if (init_done(zram)) { if (init_done(zram)) {
up_write(&zram->init_lock);
zram_meta_free(meta); zram_meta_free(meta);
up_write(&zram->init_lock);
pr_info("Cannot change disksize for initialized device\n"); pr_info("Cannot change disksize for initialized device\n");
return -EBUSY; return -EBUSY;
} }
zram->meta = meta;
zram->disksize = disksize; zram->disksize = disksize;
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
zram_init_device(zram, meta);
up_write(&zram->init_lock); up_write(&zram->init_lock);
return len; return len;
...@@ -776,7 +769,8 @@ static int create_device(struct zram *zram, int device_id) ...@@ -776,7 +769,8 @@ static int create_device(struct zram *zram, int device_id)
/* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */
set_capacity(zram->disk, 0); set_capacity(zram->disk, 0);
/* zram devices sort of resembles non-rotational disks */
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
/* /*
* To ensure that we always get PAGE_SIZE aligned * To ensure that we always get PAGE_SIZE aligned
* and n*PAGE_SIZED sized I/O requests. * and n*PAGE_SIZED sized I/O requests.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment