Skip to contentSkip to conversation

introduce new perf-script page-reclaim

PATCH Superseded Yafang Shao 3 participants 8 messages Sep 18, 2019 – Sep 26, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover introduce new perf-script page-reclaim

A new perf script page-reclaim is introduced in this patchset. This new script is used to report the page reclaim details. The possible usage of this script is as bellow,
- identify latency spike caused by direct reclaim
- whehter the latency spike is relevant with pageout
- why is page reclaim requested, i.e. whether it is because of memory fragmentation
- page reclaim efficiency
etc
In the future we may also enhance it to analyze the memcg reclaim.

Bellow is how to use this script,
# Record, one of the following
$ perf record -e 'vmscan:mm_vmscan_*' ./workload $ perf script record page-reclaim

# Report
$ perf script report page-reclaim

# Report per process latency
$ perf script report page-reclaim -- -p

# Report per process latency details. At what time and how long it # stalls at each time.
$ perf script report page-reclaim -- -v

An example of the script's report,

    $ perf script report page-reclaim
    Direct reclaims: 4924
    Direct latency (ms)        total         max         avg         min
                          177823.211    6378.977      36.114       0.051
    Direct file reclaimed 22920
    Direct file scanned 28306
    Direct file sync write I/O 0
    Direct file async write I/O 0
    Direct anon reclaimed 212567
    Direct anon scanned 1446854
    Direct anon sync write I/O 0
    Direct anon async write I/O 278325
    Direct order      0     1     3
                   4870    23    31
    Wake kswapd requests 716
    Wake order      0     1
                  715     1
    Kswapd reclaims: 9
    Kswapd latency (ms)        total         max         avg         min
                           86353.046   42128.816    9594.783     120.736
    Kswapd file reclaimed 366461
    Kswapd file scanned 369554
    Kswapd file sync write I/O 0
    Kswapd file async write I/O 0
    Kswapd anon reclaimed 362594
    Kswapd anon scanned 693938
    Kswapd anon sync write I/O 0
    Kswapd anon async write I/O 330663
    Kswapd order      0     1     3
                      3     1     5
    Kswapd re-wakes 705

    Per process latency (ms):
         pid[comm]             total         max         avg         min
               timestamp  latency(ns)
           1[systemd]        276.764     248.933       21.29       0.293
           3406860552338: 16819800
           3406877381650: 5532855
           3407458799399: 929517
           3407459796042: 916682
           3407460763220: 418989
           3407461250236: 332355
           3407461637534: 401731
           3407462092234: 449219
           3407462605855: 292857
           3407462952343: 372700
           3407463364947: 414880
           3407463829547: 949162
           3407464813883: 248933444
         163[kswapd0]      86353.046   42128.816    9594.783     120.736
           3357637025977: 1026962745
           3358915619888: 41268642175
           3400239664127: 42128816204
           3443784780373: 679641989
           3444847948969: 120735792
           3445001978784: 342713657
           3445835850664: 316851589
           3446865035476: 247457873
           3449355401352: 221223878
          ...

This script must be in sync with bellow vmscan tracepoints,
mm_vmscan_direct_reclaim_begin mm_vmscan_direct_reclaim_end mm_vmscan_kswapd_wake mm_vmscan_kswapd_sleep mm_vmscan_wakeup_kswapd mm_vmscan_lru_shrink_inactive mm_vmscan_writepage

Currently there's no easy way to make perf scripts in sync with tracepoints. One possible way is to run perf's tests regularly, another way is once we changes the definitions of tracepoints we must keep in mind that the perf scripts which are using these tracepoints must be changed as well. So I add some comment for the new introduced page-reclaim script as a reminder.

Yafang Shao (2):
perf script python: integrate page reclaim analyze script tracing, vmscan: add comments for perf script page-reclaim

 include/trace/events/vmscan.h                     |  15 +-
 tools/perf/scripts/python/bin/page-reclaim-record |   2 +
 tools/perf/scripts/python/bin/page-reclaim-report |   4 +
 tools/perf/scripts/python/page-reclaim.py         | 378 ++++++++++++++++++++++
 4 files changed, 398 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/scripts/python/bin/page-reclaim-record
 create mode 100644 tools/perf/scripts/python/bin/page-reclaim-report
 create mode 100644 tools/perf/scripts/python/page-reclaim.py
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 perf script python: integrate page reclaim analyze script

A new perf script page-reclaim is introduced in this patch. This new script is used to report the page reclaim details. The possible usage of this script is as bellow,
- identify latency spike caused by direct reclaim
- whehter the latency spike is relevant with pageout
- why is page reclaim requested, i.e. whether it is because of memory fragmentation
- page reclaim efficiency
etc
In the future we may also enhance it to analyze the memcg reclaim.

Bellow is how to use this script,
# Record, one of the following
$ perf record -e 'vmscan:mm_vmscan_*' ./workload $ perf script record page-reclaim

# Report
$ perf script report page-reclaim

# Report per process latency
$ perf script report page-reclaim -- -p

# Report per process latency details. At what time and how long it # stalls at each time.
$ perf script report page-reclaim -- -v

An example of doing mmtests,

    $ perf script report page-reclaim
    Direct reclaims: 4924
    Direct latency (ms)        total         max         avg         min
        	          177823.211    6378.977      36.114       0.051
    Direct file reclaimed 22920
    Direct file scanned 28306
    Direct file sync write I/O 0
    Direct file async write I/O 0
    Direct anon reclaimed 212567
    Direct anon scanned 1446854
    Direct anon sync write I/O 0
    Direct anon async write I/O 278325
    Direct order      0     1     3
        	   4870    23    31
    Wake kswapd requests 716
    Wake order      0     1
        	  715     1
    Kswapd reclaims: 9
    Kswapd latency (ms)        total         max         avg         min
       	                   86353.046   42128.816    9594.783     120.736
    Kswapd file reclaimed 366461
    Kswapd file scanned 369554
    Kswapd file sync write I/O 0
    Kswapd file async write I/O 0
    Kswapd anon reclaimed 362594
    Kswapd anon scanned 693938
    Kswapd anon sync write I/O 0
    Kswapd anon async write I/O 330663
    Kswapd order      0     1     3
       	              3     1     5
    Kswapd re-wakes 705

    $ perf script report page-reclaim -- -p
    # besides the above basic output, it will also summary per task
    # latency
    Per process latency (ms):
         pid[comm]             total         max         avg         min
           1[systemd]        276.764     248.933       21.29       0.293
         163[kswapd0]      86353.046   42128.816    9594.783     120.736
        7241[bash]         12787.749     859.091      94.028       0.163
        1592[master]          81.604      70.811      27.201       2.906
        1595[pickup]         496.162     374.168     165.387      14.478
        1098[auditd]           19.32       19.32       19.32       19.32
        1120[irqbalance]    5232.331    1386.352     158.555       0.169
        7236[usemem]        79649.04    1763.281      24.921       0.051
        1605[sshd]           1344.41     645.125      34.472        0.16
        7238[bash]           1158.92    1023.307     231.784       0.067
        7239[bash]         15100.776     993.447      82.069       0.145
        ...

    $ per script report page-reclaim -- -v
    # Besides the basic output, it will asl show per task latency details
    Per process latency (ms):
         pid[comm]             total         max         avg         min
               timestamp  latency(ns)
           1[systemd]        276.764     248.933       21.29       0.293
           3406860552338: 16819800
           3406877381650: 5532855
           3407458799399: 929517
           3407459796042: 916682
           3407460763220: 418989
           3407461250236: 332355
           3407461637534: 401731
           3407462092234: 449219
           3407462605855: 292857
           3407462952343: 372700
           3407463364947: 414880
           3407463829547: 949162
           3407464813883: 248933444
         163[kswapd0]      86353.046   42128.816    9594.783     120.736
           3357637025977: 1026962745
           3358915619888: 41268642175
           3400239664127: 42128816204
           3443784780373: 679641989
           3444847948969: 120735792
           3445001978784: 342713657
           3445835850664: 316851589
           3446865035476: 247457873
           3449355401352: 221223878
          ...

This script must be in sync with bellow vmscan tracepoints,
mm_vmscan_direct_reclaim_begin mm_vmscan_direct_reclaim_end mm_vmscan_kswapd_wake mm_vmscan_kswapd_sleep mm_vmscan_wakeup_kswapd mm_vmscan_lru_shrink_inactive mm_vmscan_writepage

---
 tools/perf/scripts/python/bin/page-reclaim-record |   2 +
 tools/perf/scripts/python/bin/page-reclaim-report |   4 +
 tools/perf/scripts/python/page-reclaim.py         | 378 ++++++++++++++++++++++
 3 files changed, 384 insertions(+)
 create mode 100644 tools/perf/scripts/python/bin/page-reclaim-record
 create mode 100644 tools/perf/scripts/python/bin/page-reclaim-report
 create mode 100644 tools/perf/scripts/python/page-reclaim.py
tools/perf/scripts/python/bin/page-reclaim-record new file +2 -0
new file mode 100644
index 0000000..5a16a23
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -e vmscan:mm_vmscan_direct_reclaim_begin -e vmscan:mm_vmscan_direct_reclaim_end -e vmscan:mm_vmscan_kswapd_wake -e vmscan:mm_vmscan_kswapd_sleep -e vmscan:mm_vmscan_wakeup_kswapd -e vmscan:mm_vmscan_lru_shrink_inactive -e vmscan:mm_vmscan_writepage $@
tools/perf/scripts/python/bin/page-reclaim-report new file +4 -0
new file mode 100644
index 0000000..b74e197
@@ -0,0 +1,4 @@
+#!/bin/bash
+#description: display page reclaim details
+#args: [-h] [-p] [-v]
+perf script -s "$PERF_EXEC_PATH"/scripts/python/page-reclaim.py $@
tools/perf/scripts/python/page-reclaim.py new file +378 -0

378 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 2/2 tracing, vmscan: add comments for perf script page-reclaim

In reply to Yafang Shao

Currently there's no easy way to make perf scripts in sync with tracepoints. One possible way is to run perf's tests regularly, another way is once we changes the definitions of tracepoints we must keep in mind that the perf scripts which are using these tracepoints must be changed as well. So I add this comment for the new introduced page-reclaim script as a reminder.

---
 include/trace/events/vmscan.h | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
include/trace/events/vmscan.h +14 -1
index a5ab297..f0447ad 100644
@@ -1,4 +1,17 @@
-/* SPDX-License-Identifier: GPL-2.0 */
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Bellow tracepoints are used by perf script page-reclaim:
+ *	mm_vmscan_direct_reclaim_begin
+ *	mm_vmscan_direct_reclaim_end
+ *	mm_vmscan_kswapd_wake
+ *	mm_vmscan_kswapd_sleep
+ *	mm_vmscan_wakeup_kswapd
+ *	mm_vmscan_lru_shrink_inactive
+ *	mm_vmscan_writepage
+ * We must keep the definitions of these tracepoints in sync with the perf
+ * script page-reclaim.
+ */
+
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM vmscan
 
Signature · 1 line
1.8.3.1
#7 lore raw

Re: [PATCH 2/2] tracing, vmscan: add comments for perf script page-reclaim

Quoted 8 lines · Yafang Shao

Currently there's no easy way to make perf scripts in sync with tracepoints. One possible way is to run perf's tests regularly, another way is once we changes the definitions of tracepoints we must keep in mind that the perf scripts which are using these tracepoints must be changed as well. So I add this comment for the new introduced page-reclaim script as a reminder.

This seems like the tail wagging the dog to me.  If we added this to every tp defn that is used by a perf perl/python script the tp headers would be littered with such comments.

#2 lore raw

Re: [PATCH 1/2] perf script python: integrate page reclaim analyze script

In reply to Yafang Shao
Quoted 16 lines · Yafang Shao

A new perf script page-reclaim is introduced in this patch. This new script is used to report the page reclaim details. The possible usage of this script is as bellow,
- identify latency spike caused by direct reclaim
- whehter the latency spike is relevant with pageout
- why is page reclaim requested, i.e. whether it is because of memory fragmentation
- page reclaim efficiency
etc
In the future we may also enhance it to analyze the memcg reclaim.

Bellow is how to use this script,
# Record, one of the following
$ perf record -e 'vmscan:mm_vmscan_*' ./workload $ perf script record page-reclaim

Quoted 5 lines

# Report
$ perf script report page-reclaim

# Report per process latency
$ perf script report page-reclaim -- -p

I tested it with global-dhp__pagereclaim-performance from mmtests and got what appears to be reasonable results and the output looks correct and useful.  However I'm not a vm expert so I can't comment further.  Hopefully someone on linux-mm can give more specific feedback.

There is one issue with Python3,  see below.  I didn't test with Python2.

Quoted 14 lines
tools/perf/scripts/python/page-reclaim.py new file +13 -0
+	@classmethod
+	def shrink_inactive(cls, pid, scanned, reclaimed, flags):
+		event = cls.events.get(pid)
+		if event and event.tracing():
+			# RECLAIM_WB_ANON 0x1
+			# RECLAIM_WB_FILE 0x2
+			_type = (flags & 0x2) >> 1
+			event.process_lru(lru[_type], scanned, reclaimed)
+
+	@classmethod
+	def writepage(cls, pid, flags):
+		event = cls.events.get(pid)
+		if event and event.tracing():

tools/perf/scripts/python/page-reclaim.py line 217

Quoted 10 lines
tools/perf/scripts/python/page-reclaim.py new file +10 -0
+			# RECLAIM_WB_ANON 0x1
+			# RECLAIM_WB_FILE 0x2
+			# RECLAIM_WB_SYNC 0x4
+			# RECLAIM_WB_ASYNC 0x8
+			_type = (flags & 0x2) >> 1
+			_io = (flags & 0x4) >> 2
+
+			event.process_writepage(lru[_type], sync_io[_io])
+
+        @classmethod

Space indentation on line above.  For python3 this results in:

  File "tools/perf/scripts/python/page-reclaim.py", line 217 @classmethod
               ^
TabError: inconsistent use of tabs and spaces in indentation

tools/perf/scripts/python/page-reclaim.py line 224

Quoted 7 lines
tools/perf/scripts/python/page-reclaim.py new file +7 -0
+	def iterate_proc(cls):
+		if show_opt != Show.DEFAULT:
+			print("\nPer process latency (ms):")
+			print_proc_latency(latency_metric, 'pid', '[comm]')
+
+			if show_opt == Show.VERBOSE:
+				print("%20s  %s" % ('timestamp','latency(ns)'))

Thanks

Tony

#3 lore raw

Re: [PATCH 1/2] perf script python: integrate page reclaim analyze script

Quoted 20 lines · Tony Jones
Quoted 19 lines · Yafang Shao

A new perf script page-reclaim is introduced in this patch. This new script is used to report the page reclaim details. The possible usage of this script is as bellow,
- identify latency spike caused by direct reclaim
- whehter the latency spike is relevant with pageout
- why is page reclaim requested, i.e. whether it is because of memory fragmentation
- page reclaim efficiency
etc
In the future we may also enhance it to analyze the memcg reclaim.

Bellow is how to use this script,
# Record, one of the following
$ perf record -e 'vmscan:mm_vmscan_*' ./workload $ perf script record page-reclaim

# Report
$ perf script report page-reclaim

Quoted 7 lines
Quoted 2 lines

# Report per process latency
$ perf script report page-reclaim -- -p

I tested it with global-dhp__pagereclaim-performance from mmtests and got what appears to be reasonable results and the output looks correct and useful.  However I'm not a vm expert so I can't comment further.  Hopefully someone on linux-mm can give more specific feedback.

There is one issue with Python3,  see below.  I didn't test with Python2.

Ok, I guess this wasn't actually tested with Python3 as itervalues() is Python2 only. Any scripts need to work with both Python2.6+ and Python3.

# perf script -i /tmp/perf.out -s page-reclaim.py -- -p
...

Traceback (most recent call last):
File "page-reclaim.py", line 305, in trace_end

    i.display_proc(),

File "page-reclaim.py", line 268, in display_proc
print_proc_latency(sorted(self.stat.stats['latency'].itervalues(),
AttributeError: 'dict' object has no attribute 'itervalues' Fatal Python error: problem in Python trace event handler

Use a try/except to handle this.

Thanks

Tony

#4 lore raw

Re: [PATCH 1/2] perf script python: integrate page reclaim analyze script

Quoted 37 lines · Tony Jones
Quoted 20 lines · Tony Jones
Quoted 19 lines · Yafang Shao

A new perf script page-reclaim is introduced in this patch. This new script is used to report the page reclaim details. The possible usage of this script is as bellow,
- identify latency spike caused by direct reclaim
- whehter the latency spike is relevant with pageout
- why is page reclaim requested, i.e. whether it is because of memory fragmentation
- page reclaim efficiency
etc
In the future we may also enhance it to analyze the memcg reclaim.

Bellow is how to use this script,
# Record, one of the following
$ perf record -e 'vmscan:mm_vmscan_*' ./workload $ perf script record page-reclaim

# Report
$ perf script report page-reclaim

Quoted 7 lines
Quoted 2 lines

# Report per process latency
$ perf script report page-reclaim -- -p

I tested it with global-dhp__pagereclaim-performance from mmtests and got what appears to be reasonable results and the output looks correct and useful. However I'm not a vm expert so I can't comment further. Hopefully someone on linux-mm can give more specific feedback.

There is one issue with Python3, see below. I didn't test with Python2.

Ok, I guess this wasn't actually tested with Python3 as itervalues() is Python2 only. Any scripts need to work with both Python2.6+ and Python3.

# perf script -i /tmp/perf.out -s page-reclaim.py -- -p
...

Traceback (most recent call last):
File "page-reclaim.py", line 305, in trace_end

Quoted 8 lines
    i.display_proc(),

File "page-reclaim.py", line 268, in display_proc
print_proc_latency(sorted(self.stat.stats['latency'].itervalues(),
AttributeError: 'dict' object has no attribute 'itervalues' Fatal Python error: problem in Python trace event handler

Use a try/except to handle this.

Hi Tony,

Thanks for your review.
I only verified it with python2.
I will improve it to make it work with both python2.6+ and python3.

Thanks
Yafang

#5 lore raw

Re: [PATCH 1/2] perf script python: integrate page reclaim analyze script

In reply to Tony Jones
Quoted 18 lines · Tony Jones
Quoted 16 lines · Yafang Shao

A new perf script page-reclaim is introduced in this patch. This new script is used to report the page reclaim details. The possible usage of this script is as bellow,
- identify latency spike caused by direct reclaim
- whehter the latency spike is relevant with pageout
- why is page reclaim requested, i.e. whether it is because of memory fragmentation
- page reclaim efficiency
etc
In the future we may also enhance it to analyze the memcg reclaim.

Bellow is how to use this script,
# Record, one of the following
$ perf record -e 'vmscan:mm_vmscan_*' ./workload $ perf script record page-reclaim

Quoted 9 lines
Quoted 5 lines

# Report
$ perf script report page-reclaim

# Report per process latency
$ perf script report page-reclaim -- -p

I tested it with global-dhp__pagereclaim-performance from mmtests and got what appears to be reasonable results and the output looks correct and useful. However I'm not a vm expert so I can't comment further. Hopefully someone on linux-mm can give more specific feedback.

+ Mel

Hi Mel,

This is motivated by Documentation/trace/postprocess/trace-vmscan-postprocess.pl created by you.
Could you pls. help take a look ?

Thanks
Yafang

Quoted 47 lines

There is one issue with Python3, see below. I didn't test with Python2.

Quoted 14 lines
tools/perf/scripts/python/page-reclaim.py new file +13 -0
+     @classmethod
+     def shrink_inactive(cls, pid, scanned, reclaimed, flags):
+             event = cls.events.get(pid)
+             if event and event.tracing():
+                     # RECLAIM_WB_ANON 0x1
+                     # RECLAIM_WB_FILE 0x2
+                     _type = (flags & 0x2) >> 1
+                     event.process_lru(lru[_type], scanned, reclaimed)
+
+     @classmethod
+     def writepage(cls, pid, flags):
+             event = cls.events.get(pid)
+             if event and event.tracing():

tools/perf/scripts/python/page-reclaim.py line 217

Quoted 10 lines
tools/perf/scripts/python/page-reclaim.py new file +10 -0
+                     # RECLAIM_WB_ANON 0x1
+                     # RECLAIM_WB_FILE 0x2
+                     # RECLAIM_WB_SYNC 0x4
+                     # RECLAIM_WB_ASYNC 0x8
+                     _type = (flags & 0x2) >> 1
+                     _io = (flags & 0x4) >> 2
+
+                     event.process_writepage(lru[_type], sync_io[_io])
+
+        @classmethod

Space indentation on line above. For python3 this results in:

File "tools/perf/scripts/python/page-reclaim.py", line 217

    @classmethod
               ^

TabError: inconsistent use of tabs and spaces in indentation

tools/perf/scripts/python/page-reclaim.py line 224

Quoted 7 lines
tools/perf/scripts/python/page-reclaim.py new file +7 -0
+     def iterate_proc(cls):
+             if show_opt != Show.DEFAULT:
+                     print("\nPer process latency (ms):")
+                     print_proc_latency(latency_metric, 'pid', '[comm]')
+
+                     if show_opt == Show.VERBOSE:
+                             print("%20s  %s" % ('timestamp','latency(ns)'))

Thanks

Tony