Skip to contentSkip to conversation

zram stats rework and code cleanup

PATCH In review Sergey Senozhatsky 4 participants 22 messages Jan 16, 2014 – Feb 5, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover zram stats rework and code cleanup

This patchset includes zram stats clean up and enhancements.

Sergey Senozhatsky (8):
zram: drop `init_done' struct zram member
zram: do not pass rw argument to __zram_make_request()
zram: remove good and bad compress stats
zram: use atomic64_t for all zram stats
zram: remove zram stats code duplication
zram: report failed read and write stats
zram: drop not used table `count' member
zram: move zram size warning to documentation

 Documentation/blockdev/zram.txt |   5 ++
 drivers/block/zram/zram_drv.c   | 175 +++++++++++++---------------------------
 drivers/block/zram/zram_drv.h   |  10 +--
 3 files changed, 64 insertions(+), 126 deletions(-)
Signature · 1 line
1.8.5.3.493.gb139ac2
#1 lore raw

PATCH v3 1/8 zram: drop `init_done' struct zram member

Introduce init_done() helper function which allows us to drop `init_done' struct zram member. init_done() uses the fact that ->init_done == 1 equals to ->meta != NULL.

---
 drivers/block/zram/zram_drv.c | 21 +++++++++++----------
 drivers/block/zram/zram_drv.h |  1 -
 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/block/zram/zram_drv.c +11 -10
index 011e55d..c323e05 100644
@@ -42,6 +42,11 @@ static struct zram *zram_devices;
 /* Module params (documentation at end) */
 static unsigned int num_devices = 1;
 
+static inline int init_done(struct zram *zram)
+{
+	return zram->meta != NULL;
+}
+
 static inline struct zram *dev_to_zram(struct device *dev)
 {
 	return (struct zram *)dev_to_disk(dev)->private_data;
@@ -60,7 +65,7 @@ static ssize_t initstate_show(struct device *dev,
 {
 	struct zram *zram = dev_to_zram(dev);
 
-	return sprintf(buf, "%u\n", zram->init_done);
+	return sprintf(buf, "%u\n", init_done(zram));
 }
 
 static ssize_t num_reads_show(struct device *dev,
@@ -133,7 +138,7 @@ static ssize_t mem_used_total_show(struct device *dev,
 	struct zram_meta *meta = zram->meta;
 
 	down_read(&zram->init_lock);
-	if (zram->init_done)
+	if (init_done(zram))
 		val = zs_get_total_size_bytes(meta->mem_pool);
 	up_read(&zram->init_lock);
 
@@ -546,14 +551,12 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
 	struct zram_meta *meta;
 
 	down_write(&zram->init_lock);
-	if (!zram->init_done) {
+	if (!init_done(zram)) {
 		up_write(&zram->init_lock);
 		return;
 	}
 
 	meta = zram->meta;
-	zram->init_done = 0;
-
 	/* Free all pages that are still in this zram device */
 	for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) {
 		unsigned long handle = meta->table[index].handle;
@@ -594,8 +597,6 @@ static void zram_init_device(struct zram *zram, struct zram_meta *meta)
 	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
 
 	zram->meta = meta;
-	zram->init_done = 1;
-
 	pr_debug("Initialization done!\n");
 }
 
@@ -613,7 +614,7 @@ static ssize_t disksize_store(struct device *dev,
 	disksize = PAGE_ALIGN(disksize);
 	meta = zram_meta_alloc(disksize);
 	down_write(&zram->init_lock);
-	if (zram->init_done) {
+	if (init_done(zram)) {
 		up_write(&zram->init_lock);
 		zram_meta_free(meta);
 		pr_info("Cannot change disksize for initialized device\n");
@@ -734,7 +735,7 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
 	struct zram *zram = queue->queuedata;
 
 	down_read(&zram->init_lock);
-	if (unlikely(!zram->init_done))
+	if (unlikely(!init_done(zram)))
 		goto error;
 
 	if (!valid_io_request(zram, bio)) {
@@ -857,7 +858,7 @@ static int create_device(struct zram *zram, int device_id)
 		goto out_free_disk;
 	}
 
-	zram->init_done = 0;
+	zram->meta = NULL;
 	return 0;
 
 out_free_disk:
drivers/block/zram/zram_drv.h +0 -1
index ad8aa35..e81e9cd 100644
@@ -95,7 +95,6 @@ struct zram {
 	struct zram_meta *meta;
 	struct request_queue *queue;
 	struct gendisk *disk;
-	int init_done;
 	/* Prevent concurrent execution of device init, reset and R/W request */
 	struct rw_semaphore init_lock;
 	/*
Signature · 1 line
1.8.5.3.493.gb139ac2
#2 lore raw

PATCH v3 2/8 zram: do not pass rw argument to __zram_make_request()

In reply to Sergey Senozhatsky

Do not pass rw argument down the __zram_make_request() -> zram_bvec_rw() chain, decode it in zram_bvec_rw() instead. Besides, this is the place where we distinguish READ and WRITE bio data directions, so account zram RW stats here, instead of __zram_make_request(). This also allows to account a real number of zram READ/WRITE operations, not just requests (single RW request may cause a number of zram RW ops with separate locking, compression/decompression, etc).

v2: do not check for READA return code. noted by Jerome Marchand.

---
 drivers/block/zram/zram_drv.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/block/zram/zram_drv.c +12 -18
index c323e05..b0bcb7e 100644
@@ -533,14 +533,18 @@ out:
 }
 
 static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
-			int offset, struct bio *bio, int rw)
+			int offset, struct bio *bio)
 {
 	int ret;
+	int rw = bio_data_dir(bio);
 
-	if (rw == READ)
+	if (rw == READ) {
+		atomic64_inc(&zram->stats.num_reads);
 		ret = zram_bvec_read(zram, bvec, index, offset, bio);
-	else
+	} else {
+		atomic64_inc(&zram->stats.num_writes);
 		ret = zram_bvec_write(zram, bvec, index, offset);
+	}
 
 	return ret;
 }
@@ -670,22 +674,13 @@ out:
 	return ret;
 }
 
-static void __zram_make_request(struct zram *zram, struct bio *bio, int rw)
+static void __zram_make_request(struct zram *zram, struct bio *bio)
 {
 	int offset;
 	u32 index;
 	struct bio_vec bvec;
 	struct bvec_iter iter;
 
-	switch (rw) {
-	case READ:
-		atomic64_inc(&zram->stats.num_reads);
-		break;
-	case WRITE:
-		atomic64_inc(&zram->stats.num_writes);
-		break;
-	}
-
 	index = bio->bi_iter.bi_sector >> SECTORS_PER_PAGE_SHIFT;
 	offset = (bio->bi_iter.bi_sector &
 		  (SECTORS_PER_PAGE - 1)) << SECTOR_SHIFT;
@@ -704,16 +699,15 @@ static void __zram_make_request(struct zram *zram, struct bio *bio, int rw)
 			bv.bv_len = max_transfer_size;
 			bv.bv_offset = bvec.bv_offset;
 
-			if (zram_bvec_rw(zram, &bv, index, offset, bio, rw) < 0)
+			if (zram_bvec_rw(zram, &bv, index, offset, bio) < 0)
 				goto out;
 
 			bv.bv_len = bvec.bv_len - max_transfer_size;
 			bv.bv_offset += max_transfer_size;
-			if (zram_bvec_rw(zram, &bv, index+1, 0, bio, rw) < 0)
+			if (zram_bvec_rw(zram, &bv, index + 1, 0, bio) < 0)
 				goto out;
 		} else
-			if (zram_bvec_rw(zram, &bvec, index, offset, bio, rw)
-			    < 0)
+			if (zram_bvec_rw(zram, &bvec, index, offset, bio) < 0)
 				goto out;
 
 		update_position(&index, &offset, &bvec);
@@ -743,7 +737,7 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
 		goto error;
 	}
 
-	__zram_make_request(zram, bio, bio_data_dir(bio));
+	__zram_make_request(zram, bio);
 	up_read(&zram->init_lock);
 
 	return;
Signature · 1 line
1.8.5.3.493.gb139ac2
#3 lore raw

PATCH v3 3/8 zram: remove good and bad compress stats

In reply to Sergey Senozhatsky

Remove good' and bad' compressed sub-requests stats. RW request may cause a number of RW sub-requests. zram used to account good' compressed sub-queries (with compressed size less than 50% of original size), bad' compressed sub-queries (with compressed size greater that 75% of original size), leaving sub-requests with compression size between 50% and 75% of original size not accounted and not reported. zram already accounts each sub-request's compression size so we can calculate real device compression ratio.

---
 drivers/block/zram/zram_drv.c | 11 -----------
 drivers/block/zram/zram_drv.h |  2 --
 2 files changed, 13 deletions(-)
drivers/block/zram/zram_drv.c +0 -11
index b0bcb7e..c7c7789 100644
@@ -293,7 +293,6 @@ static void zram_free_page(struct zram *zram, size_t index)
 {
 	struct zram_meta *meta = zram->meta;
 	unsigned long handle = meta->table[index].handle;
-	u16 size = meta->table[index].size;
 
 	if (unlikely(!handle)) {
 		/*
@@ -307,14 +306,8 @@ static void zram_free_page(struct zram *zram, size_t index)
 		return;
 	}
 
-	if (unlikely(size > max_zpage_size))
-		atomic_dec(&zram->stats.bad_compress);
-
 	zs_free(meta->mem_pool, handle);
 
-	if (size <= PAGE_SIZE / 2)
-		atomic_dec(&zram->stats.good_compress);
-
 	atomic64_sub(meta->table[index].size, &zram->stats.compr_size);
 	atomic_dec(&zram->stats.pages_stored);
 
@@ -478,7 +471,6 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 	}
 
 	if (unlikely(clen > max_zpage_size)) {
-		atomic_inc(&zram->stats.bad_compress);
 		clen = PAGE_SIZE;
 		src = NULL;
 		if (is_partial_io(bvec))
@@ -518,9 +510,6 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 	/* Update stats */
 	atomic64_add(clen, &zram->stats.compr_size);
 	atomic_inc(&zram->stats.pages_stored);
-	if (clen <= PAGE_SIZE / 2)
-		atomic_inc(&zram->stats.good_compress);
-
 out:
 	if (locked)
 		mutex_unlock(&meta->buffer_lock);
drivers/block/zram/zram_drv.h +0 -2
index e81e9cd..2f173cb 100644
@@ -78,8 +78,6 @@ struct zram_stats {
 	atomic64_t notify_free;	/* no. of swap slot free notifications */
 	atomic_t pages_zero;		/* no. of zero filled pages */
 	atomic_t pages_stored;	/* no. of pages currently stored */
-	atomic_t good_compress;	/* % of pages with compression ratio<=50% */
-	atomic_t bad_compress;	/* % of pages with compression ratio>=75% */
 };
 
 struct zram_meta {
Signature · 1 line
1.8.5.3.493.gb139ac2
Acked-by on v3 3/8
#4 lore raw

Re: [PATCHv3 3/8] zram: remove good and bad compress stats

Quoted 10 lines · Sergey Senozhatsky

Remove good' and bad' compressed sub-requests stats. RW request may cause a number of RW sub-requests. zram used to account good' compressed sub-queries (with compressed size less than 50% of original size), bad' compressed sub-queries (with compressed size greater that 75% of original size), leaving sub-requests with compression size between 50% and 75% of original size not accounted and not reported. zram already accounts each sub-request's compression size so we can calculate real device compression ratio.

Quoted 64 lines
---
 drivers/block/zram/zram_drv.c | 11 -----------
 drivers/block/zram/zram_drv.h |  2 --
 2 files changed, 13 deletions(-)
drivers/block/zram/zram_drv.c +0 -11
index b0bcb7e..c7c7789 100644
@@ -293,7 +293,6 @@ static void zram_free_page(struct zram *zram, size_t index)
 {
 	struct zram_meta *meta = zram->meta;
 	unsigned long handle = meta->table[index].handle;
-	u16 size = meta->table[index].size;
 
 	if (unlikely(!handle)) {
 		/*
@@ -307,14 +306,8 @@ static void zram_free_page(struct zram *zram, size_t index)
 		return;
 	}
 
-	if (unlikely(size > max_zpage_size))
-		atomic_dec(&zram->stats.bad_compress);
-
 	zs_free(meta->mem_pool, handle);
 
-	if (size <= PAGE_SIZE / 2)
-		atomic_dec(&zram->stats.good_compress);
-
 	atomic64_sub(meta->table[index].size, &zram->stats.compr_size);
 	atomic_dec(&zram->stats.pages_stored);
 
@@ -478,7 +471,6 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 	}
 
 	if (unlikely(clen > max_zpage_size)) {
-		atomic_inc(&zram->stats.bad_compress);
 		clen = PAGE_SIZE;
 		src = NULL;
 		if (is_partial_io(bvec))
@@ -518,9 +510,6 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 	/* Update stats */
 	atomic64_add(clen, &zram->stats.compr_size);
 	atomic_inc(&zram->stats.pages_stored);
-	if (clen <= PAGE_SIZE / 2)
-		atomic_inc(&zram->stats.good_compress);
-
 out:
 	if (locked)
 		mutex_unlock(&meta->buffer_lock);
drivers/block/zram/zram_drv.h +0 -2
index e81e9cd..2f173cb 100644
@@ -78,8 +78,6 @@ struct zram_stats {
 	atomic64_t notify_free;	/* no. of swap slot free notifications */
 	atomic_t pages_zero;		/* no. of zero filled pages */
 	atomic_t pages_stored;	/* no. of pages currently stored */
-	atomic_t good_compress;	/* % of pages with compression ratio<=50% */
-	atomic_t bad_compress;	/* % of pages with compression ratio>=75% */
 };
 
 struct zram_meta {
maintainer Acked-by on v3 3/8
#5 lore raw

Re: [PATCHv3 3/8] zram: remove good and bad compress stats

In reply to Sergey Senozhatsky
Quoted 9 lines · Sergey Senozhatsky

Remove good' and bad' compressed sub-requests stats. RW request may cause a number of RW sub-requests. zram used to account good' compressed sub-queries (with compressed size less than 50% of original size), bad' compressed sub-queries (with compressed size greater that 75% of original size), leaving sub-requests with compression size between 50% and 75% of original size not accounted and not reported. zram already accounts each sub-request's compression size so we can calculate real device compression ratio.

Most important thing is that we have accounted them but have not used so it doesn't break anything and we could add them again if someone need them later. :)

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

PATCH v3 4/8 zram: use atomic64_t for all zram stats

In reply to Sergey Senozhatsky

This is a preparation patch for stats code duplication removal.

1) use atomic64_t for pages_zero' and pages_stored' zram stats.
2) compr_size' and pages_zero' struct zram_stats members did not follow the existing device attr naming scheme: zram_stats.ATTR has ATTR_show() function. rename them:
-- compr_size -> compr_data_size
-- pages_zero -> zero_pages

Minchan Kim's note:
If we really have trouble with atomic stat operation, we could change it with percpu_counter so that it could solve atomic overhead and unnecessary memory space by introducing unsigned long instead of 64bit atomic_t.

---
 drivers/block/zram/zram_drv.c | 18 +++++++++---------
 drivers/block/zram/zram_drv.h |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/block/zram/zram_drv.c +9 -9
index c7c7789..0035d39 100644
@@ -109,7 +109,7 @@ static ssize_t zero_pages_show(struct device *dev,
 {
 	struct zram *zram = dev_to_zram(dev);
 
-	return sprintf(buf, "%u\n", atomic_read(&zram->stats.pages_zero));
+	return sprintf(buf, "%llu\n", (u64)atomic64_read(&zram->stats.zero_pages));
 }
 
 static ssize_t orig_data_size_show(struct device *dev,
@@ -118,7 +118,7 @@ static ssize_t orig_data_size_show(struct device *dev,
 	struct zram *zram = dev_to_zram(dev);
 
 	return sprintf(buf, "%llu\n",
-		(u64)(atomic_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
+		(u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
 }
 
 static ssize_t compr_data_size_show(struct device *dev,
@@ -127,7 +127,7 @@ static ssize_t compr_data_size_show(struct device *dev,
 	struct zram *zram = dev_to_zram(dev);
 
 	return sprintf(buf, "%llu\n",
-			(u64)atomic64_read(&zram->stats.compr_size));
+			(u64)atomic64_read(&zram->stats.compr_data_size));
 }
 
 static ssize_t mem_used_total_show(struct device *dev,
@@ -301,15 +301,15 @@ static void zram_free_page(struct zram *zram, size_t index)
 		 */
 		if (zram_test_flag(meta, index, ZRAM_ZERO)) {
 			zram_clear_flag(meta, index, ZRAM_ZERO);
-			atomic_dec(&zram->stats.pages_zero);
+			atomic64_dec(&zram->stats.zero_pages);
 		}
 		return;
 	}
 
 	zs_free(meta->mem_pool, handle);
 
-	atomic64_sub(meta->table[index].size, &zram->stats.compr_size);
-	atomic_dec(&zram->stats.pages_stored);
+	atomic64_sub(meta->table[index].size, &zram->stats.compr_data_size);
+	atomic64_dec(&zram->stats.pages_stored);
 
 	meta->table[index].handle = 0;
 	meta->table[index].size = 0;
@@ -452,7 +452,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 		zram_set_flag(meta, index, ZRAM_ZERO);
 		write_unlock(&zram->meta->tb_lock);
 
-		atomic_inc(&zram->stats.pages_zero);
+		atomic64_inc(&zram->stats.zero_pages);
 		ret = 0;
 		goto out;
 	}
@@ -508,8 +508,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 	write_unlock(&zram->meta->tb_lock);
 
 	/* Update stats */
-	atomic64_add(clen, &zram->stats.compr_size);
-	atomic_inc(&zram->stats.pages_stored);
+	atomic64_add(clen, &zram->stats.compr_data_size);
+	atomic64_inc(&zram->stats.pages_stored);
 out:
 	if (locked)
 		mutex_unlock(&meta->buffer_lock);
drivers/block/zram/zram_drv.h +3 -3
index 2f173cb..58d4ac5 100644
@@ -69,15 +69,15 @@ struct table {
 } __aligned(4);
 
 struct zram_stats {
-	atomic64_t compr_size;	/* compressed size of pages stored */
+	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_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 */
-	atomic_t pages_zero;		/* no. of zero filled pages */
-	atomic_t pages_stored;	/* no. of pages currently stored */
+	atomic64_t zero_pages;		/* no. of zero filled pages */
+	atomic64_t pages_stored;	/* no. of pages currently stored */
 };
 
 struct zram_meta {
Signature · 1 line
1.8.5.3.493.gb139ac2
Acked-by on v3 4/8
#7 lore raw

Re: [PATCHv3 4/8] zram: use atomic64_t for all zram stats

Quoted 9 lines · Sergey Senozhatsky

This is a preparation patch for stats code duplication removal.

1) use atomic64_t for pages_zero' and pages_stored' zram stats.
2) compr_size' and pages_zero' struct zram_stats members did not follow the existing device attr naming scheme: zram_stats.ATTR has ATTR_show() function. rename them:
-- compr_size -> compr_data_size
-- pages_zero -> zero_pages

Quoted 7 lines

Minchan Kim's note:
If we really have trouble with atomic stat operation, we could change it with percpu_counter so that it could solve atomic overhead and unnecessary memory space by introducing unsigned long instead of 64bit atomic_t.

Quoted 99 lines
---
 drivers/block/zram/zram_drv.c | 18 +++++++++---------
 drivers/block/zram/zram_drv.h |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/block/zram/zram_drv.c +9 -9
index c7c7789..0035d39 100644
@@ -109,7 +109,7 @@ static ssize_t zero_pages_show(struct device *dev,
 {
 	struct zram *zram = dev_to_zram(dev);
 
-	return sprintf(buf, "%u\n", atomic_read(&zram->stats.pages_zero));
+	return sprintf(buf, "%llu\n", (u64)atomic64_read(&zram->stats.zero_pages));
 }
 
 static ssize_t orig_data_size_show(struct device *dev,
@@ -118,7 +118,7 @@ static ssize_t orig_data_size_show(struct device *dev,
 	struct zram *zram = dev_to_zram(dev);
 
 	return sprintf(buf, "%llu\n",
-		(u64)(atomic_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
+		(u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
 }
 
 static ssize_t compr_data_size_show(struct device *dev,
@@ -127,7 +127,7 @@ static ssize_t compr_data_size_show(struct device *dev,
 	struct zram *zram = dev_to_zram(dev);
 
 	return sprintf(buf, "%llu\n",
-			(u64)atomic64_read(&zram->stats.compr_size));
+			(u64)atomic64_read(&zram->stats.compr_data_size));
 }
 
 static ssize_t mem_used_total_show(struct device *dev,
@@ -301,15 +301,15 @@ static void zram_free_page(struct zram *zram, size_t index)
 		 */
 		if (zram_test_flag(meta, index, ZRAM_ZERO)) {
 			zram_clear_flag(meta, index, ZRAM_ZERO);
-			atomic_dec(&zram->stats.pages_zero);
+			atomic64_dec(&zram->stats.zero_pages);
 		}
 		return;
 	}
 
 	zs_free(meta->mem_pool, handle);
 
-	atomic64_sub(meta->table[index].size, &zram->stats.compr_size);
-	atomic_dec(&zram->stats.pages_stored);
+	atomic64_sub(meta->table[index].size, &zram->stats.compr_data_size);
+	atomic64_dec(&zram->stats.pages_stored);
 
 	meta->table[index].handle = 0;
 	meta->table[index].size = 0;
@@ -452,7 +452,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 		zram_set_flag(meta, index, ZRAM_ZERO);
 		write_unlock(&zram->meta->tb_lock);
 
-		atomic_inc(&zram->stats.pages_zero);
+		atomic64_inc(&zram->stats.zero_pages);
 		ret = 0;
 		goto out;
 	}
@@ -508,8 +508,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 	write_unlock(&zram->meta->tb_lock);
 
 	/* Update stats */
-	atomic64_add(clen, &zram->stats.compr_size);
-	atomic_inc(&zram->stats.pages_stored);
+	atomic64_add(clen, &zram->stats.compr_data_size);
+	atomic64_inc(&zram->stats.pages_stored);
 out:
 	if (locked)
 		mutex_unlock(&meta->buffer_lock);
drivers/block/zram/zram_drv.h +3 -3
index 2f173cb..58d4ac5 100644
@@ -69,15 +69,15 @@ struct table {
 } __aligned(4);
 
 struct zram_stats {
-	atomic64_t compr_size;	/* compressed size of pages stored */
+	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_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 */
-	atomic_t pages_zero;		/* no. of zero filled pages */
-	atomic_t pages_stored;	/* no. of pages currently stored */
+	atomic64_t zero_pages;		/* no. of zero filled pages */
+	atomic64_t pages_stored;	/* no. of pages currently stored */
 };
 
 struct zram_meta {
maintainer Acked-by on v3 4/8
#8 lore raw

Re: [PATCHv3 4/8] zram: use atomic64_t for all zram stats

In reply to Sergey Senozhatsky
Quoted 9 lines · Sergey Senozhatsky

This is a preparation patch for stats code duplication removal.

1) use atomic64_t for pages_zero' and pages_stored' zram stats.
2) compr_size' and pages_zero' struct zram_stats members did not follow the existing device attr naming scheme: zram_stats.ATTR has ATTR_show() function. rename them:
-- compr_size -> compr_data_size
-- pages_zero -> zero_pages

Quoted 7 lines

Minchan Kim's note:
If we really have trouble with atomic stat operation, we could change it with percpu_counter so that it could solve atomic overhead and unnecessary memory space by introducing unsigned long instead of 64bit atomic_t.

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

PATCH v3 5/8 zram: remove zram stats code duplication

In reply to Sergey Senozhatsky

Introduce ZRAM_ATTR_RO macro that generates device_attribute and default ATTR show() function for existing atomic64_t zram stats.

---
 drivers/block/zram/zram_drv.c | 82 ++++++++++++-------------------------------
 1 file changed, 23 insertions(+), 59 deletions(-)
drivers/block/zram/zram_drv.c +23 -59
index 0035d39..e7102f1 100644
@@ -42,6 +42,17 @@ static struct zram *zram_devices;
 /* Module params (documentation at end) */
 static unsigned int num_devices = 1;
 
+#define ZRAM_ATTR_RO(name)						\
+static ssize_t zram_attr_##name##_show(struct device *d,		\
+				struct device_attribute *attr, char *b)	\
+{									\
+	struct zram *zram = dev_to_zram(d);				\
+	return sprintf(b, "%llu\n",					\
+		(u64)atomic64_read(&zram->stats.name));			\
+}									\
+static struct device_attribute dev_attr_##name =			\
+	__ATTR(name, S_IRUGO, zram_attr_##name##_show, NULL);
+
 static inline int init_done(struct zram *zram)
 {
 	return zram->meta != NULL;
@@ -63,53 +74,14 @@ static ssize_t disksize_show(struct device *dev,
 static ssize_t initstate_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
+	u32 val;
 	struct zram *zram = dev_to_zram(dev);
 
-	return sprintf(buf, "%u\n", init_done(zram));
-}
-
-static ssize_t num_reads_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
-{
-	struct zram *zram = dev_to_zram(dev);
-
-	return sprintf(buf, "%llu\n",
-			(u64)atomic64_read(&zram->stats.num_reads));
-}
-
-static ssize_t num_writes_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
-{
-	struct zram *zram = dev_to_zram(dev);
-
-	return sprintf(buf, "%llu\n",
-			(u64)atomic64_read(&zram->stats.num_writes));
-}
-
-static ssize_t invalid_io_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
-{
-	struct zram *zram = dev_to_zram(dev);
-
-	return sprintf(buf, "%llu\n",
-			(u64)atomic64_read(&zram->stats.invalid_io));
-}
-
-static ssize_t notify_free_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
-{
-	struct zram *zram = dev_to_zram(dev);
-
-	return sprintf(buf, "%llu\n",
-			(u64)atomic64_read(&zram->stats.notify_free));
-}
-
-static ssize_t zero_pages_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
-{
-	struct zram *zram = dev_to_zram(dev);
+	down_read(&zram->init_lock);
+	val = init_done(zram);
+	up_read(&zram->init_lock);
 
-	return sprintf(buf, "%llu\n", (u64)atomic64_read(&zram->stats.zero_pages));
+	return sprintf(buf, "%u\n", val);
 }
 
 static ssize_t orig_data_size_show(struct device *dev,
@@ -121,15 +93,6 @@ static ssize_t orig_data_size_show(struct device *dev,
 		(u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
 }
 
-static ssize_t compr_data_size_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
-{
-	struct zram *zram = dev_to_zram(dev);
-
-	return sprintf(buf, "%llu\n",
-			(u64)atomic64_read(&zram->stats.compr_data_size));
-}
-
 static ssize_t mem_used_total_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
@@ -760,15 +723,16 @@ static DEVICE_ATTR(disksize, S_IRUGO | S_IWUSR,
 		disksize_show, disksize_store);
 static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
 static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
-static DEVICE_ATTR(num_reads, S_IRUGO, num_reads_show, NULL);
-static DEVICE_ATTR(num_writes, S_IRUGO, num_writes_show, NULL);
-static DEVICE_ATTR(invalid_io, S_IRUGO, invalid_io_show, NULL);
-static DEVICE_ATTR(notify_free, S_IRUGO, notify_free_show, NULL);
-static DEVICE_ATTR(zero_pages, S_IRUGO, zero_pages_show, NULL);
 static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL);
-static DEVICE_ATTR(compr_data_size, S_IRUGO, compr_data_size_show, NULL);
 static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
 
+ZRAM_ATTR_RO(num_reads);
+ZRAM_ATTR_RO(num_writes);
+ZRAM_ATTR_RO(invalid_io);
+ZRAM_ATTR_RO(notify_free);
+ZRAM_ATTR_RO(zero_pages);
+ZRAM_ATTR_RO(compr_data_size);
+
 static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_disksize.attr,
 	&dev_attr_initstate.attr,
Signature · 1 line
1.8.5.3.493.gb139ac2
#11 lore raw

PATCH v3 6/8 zram: report failed read and write stats

In reply to Sergey Senozhatsky

zram accounted but did not report numbers of failed read and write queries. make these stats available as failed_reads and failed_writes attrs.

---
 drivers/block/zram/zram_drv.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/zram/zram_drv.c +4 -0
index e7102f1..9d67fbf 100644
@@ -728,6 +728,8 @@ static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
 
 ZRAM_ATTR_RO(num_reads);
 ZRAM_ATTR_RO(num_writes);
+ZRAM_ATTR_RO(failed_reads);
+ZRAM_ATTR_RO(failed_writes);
 ZRAM_ATTR_RO(invalid_io);
 ZRAM_ATTR_RO(notify_free);
 ZRAM_ATTR_RO(zero_pages);
@@ -739,6 +741,8 @@ static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_reset.attr,
 	&dev_attr_num_reads.attr,
 	&dev_attr_num_writes.attr,
+	&dev_attr_failed_reads.attr,
+	&dev_attr_failed_writes.attr,
 	&dev_attr_invalid_io.attr,
 	&dev_attr_notify_free.attr,
 	&dev_attr_zero_pages.attr,
Signature · 1 line
1.8.5.3.493.gb139ac2
#12 lore raw

Re: [PATCHv3 6/8] zram: report failed read and write stats

Quoted 25 lines · On Thu, 16 Jan 2014 16:12:14 +0300 Sergey Senozhatsky…

zram accounted but did not report numbers of failed read and write queries. make these stats available as failed_reads and failed_writes attrs.

---
 drivers/block/zram/zram_drv.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/zram/zram_drv.c +2 -0
index e7102f1..9d67fbf 100644
@@ -728,6 +728,8 @@ static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
 
 ZRAM_ATTR_RO(num_reads);
 ZRAM_ATTR_RO(num_writes);
+ZRAM_ATTR_RO(failed_reads);
+ZRAM_ATTR_RO(failed_writes);
 ZRAM_ATTR_RO(invalid_io);
 ZRAM_ATTR_RO(notify_free);
 ZRAM_ATTR_RO(zero_pages);

drivers/block/zram/zram_drv.c static struct attribute *zram_disk_attrs[] = { · line 748

Quoted 8 lines
drivers/block/zram/zram_drv.c +2 -0
@@ -739,6 +741,8 @@ static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_reset.attr,
 	&dev_attr_num_reads.attr,
 	&dev_attr_num_writes.attr,
+	&dev_attr_failed_reads.attr,
+	&dev_attr_failed_writes.attr,
 	&dev_attr_invalid_io.attr,
 	&dev_attr_notify_free.attr,
 	&dev_attr_zero_pages.attr,

Documentation/blockdev/zram.txt and Documentation/ABI/testing/sysfs-block-zram need updating...

#13 lore raw

Re: [PATCHv3 6/8] zram: report failed read and write stats

Quoted 39 lines · Andrew Morton

Date: Tue, 4 Feb 2014 14:18:49 -0800
From: Andrew Morton <[email protected]>
To: Sergey Senozhatsky <[email protected]>
Cc: Minchan Kim <[email protected]>, Jerome Marchand
<[email protected]>, Nitin Gupta <[email protected]>, [email protected]
Subject: Re: [PATCHv3 6/8] zram: report failed read and write stats
X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.10; x86_64-pc-linux-gnu)

Quoted 28 lines · On Thu, 16 Jan 2014 16:12:14 +0300 Sergey Senozhatsky…

zram accounted but did not report numbers of failed read and write queries. make these stats available as failed_reads and failed_writes attrs.

---
 drivers/block/zram/zram_drv.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/zram/zram_drv.c +2 -0
index e7102f1..9d67fbf 100644
@@ -728,6 +728,8 @@ static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
 
 ZRAM_ATTR_RO(num_reads);
 ZRAM_ATTR_RO(num_writes);
+ZRAM_ATTR_RO(failed_reads);
+ZRAM_ATTR_RO(failed_writes);
 ZRAM_ATTR_RO(invalid_io);
 ZRAM_ATTR_RO(notify_free);
 ZRAM_ATTR_RO(zero_pages);
@@ -739,6 +741,8 @@ static struct attribute *zram_disk_attrs[] = {
 	&dev_attr_reset.attr,
 	&dev_attr_num_reads.attr,
 	&dev_attr_num_writes.attr,
Quoted 9 lines

drivers/block/zram/zram_drv.c static struct attribute *zram_disk_attrs[] = { · line 748

Quoted 5 lines
drivers/block/zram/zram_drv.c +2 -0
+	&dev_attr_failed_reads.attr,
+	&dev_attr_failed_writes.attr,
 	&dev_attr_invalid_io.attr,
 	&dev_attr_notify_free.attr,
 	&dev_attr_zero_pages.attr,

Documentation/blockdev/zram.txt and Documentation/ABI/testing/sysfs-block-zram need updating...

Hello,
sure, will update.

	-ss
#14 lore raw

PATCH v3 7/8 zram: drop not used table `count' member

In reply to Sergey Senozhatsky

struct table `count' member is not used.

---
 drivers/block/zram/zram_drv.h | 1 -
 1 file changed, 1 deletion(-)
drivers/block/zram/zram_drv.h +0 -1
index 58d4ac5..1d5b1f5 100644
@@ -64,7 +64,6 @@ enum zram_pageflags {
 struct table {
 	unsigned long handle;
 	u16 size;	/* object size (excluding header) */
-	u8 count;	/* object ref count (not yet used) */
 	u8 flags;
 } __aligned(4);
 
Signature · 1 line
1.8.5.3.493.gb139ac2
#15 lore raw

Re: [PATCHv3 7/8] zram: drop not used table `count' member

Quoted 1 line · Sergey Senozhatsky

struct table `count' member is not used.

What was the intended use of this counter anyway?

Quoted 11 lines
---
 drivers/block/zram/zram_drv.h | 1 -
 1 file changed, 1 deletion(-)
drivers/block/zram/zram_drv.h +0 -0
index 58d4ac5..1d5b1f5 100644

drivers/block/zram/zram_drv.h enum zram_pageflags { · line 67

Quoted 5 lines
drivers/block/zram/zram_drv.h +0 -1
@@ -64,7 +64,6 @@ enum zram_pageflags {
 struct table {
 	unsigned long handle;
 	u16 size;	/* object size (excluding header) */
-	u8 count;	/* object ref count (not yet used) */
 	u8 flags;

I noticed that your earlier version of this patch changed the flags size to 16. What has changed?

Jerome

Quoted 3 lines
drivers/block/zram/zram_drv.h +0 -0
 } __aligned(4);
 
#16 lore raw

Re: [PATCHv3 7/8] zram: drop not used table `count' member

Quoted 11 lines · Jerome Marchand
Quoted 1 line · Sergey Senozhatsky

struct table `count' member is not used.

What was the intended use of this counter anyway?

Quoted 6 lines
---
 drivers/block/zram/zram_drv.h | 1 -
 1 file changed, 1 deletion(-)
Quoted 16 lines

drivers/block/zram/zram_drv.h enum zram_pageflags { · line 67

Quoted 10 lines
drivers/block/zram/zram_drv.h +0 -1
index 58d4ac5..1d5b1f5 100644
@@ -64,7 +64,6 @@ enum zram_pageflags {
 struct table {
 	unsigned long handle;
 	u16 size;	/* object size (excluding header) */
-	u8 count;	/* object ref count (not yet used) */
 	u8 flags;

I noticed that your earlier version of this patch changed the flags size to 16. What has changed?

nothing really. I was going to extend flags, but changed my plans. so it was a leftover.

	-ss
Quoted 6 lines

Jerome

Quoted 3 lines
drivers/block/zram/zram_drv.h +0 -0
 } __aligned(4);
 
maintainer Acked-by on v3 7/8
#17 lore raw

Re: [PATCHv3 7/8] zram: drop not used table `count' member

In reply to Sergey Senozhatsky
Quoted 3 lines · Sergey Senozhatsky

struct table `count' member is not used.

There is no gain with this patch in memory space ponit of view but it might reveal the lurking bug.

Quoted 24 lines
---
 drivers/block/zram/zram_drv.h | 1 -
 1 file changed, 1 deletion(-)
drivers/block/zram/zram_drv.h +0 -1
index 58d4ac5..1d5b1f5 100644
@@ -64,7 +64,6 @@ enum zram_pageflags {
 struct table {
 	unsigned long handle;
 	u16 size;	/* object size (excluding header) */
-	u8 count;	/* object ref count (not yet used) */
 	u8 flags;
 } __aligned(4);
 
Signature · 7 lines
1.8.5.3.493.gb139ac2

--
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
#18 lore raw

PATCH v3 8/8 zram: move zram size warning to documentation

In reply to Sergey Senozhatsky

Move zram warning about disksize and size of memory correlation to zram documentation.

---
 Documentation/blockdev/zram.txt |  5 +++++
 drivers/block/zram/zram_drv.c   | 15 ---------------
 2 files changed, 5 insertions(+), 15 deletions(-)
Documentation/blockdev/zram.txt +5 -0
index 2eccddf..393541be 100644
@@ -33,6 +33,11 @@ Following shows a typical sequence of steps for using zram.
             echo 512M > /sys/block/zram0/disksize
             echo 1G > /sys/block/zram0/disksize
 
+Note:
+There is little point creating a zram of greater than twice the size of memory
+since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the
+size of the disk when not in use so a huge zram is wasteful.
+
 3) Activate:
 	mkswap /dev/zram0
 	swapon /dev/zram0
drivers/block/zram/zram_drv.c +0 -15
index 9d67fbf..5ec61be 100644
@@ -535,23 +535,8 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
 
 static void zram_init_device(struct zram *zram, struct zram_meta *meta)
 {
-	if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) {
-		pr_info(
-		"There is little point creating a zram of greater than "
-		"twice the size of memory since we expect a 2:1 compression "
-		"ratio. Note that zram uses about 0.1%% of the size of "
-		"the disk when not in use so a huge zram is "
-		"wasteful.\n"
-		"\tMemory Size: %lu kB\n"
-		"\tSize you selected: %llu kB\n"
-		"Continuing anyway ...\n",
-		(totalram_pages << PAGE_SHIFT) >> 10, zram->disksize >> 10
-		);
-	}
-
 	/* zram devices sort of resembles non-rotational disks */
 	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
-
 	zram->meta = meta;
 	pr_debug("Initialization done!\n");
 }
Signature · 1 line
1.8.5.3.493.gb139ac2
maintainer
#20 lore raw
In reply to Sergey Senozhatsky
Quoted 12 lines · Sergey Senozhatsky

This patchset includes zram stats clean up and enhancements.

Sergey Senozhatsky (8):
zram: drop `init_done' struct zram member
zram: do not pass rw argument to __zram_make_request()
zram: remove good and bad compress stats
zram: use atomic64_t for all zram stats
zram: remove zram stats code duplication
zram: report failed read and write stats
zram: drop not used table `count' member
zram: move zram size warning to documentation

Quoted 4 lines
 Documentation/blockdev/zram.txt |   5 ++
 drivers/block/zram/zram_drv.c   | 175 +++++++++++++---------------------------
 drivers/block/zram/zram_drv.h   |  10 +--
 3 files changed, 64 insertions(+), 126 deletions(-)

Great clean up.

Sergey, Thanks!
I am looking forward to your next step!

Signature · 2 lines
Kind regards,
Minchan Kim
maintainer
#21 lore raw
Quoted 18 lines · Minchan Kim
Quoted 12 lines · Sergey Senozhatsky

This patchset includes zram stats clean up and enhancements.

Sergey Senozhatsky (8):
zram: drop `init_done' struct zram member
zram: do not pass rw argument to __zram_make_request()
zram: remove good and bad compress stats
zram: use atomic64_t for all zram stats
zram: remove zram stats code duplication
zram: report failed read and write stats
zram: drop not used table `count' member
zram: move zram size warning to documentation

Quoted 4 lines
 Documentation/blockdev/zram.txt |   5 ++
 drivers/block/zram/zram_drv.c   | 175 +++++++++++++---------------------------
 drivers/block/zram/zram_drv.h   |  10 +--
 3 files changed, 64 insertions(+), 126 deletions(-)
Quoted 4 lines

Great clean up.

Sergey, Thanks!
I am looking forward to your next step!

Hello Sergey,

I guess Andrew wouldn't pick this patchset until closing merge window so I picked up in my zram tree so let's do further work based on it.

https://git.kernel.org/cgit/linux/kernel/git/minchan/linux.git/log/?h=zram-next

Thanks.

Signature · 2 lines
Kind regards,
Minchan Kim