kernel: wire I/O accounting into sys_read/sys_write
sys_read increments io_rchar, io_syscr, io_read_bytes. sys_write increments io_wchar, io_syscw, io_write_bytes. This makes /proc/[pid]/io show actual I/O activity. Cross-referenced with Linux 7.1 mm/filemap.c:filemap_get_pages and include/linux/task_io_accounting.h. The fields are saturated additions to avoid overflow on long-running processes.
This commit is contained in:
@@ -818,6 +818,14 @@ pub fn sys_read(fd: FileHandle, buf: UserSliceWo, token: &mut CleanLockToken) ->
|
||||
let offset = &mut desc_arc.write(token.token()).offset;
|
||||
*offset = offset.saturating_add(bytes_read as u64)
|
||||
}
|
||||
// I/O accounting: increment rchar and syscr on current context.
|
||||
// Cross-referenced with Linux 7.1 mm/filemap.c:filemap_get_pages
|
||||
// and task_io_account_read().
|
||||
let current = context::current();
|
||||
let mut guard = current.write(token.token());
|
||||
guard.io_rchar = guard.io_rchar.saturating_add(bytes_read as u64);
|
||||
guard.io_syscr = guard.io_syscr.saturating_add(1);
|
||||
guard.io_read_bytes = guard.io_read_bytes.saturating_add(bytes_read as u64);
|
||||
Ok(bytes_read)
|
||||
}
|
||||
pub fn sys_write(fd: FileHandle, buf: UserSliceRo, token: &mut CleanLockToken) -> Result<usize> {
|
||||
@@ -838,5 +846,11 @@ pub fn sys_write(fd: FileHandle, buf: UserSliceRo, token: &mut CleanLockToken) -
|
||||
let offset = &mut desc_arc.write(token.token()).offset;
|
||||
*offset = offset.saturating_add(bytes_written as u64)
|
||||
}
|
||||
// I/O accounting: increment wchar and syscw on current context.
|
||||
let current = context::current();
|
||||
let mut guard = current.write(token.token());
|
||||
guard.io_wchar = guard.io_wchar.saturating_add(bytes_written as u64);
|
||||
guard.io_syscw = guard.io_syscw.saturating_add(1);
|
||||
guard.io_write_bytes = guard.io_write_bytes.saturating_add(bytes_written as u64);
|
||||
Ok(bytes_written)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user