mm, hwpoison: try to recover from copy-on write faults
[linux-2.6-block.git] / include / linux / delayacct.h
CommitLineData
c942fddf 1/* SPDX-License-Identifier: GPL-2.0-or-later */
ca74e92b
SN
2/* delayacct.h - per-task delay accounting
3 *
4 * Copyright (C) Shailabh Nagar, IBM Corp. 2006
ca74e92b
SN
5 */
6
7#ifndef _LINUX_DELAYACCT_H
8#define _LINUX_DELAYACCT_H
9
4025819d 10#include <uapi/linux/taskstats.h>
ca74e92b
SN
11
12#ifdef CONFIG_TASK_DELAY_ACCT
47913d4e 13struct task_delay_info {
02acc80d 14 raw_spinlock_t lock;
ca74e92b 15
47913d4e
IM
16 /* For each stat XXX, add following, aligned appropriately
17 *
18 * struct timespec XXX_start, XXX_end;
19 * u64 XXX_delay;
20 * u32 XXX_count;
21 *
22 * Atomicity of updates to XXX_delay, XXX_count protected by
23 * single lock above (split into XXX_lock if contention is an issue).
24 */
25
26 /*
27 * XXX_count is incremented on every XXX operation, the delay
28 * associated with the operation is added to XXX_delay.
29 * XXX_delay contains the accumulated delay time in nanoseconds.
30 */
a3d5dc90 31 u64 blkio_start;
47913d4e 32 u64 blkio_delay; /* wait for sync block io completion */
a3d5dc90
YY
33 u64 swapin_start;
34 u64 swapin_delay; /* wait for swapin */
47913d4e
IM
35 u32 blkio_count; /* total count of the number of sync block */
36 /* io operations performed */
a3d5dc90 37 u32 swapin_count; /* total count of swapin */
47913d4e
IM
38
39 u64 freepages_start;
40 u64 freepages_delay; /* wait for memory reclaim */
b1d29ba8
JW
41
42 u64 thrashing_start;
43 u64 thrashing_delay; /* wait for thrashing page */
44
5bf18281 45 u64 compact_start;
46 u64 compact_delay; /* wait for memory compact */
47
662ce1dc
YY
48 u64 wpcopy_start;
49 u64 wpcopy_delay; /* wait for write-protect copy */
50
47913d4e 51 u32 freepages_count; /* total count of memory reclaim */
b1d29ba8 52 u32 thrashing_count; /* total count of thrash waits */
5bf18281 53 u32 compact_count; /* total count of memory compact */
662ce1dc 54 u32 wpcopy_count; /* total count of write-protect copy */
47913d4e
IM
55};
56#endif
57
58#include <linux/sched.h>
59#include <linux/slab.h>
eee4d9fe 60#include <linux/jump_label.h>
47913d4e
IM
61
62#ifdef CONFIG_TASK_DELAY_ACCT
e4042ad4 63DECLARE_STATIC_KEY_FALSE(delayacct_key);
ca74e92b 64extern int delayacct_on; /* Delay accounting turned on/off */
e18b890b 65extern struct kmem_cache *delayacct_cache;
ca74e92b 66extern void delayacct_init(void);
0cd7c741 67
ca74e92b
SN
68extern void __delayacct_tsk_init(struct task_struct *);
69extern void __delayacct_tsk_exit(struct task_struct *);
0ff92245 70extern void __delayacct_blkio_start(void);
c96f5471 71extern void __delayacct_blkio_end(struct task_struct *);
e4042ad4 72extern int delayacct_add_tsk(struct taskstats *, struct task_struct *);
25890454 73extern __u64 __delayacct_blkio_ticks(struct task_struct *);
873b4771
KK
74extern void __delayacct_freepages_start(void);
75extern void __delayacct_freepages_end(void);
aa1cf99b
YY
76extern void __delayacct_thrashing_start(bool *in_thrashing);
77extern void __delayacct_thrashing_end(bool *in_thrashing);
a3d5dc90
YY
78extern void __delayacct_swapin_start(void);
79extern void __delayacct_swapin_end(void);
5bf18281 80extern void __delayacct_compact_start(void);
81extern void __delayacct_compact_end(void);
662ce1dc
YY
82extern void __delayacct_wpcopy_start(void);
83extern void __delayacct_wpcopy_end(void);
846c7bb0 84
ca74e92b
SN
85static inline void delayacct_tsk_init(struct task_struct *tsk)
86{
87 /* reinitialize in case parent's non-null pointer was dup'ed*/
88 tsk->delays = NULL;
163ecdff 89 if (delayacct_on)
ca74e92b
SN
90 __delayacct_tsk_init(tsk);
91}
92
35df17c5
SN
93/* Free tsk->delays. Called from bad fork and __put_task_struct
94 * where there's no risk of tsk->delays being accessed elsewhere
95 */
96static inline void delayacct_tsk_free(struct task_struct *tsk)
ca74e92b
SN
97{
98 if (tsk->delays)
35df17c5
SN
99 kmem_cache_free(delayacct_cache, tsk->delays);
100 tsk->delays = NULL;
ca74e92b
SN
101}
102
0ff92245
SN
103static inline void delayacct_blkio_start(void)
104{
e4042ad4 105 if (!static_branch_unlikely(&delayacct_key))
eee4d9fe
PZ
106 return;
107
0ff92245
SN
108 if (current->delays)
109 __delayacct_blkio_start();
110}
111
c96f5471 112static inline void delayacct_blkio_end(struct task_struct *p)
0ff92245 113{
e4042ad4 114 if (!static_branch_unlikely(&delayacct_key))
eee4d9fe
PZ
115 return;
116
b512719f 117 if (p->delays)
c96f5471 118 __delayacct_blkio_end(p);
0ff92245
SN
119}
120
25890454
SN
121static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
122{
123 if (tsk->delays)
124 return __delayacct_blkio_ticks(tsk);
125 return 0;
126}
127
873b4771
KK
128static inline void delayacct_freepages_start(void)
129{
82065b72
YY
130 if (!static_branch_unlikely(&delayacct_key))
131 return;
132
873b4771
KK
133 if (current->delays)
134 __delayacct_freepages_start();
135}
136
137static inline void delayacct_freepages_end(void)
138{
82065b72
YY
139 if (!static_branch_unlikely(&delayacct_key))
140 return;
141
873b4771
KK
142 if (current->delays)
143 __delayacct_freepages_end();
144}
145
aa1cf99b 146static inline void delayacct_thrashing_start(bool *in_thrashing)
b1d29ba8 147{
82065b72
YY
148 if (!static_branch_unlikely(&delayacct_key))
149 return;
150
b1d29ba8 151 if (current->delays)
aa1cf99b 152 __delayacct_thrashing_start(in_thrashing);
b1d29ba8
JW
153}
154
aa1cf99b 155static inline void delayacct_thrashing_end(bool *in_thrashing)
b1d29ba8 156{
82065b72
YY
157 if (!static_branch_unlikely(&delayacct_key))
158 return;
159
b1d29ba8 160 if (current->delays)
aa1cf99b 161 __delayacct_thrashing_end(in_thrashing);
b1d29ba8
JW
162}
163
a3d5dc90
YY
164static inline void delayacct_swapin_start(void)
165{
82065b72
YY
166 if (!static_branch_unlikely(&delayacct_key))
167 return;
168
a3d5dc90
YY
169 if (current->delays)
170 __delayacct_swapin_start();
171}
172
173static inline void delayacct_swapin_end(void)
174{
82065b72
YY
175 if (!static_branch_unlikely(&delayacct_key))
176 return;
177
a3d5dc90
YY
178 if (current->delays)
179 __delayacct_swapin_end();
180}
181
5bf18281 182static inline void delayacct_compact_start(void)
183{
184 if (!static_branch_unlikely(&delayacct_key))
185 return;
186
187 if (current->delays)
188 __delayacct_compact_start();
189}
190
191static inline void delayacct_compact_end(void)
192{
193 if (!static_branch_unlikely(&delayacct_key))
194 return;
195
196 if (current->delays)
197 __delayacct_compact_end();
198}
199
662ce1dc
YY
200static inline void delayacct_wpcopy_start(void)
201{
202 if (!static_branch_unlikely(&delayacct_key))
203 return;
204
205 if (current->delays)
206 __delayacct_wpcopy_start();
207}
208
209static inline void delayacct_wpcopy_end(void)
210{
211 if (!static_branch_unlikely(&delayacct_key))
212 return;
213
214 if (current->delays)
215 __delayacct_wpcopy_end();
216}
217
ca74e92b 218#else
ca74e92b
SN
219static inline void delayacct_init(void)
220{}
221static inline void delayacct_tsk_init(struct task_struct *tsk)
222{}
35df17c5 223static inline void delayacct_tsk_free(struct task_struct *tsk)
ca74e92b 224{}
0ff92245
SN
225static inline void delayacct_blkio_start(void)
226{}
c96f5471 227static inline void delayacct_blkio_end(struct task_struct *p)
0ff92245 228{}
6f44993f
SN
229static inline int delayacct_add_tsk(struct taskstats *d,
230 struct task_struct *tsk)
231{ return 0; }
25890454
SN
232static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
233{ return 0; }
846c7bb0
BS
234static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
235{ return 0; }
873b4771
KK
236static inline void delayacct_freepages_start(void)
237{}
238static inline void delayacct_freepages_end(void)
239{}
aa1cf99b 240static inline void delayacct_thrashing_start(bool *in_thrashing)
b1d29ba8 241{}
aa1cf99b 242static inline void delayacct_thrashing_end(bool *in_thrashing)
b1d29ba8 243{}
a3d5dc90
YY
244static inline void delayacct_swapin_start(void)
245{}
246static inline void delayacct_swapin_end(void)
247{}
5bf18281 248static inline void delayacct_compact_start(void)
249{}
250static inline void delayacct_compact_end(void)
251{}
662ce1dc
YY
252static inline void delayacct_wpcopy_start(void)
253{}
254static inline void delayacct_wpcopy_end(void)
255{}
873b4771 256
ca74e92b
SN
257#endif /* CONFIG_TASK_DELAY_ACCT */
258
259#endif