* [PATCH] delayacct: track delays from COW
@ 2022-03-22 11:04 cgel.zte
2022-03-23 8:49 ` David Hildenbrand
0 siblings, 1 reply; 5+ messages in thread
From: cgel.zte @ 2022-03-22 11:04 UTC (permalink / raw)
To: akpm, david; +Cc: bsingharora, linux-kernel, linux-mm, Yang Yang, Ran Xiaokai
From: Yang Yang <yang.yang29@zte.com.cn>
Delay accounting does not track the delay of COW. When tasks trigger
much COW, it may spend a amount of time waiting for it. To get the
impact of tasks in COW, measure the delay when it happens. This
could help users to do tunnings, such as decide whether to use
ksm or not.
Also update tools/accounting/getdelays.c:
/ # ./getdelays -dl -p 231
print delayacct stats ON
listen forever
PID 231
CPU count real total virtual total delay total delay average
6247 1859000000 2154070021 1674255063 0.268ms
IO count delay total delay average
0 0 0ms
SWAP count delay total delay average
0 0 0ms
RECLAIM count delay total delay average
0 0 0ms
THRASHING count delay total delay average
0 0 0ms
COMPACT count delay total delay average
3 72758 0ms
COW count delay total delay average
3635 271567604 0ms
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Reviewed-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
include/linux/delayacct.h | 28 ++++++++++++++++++++++++++++
include/uapi/linux/taskstats.h | 6 +++++-
kernel/delayacct.c | 16 ++++++++++++++++
mm/memory.c | 8 ++++++++
tools/accounting/getdelays.c | 8 +++++++-
5 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/include/linux/delayacct.h b/include/linux/delayacct.h
index 6b16a6930a19..89b202c695d3 100644
--- a/include/linux/delayacct.h
+++ b/include/linux/delayacct.h
@@ -45,9 +45,13 @@ struct task_delay_info {
u64 compact_start;
u64 compact_delay; /* wait for memory compact */
+ u64 cow_start;
+ u64 cow_delay; /* wait for cow */
+
u32 freepages_count; /* total count of memory reclaim */
u32 thrashing_count; /* total count of thrash waits */
u32 compact_count; /* total count of memory compact */
+ u32 cow_count; /* total count of cow */
};
#endif
@@ -75,6 +79,8 @@ extern void __delayacct_swapin_start(void);
extern void __delayacct_swapin_end(void);
extern void __delayacct_compact_start(void);
extern void __delayacct_compact_end(void);
+extern void __delayacct_cow_start(void);
+extern void __delayacct_cow_end(void);
static inline void delayacct_tsk_init(struct task_struct *tsk)
{
@@ -191,6 +197,24 @@ static inline void delayacct_compact_end(void)
__delayacct_compact_end();
}
+static inline void delayacct_cow_start(void)
+{
+ if (!static_branch_unlikely(&delayacct_key))
+ return;
+
+ if (current->delays)
+ __delayacct_cow_start();
+}
+
+static inline void delayacct_cow_end(void)
+{
+ if (!static_branch_unlikely(&delayacct_key))
+ return;
+
+ if (current->delays)
+ __delayacct_cow_end();
+}
+
#else
static inline void delayacct_init(void)
{}
@@ -225,6 +249,10 @@ static inline void delayacct_compact_start(void)
{}
static inline void delayacct_compact_end(void)
{}
+static inline void delayacct_cow_start(void)
+{}
+static inline void delayacct_cow_end(void)
+{}
#endif /* CONFIG_TASK_DELAY_ACCT */
diff --git a/include/uapi/linux/taskstats.h b/include/uapi/linux/taskstats.h
index 12327d32378f..cfb9a2e0e95a 100644
--- a/include/uapi/linux/taskstats.h
+++ b/include/uapi/linux/taskstats.h
@@ -34,7 +34,7 @@
*/
-#define TASKSTATS_VERSION 11
+#define TASKSTATS_VERSION 12
#define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN
* in linux/sched.h */
@@ -176,6 +176,10 @@ struct taskstats {
/* Delay waiting for memory compact */
__u64 compact_count;
__u64 compact_delay_total;
+
+ /* Delay waiting for cow */
+ __u64 cow_count;
+ __u64 cow_delay_total;
};
diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index 2c1e18f7c5cf..c9a833270fe0 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -177,11 +177,14 @@ int delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
d->thrashing_delay_total = (tmp < d->thrashing_delay_total) ? 0 : tmp;
tmp = d->compact_delay_total + tsk->delays->compact_delay;
d->compact_delay_total = (tmp < d->compact_delay_total) ? 0 : tmp;
+ tmp = d->cow_delay_total + tsk->delays->cow_delay;
+ d->cow_delay_total = (tmp < d->cow_delay_total) ? 0 : tmp;
d->blkio_count += tsk->delays->blkio_count;
d->swapin_count += tsk->delays->swapin_count;
d->freepages_count += tsk->delays->freepages_count;
d->thrashing_count += tsk->delays->thrashing_count;
d->compact_count += tsk->delays->compact_count;
+ d->cow_count += tsk->delays->cow_count;
raw_spin_unlock_irqrestore(&tsk->delays->lock, flags);
return 0;
@@ -249,3 +252,16 @@ void __delayacct_compact_end(void)
¤t->delays->compact_delay,
¤t->delays->compact_count);
}
+
+void __delayacct_cow_start(void)
+{
+ current->delays->cow_start = local_clock();
+}
+
+void __delayacct_cow_end(void)
+{
+ delayacct_end(¤t->delays->lock,
+ ¤t->delays->cow_start,
+ ¤t->delays->cow_delay,
+ ¤t->delays->cow_count);
+}
diff --git a/mm/memory.c b/mm/memory.c
index 4499cf09c21f..4111f97c91a0 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3006,6 +3006,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)
int page_copied = 0;
struct mmu_notifier_range range;
+ delayacct_cow_start();
+
if (unlikely(anon_vma_prepare(vma)))
goto oom;
@@ -3030,6 +3032,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)
put_page(new_page);
if (old_page)
put_page(old_page);
+
+ delayacct_cow_end();
return 0;
}
}
@@ -3128,12 +3132,16 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)
free_swap_cache(old_page);
put_page(old_page);
}
+
+ delayacct_cow_end();
return page_copied ? VM_FAULT_WRITE : 0;
oom_free_new:
put_page(new_page);
oom:
if (old_page)
put_page(old_page);
+
+ delayacct_cow_end();
return VM_FAULT_OOM;
}
diff --git a/tools/accounting/getdelays.c b/tools/accounting/getdelays.c
index 11e86739456d..0f6e4831a77b 100644
--- a/tools/accounting/getdelays.c
+++ b/tools/accounting/getdelays.c
@@ -207,6 +207,8 @@ static void print_delayacct(struct taskstats *t)
"THRASHING%12s%15s%15s\n"
" %15llu%15llu%15llums\n"
"COMPACT %12s%15s%15s\n"
+ " %15llu%15llu%15llums\n"
+ "COW %15s%15s%15s\n"
" %15llu%15llu%15llums\n",
"count", "real total", "virtual total",
"delay total", "delay average",
@@ -234,7 +236,11 @@ static void print_delayacct(struct taskstats *t)
"count", "delay total", "delay average",
(unsigned long long)t->compact_count,
(unsigned long long)t->compact_delay_total,
- average_ms(t->compact_delay_total, t->compact_count));
+ average_ms(t->compact_delay_total, t->compact_count),
+ "count", "delay total", "delay average",
+ (unsigned long long)t->cow_count,
+ (unsigned long long)t->cow_delay_total,
+ average_ms(t->cow_delay_total, t->cow_count));
}
static void task_context_switch_counts(struct taskstats *t)
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] delayacct: track delays from COW
2022-03-22 11:04 [PATCH] delayacct: track delays from COW cgel.zte
@ 2022-03-23 8:49 ` David Hildenbrand
2022-03-23 9:05 ` CGEL
2022-04-06 7:37 ` CGEL
0 siblings, 2 replies; 5+ messages in thread
From: David Hildenbrand @ 2022-03-23 8:49 UTC (permalink / raw)
To: cgel.zte, akpm
Cc: bsingharora, linux-kernel, linux-mm, Yang Yang, Ran Xiaokai
On 22.03.22 12:04, cgel.zte@gmail.com wrote:
> From: Yang Yang <yang.yang29@zte.com.cn>
>
> Delay accounting does not track the delay of COW. When tasks trigger
> much COW, it may spend a amount of time waiting for it. To get the
> impact of tasks in COW, measure the delay when it happens. This
> could help users to do tunnings, such as decide whether to use
> ksm or not.
>
> Also update tools/accounting/getdelays.c:
>
> / # ./getdelays -dl -p 231
> print delayacct stats ON
> listen forever
> PID 231
>
> CPU count real total virtual total delay total delay average
> 6247 1859000000 2154070021 1674255063 0.268ms
> IO count delay total delay average
> 0 0 0ms
> SWAP count delay total delay average
> 0 0 0ms
> RECLAIM count delay total delay average
> 0 0 0ms
> THRASHING count delay total delay average
> 0 0 0ms
> COMPACT count delay total delay average
> 3 72758 0ms
> COW count delay total delay average
> 3635 271567604 0ms
You should also update Documentation/accounting/delay-accounting.rst
most probably.
Overall LGTM and this might be of value not only for KSM but for anybody
using fork(). There will be collisions with [1], especially [2], which I
want to get in -next early after we have v5.18-rc1 (after rebasing [1]
on top of this).
We'll have to decide if we want to also account hugetlb wp code
(hugetlb_cow), and if we want to account "unsharing" here as well under
cow (I tend to say that we want to for simplicity). For THP, we only
split and don't copy, so there isn't anything to account.
[1] https://lore.kernel.org/r/20220315104741.63071-1-david@redhat.com
[2] https://lore.kernel.org/r/20220315104741.63071-14-david@redhat.com
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] delayacct: track delays from COW
2022-03-23 8:49 ` David Hildenbrand
@ 2022-03-23 9:05 ` CGEL
2022-04-06 7:37 ` CGEL
1 sibling, 0 replies; 5+ messages in thread
From: CGEL @ 2022-03-23 9:05 UTC (permalink / raw)
To: David Hildenbrand
Cc: akpm, bsingharora, linux-kernel, linux-mm, Yang Yang, Ran Xiaokai
On Wed, Mar 23, 2022 at 09:49:46AM +0100, David Hildenbrand wrote:
> On 22.03.22 12:04, cgel.zte@gmail.com wrote:
> > From: Yang Yang <yang.yang29@zte.com.cn>
> >
> > Delay accounting does not track the delay of COW. When tasks trigger
> > much COW, it may spend a amount of time waiting for it. To get the
> > impact of tasks in COW, measure the delay when it happens. This
> > could help users to do tunnings, such as decide whether to use
> > ksm or not.
> >
> > Also update tools/accounting/getdelays.c:
> >
> > / # ./getdelays -dl -p 231
> > print delayacct stats ON
> > listen forever
> > PID 231
> >
> > CPU count real total virtual total delay total delay average
> > 6247 1859000000 2154070021 1674255063 0.268ms
> > IO count delay total delay average
> > 0 0 0ms
> > SWAP count delay total delay average
> > 0 0 0ms
> > RECLAIM count delay total delay average
> > 0 0 0ms
> > THRASHING count delay total delay average
> > 0 0 0ms
> > COMPACT count delay total delay average
> > 3 72758 0ms
> > COW count delay total delay average
> > 3635 271567604 0ms
>
> You should also update Documentation/accounting/delay-accounting.rst
> most probably.
I will update this documentation immediately if this patch is merged.
> Overall LGTM and this might be of value not only for KSM but for anybody
> using fork(). There will be collisions with [1], especially [2], which I
> want to get in -next early after we have v5.18-rc1 (after rebasing [1]
> on top of this).
>
> We'll have to decide if we want to also account hugetlb wp code
> (hugetlb_cow), and if we want to account "unsharing" here as well under
> cow (I tend to say that we want to for simplicity). For THP, we only
> split and don't copy, so there isn't anything to account.
>
Thanks for your reminding, we will work on that too.
> [1] https://lore.kernel.org/r/20220315104741.63071-1-david@redhat.com
> [2] https://lore.kernel.org/r/20220315104741.63071-14-david@redhat.com
>
> --
> Thanks,
>
> David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] delayacct: track delays from COW
2022-03-23 8:49 ` David Hildenbrand
2022-03-23 9:05 ` CGEL
@ 2022-04-06 7:37 ` CGEL
2022-04-08 7:31 ` David Hildenbrand
1 sibling, 1 reply; 5+ messages in thread
From: CGEL @ 2022-04-06 7:37 UTC (permalink / raw)
To: David Hildenbrand
Cc: akpm, bsingharora, linux-kernel, linux-mm, Yang Yang, Ran Xiaokai
On Wed, Mar 23, 2022 at 09:49:46AM +0100, David Hildenbrand wrote:
> On 22.03.22 12:04, cgel.zte@gmail.com wrote:
> > From: Yang Yang <yang.yang29@zte.com.cn>
> >
> > Delay accounting does not track the delay of COW. When tasks trigger
> > much COW, it may spend a amount of time waiting for it. To get the
> > impact of tasks in COW, measure the delay when it happens. This
> > could help users to do tunnings, such as decide whether to use
> > ksm or not.
> >
> > Also update tools/accounting/getdelays.c:
> >
> > / # ./getdelays -dl -p 231
> > print delayacct stats ON
> > listen forever
> > PID 231
> >
> > CPU count real total virtual total delay total delay average
> > 6247 1859000000 2154070021 1674255063 0.268ms
> > IO count delay total delay average
> > 0 0 0ms
> > SWAP count delay total delay average
> > 0 0 0ms
> > RECLAIM count delay total delay average
> > 0 0 0ms
> > THRASHING count delay total delay average
> > 0 0 0ms
> > COMPACT count delay total delay average
> > 3 72758 0ms
> > COW count delay total delay average
> > 3635 271567604 0ms
>
> You should also update Documentation/accounting/delay-accounting.rst
> most probably.
>
> Overall LGTM and this might be of value not only for KSM but for anybody
> using fork(). There will be collisions with [1], especially [2], which I
> want to get in -next early after we have v5.18-rc1 (after rebasing [1]
> on top of this).
>
> We'll have to decide if we want to also account hugetlb wp code
> (hugetlb_cow), and if we want to account "unsharing" here as well under
> cow (I tend to say that we want to for simplicity). For THP, we only
> split and don't copy, so there isn't anything to account.
>
As for simplicity, what about account "PAGECOPY" instead of "COW"?
"PAGECOPY" include COW and unsharing. And we may also account hugetlb
wp in follow-up patches, based on this patch is sufficient reviewed.
> [1] https://lore.kernel.org/r/20220315104741.63071-1-david@redhat.com
> [2] https://lore.kernel.org/r/20220315104741.63071-14-david@redhat.com
>
> --
> Thanks,
>
> David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] delayacct: track delays from COW
2022-04-06 7:37 ` CGEL
@ 2022-04-08 7:31 ` David Hildenbrand
0 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2022-04-08 7:31 UTC (permalink / raw)
To: CGEL; +Cc: akpm, bsingharora, linux-kernel, linux-mm, Yang Yang, Ran Xiaokai
On 06.04.22 09:37, CGEL wrote:
> On Wed, Mar 23, 2022 at 09:49:46AM +0100, David Hildenbrand wrote:
>> On 22.03.22 12:04, cgel.zte@gmail.com wrote:
>>> From: Yang Yang <yang.yang29@zte.com.cn>
>>>
>>> Delay accounting does not track the delay of COW. When tasks trigger
>>> much COW, it may spend a amount of time waiting for it. To get the
>>> impact of tasks in COW, measure the delay when it happens. This
>>> could help users to do tunnings, such as decide whether to use
>>> ksm or not.
>>>
>>> Also update tools/accounting/getdelays.c:
>>>
>>> / # ./getdelays -dl -p 231
>>> print delayacct stats ON
>>> listen forever
>>> PID 231
>>>
>>> CPU count real total virtual total delay total delay average
>>> 6247 1859000000 2154070021 1674255063 0.268ms
>>> IO count delay total delay average
>>> 0 0 0ms
>>> SWAP count delay total delay average
>>> 0 0 0ms
>>> RECLAIM count delay total delay average
>>> 0 0 0ms
>>> THRASHING count delay total delay average
>>> 0 0 0ms
>>> COMPACT count delay total delay average
>>> 3 72758 0ms
>>> COW count delay total delay average
>>> 3635 271567604 0ms
>>
>> You should also update Documentation/accounting/delay-accounting.rst
>> most probably.
>>
>> Overall LGTM and this might be of value not only for KSM but for anybody
>> using fork(). There will be collisions with [1], especially [2], which I
>> want to get in -next early after we have v5.18-rc1 (after rebasing [1]
>> on top of this).
>>
>> We'll have to decide if we want to also account hugetlb wp code
>> (hugetlb_cow), and if we want to account "unsharing" here as well under
>> cow (I tend to say that we want to for simplicity). For THP, we only
>> split and don't copy, so there isn't anything to account.
>>
> As for simplicity, what about account "PAGECOPY" instead of "COW"?
> "PAGECOPY" include COW and unsharing. And we may also account hugetlb
> wp in follow-up patches, based on this patch is sufficient reviewed.
PAGECOPY might be too generic. You actually want to express "potentially
shared page was copied by the write-fault handler while it was write
protected".
do_wp_page()->wp_page_copy()
Maybe simply "WP_COPY" as a prefix ("Write-protect copy") ?
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-08 7:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-22 11:04 [PATCH] delayacct: track delays from COW cgel.zte
2022-03-23 8:49 ` David Hildenbrand
2022-03-23 9:05 ` CGEL
2022-04-06 7:37 ` CGEL
2022-04-08 7:31 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).