Skip to content

Commit 0cf1e9d

Browse files
chaseyutorvalds
authored andcommitted
zram: fix incorrect stat with failed_reads
Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in commit 924bd88 ("Staging: zram: allow partial page operations"), our ->failed_reads value may be incorrect as we do not increase its value when failing to allocate the temporary buffer. Let's fix this issue and correct the annotation of failed_reads. Signed-off-by: Chao Yu <[email protected]> Acked-by: Minchan Kim <[email protected]> Cc: Nitin Gupta <[email protected]> Acked-by: Jerome Marchand <[email protected]> Acked-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0c38e1f commit 0cf1e9d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
378378
/* Should NEVER happen. Return bio error if it does. */
379379
if (unlikely(ret)) {
380380
pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
381-
atomic64_inc(&zram->stats.failed_reads);
382381
return ret;
383382
}
384383

@@ -547,8 +546,6 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
547546
zcomp_strm_release(zram->comp, zstrm);
548547
if (is_partial_io(bvec))
549548
kfree(uncmem);
550-
if (ret)
551-
atomic64_inc(&zram->stats.failed_writes);
552549
return ret;
553550
}
554551

@@ -566,6 +563,13 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
566563
ret = zram_bvec_write(zram, bvec, index, offset);
567564
}
568565

566+
if (unlikely(ret)) {
567+
if (rw == READ)
568+
atomic64_inc(&zram->stats.failed_reads);
569+
else
570+
atomic64_inc(&zram->stats.failed_writes);
571+
}
572+
569573
return ret;
570574
}
571575

drivers/block/zram/zram_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct zram_stats {
8484
atomic64_t compr_data_size; /* compressed size of pages stored */
8585
atomic64_t num_reads; /* failed + successful */
8686
atomic64_t num_writes; /* --do-- */
87-
atomic64_t failed_reads; /* should NEVER! happen */
87+
atomic64_t failed_reads; /* can happen when memory is too low */
8888
atomic64_t failed_writes; /* can happen when memory is too low */
8989
atomic64_t invalid_io; /* non-page-aligned I/O requests */
9090
atomic64_t notify_free; /* no. of swap slot free notifications */

0 commit comments

Comments
 (0)