]> git.baikalelectronics.ru Git - kernel.git/commitdiff
delayacct: track delays from memory compact
authorwangyong <wang.yong12@zte.com.cn>
Thu, 20 Jan 2022 02:10:15 +0000 (18:10 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 20 Jan 2022 06:52:55 +0000 (08:52 +0200)
Delay accounting does not track the delay of memory compact.  When there
is not enough free memory, tasks can spend a amount of their time
waiting for compact.

To get the impact of tasks in direct memory compact, measure the delay
when allocating memory through memory compact.

Also update tools/accounting/getdelays.c:

    / # ./getdelays_next  -di -p 304
    print delayacct stats ON
    printing IO accounting
    PID     304

    CPU             count     real total  virtual total    delay total  delay average
                      277      780000000      849039485       18877296          0.068ms
    IO              count    delay total  delay average
                        0              0              0ms
    SWAP            count    delay total  delay average
                        0              0              0ms
    RECLAIM         count    delay total  delay average
                        5    11088812685           2217ms
    THRASHING       count    delay total  delay average
                        0              0              0ms
    COMPACT         count    delay total  delay average
                        3          72758              0ms
    watch: read=0, write=0, cancelled_write=0

Link: https://lkml.kernel.org/r/1638619795-71451-1-git-send-email-wang.yong12@zte.com.cn
Signed-off-by: wangyong <wang.yong12@zte.com.cn>
Reviewed-by: Jiang Xuexin <jiang.xuexin@zte.com.cn>
Reviewed-by: Zhang Wenya <zhang.wenya1@zte.com.cn>
Reviewed-by: Yang Yang <yang.yang29@zte.com.cn>
Reviewed-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/delayacct.h
include/uapi/linux/taskstats.h
kernel/delayacct.c
mm/page_alloc.c
tools/accounting/getdelays.c

index 435c3654a0ff074a60ceb7b755d1505bc47d3d1d..3e03d010bd2e3e207f0b59fd3570d4867a56941a 100644 (file)
@@ -42,8 +42,12 @@ struct task_delay_info {
        u64 thrashing_start;
        u64 thrashing_delay;    /* wait for thrashing page */
 
+       u64 compact_start;
+       u64 compact_delay;      /* wait for memory compact */
+
        u32 freepages_count;    /* total count of memory reclaim */
        u32 thrashing_count;    /* total count of thrash waits */
+       u32 compact_count;      /* total count of memory compact */
 };
 #endif
 
@@ -72,6 +76,8 @@ extern void __delayacct_thrashing_start(void);
 extern void __delayacct_thrashing_end(void);
 extern void __delayacct_swapin_start(void);
 extern void __delayacct_swapin_end(void);
+extern void __delayacct_compact_start(void);
+extern void __delayacct_compact_end(void);
 
 static inline void delayacct_tsk_init(struct task_struct *tsk)
 {
@@ -170,6 +176,24 @@ static inline void delayacct_swapin_end(void)
                __delayacct_swapin_end();
 }
 
+static inline void delayacct_compact_start(void)
+{
+       if (!static_branch_unlikely(&delayacct_key))
+               return;
+
+       if (current->delays)
+               __delayacct_compact_start();
+}
+
+static inline void delayacct_compact_end(void)
+{
+       if (!static_branch_unlikely(&delayacct_key))
+               return;
+
+       if (current->delays)
+               __delayacct_compact_end();
+}
+
 #else
 static inline void delayacct_init(void)
 {}
@@ -200,6 +224,10 @@ static inline void delayacct_swapin_start(void)
 {}
 static inline void delayacct_swapin_end(void)
 {}
+static inline void delayacct_compact_start(void)
+{}
+static inline void delayacct_compact_end(void)
+{}
 
 #endif /* CONFIG_TASK_DELAY_ACCT */
 
index ccbd0870932173a5f9315e40cc2c55da88530f83..12327d32378f5f62fa72a85bd6fa9db58d9cfb5f 100644 (file)
@@ -34,7 +34,7 @@
  */
 
 
-#define TASKSTATS_VERSION      10
+#define TASKSTATS_VERSION      11
 #define TS_COMM_LEN            32      /* should be >= TASK_COMM_LEN
                                         * in linux/sched.h */
 
@@ -172,6 +172,10 @@ struct taskstats {
 
        /* v10: 64-bit btime to avoid overflow */
        __u64   ac_btime64;             /* 64-bit begin time */
+
+       /* Delay waiting for memory compact */
+       __u64   compact_count;
+       __u64   compact_delay_total;
 };
 
 
index 97699848c1f0c421c961760358c7a521e7f71c62..c5e8cea9e05ff2139ffab2ac6f0e7a178c9f20ce 100644 (file)
@@ -155,10 +155,13 @@ int delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
        d->freepages_delay_total = (tmp < d->freepages_delay_total) ? 0 : tmp;
        tmp = d->thrashing_delay_total + tsk->delays->thrashing_delay;
        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;
        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;
        raw_spin_unlock_irqrestore(&tsk->delays->lock, flags);
 
        return 0;
@@ -213,3 +216,16 @@ void __delayacct_swapin_end(void)
                      &current->delays->swapin_delay,
                      &current->delays->swapin_count);
 }
+
+void __delayacct_compact_start(void)
+{
+       current->delays->compact_start = local_clock();
+}
+
+void __delayacct_compact_end(void)
+{
+       delayacct_end(&current->delays->lock,
+                     &current->delays->compact_start,
+                     &current->delays->compact_delay,
+                     &current->delays->compact_count);
+}
index c5952749ad40bdee7287e42eff1574c81928b536..635063f4967106d7bb7e56e02b407adce88a4632 100644 (file)
@@ -72,6 +72,7 @@
 #include <linux/padata.h>
 #include <linux/khugepaged.h>
 #include <linux/buffer_head.h>
+#include <linux/delayacct.h>
 #include <asm/sections.h>
 #include <asm/tlbflush.h>
 #include <asm/div64.h>
@@ -4348,6 +4349,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
                return NULL;
 
        psi_memstall_enter(&pflags);
+       delayacct_compact_start();
        noreclaim_flag = memalloc_noreclaim_save();
 
        *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac,
@@ -4355,6 +4357,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 
        memalloc_noreclaim_restore(noreclaim_flag);
        psi_memstall_leave(&pflags);
+       delayacct_compact_end();
 
        if (*compact_result == COMPACT_SKIPPED)
                return NULL;
index 5ef1c15e88ad2e3d4d4483a6a31c88770b939810..11e86739456d82bcd336d4d722573654bee4d517 100644 (file)
@@ -205,6 +205,8 @@ static void print_delayacct(struct taskstats *t)
               "RECLAIM  %12s%15s%15s\n"
               "      %15llu%15llu%15llums\n"
               "THRASHING%12s%15s%15s\n"
+              "      %15llu%15llu%15llums\n"
+              "COMPACT  %12s%15s%15s\n"
               "      %15llu%15llu%15llums\n",
               "count", "real total", "virtual total",
               "delay total", "delay average",
@@ -228,7 +230,11 @@ static void print_delayacct(struct taskstats *t)
               "count", "delay total", "delay average",
               (unsigned long long)t->thrashing_count,
               (unsigned long long)t->thrashing_delay_total,
-              average_ms(t->thrashing_delay_total, t->thrashing_count));
+              average_ms(t->thrashing_delay_total, t->thrashing_count),
+              "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));
 }
 
 static void task_context_switch_counts(struct taskstats *t)