Skip to contentSkip to conversation

zram: fix incorrectly stat with failed_reads

PATCH In review Chao Yu 4 participants 8 messages Aug 13, 2014 – Aug 14, 2014

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH v2 1/1 zram: fix incorrectly stat with failed_reads

Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in this commit 924bd88d703e53d30f393fac6117f8f1bc79aab6 (Staging:
zram: allow partial page operations), our ->failed_reads value may be incorrect as we do not increase its value when failed to allocate the temporary buffer.

Let's fix this issue and correct the annotation of failed_reads.

v2: clean codes of failed_{reads,writes} stat pointed out by Minchan Kim, and
this cleanup also fix incorrectly stat when fail in zram_decompress_page.

---
 drivers/block/zram/zram_drv.c | 10 +++++++---
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/block/zram/zram_drv.c +7 -3
index dfa4024..d00831c 100644
@@ -378,7 +378,6 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
 	/* Should NEVER happen. Return bio error if it does. */
 	if (unlikely(ret)) {
 		pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
-		atomic64_inc(&zram->stats.failed_reads);
 		return ret;
 	}
 
@@ -547,8 +546,6 @@ out:
 		zcomp_strm_release(zram->comp, zstrm);
 	if (is_partial_io(bvec))
 		kfree(uncmem);
-	if (ret)
-		atomic64_inc(&zram->stats.failed_writes);
 	return ret;
 }
 
@@ -566,6 +563,13 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
 		ret = zram_bvec_write(zram, bvec, index, offset);
 	}
 
+	if (unlikely(ret)) {
+		if (rw == READ)
+			atomic64_inc(&zram->stats.failed_reads);
+		else
+			atomic64_inc(&zram->stats.failed_writes);
+	}
+
 	return ret;
 }
 
drivers/block/zram/zram_drv.h +1 -1
index 5b0afde..e0f725c 100644
@@ -84,7 +84,7 @@ struct zram_stats {
 	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t num_reads;	/* failed + successful */
 	atomic64_t num_writes;	/* --do-- */
-	atomic64_t failed_reads;	/* should NEVER! happen */
+	atomic64_t failed_reads;	/* can happen when memory is too low */
 	atomic64_t failed_writes;	/* can happen when memory is too low */
 	atomic64_t invalid_io;	/* non-page-aligned I/O requests */
 	atomic64_t notify_free;	/* no. of swap slot free notifications */
Signature · 1 line
2.0.1.474.g72c7794
Acked-by on v2 1/1
#1 lore raw
Quoted 11 lines · Chao Yu

Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in this commit 924bd88d703e53d30f393fac6117f8f1bc79aab6 (Staging:
zram: allow partial page operations), our ->failed_reads value may be incorrect as we do not increase its value when failed to allocate the temporary buffer.

Let's fix this issue and correct the annotation of failed_reads.

v2: clean codes of failed_{reads,writes} stat pointed out by Minchan Kim, and
this cleanup also fix incorrectly stat when fail in zram_decompress_page.

Quoted 54 lines
---
 drivers/block/zram/zram_drv.c | 10 +++++++---
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/block/zram/zram_drv.c +7 -3
index dfa4024..d00831c 100644
@@ -378,7 +378,6 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
 	/* Should NEVER happen. Return bio error if it does. */
 	if (unlikely(ret)) {
 		pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
-		atomic64_inc(&zram->stats.failed_reads);
 		return ret;
 	}
 
@@ -547,8 +546,6 @@ out:
 		zcomp_strm_release(zram->comp, zstrm);
 	if (is_partial_io(bvec))
 		kfree(uncmem);
-	if (ret)
-		atomic64_inc(&zram->stats.failed_writes);
 	return ret;
 }
 
@@ -566,6 +563,13 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
 		ret = zram_bvec_write(zram, bvec, index, offset);
 	}
 
+	if (unlikely(ret)) {
+		if (rw == READ)
+			atomic64_inc(&zram->stats.failed_reads);
+		else
+			atomic64_inc(&zram->stats.failed_writes);
+	}
+
 	return ret;
 }
 
drivers/block/zram/zram_drv.h +1 -1
index 5b0afde..e0f725c 100644
@@ -84,7 +84,7 @@ struct zram_stats {
 	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t num_reads;	/* failed + successful */
 	atomic64_t num_writes;	/* --do-- */
-	atomic64_t failed_reads;	/* should NEVER! happen */
+	atomic64_t failed_reads;	/* can happen when memory is too low */
 	atomic64_t failed_writes;	/* can happen when memory is too low */
 	atomic64_t invalid_io;	/* non-page-aligned I/O requests */
 	atomic64_t notify_free;	/* no. of swap slot free notifications */
#2 lore raw
Quoted 16 lines · Jerome Marchand

Date: Wed, 13 Aug 2014 10:31:45 +0200
From: Jerome Marchand <[email protected]>
To: Chao Yu <[email protected]>, [email protected]
CC: [email protected], [email protected], 'Sergey Senozhatsky'
<[email protected]>, 'Andrew Morton' <[email protected]>
Subject: Re: [PATCH v2] zram: fix incorrectly stat with failed_reads
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101
Thunderbird/24.6.0

Quoted 5 lines · Chao Yu

Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in this commit 924bd88d703e53d30f393fac6117f8f1bc79aab6 (Staging:
zram: allow partial page operations), our ->failed_reads value may be incorrect as we do not increase its value when failed to allocate the temporary buffer.

Quoted 8 lines
Quoted 6 lines

Let's fix this issue and correct the annotation of failed_reads.

v2: clean codes of failed_{reads,writes} stat pointed out by Minchan Kim, and
this cleanup also fix incorrectly stat when fail in zram_decompress_page.

	-ss
Quoted 56 lines
Quoted 54 lines
---
 drivers/block/zram/zram_drv.c | 10 +++++++---
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/block/zram/zram_drv.c +7 -3
index dfa4024..d00831c 100644
@@ -378,7 +378,6 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
 	/* Should NEVER happen. Return bio error if it does. */
 	if (unlikely(ret)) {
 		pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
-		atomic64_inc(&zram->stats.failed_reads);
 		return ret;
 	}
 
@@ -547,8 +546,6 @@ out:
 		zcomp_strm_release(zram->comp, zstrm);
 	if (is_partial_io(bvec))
 		kfree(uncmem);
-	if (ret)
-		atomic64_inc(&zram->stats.failed_writes);
 	return ret;
 }
 
@@ -566,6 +563,13 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
 		ret = zram_bvec_write(zram, bvec, index, offset);
 	}
 
+	if (unlikely(ret)) {
+		if (rw == READ)
+			atomic64_inc(&zram->stats.failed_reads);
+		else
+			atomic64_inc(&zram->stats.failed_writes);
+	}
+
 	return ret;
 }
 
drivers/block/zram/zram_drv.h +1 -1
index 5b0afde..e0f725c 100644
@@ -84,7 +84,7 @@ struct zram_stats {
 	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t num_reads;	/* failed + successful */
 	atomic64_t num_writes;	/* --do-- */
-	atomic64_t failed_reads;	/* should NEVER! happen */
+	atomic64_t failed_reads;	/* can happen when memory is too low */
 	atomic64_t failed_writes;	/* can happen when memory is too low */
 	atomic64_t invalid_io;	/* non-page-aligned I/O requests */
 	atomic64_t notify_free;	/* no. of swap slot free notifications */
#3 lore raw

Hello,

Quoted 70 lines · Sergey Senozhatsky
Quoted 16 lines · Jerome Marchand

Date: Wed, 13 Aug 2014 10:31:45 +0200
From: Jerome Marchand <[email protected]>
To: Chao Yu <[email protected]>, [email protected]
CC: [email protected], [email protected], 'Sergey Senozhatsky'
<[email protected]>, 'Andrew Morton' <[email protected]>
Subject: Re: [PATCH v2] zram: fix incorrectly stat with failed_reads
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101
Thunderbird/24.6.0

Quoted 5 lines · Chao Yu

Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in this commit 924bd88d703e53d30f393fac6117f8f1bc79aab6 (Staging:
zram: allow partial page operations), our ->failed_reads value may be incorrect as we do not increase its value when failed to allocate the temporary buffer.

Quoted 8 lines
Quoted 6 lines

Let's fix this issue and correct the annotation of failed_reads.

v2: clean codes of failed_{reads,writes} stat pointed out by Minchan Kim, and
this cleanup also fix incorrectly stat when fail in zram_decompress_page.

	-ss
Quoted 40 lines
Quoted 40 lines
---
 drivers/block/zram/zram_drv.c | 10 +++++++---
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/block/zram/zram_drv.c +7 -3
index dfa4024..d00831c 100644
@@ -378,7 +378,6 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
 	/* Should NEVER happen. Return bio error if it does. */
 	if (unlikely(ret)) {
 		pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
-		atomic64_inc(&zram->stats.failed_reads);
 		return ret;
 	}
 
@@ -547,8 +546,6 @@ out:
 		zcomp_strm_release(zram->comp, zstrm);
 	if (is_partial_io(bvec))
 		kfree(uncmem);
-	if (ret)
-		atomic64_inc(&zram->stats.failed_writes);
 	return ret;
 }
 
@@ -566,6 +563,13 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
 		ret = zram_bvec_write(zram, bvec, index, offset);
 	}
 
+	if (unlikely(ret)) {
+		if (rw == READ)
+			atomic64_inc(&zram->stats.failed_reads);
+		else
+			atomic64_inc(&zram->stats.failed_writes);
+	}
+
 	return ret;
 }
 
Quoted 10 lines
Quoted 10 lines

drivers/block/zram/zram_drv.h struct zram_stats { · line 87

Quoted 10 lines
drivers/block/zram/zram_drv.h +1 -1
index 5b0afde..e0f725c 100644
@@ -84,7 +84,7 @@ struct zram_stats {
 	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t num_reads;	/* failed + successful */
 	atomic64_t num_writes;	/* --do-- */
-	atomic64_t failed_reads;	/* should NEVER! happen */
+	atomic64_t failed_reads;	/* can happen when memory is too low */

this grabbed my attention.

"failed_writes; /* can happen when memory is too low */"

theoretically, we can have a misbehaving compression algorithm. so the question is -- should we fail write() if compression has failed for any other reason, rather than -ENOMEM? alternatively, we can store uncompressed user mem, just the same way we do for `badly' compressed buffers, set a FAILED_COMPRESSION flag (so we will not leak kernel memory on read() if we failed to compress is_partial_io() bv_page), and on read() copy it out as is, just as we do for `badly' compessed pages.

so, what do you think? /* I can take a look on it */

	-ss
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
drivers/block/zram/zram_drv.h +0 -0
 	atomic64_t failed_writes;	/* can happen when memory is too low */
 	atomic64_t invalid_io;	/* non-page-aligned I/O requests */
 	atomic64_t notify_free;	/* no. of swap slot free notifications */
#4 lore raw
Quoted 89 lines · Sergey Senozhatsky

Hello,

Quoted 70 lines · Sergey Senozhatsky
Quoted 16 lines · Jerome Marchand

Date: Wed, 13 Aug 2014 10:31:45 +0200
From: Jerome Marchand <[email protected]>
To: Chao Yu <[email protected]>, [email protected]
CC: [email protected], [email protected], 'Sergey Senozhatsky'
<[email protected]>, 'Andrew Morton' <[email protected]>
Subject: Re: [PATCH v2] zram: fix incorrectly stat with failed_reads
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101
Thunderbird/24.6.0

Quoted 5 lines · Chao Yu

Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in this commit 924bd88d703e53d30f393fac6117f8f1bc79aab6 (Staging:
zram: allow partial page operations), our ->failed_reads value may be incorrect as we do not increase its value when failed to allocate the temporary buffer.

Quoted 8 lines
Quoted 6 lines

Let's fix this issue and correct the annotation of failed_reads.

v2: clean codes of failed_{reads,writes} stat pointed out by Minchan Kim, and
this cleanup also fix incorrectly stat when fail in zram_decompress_page.

	-ss
Quoted 40 lines
Quoted 40 lines
---
 drivers/block/zram/zram_drv.c | 10 +++++++---
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/block/zram/zram_drv.c +7 -3
index dfa4024..d00831c 100644
@@ -378,7 +378,6 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
 	/* Should NEVER happen. Return bio error if it does. */
 	if (unlikely(ret)) {
 		pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
-		atomic64_inc(&zram->stats.failed_reads);
 		return ret;
 	}
 
@@ -547,8 +546,6 @@ out:
 		zcomp_strm_release(zram->comp, zstrm);
 	if (is_partial_io(bvec))
 		kfree(uncmem);
-	if (ret)
-		atomic64_inc(&zram->stats.failed_writes);
 	return ret;
 }
 
@@ -566,6 +563,13 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
 		ret = zram_bvec_write(zram, bvec, index, offset);
 	}
 
+	if (unlikely(ret)) {
+		if (rw == READ)
+			atomic64_inc(&zram->stats.failed_reads);
+		else
+			atomic64_inc(&zram->stats.failed_writes);
+	}
+
 	return ret;
 }
 
Quoted 10 lines
Quoted 10 lines

drivers/block/zram/zram_drv.h struct zram_stats { · line 87

Quoted 10 lines
drivers/block/zram/zram_drv.h +1 -1
index 5b0afde..e0f725c 100644
@@ -84,7 +84,7 @@ struct zram_stats {
 	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t num_reads;	/* failed + successful */
 	atomic64_t num_writes;	/* --do-- */
-	atomic64_t failed_reads;	/* should NEVER! happen */
+	atomic64_t failed_reads;	/* can happen when memory is too low */

this grabbed my attention.

"failed_writes; /* can happen when memory is too low */"

Quoted 8 lines

theoretically, we can have a misbehaving compression algorithm. so the question is -- should we fail write() if compression has failed for any other reason, rather than -ENOMEM? alternatively, we can store uncompressed user mem, just the same way we do for `badly' compressed buffers, set a FAILED_COMPRESSION flag (so we will not leak kernel memory on read() if we failed to compress is_partial_io() bv_page), and on read() copy it out as is, just as we do for `badly' compessed pages.

though this will surely complicate both write() and read() paths, but still.

	-ss
Quoted 13 lines

so, what do you think? /* I can take a look on it */

	-ss
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
drivers/block/zram/zram_drv.h +0 -0
 	atomic64_t failed_writes;	/* can happen when memory is too low */
 	atomic64_t invalid_io;	/* non-page-aligned I/O requests */
 	atomic64_t notify_free;	/* no. of swap slot free notifications */
maintainer
#5 lore raw
In reply to Sergey Senozhatsky

Hi Sergey,

Quoted 97 lines · Sergey Senozhatsky

Hello,

Quoted 70 lines · Sergey Senozhatsky
Quoted 16 lines · Jerome Marchand

Date: Wed, 13 Aug 2014 10:31:45 +0200
From: Jerome Marchand <[email protected]>
To: Chao Yu <[email protected]>, [email protected]
CC: [email protected], [email protected], 'Sergey Senozhatsky'
<[email protected]>, 'Andrew Morton' <[email protected]>
Subject: Re: [PATCH v2] zram: fix incorrectly stat with failed_reads
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101
Thunderbird/24.6.0

Quoted 5 lines · Chao Yu

Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in this commit 924bd88d703e53d30f393fac6117f8f1bc79aab6 (Staging:
zram: allow partial page operations), our ->failed_reads value may be incorrect as we do not increase its value when failed to allocate the temporary buffer.

Quoted 8 lines
Quoted 6 lines

Let's fix this issue and correct the annotation of failed_reads.

v2: clean codes of failed_{reads,writes} stat pointed out by Minchan Kim, and
this cleanup also fix incorrectly stat when fail in zram_decompress_page.

	-ss
Quoted 40 lines
Quoted 40 lines
---
 drivers/block/zram/zram_drv.c | 10 +++++++---
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/block/zram/zram_drv.c +7 -3
index dfa4024..d00831c 100644
@@ -378,7 +378,6 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
 	/* Should NEVER happen. Return bio error if it does. */
 	if (unlikely(ret)) {
 		pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
-		atomic64_inc(&zram->stats.failed_reads);
 		return ret;
 	}
 
@@ -547,8 +546,6 @@ out:
 		zcomp_strm_release(zram->comp, zstrm);
 	if (is_partial_io(bvec))
 		kfree(uncmem);
-	if (ret)
-		atomic64_inc(&zram->stats.failed_writes);
 	return ret;
 }
 
@@ -566,6 +563,13 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
 		ret = zram_bvec_write(zram, bvec, index, offset);
 	}
 
+	if (unlikely(ret)) {
+		if (rw == READ)
+			atomic64_inc(&zram->stats.failed_reads);
+		else
+			atomic64_inc(&zram->stats.failed_writes);
+	}
+
 	return ret;
 }
 
Quoted 10 lines
Quoted 10 lines

drivers/block/zram/zram_drv.h struct zram_stats { · line 87

Quoted 10 lines
drivers/block/zram/zram_drv.h +1 -1
index 5b0afde..e0f725c 100644
@@ -84,7 +84,7 @@ struct zram_stats {
 	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t num_reads;	/* failed + successful */
 	atomic64_t num_writes;	/* --do-- */
-	atomic64_t failed_reads;	/* should NEVER! happen */
+	atomic64_t failed_reads;	/* can happen when memory is too low */

this grabbed my attention.

"failed_writes; /* can happen when memory is too low */"

theoretically, we can have a misbehaving compression algorithm. so the question is -- should we fail write() if compression has failed for any other reason, rather than -ENOMEM? alternatively, we can store uncompressed user mem, just the same way we do for `badly' compressed buffers, set a FAILED_COMPRESSION flag (so we will not leak kernel memory on read() if we failed to compress is_partial_io() bv_page), and on read() copy it out as is, just as we do for `badly' compessed pages.

Quoted 1 line

so, what do you think? /* I can take a look on it */

How often does it happen?
I don't think it's valuable to maintain if it's too rare. Rather, I'd like to remove the comment on failed_writes. :)

Quoted 16 lines
	-ss
Quoted 8 lines
Quoted 6 lines

drivers/block/zram/zram_drv.h struct zram_stats { · line 90

Quoted 4 lines
drivers/block/zram/zram_drv.h +0 -0
 	atomic64_t failed_writes;	/* can happen when memory is too low */
 	atomic64_t invalid_io;	/* non-page-aligned I/O requests */
 	atomic64_t notify_free;	/* no. of swap slot free notifications */

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
Kind regards,
Minchan Kim
#6 lore raw

Hi,

Quoted 98 lines · Minchan Kim
Quoted 97 lines · Sergey Senozhatsky

Hello,

Quoted 70 lines · Sergey Senozhatsky
Quoted 16 lines · Jerome Marchand

Date: Wed, 13 Aug 2014 10:31:45 +0200
From: Jerome Marchand <[email protected]>
To: Chao Yu <[email protected]>, [email protected]
CC: [email protected], [email protected], 'Sergey Senozhatsky'
<[email protected]>, 'Andrew Morton' <[email protected]>
Subject: Re: [PATCH v2] zram: fix incorrectly stat with failed_reads
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101
Thunderbird/24.6.0

Quoted 5 lines · Chao Yu

Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in this commit 924bd88d703e53d30f393fac6117f8f1bc79aab6 (Staging:
zram: allow partial page operations), our ->failed_reads value may be incorrect as we do not increase its value when failed to allocate the temporary buffer.

Quoted 8 lines
Quoted 6 lines

Let's fix this issue and correct the annotation of failed_reads.

v2: clean codes of failed_{reads,writes} stat pointed out by Minchan Kim, and
this cleanup also fix incorrectly stat when fail in zram_decompress_page.

	-ss
Quoted 40 lines
Quoted 40 lines
---
 drivers/block/zram/zram_drv.c | 10 +++++++---
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/block/zram/zram_drv.c +7 -3
index dfa4024..d00831c 100644
@@ -378,7 +378,6 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
 	/* Should NEVER happen. Return bio error if it does. */
 	if (unlikely(ret)) {
 		pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
-		atomic64_inc(&zram->stats.failed_reads);
 		return ret;
 	}
 
@@ -547,8 +546,6 @@ out:
 		zcomp_strm_release(zram->comp, zstrm);
 	if (is_partial_io(bvec))
 		kfree(uncmem);
-	if (ret)
-		atomic64_inc(&zram->stats.failed_writes);
 	return ret;
 }
 
@@ -566,6 +563,13 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
 		ret = zram_bvec_write(zram, bvec, index, offset);
 	}
 
+	if (unlikely(ret)) {
+		if (rw == READ)
+			atomic64_inc(&zram->stats.failed_reads);
+		else
+			atomic64_inc(&zram->stats.failed_writes);
+	}
+
 	return ret;
 }
 
Quoted 10 lines
Quoted 10 lines

drivers/block/zram/zram_drv.h struct zram_stats { · line 87

Quoted 10 lines
drivers/block/zram/zram_drv.h +1 -1
index 5b0afde..e0f725c 100644
@@ -84,7 +84,7 @@ struct zram_stats {
 	atomic64_t compr_data_size;	/* compressed size of pages stored */
 	atomic64_t num_reads;	/* failed + successful */
 	atomic64_t num_writes;	/* --do-- */
-	atomic64_t failed_reads;	/* should NEVER! happen */
+	atomic64_t failed_reads;	/* can happen when memory is too low */

this grabbed my attention.

"failed_writes; /* can happen when memory is too low */"

theoretically, we can have a misbehaving compression algorithm. so the question is -- should we fail write() if compression has failed for any other reason, rather than -ENOMEM? alternatively, we can store uncompressed user mem, just the same way we do for `badly' compressed buffers, set a FAILED_COMPRESSION flag (so we will not leak kernel memory on read() if we failed to compress is_partial_io() bv_page), and on read() copy it out as is, just as we do for `badly' compessed pages.

Quoted 6 lines
Quoted 1 line

so, what do you think? /* I can take a look on it */

How often does it happen?
I don't think it's valuable to maintain if it's too rare. Rather, I'd like to remove the comment on failed_writes. :)

I don't think I've ever observed any errors. and, apparently, lzo is always `return LZO_E_OK'. so let's just drop it.

	-ss
maintainer Acked-by on v2 1/1
#7 lore raw
In reply to Chao Yu
Quoted 11 lines · Chao Yu

Since we allocate a temporary buffer in zram_bvec_read to handle partial page operations in this commit 924bd88d703e53d30f393fac6117f8f1bc79aab6 (Staging:
zram: allow partial page operations), our ->failed_reads value may be incorrect as we do not increase its value when failed to allocate the temporary buffer.

Let's fix this issue and correct the annotation of failed_reads.

v2: clean codes of failed_{reads,writes} stat pointed out by Minchan Kim, and
this cleanup also fix incorrectly stat when fail in zram_decompress_page.

Thanks!

Signature · 2 lines
Kind regards,
Minchan Kim