BSD accounting: update chars transferred value
Subsystems (4)
PATCH 1/1 BSD accounting: update chars transferred value
Hello,
The goal of this patch is to improve BSD accounting by using what
is done in the CSA into BSD accounting. The final goal is to have a uniform accounting structure.
This patch updates information given by BSD accounting concerning
bytes read and written. A field is already present in the BSD accounting structure but it is never updated. We don't add information about blocks read and written because, as it was discussed in previous email, the information is inaccurate. Most writes which are flushed delayed would get accounted to pdflushd. Thus, one solution to get this kind of information is to add counters when the write back is performed. The problem is that we don't know how to get information about the IID at the page level (ie from struct page). So we remove this information for the moment and it will be provided in another patch.
Changelog:
- Adds two counters in the task_struct (rchar, wchar)
- Init fields during the creation of the process (during the fork)
- File I/O operations are done through sys_read(), sys_write(), sys_readv(), sys_writev() and sys_sendfile(). Thus we increment counters into those functions except with sys_sendfile(). For the latter, the incrementation is done in the do_sendfile() because this routine be directly called from the return of sys_sendfile().
fs/read_write.c +17 -0
@@ -294,6 +294,9 @@ asmlinkage ssize_t sys_read(unsigned intfput_light (file, fput_needed); } +if (ret >0 ) + current->rchar += ret; +return ret; }EXPORT_SYMBOL_GPL (sys_read);
@@ -312,6 +315,9 @@ asmlinkage ssize_t sys_write(unsigned infput_light (file, fput_needed); } +if (ret >0 ) + current->wchar += ret; +return ret; }
@@ -540,6 +546,9 @@ sys_readv(unsigned long fd, const structfput_light (file, fput_needed); } +if (ret >0 ) + current->rchar += ret; +return ret; }
@@ -558,6 +567,9 @@ sys_writev(unsigned long fd, const strucfput_light (file, fput_needed); } +if (ret >0 ) + current->wchar += ret; +return ret; }
@@ -639,6 +651,11 @@ static ssize_t do_sendfile(int out_fd, iif (*ppos > max) retval = -EOVERFLOW ; +if (retval >0 ) { + current->rchar += retval; + current->wchar += retval; + } + fput_out:fput_light (out_file, fput_needed_out); fput_in:
include/linux/sched.h +3 -0
@@ -523,6 +523,9 @@ struct task_struct {unsigned long ptrace_message;siginfo_t *last_siginfo;/* For ptrace use. */ +/* IO counters: bytes read, bytes written */ +unsigned long rchar, wchar; +#ifdef CONFIG_NUMA struct mempolicy *mempolicy;short il_next;/* could be shared with used_math */
kernel/acct.c +2 -2
@@ -464,8 +464,8 @@ static void do_acct_process(long exitcod } vsize = vsize /1024 ; ac.ac_mem =encode_comp_t (vsize); - ac.ac_io =encode_comp_t (0 /* current->io_usage */ );/* %% */ - ac.ac_rw =encode_comp_t (ac.ac_io /1024 ); + ac.ac_io =encode_comp_t (current->rchar + current->wchar); + ac.ac_rw =encode_comp_t (0 /* ac.ac_io / 1024 */ );/* %% */ ac.ac_minflt =encode_comp_t (current->min_flt); ac.ac_majflt =encode_comp_t (current->maj_flt); ac.ac_swaps =encode_comp_t (0 );
kernel/fork.c +1 -0
@@ -965,6 +965,7 @@ struct task_struct *copy_process(unsigne p->security =NULL ; p->io_context =NULL ; p->audit_context =NULL ; + p->rchar = p->wchar =0 ;#ifdef CONFIG_NUMA p->mempolicy =mpol_copy (p->mempolicy);if (IS_ERR (p->mempolicy)) {
Quoted 19 lines · Guillaume Thouvenin
Hello,
The goal of this patch is to improve BSD accounting by using what
is done in the CSA into BSD accounting. The final goal is to have a uniform accounting structure.This patch updates information given by BSD accounting concerning
bytes read and written. A field is already present in the BSD accounting structure but it is never updated. We don't add information about blocks read and written because, as it was discussed in previous email, the information is inaccurate. Most writes which are flushed delayed would get accounted to pdflushd. Thus, one solution to get this kind of information is to add counters when the write back is performed. The problem is that we don't know how to get information about the IID at the page level (ie from struct page). So we remove this information for the moment and it will be provided in another patch.Changelog:
Quoted 7 lines
- Adds two counters in the
task_struct(rchar, wchar)
- Init fields during the creation of the process (during the fork)
- File I/O operations are done throughsys_read(),sys_write(),sys_readv(),sys_writev()andsys_sendfile(). Thus we increment counters into those functions except withsys_sendfile(). For the latter, the incrementation is done in thedo_sendfile()because this routine be directly called from the return ofsys_sendfile().
I think it should be done in vfs_readv/vfs_write. Else we'll miss the updates from inekrnel consumers like nfsd.
Quoted 28 lines · Christoph Hellwig
Quoted 19 lines · Guillaume Thouvenin
Hello,
The goal of this patch is to improve BSD accounting by using what
is done in the CSA into BSD accounting. The final goal is to have a uniform accounting structure.This patch updates information given by BSD accounting concerning
bytes read and written. A field is already present in the BSD accounting structure but it is never updated. We don't add information about blocks read and written because, as it was discussed in previous email, the information is inaccurate. Most writes which are flushed delayed would get accounted to pdflushd. Thus, one solution to get this kind of information is to add counters when the write back is performed. The problem is that we don't know how to get information about the IID at the page level (ie from struct page). So we remove this information for the moment and it will be provided in another patch.Changelog:
Quoted 7 lines
- Adds two counters in the
task_struct(rchar, wchar)
- Init fields during the creation of the process (during the fork)
- File I/O operations are done throughsys_read(),sys_write(),sys_readv(),sys_writev()andsys_sendfile(). Thus we increment counters into those functions except withsys_sendfile(). For the latter, the incrementation is done in thedo_sendfile()because this routine be directly called from the return ofsys_sendfile().
Quoted 2 lines
I think it should be done in vfs_readv/vfs_write. Else we'll miss the updates from inekrnel consumers like nfsd.
Yes you're right. vfs_readv() and vfs_writev() called do_readv_writev(). Thus I will send a new patch which updates counters in functions vfs_read(), vfs_write(), do_readv_writev() and sys_sendfile()