Skip to content

Commit e7be8d1

Browse files
mRrvzakpm00
authored andcommitted
zram: remove double compression logic
The 2nd trial allocation under per-cpu presumption has been used to prevent regression of allocation failure. However, it makes trouble for maintenance without significant benefit. The slowpath branch is executed extremely rarely: getting there is problematic. Therefore, we delete this branch. Since b09ab05 ("zram: support BDI_CAP_STABLE_WRITES"), zram has used QUEUE_FLAG_STABLE_WRITES to prevent buffer change between 1st and 2nd memory allocations. Since we remove second trial memory allocation logic, we could remove the STABLE_WRITES flag because there is no change buffer to be modified under us. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Alexey Romanov <[email protected]> Signed-off-by: Dmitry Rokosov <[email protected]> Acked-by: Minchan Kim <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Cc: Nitin Gupta <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f67bed1 commit e7be8d1

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,15 +1144,14 @@ static ssize_t bd_stat_show(struct device *dev,
11441144
static ssize_t debug_stat_show(struct device *dev,
11451145
struct device_attribute *attr, char *buf)
11461146
{
1147-
int version = 1;
1147+
int version = 2;
11481148
struct zram *zram = dev_to_zram(dev);
11491149
ssize_t ret;
11501150

11511151
down_read(&zram->init_lock);
11521152
ret = scnprintf(buf, PAGE_SIZE,
1153-
"version: %d\n%8llu %8llu\n",
1153+
"version: %d\n%8llu\n",
11541154
version,
1155-
(u64)atomic64_read(&zram->stats.writestall),
11561155
(u64)atomic64_read(&zram->stats.miss_free));
11571156
up_read(&zram->init_lock);
11581157

@@ -1368,7 +1367,6 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
13681367
}
13691368
kunmap_atomic(mem);
13701369

1371-
compress_again:
13721370
zstrm = zcomp_stream_get(zram->comp);
13731371
src = kmap_atomic(page);
13741372
ret = zcomp_compress(zstrm, src, &comp_len);
@@ -1377,39 +1375,20 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
13771375
if (unlikely(ret)) {
13781376
zcomp_stream_put(zram->comp);
13791377
pr_err("Compression failed! err=%d\n", ret);
1380-
zs_free(zram->mem_pool, handle);
13811378
return ret;
13821379
}
13831380

13841381
if (comp_len >= huge_class_size)
13851382
comp_len = PAGE_SIZE;
1386-
/*
1387-
* handle allocation has 2 paths:
1388-
* a) fast path is executed with preemption disabled (for
1389-
* per-cpu streams) and has __GFP_DIRECT_RECLAIM bit clear,
1390-
* since we can't sleep;
1391-
* b) slow path enables preemption and attempts to allocate
1392-
* the page with __GFP_DIRECT_RECLAIM bit set. we have to
1393-
* put per-cpu compression stream and, thus, to re-do
1394-
* the compression once handle is allocated.
1395-
*
1396-
* if we have a 'non-null' handle here then we are coming
1397-
* from the slow path and handle has already been allocated.
1398-
*/
1399-
if (!handle)
1400-
handle = zs_malloc(zram->mem_pool, comp_len,
1401-
__GFP_KSWAPD_RECLAIM |
1402-
__GFP_NOWARN |
1403-
__GFP_HIGHMEM |
1404-
__GFP_MOVABLE);
1405-
if (!handle) {
1383+
1384+
handle = zs_malloc(zram->mem_pool, comp_len,
1385+
__GFP_KSWAPD_RECLAIM |
1386+
__GFP_NOWARN |
1387+
__GFP_HIGHMEM |
1388+
__GFP_MOVABLE);
1389+
1390+
if (unlikely(!handle)) {
14061391
zcomp_stream_put(zram->comp);
1407-
atomic64_inc(&zram->stats.writestall);
1408-
handle = zs_malloc(zram->mem_pool, comp_len,
1409-
GFP_NOIO | __GFP_HIGHMEM |
1410-
__GFP_MOVABLE);
1411-
if (handle)
1412-
goto compress_again;
14131392
return -ENOMEM;
14141393
}
14151394

@@ -1967,7 +1946,6 @@ static int zram_add(void)
19671946
if (ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE)
19681947
blk_queue_max_write_zeroes_sectors(zram->disk->queue, UINT_MAX);
19691948

1970-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, zram->disk->queue);
19711949
ret = device_add_disk(NULL, zram->disk, zram_disk_groups);
19721950
if (ret)
19731951
goto out_cleanup_disk;

drivers/block/zram/zram_drv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ struct zram_stats {
8181
atomic64_t huge_pages_since; /* no. of huge pages since zram set up */
8282
atomic64_t pages_stored; /* no. of pages currently stored */
8383
atomic_long_t max_used_pages; /* no. of maximum pages stored */
84-
atomic64_t writestall; /* no. of write slow paths */
8584
atomic64_t miss_free; /* no. of missed free */
8685
#ifdef CONFIG_ZRAM_WRITEBACK
8786
atomic64_t bd_count; /* no. of pages in backing device */

0 commit comments

Comments
 (0)