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

zram: move comp allocation out of init_lock

While fixing lockdep spew of ->init_lock reported by Sasha Levin [1],
Minchan Kim noted [2] that it's better to move compression backend
allocation (using GPF_KERNEL) out of the ->init_lock lock, same way as
with zram_meta_alloc(), in order to prevent the same lockdep spew.

[1] https://lkml.org/lkml/2014/2/27/337
[2] https://lkml.org/lkml/2014/3/3/32Signed-off-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Reported-by: default avatarMinchan Kim <minchan@kernel.org>
Acked-by: default avatarMinchan Kim <minchan@kernel.org>
Cc: Sasha Levin <sasha.levin@oracle.com>
Acked-by: default avatarJerome Marchand <jmarchan@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6e76668e
...@@ -580,9 +580,10 @@ static ssize_t disksize_store(struct device *dev, ...@@ -580,9 +580,10 @@ 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)
{ {
u64 disksize; u64 disksize;
struct zcomp *comp;
struct zram_meta *meta; struct zram_meta *meta;
struct zram *zram = dev_to_zram(dev); struct zram *zram = dev_to_zram(dev);
int err; int err = -EINVAL;
disksize = memparse(buf, NULL); disksize = memparse(buf, NULL);
if (!disksize) if (!disksize)
...@@ -593,30 +594,32 @@ static ssize_t disksize_store(struct device *dev, ...@@ -593,30 +594,32 @@ static ssize_t disksize_store(struct device *dev,
if (!meta) if (!meta)
return -ENOMEM; return -ENOMEM;
comp = zcomp_create(zram->compressor, zram->max_comp_streams);
if (!comp) {
pr_info("Cannot initialise %s compressing backend\n",
zram->compressor);
goto out_cleanup;
}
down_write(&zram->init_lock); down_write(&zram->init_lock);
if (init_done(zram)) { if (init_done(zram)) {
up_write(&zram->init_lock);
pr_info("Cannot change disksize for initialized device\n"); pr_info("Cannot change disksize for initialized device\n");
err = -EBUSY; err = -EBUSY;
goto out_free_meta; goto out_cleanup;
}
zram->comp = zcomp_create(zram->compressor, zram->max_comp_streams);
if (!zram->comp) {
pr_info("Cannot initialise %s compressing backend\n",
zram->compressor);
err = -EINVAL;
goto out_free_meta;
} }
zram->meta = meta; zram->meta = meta;
zram->comp = comp;
zram->disksize = disksize; zram->disksize = disksize;
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
up_write(&zram->init_lock); up_write(&zram->init_lock);
return len; return len;
out_free_meta: out_cleanup:
up_write(&zram->init_lock); if (comp)
zcomp_destroy(comp);
zram_meta_free(meta); zram_meta_free(meta);
return err; return err;
} }
......
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