Skip to content

Commit 43209ea

Browse files
sergey-senozhatskytorvalds
authored andcommitted
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>
1 parent d34f615 commit 43209ea

4 files changed

Lines changed: 19 additions & 59 deletions

File tree

‎Documentation/blockdev/zram.txt‎

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,16 @@ num_devices parameter is optional and tells zram how many devices should be
5959
pre-created. Default: 1.
6060

6161
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.
65-
66-
Examples:
67-
#show max compression streams number
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.
68+
69+
To find out how many streams are currently available:
6870
cat /sys/block/zram0/max_comp_streams
6971

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-
8372
3) Select compression algorithm
8473
Using comp_algorithm device attribute one can see available and
8574
currently selected (shown in square brackets) compression algorithms,

‎drivers/block/zram/zcomp.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ bool zcomp_available_algorithm(const char *comp)
9595
return find_backend(comp) != NULL;
9696
}
9797

98-
bool zcomp_set_max_streams(struct zcomp *comp, int num_strm)
99-
{
100-
return true;
101-
}
102-
10398
struct zcomp_strm *zcomp_strm_find(struct zcomp *comp)
10499
{
105100
return *get_cpu_ptr(comp->stream);

‎drivers/block/zram/zram_drv.c‎

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -304,46 +304,25 @@ static ssize_t mem_used_max_store(struct device *dev,
304304
return len;
305305
}
306306

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+
*/
307316
static ssize_t max_comp_streams_show(struct device *dev,
308317
struct device_attribute *attr, char *buf)
309318
{
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());
318320
}
319321

320322
static ssize_t max_comp_streams_store(struct device *dev,
321323
struct device_attribute *attr, const char *buf, size_t len)
322324
{
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;
347326
}
348327

349328
static ssize_t comp_algorithm_show(struct device *dev,
@@ -1035,7 +1014,6 @@ static void zram_reset_device(struct zram *zram)
10351014
/* Reset stats */
10361015
memset(&zram->stats, 0, sizeof(zram->stats));
10371016
zram->disksize = 0;
1038-
zram->max_comp_streams = 1;
10391017

10401018
set_capacity(zram->disk, 0);
10411019
part_stat_set_all(&zram->disk->part0, 0);
@@ -1299,7 +1277,6 @@ static int zram_add(void)
12991277
}
13001278
strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));
13011279
zram->meta = NULL;
1302-
zram->max_comp_streams = 1;
13031280

13041281
pr_info("Added device: %s\n", zram->disk->disk_name);
13051282
return device_id;

‎drivers/block/zram/zram_drv.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ struct zram {
102102
* the number of pages zram can consume for storing compressed data
103103
*/
104104
unsigned long limit_pages;
105-
int max_comp_streams;
106105

107106
struct zram_stats stats;
108107
atomic_t refcount; /* refcount for zram_meta */

0 commit comments

Comments
 (0)