Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp981179imm; Wed, 1 Aug 2018 08:18:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc1wuGaXIlb3fv3vlfUrYNS9GMR8YvWX9xNzs8T/Of9m/NcEy1kIXvYZbzU3mZIqIvhsQ/V X-Received: by 2002:a17:902:46e:: with SMTP id 101-v6mr25409671ple.39.1533136718321; Wed, 01 Aug 2018 08:18:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533136718; cv=none; d=google.com; s=arc-20160816; b=Wmrbt2WImsAMGwcEj0LfAkVyvKK6TG9ctaV0PJXXTLB0o42gkMQLJWmNnZtnz3hnEu 6gfF0vQZaWV57A8c4fYjtiZOh47/RYw/z6e2yvxT93/4utRNG4NZ3U8DNpPAWXF/lrFi eT3Wq4LR57HMrEb2jqtqfzMN2y40hEcT9/kc59N4mTPDngoA7px5JNqZDV7vVi2mllSa UZjT9zeYvqVJGduV1EibG7Vfy8VcE1TLjmJNq1bBkhsZUpA+fc2enyvbCXgd5QRA8f46 t0KiAMgBgXaY/GXlLpC30teMiIKU3kRoFoKPML4Ye5ZeM57IW5vpGCN4uusdVUIMP8aA +Y+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=yu9UdCtaoT51hJzI6OxnWMzNlhzbw5nOYEshpoGdmog=; b=oyK1CNuZFKLTytabDgstRloLRCo87Q1c5g7wBqU5AUEV6CGtpravc6AE8xyvP8fZIr aheqZwrl3xqRCPDXmCWGoGAO3krPzj1ljIoZQiyx7qG0fBUIqLkCoFN9IW5EAs4NjUBa yFl3pUeNJNwS6cHkBAMSYs0n/PxlbeKYBukFSExfYYgZM9RKyuVRQiLVSzH6w5xk+9QF 9NsDdv1IOAnaZOyUNGYcyfm2704Dp8K9uvt/A+rsUIS4yk9HRduQUS0z35jg05Kx7/mT IxxyqzcG/hdGUIxiIQLJFCgfShBwj5+NP/i28SD6QzMsGZJUCKY9xDdxe+DI6JHAM60k vNUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=nU6nW8aD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8-v6si14014676pgp.548.2018.08.01.08.18.23; Wed, 01 Aug 2018 08:18:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=nU6nW8aD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389772AbeHARDd (ORCPT + 99 others); Wed, 1 Aug 2018 13:03:33 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:37377 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389762AbeHARDc (ORCPT ); Wed, 1 Aug 2018 13:03:32 -0400 Received: by mail-qt0-f193.google.com with SMTP id n6-v6so20281732qtl.4 for ; Wed, 01 Aug 2018 08:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yu9UdCtaoT51hJzI6OxnWMzNlhzbw5nOYEshpoGdmog=; b=nU6nW8aDdAj9ucMbCPQn1mbv/ysQnX3z6H7LWSDwFF1stR3Qyduqrk//UnYBPInyTF iPsLNFLpy0A63l3pkYzxk3ygw11H6zUd8UQHocl75N/IuftWxi21WVJvIJkLdi4PjNL+ cjwW7VDtq+y/njFgGDt0R2d0qw5rxP5lkUy7bFNkDuffOoYMJQGHqoIqnIKDP69un0rX sc7RaGWd4qpIjYNt1eachJPf48l5IO21txIkRAsorLweu+NuOtRvNfK/RpV9L0dSrG9V kawmB9mzco0i5athlAaWMOsR7nPiu0/wNpmcdjNrDzTkRRIZz3YBq3YE6rCA335/dDEc +pOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yu9UdCtaoT51hJzI6OxnWMzNlhzbw5nOYEshpoGdmog=; b=Mm+KUGNioRAeAgJMa4TtFVENocOtN+DE8CNdRQKPr1rtB7NMdK9Co8i0mLE47+lVCR /AMnW+wJPeIIq72d9uJuh9HNabAD0gxfhNWT8/6AiGODuiATFC7q7oDYClHTxFOdmp0c vstNJA7oKAfzwgthGLCqfG2Ff/ZD1SKSsKkl9cxj7FRyJAgjcoMiB9UjGSjz+iag/Bfo avIN00Pb643zLw3r0/9Dhs39ICo5kP8ImF1wUzt3PstSw7Qd79tZqx9nFB5eW/R3JDhY /SCAiqbUHYUmRkQo0hHjSd2IOvL2XrNgfjE5LDtkZ/jlRMjPhUOGp/s87MBcPMN0ZG9k D5JA== X-Gm-Message-State: AOUpUlEBsbrN+D5RGJ9HXWxvfW5v94lw3peVJwd2RyzZkOfIeEFp7DHP wTylR2A/ScsHBsOHDv442S0rJw== X-Received: by 2002:a0c:b888:: with SMTP id y8-v6mr23729437qvf.203.1533136640724; Wed, 01 Aug 2018 08:17:20 -0700 (PDT) Received: from localhost (216.49.36.201.res-cmts.bus.ptd.net. [216.49.36.201]) by smtp.gmail.com with ESMTPSA id c93-v6sm17611210qkh.90.2018.08.01.08.17.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Aug 2018 08:17:19 -0700 (PDT) From: Johannes Weiner To: Ingo Molnar , Peter Zijlstra , Andrew Morton , Linus Torvalds Cc: Tejun Heo , Suren Baghdasaryan , Daniel Drake , Vinayak Menon , Christopher Lameter , Mike Galbraith , Shakeel Butt , Peter Enderborg , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 3/9] delayacct: track delays from thrashing cache pages Date: Wed, 1 Aug 2018 11:19:52 -0400 Message-Id: <20180801151958.32590-4-hannes@cmpxchg.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801151958.32590-1-hannes@cmpxchg.org> References: <20180801151958.32590-1-hannes@cmpxchg.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Delay accounting already measures the time a task spends in direct reclaim and waiting for swapin, but in low memory situations tasks spend can spend a significant amount of their time waiting on thrashing page cache. This isn't tracked right now. To know the full impact of memory contention on an individual task, measure the delay when waiting for a recently evicted active cache page to read back into memory. Also update tools/accounting/getdelays.c: [hannes@computer accounting]$ sudo ./getdelays -d -p 1 print delayacct stats ON PID 1 CPU count real total virtual total delay total delay average 50318 745000000 847346785 400533713 0.008ms IO count delay total delay average 435 122601218 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 19 12621439 0ms Signed-off-by: Johannes Weiner --- include/linux/delayacct.h | 23 +++++++++++++++++++++++ include/uapi/linux/taskstats.h | 6 +++++- kernel/delayacct.c | 15 +++++++++++++++ mm/filemap.c | 11 +++++++++++ tools/accounting/getdelays.c | 8 +++++++- 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/include/linux/delayacct.h b/include/linux/delayacct.h index 5e335b6203f4..d3e75b3ba487 100644 --- a/include/linux/delayacct.h +++ b/include/linux/delayacct.h @@ -57,7 +57,12 @@ struct task_delay_info { u64 freepages_start; u64 freepages_delay; /* wait for memory reclaim */ + + u64 thrashing_start; + u64 thrashing_delay; /* wait for thrashing page */ + u32 freepages_count; /* total count of memory reclaim */ + u32 thrashing_count; /* total count of thrash waits */ }; #endif @@ -76,6 +81,8 @@ extern int __delayacct_add_tsk(struct taskstats *, struct task_struct *); extern __u64 __delayacct_blkio_ticks(struct task_struct *); extern void __delayacct_freepages_start(void); extern void __delayacct_freepages_end(void); +extern void __delayacct_thrashing_start(void); +extern void __delayacct_thrashing_end(void); static inline int delayacct_is_task_waiting_on_io(struct task_struct *p) { @@ -156,6 +163,18 @@ static inline void delayacct_freepages_end(void) __delayacct_freepages_end(); } +static inline void delayacct_thrashing_start(void) +{ + if (current->delays) + __delayacct_thrashing_start(); +} + +static inline void delayacct_thrashing_end(void) +{ + if (current->delays) + __delayacct_thrashing_end(); +} + #else static inline void delayacct_set_flag(int flag) {} @@ -182,6 +201,10 @@ static inline void delayacct_freepages_start(void) {} static inline void delayacct_freepages_end(void) {} +static inline void delayacct_thrashing_start(void) +{} +static inline void delayacct_thrashing_end(void) +{} #endif /* CONFIG_TASK_DELAY_ACCT */ diff --git a/include/uapi/linux/taskstats.h b/include/uapi/linux/taskstats.h index b7aa7bb2349f..5e8ca16a9079 100644 --- a/include/uapi/linux/taskstats.h +++ b/include/uapi/linux/taskstats.h @@ -34,7 +34,7 @@ */ -#define TASKSTATS_VERSION 8 +#define TASKSTATS_VERSION 9 #define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN * in linux/sched.h */ @@ -164,6 +164,10 @@ struct taskstats { /* Delay waiting for memory reclaim */ __u64 freepages_count; __u64 freepages_delay_total; + + /* Delay waiting for thrashing page */ + __u64 thrashing_count; + __u64 thrashing_delay_total; }; diff --git a/kernel/delayacct.c b/kernel/delayacct.c index e2764d767f18..02ba745c448d 100644 --- a/kernel/delayacct.c +++ b/kernel/delayacct.c @@ -134,9 +134,12 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk) d->swapin_delay_total = (tmp < d->swapin_delay_total) ? 0 : tmp; tmp = d->freepages_delay_total + tsk->delays->freepages_delay; 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; 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; spin_unlock_irqrestore(&tsk->delays->lock, flags); return 0; @@ -168,3 +171,15 @@ void __delayacct_freepages_end(void) ¤t->delays->freepages_count); } +void __delayacct_thrashing_start(void) +{ + current->delays->thrashing_start = ktime_get_ns(); +} + +void __delayacct_thrashing_end(void) +{ + delayacct_end(¤t->delays->lock, + ¤t->delays->thrashing_start, + ¤t->delays->thrashing_delay, + ¤t->delays->thrashing_count); +} diff --git a/mm/filemap.c b/mm/filemap.c index bd36b7226cf4..e49961e13dd9 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "internal.h" #define CREATE_TRACE_POINTS @@ -1073,8 +1074,15 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q, { struct wait_page_queue wait_page; wait_queue_entry_t *wait = &wait_page.wait; + bool thrashing = false; int ret = 0; + if (bit_nr == PG_locked && !PageSwapBacked(page) && + !PageUptodate(page) && PageWorkingset(page)) { + delayacct_thrashing_start(); + thrashing = true; + } + init_wait(wait); wait->flags = lock ? WQ_FLAG_EXCLUSIVE : 0; wait->func = wake_page_function; @@ -1113,6 +1121,9 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q, finish_wait(q, wait); + if (thrashing) + delayacct_thrashing_end(); + /* * A signal could leave PageWaiters set. Clearing it here if * !waitqueue_active would be possible (by open-coding finish_wait), diff --git a/tools/accounting/getdelays.c b/tools/accounting/getdelays.c index 9f420d98b5fb..8cb504d30384 100644 --- a/tools/accounting/getdelays.c +++ b/tools/accounting/getdelays.c @@ -203,6 +203,8 @@ static void print_delayacct(struct taskstats *t) "SWAP %15s%15s%15s\n" " %15llu%15llu%15llums\n" "RECLAIM %12s%15s%15s\n" + " %15llu%15llu%15llums\n" + "THRASHING%12s%15s%15s\n" " %15llu%15llu%15llums\n", "count", "real total", "virtual total", "delay total", "delay average", @@ -222,7 +224,11 @@ static void print_delayacct(struct taskstats *t) "count", "delay total", "delay average", (unsigned long long)t->freepages_count, (unsigned long long)t->freepages_delay_total, - average_ms(t->freepages_delay_total, t->freepages_count)); + average_ms(t->freepages_delay_total, t->freepages_count), + "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)); } static void task_context_switch_counts(struct taskstats *t) -- 2.18.0