mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
zram: drop pp_in_progress
pp_in_progress makes sure that only one post-processing (writeback or recomrpession) is active at any given time. Functionality wise it, basically, shadows zram init_lock, when init_lock is acquired in writer mode. Switch recompress_store() and writeback_store() to take zram init_lock in writer mode, like all store() sysfs handlers should do, so that we can drop pp_in_progress. Recompression and writeback can be somewhat slow, so holding init_lock in writer mode can block zram attrs reads, but in reality the only zram attrs reads that take place are mm_stat reads, and usually it's the same process that reads mm_stat and does recompression or writeback. Link: https://lkml.kernel.org/r/20251216071342.687993-1-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Brian Geffon <bgeffon@google.com> Cc: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
9082f24bd3
commit
657a81fe3b
|
|
@ -902,7 +902,7 @@ static struct zram_wb_ctl *init_wb_ctl(struct zram *zram)
|
|||
|
||||
static void zram_account_writeback_rollback(struct zram *zram)
|
||||
{
|
||||
lockdep_assert_held_read(&zram->init_lock);
|
||||
lockdep_assert_held_write(&zram->init_lock);
|
||||
|
||||
if (zram->wb_limit_enable)
|
||||
zram->bd_wb_limit += 1UL << (PAGE_SHIFT - 12);
|
||||
|
|
@ -910,7 +910,7 @@ static void zram_account_writeback_rollback(struct zram *zram)
|
|||
|
||||
static void zram_account_writeback_submit(struct zram *zram)
|
||||
{
|
||||
lockdep_assert_held_read(&zram->init_lock);
|
||||
lockdep_assert_held_write(&zram->init_lock);
|
||||
|
||||
if (zram->wb_limit_enable && zram->bd_wb_limit > 0)
|
||||
zram->bd_wb_limit -= 1UL << (PAGE_SHIFT - 12);
|
||||
|
|
@ -1264,24 +1264,16 @@ static ssize_t writeback_store(struct device *dev,
|
|||
ssize_t ret = len;
|
||||
int err, mode = 0;
|
||||
|
||||
guard(rwsem_read)(&zram->init_lock);
|
||||
guard(rwsem_write)(&zram->init_lock);
|
||||
if (!init_done(zram))
|
||||
return -EINVAL;
|
||||
|
||||
/* Do not permit concurrent post-processing actions. */
|
||||
if (atomic_xchg(&zram->pp_in_progress, 1))
|
||||
return -EAGAIN;
|
||||
|
||||
if (!zram->backing_dev) {
|
||||
ret = -ENODEV;
|
||||
goto out;
|
||||
}
|
||||
if (!zram->backing_dev)
|
||||
return -ENODEV;
|
||||
|
||||
pp_ctl = init_pp_ctl();
|
||||
if (!pp_ctl) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
if (!pp_ctl)
|
||||
return -ENOMEM;
|
||||
|
||||
wb_ctl = init_wb_ctl(zram);
|
||||
if (!wb_ctl) {
|
||||
|
|
@ -1358,7 +1350,6 @@ static ssize_t writeback_store(struct device *dev,
|
|||
out:
|
||||
release_pp_ctl(zram, pp_ctl);
|
||||
release_wb_ctl(wb_ctl);
|
||||
atomic_set(&zram->pp_in_progress, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -2619,14 +2610,10 @@ static ssize_t recompress_store(struct device *dev,
|
|||
if (threshold >= huge_class_size)
|
||||
return -EINVAL;
|
||||
|
||||
guard(rwsem_read)(&zram->init_lock);
|
||||
guard(rwsem_write)(&zram->init_lock);
|
||||
if (!init_done(zram))
|
||||
return -EINVAL;
|
||||
|
||||
/* Do not permit concurrent post-processing actions. */
|
||||
if (atomic_xchg(&zram->pp_in_progress, 1))
|
||||
return -EAGAIN;
|
||||
|
||||
if (algo) {
|
||||
bool found = false;
|
||||
|
||||
|
|
@ -2697,7 +2684,6 @@ static ssize_t recompress_store(struct device *dev,
|
|||
if (page)
|
||||
__free_page(page);
|
||||
release_pp_ctl(zram, ctl);
|
||||
atomic_set(&zram->pp_in_progress, 0);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -2888,7 +2874,6 @@ static void zram_reset_device(struct zram *zram)
|
|||
zram->disksize = 0;
|
||||
zram_destroy_comps(zram);
|
||||
memset(&zram->stats, 0, sizeof(zram->stats));
|
||||
atomic_set(&zram->pp_in_progress, 0);
|
||||
reset_bdev(zram);
|
||||
|
||||
comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor);
|
||||
|
|
@ -3124,7 +3109,6 @@ static int zram_add(void)
|
|||
zram->disk->fops = &zram_devops;
|
||||
zram->disk->private_data = zram;
|
||||
snprintf(zram->disk->disk_name, 16, "zram%d", device_id);
|
||||
atomic_set(&zram->pp_in_progress, 0);
|
||||
zram_comp_params_reset(zram);
|
||||
comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor);
|
||||
|
||||
|
|
|
|||
|
|
@ -143,6 +143,5 @@ struct zram {
|
|||
#ifdef CONFIG_ZRAM_MEMORY_TRACKING
|
||||
struct dentry *debugfs_dir;
|
||||
#endif
|
||||
atomic_t pp_in_progress;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user