f2fs: add sysfs nodes to get runtime compression stat
PATCH v4 1/1 f2fs: add sysfs nodes to get runtime compression stat
From: Daeho Jeong <[email protected]>
I've added new sysfs nodes to show runtime compression stat since mount. compr_written_block - show the block count written after compression compr_saved_block - show the saved block count with compression compr_new_inode - show the count of inode newly enabled for compression
---
v2: thanks to kernel test robot <[email protected]>, fixed compile issue
related to kernel config
v3: changed sysfs nodes' names and made them runtime stat, not
persistent on disk
v4: changed sysfs nodes' desctiption
--- Documentation/ABI/testing/sysfs-fs-f2fs | 24 ++++++++++ fs/f2fs/compress.c | 1 + fs/f2fs/f2fs.h | 19 ++++++++ fs/f2fs/super.c | 7 +++ fs/f2fs/sysfs.c | 58 +++++++++++++++++++++++++ 5 files changed, 109 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +24 -0
@@ -409,3 +409,27 @@ Description: Give a way to change checkpoint merge daemon's io priority. I/O priority "3". We can select the class between "rt" and "be", and set the I/O priority within valid range of it. "," delimiter is necessary in between I/O class and priority number. + +What: /sys/fs/f2fs/<disk>/compr_written_block +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the block count written after compression since mount. Note + that when the compressed blocks are deleted, this count doesn't + decrease. If you write "0" here, you can initialize + compr_written_block and compr_saved_block to "0". + +What: /sys/fs/f2fs/<disk>/compr_saved_block +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the saved block count with compression since mount. Note + that when the compressed blocks are deleted, this count doesn't + decrease. If you write "0" here, you can initialize + compr_written_block and compr_saved_block to "0". + +What: /sys/fs/f2fs/<disk>/compr_new_inode +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the count of inode newly enabled for compression since mount. + Note that when the compression is disabled for the files, this count + doesn't decrease. If you write "0" here, you can initialize + compr_new_inode to "0".
fs/f2fs/compress.c +1 -0
@@ -1353,6 +1353,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,if (fio.compr_blocks)f2fs_i_compr_blocks_update (inode, fio.compr_blocks -1 , false);f2fs_i_compr_blocks_update (inode, cc->nr_cpages, true); +add_compr_block_stat (inode, cc->nr_cpages);set_inode_flag (cc->inode,FI_APPEND_WRITE );if (cc->cluster_idx ==0 )
fs/f2fs/f2fs.h +19 -0
@@ -1623,6 +1623,11 @@ struct f2fs_sb_info {#ifdef CONFIG_F2FS_FS_COMPRESSION struct kmem_cache *page_array_slab;/* page array entry */ unsigned int page_array_slab_size;/* default page array slab size */ + +/* For runtime compression statistics */ +atomic64_t compr_written_block; +atomic64_t compr_saved_block; +atomic_t compr_new_inode;#endif };
@@ -3955,6 +3960,18 @@ int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi);void f2fs_destroy_page_array_cache (struct f2fs_sb_info *sbi);int __init f2fs_init_compress_cache (void );void f2fs_destroy_compress_cache (void ); +#define inc_compr_inode_stat (inode) \ + do { \ + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ + atomic_inc(&sbi->compr_new_inode); \ + } while (0) +#define add_compr_block_stat (inode, blocks) \ + do { \ + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ + int diff = F2FS_I(inode)->i_cluster_size - blocks; \ + atomic64_add(blocks, &sbi->compr_written_block); \ + atomic64_add(diff, &sbi->compr_saved_block); \ + } while (0)#else static inline bool f2fs_is_compressed_page (struct page *page) {return false; }static inline bool f2fs_is_compress_backend_ready (struct inode *inode)
@@ -3983,6 +4000,7 @@ static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { returnstatic inline void f2fs_destroy_page_array_cache (struct f2fs_sb_info *sbi) { }static inline int __init f2fs_init_compress_cache (void ) {return 0 ; }static inline void f2fs_destroy_compress_cache (void ) { } +#define inc_compr_inode_stat (inode) do { } while (0)#endif static inline void set_compress_context (struct inode *inode)
@@ -4006,6 +4024,7 @@ static inline void set_compress_context(struct inode *inode)F2FS_I (inode)->i_flags |=F2FS_COMPR_FL ;set_inode_flag (inode,FI_COMPRESSED_FILE );stat_inc_compr_inode (inode); +inc_compr_inode_stat (inode);f2fs_mark_inode_dirty_sync (inode, true); }
fs/f2fs/super.c +7 -0
@@ -3260,6 +3260,13 @@ static void init_sb_info(struct f2fs_sb_info *sbi)init_rwsem (&sbi->sb_lock);init_rwsem (&sbi->pin_sem); + +#ifdef CONFIG_F2FS_FS_COMPRESSION +/* For runtime compression statistics */ +atomic64_set (&sbi->compr_written_block,0 ); +atomic64_set (&sbi->compr_saved_block,0 ); +atomic_set (&sbi->compr_new_inode,0 ); +#endif }static int init_percpu_info (struct f2fs_sb_info *sbi)
fs/f2fs/sysfs.c +58 -0
82 lines not on this page · raw message
Signature · 8 lines
2.31.0.rc2.261.g7f71774620-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 71 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
I've added new sysfs nodes to show runtime compression stat since mount.
compr_written_block- show the block count written after compressioncompr_saved_block- show the saved block count with compressioncompr_new_inode- show the count of inode newly enabled for compressionSigned-off-by Daeho Jeong <[email protected]>---
v2: thanks to kernel test robot <[email protected]>, fixed compile issue
related to kernel config
v3: changed sysfs nodes' names and made them runtime stat, not
persistent on disk
v4: changed sysfs nodes' desctiption--- Documentation/ABI/testing/sysfs-fs-f2fs | 24 ++++++++++ fs/f2fs/compress.c | 1 + fs/f2fs/f2fs.h | 19 ++++++++ fs/f2fs/super.c | 7 +++ fs/f2fs/sysfs.c | 58 +++++++++++++++++++++++++ 5 files changed, 109 insertions(+)Documentation/ABI/testing/sysfs-fs-f2fs +24
-0@@ -409,3 +409,27 @@ Description: Give a way to change checkpoint merge daemon's io priority. I/O priority "3". We can select the class between "rt" and "be", and set the I/O priority within valid range of it. "," delimiter is necessary in between I/O class and priority number. + +What: /sys/fs/f2fs/<disk>/compr_written_block +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the block count written after compression since mount. Note + that when the compressed blocks are deleted, this count doesn't + decrease. If you write "0" here, you can initialize + compr_written_block and compr_saved_block to "0". + +What: /sys/fs/f2fs/<disk>/compr_saved_block +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the saved block count with compression since mount. Note + that when the compressed blocks are deleted, this count doesn't + decrease. If you write "0" here, you can initialize + compr_written_block and compr_saved_block to "0". + +What: /sys/fs/f2fs/<disk>/compr_new_inode +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the count of inode newly enabled for compression since mount. + Note that when the compression is disabled for the files, this count + doesn't decrease. If you write "0" here, you can initialize + compr_new_inode to "0".fs/f2fs/compress.c +1
-0@@ -1353,6 +1353,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,if (fio.compr_blocks)f2fs_i_compr_blocks_update (inode, fio.compr_blocks -1 , false);f2fs_i_compr_blocks_update (inode, cc->nr_cpages, true); +add_compr_block_stat (inode, cc->nr_cpages);set_inode_flag (cc->inode,FI_APPEND_WRITE );if (cc->cluster_idx ==0 )fs/f2fs/f2fs.h +0
-0
fs/f2fs/f2fs.h struct f2fs_sb_info { · line 1630
Quoted 8 lines
fs/f2fs/f2fs.h +5
-0@@ -1623,6 +1623,11 @@ struct f2fs_sb_info {#ifdef CONFIG_F2FS_FS_COMPRESSION struct kmem_cache *page_array_slab;/* page array entry */ unsigned int page_array_slab_size;/* default page array slab size */ + +/* For runtime compression statistics */ +atomic64_t compr_written_block; +atomic64_t compr_saved_block; +atomic_t compr_new_inode;
Why do you need these to be atomic? What requires this?
fs/f2fs/f2fs.h struct f2fs_sb_info {
Quoted 8 lines
fs/f2fs/f2fs.h +8
-0+#ifdef CONFIG_F2FS_FS_COMPRESSION +if (!strcmp (a->attr.name,"compr_written_block" )) { +u64 bcount; +int len; + + bcount =atomic64_read (&sbi->compr_written_block); + + len =scnprintf (buf,PAGE_SIZE ,"%llu\n" , bcount);
Please use sysfs_emit() for new sysfs entries like these. Makes it much simpler.
And look, you really do not need an atomic value as this is just a random number you are sending to userspace that could be stale the minute you read from it.
Please just use a normal u64 and save the cpu sync for stuff like this.
thanks,
greg k-h
Thanks for suggesting me sysfs_emit().
For atomic values, actually, those are needed for writer part, not reader.
+#define add_compr_block_stat(inode, blocks) \
+ do { \
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \
+ int diff = F2FS_I(inode)->i_cluster_size - blocks; \
+ atomic64_add(blocks, &sbi->compr_written_block); \
+ atomic64_add(diff, &sbi->compr_saved_block); \+ } while (0)
I needed a protection here, because they might be updated in the race condition.
2021년 3월 12일 (금) 오후 9:39, Greg KH <[email protected]>님이 작성:
Quoted 100 lines · Daeho Jeong
Quoted 71 lines
From: Daeho Jeong <[email protected]>
I've added new sysfs nodes to show runtime compression stat since mount.
compr_written_block- show the block count written after compressioncompr_saved_block- show the saved block count with compressioncompr_new_inode- show the count of inode newly enabled for compressionSigned-off-by Daeho Jeong <[email protected]>---
v2: thanks to kernel test robot <[email protected]>, fixed compile issue
related to kernel config
v3: changed sysfs nodes' names and made them runtime stat, not
persistent on disk
v4: changed sysfs nodes' desctiption--- Documentation/ABI/testing/sysfs-fs-f2fs | 24 ++++++++++ fs/f2fs/compress.c | 1 + fs/f2fs/f2fs.h | 19 ++++++++ fs/f2fs/super.c | 7 +++ fs/f2fs/sysfs.c | 58 +++++++++++++++++++++++++ 5 files changed, 109 insertions(+)Documentation/ABI/testing/sysfs-fs-f2fs +24
-0@@ -409,3 +409,27 @@ Description: Give a way to change checkpoint merge daemon's io priority. I/O priority "3". We can select the class between "rt" and "be", and set the I/O priority within valid range of it. "," delimiter is necessary in between I/O class and priority number. + +What: /sys/fs/f2fs/<disk>/compr_written_block +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the block count written after compression since mount. Note + that when the compressed blocks are deleted, this count doesn't + decrease. If you write "0" here, you can initialize + compr_written_block and compr_saved_block to "0". + +What: /sys/fs/f2fs/<disk>/compr_saved_block +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the saved block count with compression since mount. Note + that when the compressed blocks are deleted, this count doesn't + decrease. If you write "0" here, you can initialize + compr_written_block and compr_saved_block to "0". + +What: /sys/fs/f2fs/<disk>/compr_new_inode +Date: March 2021 +Contact: "Daeho Jeong" <[email protected]> +Description: Show the count of inode newly enabled for compression since mount. + Note that when the compression is disabled for the files, this count + doesn't decrease. If you write "0" here, you can initialize + compr_new_inode to "0".fs/f2fs/compress.c +1
-0@@ -1353,6 +1353,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,if (fio.compr_blocks)f2fs_i_compr_blocks_update (inode, fio.compr_blocks -1 , false);f2fs_i_compr_blocks_update (inode, cc->nr_cpages, true); +add_compr_block_stat (inode, cc->nr_cpages);set_inode_flag (cc->inode,FI_APPEND_WRITE );if (cc->cluster_idx ==0 )fs/f2fs/f2fs.h +0
-0fs/f2fs/f2fs.h struct f2fs_sb_info { · line 1630
Quoted 8 lines
fs/f2fs/f2fs.h +5
-0@@ -1623,6 +1623,11 @@ struct f2fs_sb_info {#ifdef CONFIG_F2FS_FS_COMPRESSION struct kmem_cache *page_array_slab;/* page array entry */ unsigned int page_array_slab_size;/* default page array slab size */ + +/* For runtime compression statistics */ +atomic64_t compr_written_block; +atomic64_t compr_saved_block; +atomic_t compr_new_inode;Why do you need these to be atomic? What requires this?
fs/f2fs/f2fs.h struct f2fs_sb_info {
Quoted 8 lines
fs/f2fs/f2fs.h +8
-0+#ifdef CONFIG_F2FS_FS_COMPRESSION +if (!strcmp (a->attr.name,"compr_written_block" )) { +u64 bcount; +int len; + + bcount =atomic64_read (&sbi->compr_written_block); + + len =scnprintf (buf,PAGE_SIZE ,"%llu\n" , bcount);Please use
sysfs_emit()for new sysfs entries like these. Makes it much simpler.And look, you really do not need an atomic value as this is just a random number you are sending to userspace that could be stale the minute you read from it.
Quoted 5 lines
Please just use a normal u64 and save the cpu sync for stuff like this.
thanks,
greg k-h
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 12 lines · Daeho Jeong
Thanks for suggesting me
sysfs_emit().For atomic values, actually, those are needed for writer part, not reader.
fs/f2fs/f2fs.h +7
-0+#define add_compr_block_stat (inode, blocks) \ + do { \ + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ + int diff = F2FS_I(inode)->i_cluster_size - blocks; \ + atomic64_add(blocks, &sbi->compr_written_block); \ + atomic64_add(diff, &sbi->compr_saved_block); \ + } while (0)
Quoted 1 line
I needed a protection here, because they might be updated in the race condition.
Why? What are you trying to protect from "racing" here?
thanks,
greg k-h
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
As you can see, if we're doing like the below.
sbi->compr_written_block += blocks;
Let's assume the initial value as 0.
<thread A> <thread B>sbi->compr_written_block = 0;
sbi->compr_written_block = 0;
+blocks(3);
+ blocks(2);sbi->compr_written_block = 3;
sbi->compr_written_block = 2;
Finally, we end up with 2, not 5.
As more threads are participating it, we might miss more counting.
2021년 3월 12일 (금) 오후 11:04, Greg KH <[email protected]>님이 작성:
Quoted 14 lines · Daeho Jeong
Quoted 12 lines
Thanks for suggesting me
sysfs_emit().For atomic values, actually, those are needed for writer part, not reader.
fs/f2fs/f2fs.h +7
-0+#define add_compr_block_stat (inode, blocks) \ + do { \ + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ + int diff = F2FS_I(inode)->i_cluster_size - blocks; \ + atomic64_add(blocks, &sbi->compr_written_block); \ + atomic64_add(diff, &sbi->compr_saved_block); \ + } while (0)
Quoted 7 lines
Quoted 1 line
I needed a protection here, because they might be updated in the race condition.
Why? What are you trying to protect from "racing" here?
thanks,
greg k-h
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
So, do you want we protect the values here with spin_lock and just read without spin_lock in sysfs read part?
2021년 3월 12일 (금) 오후 11:37, Daeho Jeong <[email protected]>님이 작성:
Quoted 15 lines
As you can see, if we're doing like the below.
sbi->compr_written_block+= blocks;Let's assume the initial value as 0.
<thread A> <thread B>
sbi->compr_written_block= 0;
sbi->compr_written_block= 0;
+blocks(3);
+ blocks(2);sbi->compr_written_block= 3;
Quoted 28 lines
sbi->compr_written_block= 2;Finally, we end up with 2, not 5.
As more threads are participating it, we might miss more counting.
2021년 3월 12일 (금) 오후 11:04, Greg KH <[email protected]>님이 작성:
Quoted 21 lines · Daeho Jeong
Quoted 12 lines
Thanks for suggesting me
sysfs_emit().For atomic values, actually, those are needed for writer part, not reader.
fs/f2fs/f2fs.h +7
-0+#define add_compr_block_stat (inode, blocks) \ + do { \ + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ + int diff = F2FS_I(inode)->i_cluster_size - blocks; \ + atomic64_add(blocks, &sbi->compr_written_block); \ + atomic64_add(diff, &sbi->compr_saved_block); \ + } while (0)Quoted 1 line
I needed a protection here, because they might be updated in the race condition.
Why? What are you trying to protect from "racing" here?
thanks,
greg k-h
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 2 lines · Daeho Jeong
So, do you want we protect the values here with
spin_lockand just read withoutspin_lockin sysfs read part?
I would not use any lock at all if this were my code. Remember, this is for debugging/information only, right? And the data is always "stale" so what is it going to be used for?
thanks,
greg k-h
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
A: No.
Q: Should I include quotations after my reply?
http://daringfireball.net/2007/07/on_top
Quoted 14 lines · Daeho Jeong
As you can see, if we're doing like the below.
sbi->compr_written_block+= blocks;Let's assume the initial value as 0.
<thread A> <thread B>
sbi->compr_written_block= 0;
sbi->compr_written_block= 0;
+blocks(3);
+ blocks(2);sbi->compr_written_block= 3;
Quoted 5 lines
sbi->compr_written_block= 2;Finally, we end up with 2, not 5.
As more threads are participating it, we might miss more counting.
Are you sure? Isn't adding a number something that should happen in a "safe" way?
And if you miss 2 blocks, who cares? What is so critical about these things that you take the cache flush of 2 atomic writes just for a debugging statistic?
Why not just take 1 lock for everything if it's so important to get these "correct"?
What is the performance throughput degradation of adding 2 atomic writes to each time you write a block?
But really, will you ever notice missing a few, even if that could be possible on your cpu (and I strongly doubt most modern cpus will miss this...)
But this isn't my code, I just hate seeing atomic variables used for silly things like debugging stats when they do not seem to be really needed. So if you want to keep them, go ahead, but realize that the number you are reading has nothing to do with being "atomic" at all.
thanks,
greg k-h
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
2021년 3월 12일 (금) 오후 11:45, Greg KH <[email protected]>님이 작성:
Quoted 8 lines
A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
Quoted 5 lines
A: No.
Q: Should I include quotations after my reply?
Thanks for letting me know this!
Quoted 39 lines · Daeho Jeong
Quoted 14 lines
As you can see, if we're doing like the below.
sbi->compr_written_block+= blocks;Let's assume the initial value as 0.
<thread A> <thread B>
sbi->compr_written_block= 0;
sbi->compr_written_block= 0;
+blocks(3);
+ blocks(2);sbi->compr_written_block= 3;Quoted 5 lines
sbi->compr_written_block= 2;Finally, we end up with 2, not 5.
As more threads are participating it, we might miss more counting.
Are you sure? Isn't adding a number something that should happen in a "safe" way?
And if you miss 2 blocks, who cares? What is so critical about these things that you take the cache flush of 2 atomic writes just for a debugging statistic?
Why not just take 1 lock for everything if it's so important to get these "correct"?
What is the performance throughput degradation of adding 2 atomic writes to each time you write a block?
But really, will you ever notice missing a few, even if that could be possible on your cpu (and I strongly doubt most modern cpus will miss this...)
Quoted 7 lines
But this isn't my code, I just hate seeing atomic variables used for silly things like debugging stats when they do not seem to be really needed. So if you want to keep them, go ahead, but realize that the number you are reading has nothing to do with being "atomic" at all.
thanks,
I agree that missing number would be extremely few and the overhead of updating the numbers would be quite bad.
Thanks for your valuable comments. :)
Quoted 1 line
greg k-h
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel