lkml.org 
[lkml]   [2020]   [Mar]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] psi, tracepoint: introduce tracepoints for psi_memstall_{enter, leave}
Date
With the new parameter introduced in psi_memstall_{enter, leave} we can
get the specific type of memstal. To make it easier to use, we'd better
introduce tracepoints for them. Once these two tracepoints are added we
can easily use other tools like ebpf or bash script to collect the
memstall data and analyze.

Here's one example with bpftrace to measure application's latency.
tracepoint:sched:psi_memstall_enter
{
@start[tid, args->type] = nsecs
}

tracepoint:sched:psi_memstall_leave
{
@time[comm, args->type] = hist(nsecs - @start[tid, args->type]);
delete(@start[tid, args->type]);
}

Bellow is part of the result after producing some memory pressure.
@time[objdump, 7]:
[256K, 512K) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[512K, 1M) 0 | |
[1M, 2M) 0 | |
[2M, 4M) 0 | |
[4M, 8M) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|

@time[objdump, 6]:
[8K, 16K) 2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|

@time[objcopy, 7]:
[16K, 32K) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[32K, 64K) 0 | |
[64K, 128K) 0 | |
[128K, 256K) 0 | |
[256K, 512K) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|

@time[ld, 7]:
[4M, 8M) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[8M, 16M) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|

@time[khugepaged, 5]:
[4K, 8K) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[8K, 16K) 0 | |
[16K, 32K) 0 | |
[32K, 64K) 0 | |
[64K, 128K) 0 | |
[128K, 256K) 0 | |
[256K, 512K) 0 | |
[512K, 1M) 0 | |
[1M, 2M) 0 | |
[2M, 4M) 0 | |
[4M, 8M) 0 | |
[8M, 16M) 0 | |
[16M, 32M) 0 | |
[32M, 64M) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|

@time[kswapd0, 0]:
[16K, 32K) 1 |@@@@@ |
[32K, 64K) 0 | |
[64K, 128K) 0 | |
[128K, 256K) 0 | |
[256K, 512K) 0 | |
[512K, 1M) 0 | |
[1M, 2M) 0 | |
[2M, 4M) 0 | |
[4M, 8M) 0 | |
[8M, 16M) 1 |@@@@@ |
[16M, 32M) 10 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[32M, 64M) 9 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
[64M, 128M) 2 |@@@@@@@@@@ |
[128M, 256M) 2 |@@@@@@@@@@ |
[256M, 512M) 3 |@@@@@@@@@@@@@@@ |
[512M, 1G) 1 |@@@@@ |

@time[kswapd1, 0]:
[1M, 2M) 1 |@@@@ |
[2M, 4M) 2 |@@@@@@@@ |
[4M, 8M) 0 | |
[8M, 16M) 12 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[16M, 32M) 7 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
[32M, 64M) 5 |@@@@@@@@@@@@@@@@@@@@@ |
[64M, 128M) 5 |@@@@@@@@@@@@@@@@@@@@@ |
[128M, 256M) 3 |@@@@@@@@@@@@@ |
[256M, 512M) 1 |@@@@ |

@time[khugepaged, 1]:
[2M, 4M) 1 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|

With the builtin variable 'cgroup' of bpftrace we can also filter a
memcg and its descendants.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
include/trace/events/sched.h | 41 +++++++++++++++++++++++++++++++++++++++++
kernel/sched/psi.c | 8 ++++++++
2 files changed, 49 insertions(+)

diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index 420e80e..6aca996 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -7,8 +7,20 @@

#include <linux/sched/numa_balancing.h>
#include <linux/tracepoint.h>
+#include <linux/psi_types.h>
#include <linux/binfmts.h>

+#define show_psi_memstall_type(type) __print_symbolic(type, \
+ {MEMSTALL_KSWAPD, "MEMSTALL_KSWAPD"}, \
+ {MEMSTALL_RECLAIM_DIRECT, "MEMSTALL_RECLAIM_DIRECT"}, \
+ {MEMSTALL_RECLAIM_MEMCG, "MEMSTALL_RECLAIM_MEMCG"}, \
+ {MEMSTALL_RECLAIM_HIGH, "MEMSTALL_RECLAIM_HIGH"}, \
+ {MEMSTALL_KCOMPACTD, "MEMSTALL_KCOMPACTD"}, \
+ {MEMSTALL_COMPACT, "MEMSTALL_COMPACT"}, \
+ {MEMSTALL_WORKINGSET, "MEMSTALL_WORKINGSET"}, \
+ {MEMSTALL_PGLOCK, "MEMSTALL_PGLOCK"}, \
+ {MEMSTALL_MEMDELAY, "MEMSTALL_MEMDELAY"}, \
+ {MEMSTALL_SWAP, "MEMSTALL_SWAP"})
/*
* Tracepoint for calling kthread_stop, performed to end a kthread:
*/
@@ -625,6 +637,35 @@ static inline long __trace_sched_switch_state(bool preempt, struct task_struct *
TP_PROTO(struct root_domain *rd, bool overutilized),
TP_ARGS(rd, overutilized));

+DECLARE_EVENT_CLASS(psi_memstall_template,
+
+ TP_PROTO(int type),
+
+ TP_ARGS(type),
+
+ TP_STRUCT__entry(
+ __field(int, type)
+ ),
+
+ TP_fast_assign(
+ __entry->type = type;
+ ),
+
+ TP_printk("type=%s",
+ show_psi_memstall_type(__entry->type))
+);
+
+DEFINE_EVENT(psi_memstall_template, psi_memstall_enter,
+ TP_PROTO(int type),
+ TP_ARGS(type)
+);
+
+DEFINE_EVENT(psi_memstall_template, psi_memstall_leave,
+ TP_PROTO(int type),
+ TP_ARGS(type)
+);
+
+
#endif /* _TRACE_SCHED_H */

/* This part must be outside protection */
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 460f084..4c5a402 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -142,6 +142,8 @@
#include <linux/psi.h>
#include "sched.h"

+#include <trace/events/sched.h>
+
static int psi_bug __read_mostly;

DEFINE_STATIC_KEY_FALSE(psi_disabled);
@@ -822,6 +824,9 @@ void psi_memstall_enter(unsigned long *flags, enum memstall_types type)
*flags = current->flags & PF_MEMSTALL;
if (*flags)
return;
+
+ trace_psi_memstall_enter(type);
+
/*
* PF_MEMSTALL setting & accounting needs to be atomic wrt
* changes to the task's scheduling state, otherwise we can
@@ -852,6 +857,9 @@ void psi_memstall_leave(unsigned long *flags, enum memstall_types type)

if (*flags)
return;
+
+ trace_psi_memstall_leave(type);
+
/*
* PF_MEMSTALL clearing & accounting needs to be atomic wrt
* changes to the task's scheduling state, otherwise we could
--
1.8.3.1
\
 
 \ /
  Last update: 2020-03-26 12:13    [W:0.054 / U:0.712 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site