aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu2020-11-27 07:20:06 -0600
committerJaegeuk Kim2020-12-21 15:33:15 -0600
commit5a11975441c84d1fcdbe2cae760fd50df4c1dda5 (patch)
treebc368736f63ea431482993af9996d347c706367f
parent1f004d62f8511630201b3f20f46e3d8864f877c6 (diff)
downloadkernel-5a11975441c84d1fcdbe2cae760fd50df4c1dda5.tar.gz
kernel-5a11975441c84d1fcdbe2cae760fd50df4c1dda5.tar.xz
kernel-5a11975441c84d1fcdbe2cae760fd50df4c1dda5.zip
f2fs: fix kbytes written stat for multi-device case
For multi-device case, one f2fs image includes multi devices, so it needs to account bytes written of all block devices belong to the image rather than one main block device, fix it. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/checkpoint.c27
-rw-r--r--fs/f2fs/f2fs.h8
-rw-r--r--fs/f2fs/super.c5
-rw-r--r--fs/f2fs/sysfs.c3
4 files changed, 27 insertions, 16 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index e5d2ffa80b56..14ba1519639e 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1385,6 +1385,27 @@ static void commit_checkpoint(struct f2fs_sb_info *sbi,
1385 f2fs_submit_merged_write(sbi, META_FLUSH); 1385 f2fs_submit_merged_write(sbi, META_FLUSH);
1386} 1386}
1387 1387
1388static inline u64 get_sectors_written(struct block_device *bdev)
1389{
1390 return bdev->bd_part ?
1391 (u64)part_stat_read(bdev->bd_part, sectors[STAT_WRITE]) : 0;
1392}
1393
1394u64 f2fs_get_sectors_written(struct f2fs_sb_info *sbi)
1395{
1396 if (f2fs_is_multi_device(sbi)) {
1397 u64 sectors = 0;
1398 int i;
1399
1400 for (i = 0; i < sbi->s_ndevs; i++)
1401 sectors += get_sectors_written(FDEV(i).bdev);
1402
1403 return sectors;
1404 }
1405
1406 return get_sectors_written(sbi->sb->s_bdev);
1407}
1408
1388static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1409static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1389{ 1410{
1390 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1411 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
@@ -1395,7 +1416,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1395 __u32 crc32 = 0; 1416 __u32 crc32 = 0;
1396 int i; 1417 int i;
1397 int cp_payload_blks = __cp_payload(sbi); 1418 int cp_payload_blks = __cp_payload(sbi);
1398 struct super_block *sb = sbi->sb;
1399 struct curseg_info *seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); 1419 struct curseg_info *seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
1400 u64 kbytes_written; 1420 u64 kbytes_written;
1401 int err; 1421 int err;
@@ -1490,9 +1510,8 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1490 1510
1491 /* Record write statistics in the hot node summary */ 1511 /* Record write statistics in the hot node summary */
1492 kbytes_written = sbi->kbytes_written; 1512 kbytes_written = sbi->kbytes_written;
1493 if (sb->s_bdev->bd_part) 1513 kbytes_written += (f2fs_get_sectors_written(sbi) -
1494 kbytes_written += BD_PART_WRITTEN(sbi); 1514 sbi->sectors_written_start) >> 1;
1495
1496 seg_i->journal->info.kbytes_written = cpu_to_le64(kbytes_written); 1515 seg_i->journal->info.kbytes_written = cpu_to_le64(kbytes_written);
1497 1516
1498 if (__remain_node_summaries(cpc->reason)) { 1517 if (__remain_node_summaries(cpc->reason)) {
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 0b314b2034d8..90e1fe0ce4bb 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1603,13 +1603,6 @@ static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi)
1603 return sbi->s_ndevs > 1; 1603 return sbi->s_ndevs > 1;
1604} 1604}
1605 1605
1606/* For write statistics. Suppose sector size is 512 bytes,
1607 * and the return value is in kbytes. s is of struct f2fs_sb_info.
1608 */
1609#define BD_PART_WRITTEN(s) \
1610(((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \
1611 (s)->sectors_written_start) >> 1)
1612
1613static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 1606static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
1614{ 1607{
1615 unsigned long now = jiffies; 1608 unsigned long now = jiffies;
@@ -3382,6 +3375,7 @@ void f2fs_update_dirty_page(struct inode *inode, struct page *page);
3382void f2fs_remove_dirty_inode(struct inode *inode); 3375void f2fs_remove_dirty_inode(struct inode *inode);
3383int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 3376int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type);
3384void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type); 3377void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type);
3378u64 f2fs_get_sectors_written(struct f2fs_sb_info *sbi);
3385int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 3379int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc);
3386void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); 3380void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi);
3387int __init f2fs_create_checkpoint_caches(void); 3381int __init f2fs_create_checkpoint_caches(void);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index f3d919ee4dee..0ac4dbd6488a 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -3701,10 +3701,7 @@ try_onemore:
3701 } 3701 }
3702 3702
3703 /* For write statistics */ 3703 /* For write statistics */
3704 if (sb->s_bdev->bd_part) 3704 sbi->sectors_written_start = f2fs_get_sectors_written(sbi);
3705 sbi->sectors_written_start =
3706 (u64)part_stat_read(sb->s_bdev->bd_part,
3707 sectors[STAT_WRITE]);
3708 3705
3709 /* Read accumulated write IO statistics if exists */ 3706 /* Read accumulated write IO statistics if exists */
3710 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); 3707 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index ec77ccfea923..fce2997382af 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -97,7 +97,8 @@ static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
97 97
98 return sprintf(buf, "%llu\n", 98 return sprintf(buf, "%llu\n",
99 (unsigned long long)(sbi->kbytes_written + 99 (unsigned long long)(sbi->kbytes_written +
100 BD_PART_WRITTEN(sbi))); 100 ((f2fs_get_sectors_written(sbi) -
101 sbi->sectors_written_start) >> 1)));
101} 102}
102 103
103static ssize_t features_show(struct f2fs_attr *a, 104static ssize_t features_show(struct f2fs_attr *a,