Skip to content

Commit 2e3f7dd

Browse files
Zhou JifengMiklos Szeredi
authored andcommitted
fuse: Track process write operations in both direct and writethrough modes
Due to the fact that fuse does not count the write IO of processes in the direct and writethrough write modes, user processes cannot track write_bytes through the “/proc/[pid]/io” path. For example, the system tool iotop cannot count the write operations of the corresponding process. Signed-off-by: Zhou Jifeng <zhoujifeng@kylinos.com.cn> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 9e7f529 commit 2e3f7dd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fs/fuse/file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/fs.h>
2121
#include <linux/filelock.h>
2222
#include <linux/splice.h>
23+
#include <linux/task_io_accounting_ops.h>
2324

2425
static int fuse_send_open(struct fuse_mount *fm, u64 nodeid,
2526
unsigned int open_flags, int opcode,
@@ -1405,7 +1406,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
14051406
struct address_space *mapping = file->f_mapping;
14061407
ssize_t written = 0;
14071408
struct inode *inode = mapping->host;
1408-
ssize_t err;
1409+
ssize_t err, count;
14091410
struct fuse_conn *fc = get_fuse_conn(inode);
14101411

14111412
if (fc->writeback_cache) {
@@ -1427,10 +1428,12 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
14271428
writethrough:
14281429
inode_lock(inode);
14291430

1430-
err = generic_write_checks(iocb, from);
1431+
err = count = generic_write_checks(iocb, from);
14311432
if (err <= 0)
14321433
goto out;
14331434

1435+
task_io_account_write(count);
1436+
14341437
err = file_remove_privs(file);
14351438
if (err)
14361439
goto out;
@@ -1668,6 +1671,7 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)
16681671
fuse_dio_lock(iocb, from, &exclusive);
16691672
res = generic_write_checks(iocb, from);
16701673
if (res > 0) {
1674+
task_io_account_write(res);
16711675
if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) {
16721676
res = fuse_direct_IO(iocb, from);
16731677
} else {

0 commit comments

Comments
 (0)