Skip to contentSkip to conversation

f2fs: add sysfs nodes to get accumulated compression info

PATCH Superseded Daeho Jeong 2 participants 5 messages Mar 5, 2021 – Mar 10, 2021 F2FS file system

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 f2fs: add sysfs nodes to get accumulated compression info

From: Daeho Jeong <[email protected]>

Added acc_compr_inodes to show accumulated compressed inode count and acc_compr_blocks to show accumulated secured block count with compression in sysfs. These can be re-initialized to "0" by writing "0" value in one of both.

---
v2: thanks to kernel test robot <[email protected]>, fixed compile issue
related to kernel config.

---
 Documentation/ABI/testing/sysfs-fs-f2fs | 13 +++++++
 fs/f2fs/checkpoint.c                    |  8 ++++
 fs/f2fs/compress.c                      |  4 +-
 fs/f2fs/data.c                          |  2 +-
 fs/f2fs/f2fs.h                          | 50 ++++++++++++++++++++++++-
 fs/f2fs/file.c                          |  8 ++--
 fs/f2fs/inode.c                         |  1 +
 fs/f2fs/super.c                         | 10 ++++-
 fs/f2fs/sysfs.c                         | 45 ++++++++++++++++++++++
 include/linux/f2fs_fs.h                 |  4 +-
 10 files changed, 135 insertions(+), 10 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +13 -0
index cbeac1bebe2f..f4fc87503754 100644
@@ -409,3 +409,16 @@ 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>/acc_compr_inodes
+Date:		March 2021
+Contact:	"Daeho Jeong" <[email protected]>
+Description:	Show accumulated compressed inode count. If you write "0" here,
+		you can initialize acc_compr_inodes and acc_compr_blocks as "0".
+
+What:		/sys/fs/f2fs/<disk>/acc_compr_blocks
+Date:		March 2021
+Contact:	"Daeho Jeong" <[email protected]>
+Description:	Show accumulated secured block count with compression.
+		If you write "0" here, you can initialize acc_compr_inodes and
+		acc_compr_blocks as "0".
fs/f2fs/checkpoint.c +8 -0
index 174a0819ad96..cd944a569162 100644
@@ -1514,6 +1514,14 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	seg_i->journal->info.kbytes_written = cpu_to_le64(kbytes_written);
 
 	if (__remain_node_summaries(cpc->reason)) {
+		/* Record compression statistics in the hot node summary */
+		spin_lock(&sbi->acc_compr_lock);
+		seg_i->journal->info.acc_compr_blocks =
+			cpu_to_le64(sbi->acc_compr_blocks);
+		seg_i->journal->info.acc_compr_inodes =
+			cpu_to_le32(sbi->acc_compr_inodes);
+		spin_unlock(&sbi->acc_compr_lock);
+
 		f2fs_write_node_summaries(sbi, start_blk);
 		start_blk += NR_CURSEG_NODE_TYPE;
 	}
fs/f2fs/compress.c +2 -2
index 77fa342de38f..9029e95f4ae4 100644
@@ -1351,8 +1351,8 @@ 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);
+		f2fs_i_compr_blocks_update(inode, fio.compr_blocks - 1, false, true);
+	f2fs_i_compr_blocks_update(inode, cc->nr_cpages, true, true);
 
 	set_inode_flag(cc->inode, FI_APPEND_WRITE);
 	if (cc->cluster_idx == 0)
fs/f2fs/data.c +1 -1
index b9721c8f116c..d3afb9b0090e 100644
@@ -2591,7 +2591,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
 	ClearPageError(page);
 
 	if (fio->compr_blocks && fio->old_blkaddr == COMPRESS_ADDR)
-		f2fs_i_compr_blocks_update(inode, fio->compr_blocks - 1, false);
+		f2fs_i_compr_blocks_update(inode, fio->compr_blocks - 1, false, true);
 
 	/* LFS mode write path */
 	f2fs_outplace_write_data(&dn, fio);
fs/f2fs/f2fs.h +49 -1

89 lines not on this page · raw message

fs/f2fs/file.c +4 -4
index d26ff2ae3f5e..6e704383fe86 100644
@@ -568,7 +568,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
 					!(cluster_index & (cluster_size - 1))) {
 			if (compressed_cluster)
 				f2fs_i_compr_blocks_update(dn->inode,
-							valid_blocks, false);
+							valid_blocks, false, true);
 			compressed_cluster = (blkaddr == COMPRESS_ADDR);
 			valid_blocks = 0;
 		}
@@ -597,7 +597,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
 	}
 
 	if (compressed_cluster)
-		f2fs_i_compr_blocks_update(dn->inode, valid_blocks, false);
+		f2fs_i_compr_blocks_update(dn->inode, valid_blocks, false, true);
 
 	if (nr_free) {
 		pgoff_t fofs;
@@ -3503,7 +3503,7 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count)
 			f2fs_set_data_blkaddr(dn);
 		}
 
-		f2fs_i_compr_blocks_update(dn->inode, compr_blocks, false);
+		f2fs_i_compr_blocks_update(dn->inode, compr_blocks, false, false);
 		dec_valid_block_count(sbi, dn->inode,
 					cluster_size - compr_blocks);
 
@@ -3675,7 +3675,7 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count)
 		if (reserved != cluster_size - compr_blocks)
 			return -ENOSPC;
 
-		f2fs_i_compr_blocks_update(dn->inode, compr_blocks, true);
+		f2fs_i_compr_blocks_update(dn->inode, compr_blocks, true, false);
 
 		reserved_blocks += reserved;
 next:
fs/f2fs/inode.c +1 -0
index 349d9cb933ee..32a3cbb60409 100644
@@ -776,6 +776,7 @@ void f2fs_evict_inode(struct inode *inode)
 			set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
 	}
 	sb_end_intwrite(inode->i_sb);
+	dec_acc_compr_inodes(inode);
 no_delete:
 	dquot_drop(inode);
 
fs/f2fs/super.c +9 -1
index 7069793752f1..994895e0d326 100644
@@ -3861,11 +3861,19 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 	/* For write statistics */
 	sbi->sectors_written_start = f2fs_get_sectors_written(sbi);
 
+	/* For accumulated compression statistics */
+	spin_lock_init(&sbi->acc_compr_lock);
+
 	/* Read accumulated write IO statistics if exists */
 	seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
-	if (__exist_node_summaries(sbi))
+	if (__exist_node_summaries(sbi)) {
 		sbi->kbytes_written =
 			le64_to_cpu(seg_i->journal->info.kbytes_written);
+		sbi->acc_compr_blocks =
+			le64_to_cpu(seg_i->journal->info.acc_compr_blocks);
+		sbi->acc_compr_inodes =
+			le32_to_cpu(seg_i->journal->info.acc_compr_inodes);
+	}
 
 	f2fs_build_gc_manager(sbi);
 
fs/f2fs/sysfs.c +45 -0

69 lines not on this page · raw message

include/linux/f2fs_fs.h +3 -1
index c6cc0a566ef5..7b707ddeca99 100644
@@ -429,7 +429,7 @@ struct summary_footer {
 /* Reserved area should make size of f2fs_extra_info equals to
  * that of nat_journal and sit_journal.
  */
-#define EXTRA_INFO_RESERVED	(SUM_JOURNAL_SIZE - 2 - 8)
+#define EXTRA_INFO_RESERVED	(SUM_JOURNAL_SIZE - 2 - 20)
 
 /*
  * frequently updated NAT/SIT entries can be stored in the spare area in
@@ -462,6 +462,8 @@ struct sit_journal {
 
 struct f2fs_extra_info {
 	__le64 kbytes_written;
+	__le64 acc_compr_blocks;
+	__le32 acc_compr_inodes;
 	__u8 reserved[EXTRA_INFO_RESERVED];
 } __packed;
 
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
#1 lore raw
Quoted 4 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

Added acc_compr_inodes to show accumulated compressed inode count and acc_compr_blocks to show accumulated secured block count with

I noticed that these stat numbers are recorded in extra reserved area in hot node curseg journal, the journal will be persisted only for umount or fastboot checkpoint, so the numbers are not so accurate... does this satisfy your requirement?

Quoted 2 lines

compression in sysfs. These can be re-initialized to "0" by writing "0" value in one of both.

Why do we allow reset the stat numbers?

Why not covering all code with macro CONFIG_F2FS_FS_COMPRESSION, since these numbers are only be updated when we enable compression.

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw

2021년 3월 9일 (화) 오후 6:22, Chao Yu <[email protected]>님이 작성:

Quoted 12 lines · Daeho Jeong
Quoted 4 lines

From: Daeho Jeong <[email protected]>

Added acc_compr_inodes to show accumulated compressed inode count and acc_compr_blocks to show accumulated secured block count with

I noticed that these stat numbers are recorded in extra reserved area in hot node curseg journal, the journal will be persisted only for umount or fastboot checkpoint, so the numbers are not so accurate... does this satisfy your requirement?

Yes, we are satisfied with just getting rough number of them. But, it would be better if you suggest more accurate way. :)

Quoted 5 lines
Quoted 2 lines

compression in sysfs. These can be re-initialized to "0" by writing "0" value in one of both.

Why do we allow reset the stat numbers?

Actually, I want to have a way to clear any stale number of them, but I agree we don't need this.

Quoted 3 lines

Why not covering all code with macro CONFIG_F2FS_FS_COMPRESSION, since these numbers are only be updated when we enable compression.

I wanted to keep the info even in the kernel with doesn't support per-file compression if those had been written once. What do you think?

Quoted 1 line

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw
Quoted 8 lines · Daeho Jeong

2021년 3월 9일 (화) 오후 6:22, Chao Yu <[email protected]>님이 작성:

Quoted 7 lines · Daeho Jeong
Quoted 4 lines

From: Daeho Jeong <[email protected]>

Added acc_compr_inodes to show accumulated compressed inode count and acc_compr_blocks to show accumulated secured block count with

Quoted 7 lines
Quoted 5 lines

I noticed that these stat numbers are recorded in extra reserved area in hot node curseg journal, the journal will be persisted only for umount or fastboot checkpoint, so the numbers are not so accurate... does this satisfy your requirement?

Yes, we are satisfied with just getting rough number of them. But, it

Alright,

Quoted 1 line

would be better if you suggest more accurate way. :)

I think this is the cheapest way to store rough number, otherwise it needs to change f2fs_checkpoint structure layout or add a new inner inode to persist these stat numbers if we want more accurate one.

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

compression in sysfs. These can be re-initialized to "0" by writing "0" value in one of both.

Why do we allow reset the stat numbers?

Actually, I want to have a way to clear any stale number of them, but I agree we don't need this.

Quoted 7 lines
Quoted 3 lines

Why not covering all code with macro CONFIG_F2FS_FS_COMPRESSION, since these numbers are only be updated when we enable compression.

I wanted to keep the info even in the kernel with doesn't support per-file compression if those had been written once. What do you think?

Sure, if so it's fine to me. :)

Thanks,

Quoted 4 lines
Quoted 2 lines

Thanks,

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw

We've reconsidered this feature and decided to get just runtime info of them, not persistent on disk.
I am re-writing it.

Thanks,

2021년 3월 10일 (수) 오전 10:31, Chao Yu <[email protected]>님이 작성:

Quoted 40 lines · Daeho Jeong
Quoted 8 lines

2021년 3월 9일 (화) 오후 6:22, Chao Yu <[email protected]>님이 작성:

Quoted 7 lines · Daeho Jeong
Quoted 4 lines

From: Daeho Jeong <[email protected]>

Added acc_compr_inodes to show accumulated compressed inode count and acc_compr_blocks to show accumulated secured block count with

Quoted 7 lines
Quoted 5 lines

I noticed that these stat numbers are recorded in extra reserved area in hot node curseg journal, the journal will be persisted only for umount or fastboot checkpoint, so the numbers are not so accurate... does this satisfy your requirement?

Yes, we are satisfied with just getting rough number of them. But, it

Alright,

Quoted 1 line

would be better if you suggest more accurate way. :)

I think this is the cheapest way to store rough number, otherwise it needs to change f2fs_checkpoint structure layout or add a new inner inode to persist these stat numbers if we want more accurate one.

Quoted 14 lines
Quoted 6 lines
Quoted 3 lines

compression in sysfs. These can be re-initialized to "0" by writing "0" value in one of both.

Why do we allow reset the stat numbers?

Actually, I want to have a way to clear any stale number of them, but I agree we don't need this.

Quoted 3 lines

Why not covering all code with macro CONFIG_F2FS_FS_COMPRESSION, since these numbers are only be updated when we enable compression.

Quoted 12 lines
Quoted 3 lines

I wanted to keep the info even in the kernel with doesn't support per-file compression if those had been written once. What do you think?

Sure, if so it's fine to me. :)

Thanks,

Quoted 4 lines
Quoted 2 lines

Thanks,

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel