Skip to content

Commit 940389b

Browse files
arighitorvalds
authored andcommitted
task IO accounting: move all IO statistics in struct task_io_accounting
Simplify the code of include/linux/task_io_accounting.h. It is also more reasonable to have all the task i/o-related statistics in a single struct (task_io_accounting). Signed-off-by: Andrea Righi <righi.andrea@gmail.com> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 837b41b commit 940389b

5 files changed

Lines changed: 44 additions & 57 deletions

File tree

‎fs/proc/base.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,7 @@ static int proc_base_fill_cache(struct file *filp, void *dirent,
24032403
#ifdef CONFIG_TASK_IO_ACCOUNTING
24042404
static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
24052405
{
2406-
struct proc_io_accounting acct = task->ioac;
2406+
struct task_io_accounting acct = task->ioac;
24072407
unsigned long flags;
24082408

24092409
if (whole && lock_task_sighand(task, &flags)) {
@@ -2423,10 +2423,10 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
24232423
"read_bytes: %llu\n"
24242424
"write_bytes: %llu\n"
24252425
"cancelled_write_bytes: %llu\n",
2426-
acct.chr.rchar, acct.chr.wchar,
2427-
acct.chr.syscr, acct.chr.syscw,
2428-
acct.blk.read_bytes, acct.blk.write_bytes,
2429-
acct.blk.cancelled_write_bytes);
2426+
acct.rchar, acct.wchar,
2427+
acct.syscr, acct.syscw,
2428+
acct.read_bytes, acct.write_bytes,
2429+
acct.cancelled_write_bytes);
24302430
}
24312431

24322432
static int proc_tid_io_accounting(struct task_struct *task, char *buffer)

‎include/linux/sched.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ struct signal_struct {
505505
unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
506506
unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
507507
unsigned long inblock, oublock, cinblock, coublock;
508-
struct proc_io_accounting ioac;
508+
struct task_io_accounting ioac;
509509

510510
/*
511511
* Cumulative ns of scheduled CPU time for dead threads in the
@@ -1253,7 +1253,7 @@ struct task_struct {
12531253

12541254
unsigned long ptrace_message;
12551255
siginfo_t *last_siginfo; /* For ptrace use. */
1256-
struct proc_io_accounting ioac;
1256+
struct task_io_accounting ioac;
12571257
#if defined(CONFIG_TASK_XACCT)
12581258
u64 acct_rss_mem1; /* accumulated rss usage */
12591259
u64 acct_vm_mem1; /* accumulated virtual memory usage */
@@ -2183,22 +2183,22 @@ extern long sched_group_rt_period(struct task_group *tg);
21832183
#ifdef CONFIG_TASK_XACCT
21842184
static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
21852185
{
2186-
tsk->ioac.chr.rchar += amt;
2186+
tsk->ioac.rchar += amt;
21872187
}
21882188

21892189
static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
21902190
{
2191-
tsk->ioac.chr.wchar += amt;
2191+
tsk->ioac.wchar += amt;
21922192
}
21932193

21942194
static inline void inc_syscr(struct task_struct *tsk)
21952195
{
2196-
tsk->ioac.chr.syscr++;
2196+
tsk->ioac.syscr++;
21972197
}
21982198

21992199
static inline void inc_syscw(struct task_struct *tsk)
22002200
{
2201-
tsk->ioac.chr.syscw++;
2201+
tsk->ioac.syscw++;
22022202
}
22032203
#else
22042204
static inline void add_rchar(struct task_struct *tsk, ssize_t amt)

‎include/linux/task_io_accounting.h‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* proc_io_accounting: a structure which is used for recording a single task's
2+
* task_io_accounting: a structure which is used for recording a single task's
33
* IO statistics.
44
*
55
* Don't include this header file directly - it is designed to be dragged in via
@@ -8,8 +8,8 @@
88
* Blame akpm@osdl.org for all this.
99
*/
1010

11+
struct task_io_accounting {
1112
#ifdef CONFIG_TASK_XACCT
12-
struct task_chr_io_accounting {
1313
/* bytes read */
1414
u64 rchar;
1515
/* bytes written */
@@ -18,14 +18,9 @@ struct task_chr_io_accounting {
1818
u64 syscr;
1919
/* # of write syscalls */
2020
u64 syscw;
21-
};
22-
#else /* CONFIG_TASK_XACCT */
23-
struct task_chr_io_accounting {
24-
};
2521
#endif /* CONFIG_TASK_XACCT */
2622

2723
#ifdef CONFIG_TASK_IO_ACCOUNTING
28-
struct task_io_accounting {
2924
/*
3025
* The number of bytes which this task has caused to be read from
3126
* storage.
@@ -46,13 +41,5 @@ struct task_io_accounting {
4641
* information loss in doing that.
4742
*/
4843
u64 cancelled_write_bytes;
49-
};
50-
#else /* CONFIG_TASK_IO_ACCOUNTING */
51-
struct task_io_accounting {
52-
};
5344
#endif /* CONFIG_TASK_IO_ACCOUNTING */
54-
55-
struct proc_io_accounting {
56-
struct task_chr_io_accounting chr;
57-
struct task_io_accounting blk;
5845
};

‎include/linux/task_io_accounting_ops.h‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifdef CONFIG_TASK_IO_ACCOUNTING
1010
static inline void task_io_account_read(size_t bytes)
1111
{
12-
current->ioac.blk.read_bytes += bytes;
12+
current->ioac.read_bytes += bytes;
1313
}
1414

1515
/*
@@ -18,12 +18,12 @@ static inline void task_io_account_read(size_t bytes)
1818
*/
1919
static inline unsigned long task_io_get_inblock(const struct task_struct *p)
2020
{
21-
return p->ioac.blk.read_bytes >> 9;
21+
return p->ioac.read_bytes >> 9;
2222
}
2323

2424
static inline void task_io_account_write(size_t bytes)
2525
{
26-
current->ioac.blk.write_bytes += bytes;
26+
current->ioac.write_bytes += bytes;
2727
}
2828

2929
/*
@@ -32,25 +32,25 @@ static inline void task_io_account_write(size_t bytes)
3232
*/
3333
static inline unsigned long task_io_get_oublock(const struct task_struct *p)
3434
{
35-
return p->ioac.blk.write_bytes >> 9;
35+
return p->ioac.write_bytes >> 9;
3636
}
3737

3838
static inline void task_io_account_cancelled_write(size_t bytes)
3939
{
40-
current->ioac.blk.cancelled_write_bytes += bytes;
40+
current->ioac.cancelled_write_bytes += bytes;
4141
}
4242

43-
static inline void task_io_accounting_init(struct proc_io_accounting *ioac)
43+
static inline void task_io_accounting_init(struct task_io_accounting *ioac)
4444
{
4545
memset(ioac, 0, sizeof(*ioac));
4646
}
4747

48-
static inline void task_blk_io_accounting_add(struct proc_io_accounting *dst,
49-
struct proc_io_accounting *src)
48+
static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
49+
struct task_io_accounting *src)
5050
{
51-
dst->blk.read_bytes += src->blk.read_bytes;
52-
dst->blk.write_bytes += src->blk.write_bytes;
53-
dst->blk.cancelled_write_bytes += src->blk.cancelled_write_bytes;
51+
dst->read_bytes += src->read_bytes;
52+
dst->write_bytes += src->write_bytes;
53+
dst->cancelled_write_bytes += src->cancelled_write_bytes;
5454
}
5555

5656
#else
@@ -77,35 +77,35 @@ static inline void task_io_account_cancelled_write(size_t bytes)
7777
{
7878
}
7979

80-
static inline void task_io_accounting_init(struct proc_io_accounting *ioac)
80+
static inline void task_io_accounting_init(struct task_io_accounting *ioac)
8181
{
8282
}
8383

84-
static inline void task_blk_io_accounting_add(struct proc_io_accounting *dst,
85-
struct proc_io_accounting *src)
84+
static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
85+
struct task_io_accounting *src)
8686
{
8787
}
8888

8989
#endif /* CONFIG_TASK_IO_ACCOUNTING */
9090

9191
#ifdef CONFIG_TASK_XACCT
92-
static inline void task_chr_io_accounting_add(struct proc_io_accounting *dst,
93-
struct proc_io_accounting *src)
92+
static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
93+
struct task_io_accounting *src)
9494
{
95-
dst->chr.rchar += src->chr.rchar;
96-
dst->chr.wchar += src->chr.wchar;
97-
dst->chr.syscr += src->chr.syscr;
98-
dst->chr.syscw += src->chr.syscw;
95+
dst->rchar += src->rchar;
96+
dst->wchar += src->wchar;
97+
dst->syscr += src->syscr;
98+
dst->syscw += src->syscw;
9999
}
100100
#else
101-
static inline void task_chr_io_accounting_add(struct proc_io_accounting *dst,
102-
struct proc_io_accounting *src)
101+
static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
102+
struct task_io_accounting *src)
103103
{
104104
}
105105
#endif /* CONFIG_TASK_XACCT */
106106

107-
static inline void task_io_accounting_add(struct proc_io_accounting *dst,
108-
struct proc_io_accounting *src)
107+
static inline void task_io_accounting_add(struct task_io_accounting *dst,
108+
struct task_io_accounting *src)
109109
{
110110
task_chr_io_accounting_add(dst, src);
111111
task_blk_io_accounting_add(dst, src);

‎kernel/tsacct.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
9494
stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB;
9595
mmput(mm);
9696
}
97-
stats->read_char = p->ioac.chr.rchar;
98-
stats->write_char = p->ioac.chr.wchar;
99-
stats->read_syscalls = p->ioac.chr.syscr;
100-
stats->write_syscalls = p->ioac.chr.syscw;
97+
stats->read_char = p->ioac.rchar;
98+
stats->write_char = p->ioac.wchar;
99+
stats->read_syscalls = p->ioac.syscr;
100+
stats->write_syscalls = p->ioac.syscw;
101101
#ifdef CONFIG_TASK_IO_ACCOUNTING
102-
stats->read_bytes = p->ioac.blk.read_bytes;
103-
stats->write_bytes = p->ioac.blk.write_bytes;
104-
stats->cancelled_write_bytes = p->ioac.blk.cancelled_write_bytes;
102+
stats->read_bytes = p->ioac.read_bytes;
103+
stats->write_bytes = p->ioac.write_bytes;
104+
stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
105105
#else
106106
stats->read_bytes = 0;
107107
stats->write_bytes = 0;

0 commit comments

Comments
 (0)