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

zram: remove max_comp_streams internals

Remove the internal part of max_comp_streams interface, since we
switched to per-cpu streams. We will keep RW max_comp_streams attr
around, because:

a) we may (silently) switch back to idle compression streams list and
don't want to disturb user space

b) max_comp_streams attr must wait for the next 'lay off cycle'; we
give user space 2 years to adjust before we remove/downgrade the attr,
and there are already several attrs scheduled for removal in 4.11, so
it's too late for max_comp_streams.

This slightly change a user visible behaviour:

- First, reading from max_comp_stream file now will always return the
number of online CPUs.

- Second, writing to max_comp_stream will not take any effect.

Link: http://lkml.kernel.org/r/20160503165546.25201-1-sergey.senozhatsky@gmail.com
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>
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
43209ea2 d34f6157

+18 -58
+7 -18
Documentation/blockdev/zram.txt
··· 59 59 pre-created. Default: 1. 60 60 61 61 2) Set max number of compression streams 62 - Compression backend may use up to max_comp_streams compression streams, 63 - thus allowing up to max_comp_streams concurrent compression operations. 64 - By default, compression backend uses single compression stream. 62 + Regardless the value passed to this attribute, ZRAM will always 63 + allocate multiple compression streams - one per online CPUs - thus 64 + allowing several concurrent compression operations. The number of 65 + allocated compression streams goes down when some of the CPUs 66 + become offline. There is no single-compression-stream mode anymore, 67 + unless you are running a UP system or has only 1 CPU online. 65 68 66 - Examples: 67 - #show max compression streams number 69 + To find out how many streams are currently available: 68 70 cat /sys/block/zram0/max_comp_streams 69 - 70 - #set max compression streams number to 3 71 - echo 3 > /sys/block/zram0/max_comp_streams 72 - 73 - Note: 74 - In order to enable compression backend's multi stream support max_comp_streams 75 - must be initially set to desired concurrency level before ZRAM device 76 - initialisation. Once the device initialised as a single stream compression 77 - backend (max_comp_streams equals to 1), you will see error if you try to change 78 - the value of max_comp_streams because single stream compression backend 79 - implemented as a special case by lock overhead issue and does not support 80 - dynamic max_comp_streams. Only multi stream backend supports dynamic 81 - max_comp_streams adjustment. 82 71 83 72 3) Select compression algorithm 84 73 Using comp_algorithm device attribute one can see available and
-5
drivers/block/zram/zcomp.c
··· 95 95 return find_backend(comp) != NULL; 96 96 } 97 97 98 - bool zcomp_set_max_streams(struct zcomp *comp, int num_strm) 99 - { 100 - return true; 101 - } 102 - 103 98 struct zcomp_strm *zcomp_strm_find(struct zcomp *comp) 104 99 { 105 100 return *get_cpu_ptr(comp->stream);
+11 -34
drivers/block/zram/zram_drv.c
··· 304 304 return len; 305 305 } 306 306 307 + /* 308 + * We switched to per-cpu streams and this attr is not needed anymore. 309 + * However, we will keep it around for some time, because: 310 + * a) we may revert per-cpu streams in the future 311 + * b) it's visible to user space and we need to follow our 2 years 312 + * retirement rule; but we already have a number of 'soon to be 313 + * altered' attrs, so max_comp_streams need to wait for the next 314 + * layoff cycle. 315 + */ 307 316 static ssize_t max_comp_streams_show(struct device *dev, 308 317 struct device_attribute *attr, char *buf) 309 318 { 310 - int val; 311 - struct zram *zram = dev_to_zram(dev); 312 - 313 - down_read(&zram->init_lock); 314 - val = zram->max_comp_streams; 315 - up_read(&zram->init_lock); 316 - 317 - return scnprintf(buf, PAGE_SIZE, "%d\n", val); 319 + return scnprintf(buf, PAGE_SIZE, "%d\n", num_online_cpus()); 318 320 } 319 321 320 322 static ssize_t max_comp_streams_store(struct device *dev, 321 323 struct device_attribute *attr, const char *buf, size_t len) 322 324 { 323 - int num; 324 - struct zram *zram = dev_to_zram(dev); 325 - int ret; 326 - 327 - ret = kstrtoint(buf, 0, &num); 328 - if (ret < 0) 329 - return ret; 330 - if (num < 1) 331 - return -EINVAL; 332 - 333 - down_write(&zram->init_lock); 334 - if (init_done(zram)) { 335 - if (!zcomp_set_max_streams(zram->comp, num)) { 336 - pr_info("Cannot change max compression streams\n"); 337 - ret = -EINVAL; 338 - goto out; 339 - } 340 - } 341 - 342 - zram->max_comp_streams = num; 343 - ret = len; 344 - out: 345 - up_write(&zram->init_lock); 346 - return ret; 325 + return len; 347 326 } 348 327 349 328 static ssize_t comp_algorithm_show(struct device *dev, ··· 1014 1035 /* Reset stats */ 1015 1036 memset(&zram->stats, 0, sizeof(zram->stats)); 1016 1037 zram->disksize = 0; 1017 - zram->max_comp_streams = 1; 1018 1038 1019 1039 set_capacity(zram->disk, 0); 1020 1040 part_stat_set_all(&zram->disk->part0, 0); ··· 1277 1299 } 1278 1300 strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor)); 1279 1301 zram->meta = NULL; 1280 - zram->max_comp_streams = 1; 1281 1302 1282 1303 pr_info("Added device: %s\n", zram->disk->disk_name); 1283 1304 return device_id;
-1
drivers/block/zram/zram_drv.h
··· 102 102 * the number of pages zram can consume for storing compressed data 103 103 */ 104 104 unsigned long limit_pages; 105 - int max_comp_streams; 106 105 107 106 struct zram_stats stats; 108 107 atomic_t refcount; /* refcount for zram_meta */