From patchwork Wed Feb 6 02:34:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10798751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6213746 for ; Wed, 6 Feb 2019 02:35:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F2392ABA2 for ; Wed, 6 Feb 2019 02:35:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B0A52BFDF; Wed, 6 Feb 2019 02:35:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11B122ABA2 for ; Wed, 6 Feb 2019 02:35:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C9FA8E00A5; Tue, 5 Feb 2019 21:35:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6542B8E001C; Tue, 5 Feb 2019 21:35:05 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A7768E00A5; Tue, 5 Feb 2019 21:35:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id E42198E001C for ; Tue, 5 Feb 2019 21:35:04 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id o17so3626287pgi.14 for ; Tue, 05 Feb 2019 18:35:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:mime-version:content-transfer-encoding; bh=ApKCEzo8RhYd2Jky/u2pYoeIXX1Nl4FeNibEZamIk9M=; b=siEbE01phtQJ2YyCcaNN1IiIkpihX5gienRydaLKEvNe00MPtPhDRlHbhomLlZGePJ j05R67gYT2Unna41iKRHkfJ/7Sd5W4B0fsqtECRrQxHxN6LKRlrWJa1kkZMFVo+1QJsi 57LBwArDe73aOXqPvqSFD+knu1/RQp5DT1kJzn3fU3FiiwBpLuBC2bTUBXs0Kt2qjslA otm8pRqlAPldBuA5YOZor/TIgiuiMr8QAgC6yWh+GrUIwNKnf5H3lajV60hh0UTgSNIq 31CsrTzAgrufyQu+EOgje3hO+W+KXjKO03LMq7g3+kNuqI586RkwxYE8WuG+6IEc2yIL efLg== X-Gm-Message-State: AHQUAuYnsvFnqpWPjsaY6KcixNky8s1SbdTZl1Ix4xNFGXZplHMBQStI qReJkYiqz35/x8wfLIN/BqZW87PdZiV7GifyRRH4QEpy94fwsk+IOPDSg7xprvl1RqxW4BpkwFm jhTcUs2Jnujl6IJUeWNFIf1XUmm0UVxhuQzCVyllApZyXpW3ndGYP/mO5lDvZ7sWPoZfTeutI56 rjl6Iw8OF1BmM06xQLbJ5jdx2AbA6IOF+I8KZyAMY0rhr20OMir5LTfD986BiSjMVMJqUdtxnWo yXmDHs9dfRHL6b9Nx9VOyIMEWofuBKCdX0GEirHA6ikidkdu8xf73akyIzzjFUP/qozvDfk+/Y3 gtCTydi87AgsAD2oA69K9AAEDmoWEBskSgyOkZ2/JLIKM9ATdE5Tl5NN0SmzPOilxTbodBABlDO / X-Received: by 2002:a62:3141:: with SMTP id x62mr8129203pfx.12.1549420504263; Tue, 05 Feb 2019 18:35:04 -0800 (PST) X-Received: by 2002:a62:3141:: with SMTP id x62mr8128982pfx.12.1549420500410; Tue, 05 Feb 2019 18:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549420500; cv=none; d=google.com; s=arc-20160816; b=m0dbr75fO33p0mQbxQK0GFAaw/2q6btJUqbvrCP3qRN7CcAE8cE4+32/eMZ5P70CZY CZD0ERj72bt8VPlu1GqoHYmhxhi6SpWbWINdYIBiK8XoBadjM5zeT2VgerN79rWXKf7e U/EE69rFAObZXPsrDE74OGV9zOWHUvCaRv58V+Z0RaCF9j5LioUxT6JfORotghvdjYzQ pCWS2Sh2+iCP0mCo3I11Co4tx/2cz+7r0itLbWecATkyKOruffXdwLz80VfhgD5F0iSO SnMeoDMxpa+NeyyAjboLa5SkyybgXNp36W3xZJvO9RrDT8cJcd9AGGFUcRCd4zIvoTkB sC0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=ApKCEzo8RhYd2Jky/u2pYoeIXX1Nl4FeNibEZamIk9M=; b=NA49OBl4Gj2y0O+PNmBfVlviixwx4DhbKd7o76cRSPVBbSF+q62CaT85zs5czUnvS0 UWk111NkSREaGL/MqmbdkV4TPWLFdi6KiEsxRgSbePrzF+Tb818t/lzT1HFbjQ59YE9/ HMRSxV5+Hu2cvjDFfyk7aEcasx7rKqvHirZfHw4IvDqV3HkUfvdJvt833xD6+RBrYDID mrq7i9ZMDHS1aWp3r2YTO7/55d8FJdxd+ScEvXnPGU0K+nk3GCNmQAYLVxjqO8kSUfY8 BgZIfdPUuDFDcsTIZC5fG6PcGHEMrmB9lZ6PgzxJGcxqi+JGc6fJ/bljaaEY34yW4Slp AbHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=agWp14HF; spf=pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p3sor7288968plo.56.2019.02.05.18.35.00 for (Google Transport Security); Tue, 05 Feb 2019 18:35:00 -0800 (PST) Received-SPF: pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=agWp14HF; spf=pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ApKCEzo8RhYd2Jky/u2pYoeIXX1Nl4FeNibEZamIk9M=; b=agWp14HFiOLZO45M2BpSB7s1w7kG3D3c98BgKK54IlfrWf6reLeELjTy3eqKXklD8o dQGxrjmvRxtpXnfrkXGqyHHcFYXraX51LnXgKCg3N7Doz7BFmO0sHPGp9vk0kBKACrLD J7djI1oBNd00VVSWlvvwDYkcDu6dvhxz0lcYDCtTVj78w6lNCbAydOmTe0Rd5VhLhAWW LoQDKSJ4JSHjtYb/1krgNGSFS1AuyjaFutUwaou4pcPRhGLULC2i8gYNtqO+f1jUhw1I HrWfSvFZQgccXykpLy4RsIyK/lkPjY2m0mGMytuUMpefPeShEbrBoB//0DLXOctCa7mO al7A== X-Google-Smtp-Source: AHgI3IaN/oyoJISr5usvYncbOg3giDKskU77Xv9iT1jncDlZrvDrQTfVoZaFhs4u76goixtpjc+Ovw== X-Received: by 2002:a17:902:8b81:: with SMTP id ay1mr1877863plb.320.1549420499013; Tue, 05 Feb 2019 18:34:59 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id o2sm6173221pgq.90.2019.02.05.18.34.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 18:34:58 -0800 (PST) From: Suren Baghdasaryan To: gregkh@linuxfoundation.org Cc: tj@kernel.org, lizefan@huawei.com, hannes@cmpxchg.org, axboe@kernel.dk, dennis@kernel.org, dennisszhou@gmail.com, mingo@redhat.com, peterz@infradead.org, akpm@linux-foundation.org, corbet@lwn.net, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Suren Baghdasaryan Subject: [PATCH v4 1/1] psi: introduce psi monitor Date: Tue, 5 Feb 2019 18:34:46 -0800 Message-Id: <20190206023446.177362-1-surenb@google.com> X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Psi monitor aims to provide a low-latency short-term pressure detection mechanism configurable by users. It allows users to monitor psi metrics growth and trigger events whenever a metric raises above user-defined threshold within user-defined time window. Time window and threshold are both expressed in usecs. Multiple psi resources with different thresholds and window sizes can be monitored concurrently. Psi monitors activate when system enters stall state for the monitored psi metric and deactivate upon exit from the stall state. While system is in the stall state psi signal growth is monitored at a rate of 10 times per tracking window. Min window size is 500ms, therefore the min monitoring interval is 50ms. Max window size is 10s with monitoring interval of 1s. When activated psi monitor stays active for at least the duration of one tracking window to avoid repeated activations/deactivations when psi signal is bouncing. Notifications to the users are rate-limited to one per tracking window. Signed-off-by: Suren Baghdasaryan Signed-off-by: Johannes Weiner --- This is respin of: https://lwn.net/ml/linux-kernel/20190124211518.244221-1-surenb%40google.com/ First 4 patches in the series are in linux-next: 1. fs: kernfs: add poll file operation https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=6a78cef7ad8a1734477a1352dd04a97f1dc58a70 2. kernel: cgroup: add poll file operation https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=c88177361203be291a49956b6c9d5ec164ea24b2 3. psi: introduce state_mask to represent stalled psi states https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=9d8a0c4a7f1c197de9c12bd53ef45fb6d273374e 4. psi: rename psi fields in preparation for psi trigger addition https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=0ef9bb049a4db519152a8664088f7ce34bbee5ac This patch can be cleanly applied either over linux-next tree (tag: next-20190201) or over linux-stable v5.0-rc4 after applying abovementioned 4 patches. Changes in v4: - Resolved conflict with "psi: fix aggregation idle shut-off" patch, as per Andrew Morton - Replaced smp_mb__after_atomic() with smp_mb() for proper ordering, as per Peter - Moved now=sched_clock() in psi_update_work() after mutex acquisition, as per Peter - Expanded comments to explain why smp_mb() is needed in psi_update_work, as per Peter - Fixed g->polling operation order in the diagram above psi_update_work(), as per Johannes - Merged psi_trigger_parse() into psi_trigger_create(), as per Johannes - Replaced list_del_init with list_del in psi_trigger_destroy(), as per Minchan - Replaced return value in get_recent_times and collect_percpu_times to return-by-parameter, as per Minchan - Renamed window_init into window_reset and reused it, as per Minchan - Replaced kzalloc with kmalloc, as per Minchan - Added explanation in psi.txt for min/max window size choices, as per Minchan - Misc variable name cleanups, as per Minchan and Johannes Documentation/accounting/psi.txt | 107 ++++++ include/linux/psi.h | 8 + include/linux/psi_types.h | 59 ++++ kernel/cgroup/cgroup.c | 95 +++++- kernel/sched/psi.c | 559 +++++++++++++++++++++++++++++-- 5 files changed, 794 insertions(+), 34 deletions(-) diff --git a/Documentation/accounting/psi.txt b/Documentation/accounting/psi.txt index b8ca28b60215..4fb40fe94828 100644 --- a/Documentation/accounting/psi.txt +++ b/Documentation/accounting/psi.txt @@ -63,6 +63,110 @@ tracked and exported as well, to allow detection of latency spikes which wouldn't necessarily make a dent in the time averages, or to average trends over custom time frames. +Monitoring for pressure thresholds +================================== + +Users can register triggers and use poll() to be woken up when resource +pressure exceeds certain thresholds. + +A trigger describes the maximum cumulative stall time over a specific +time window, e.g. 100ms of total stall time within any 500ms window to +generate a wakeup event. + +To register a trigger user has to open psi interface file under +/proc/pressure/ representing the resource to be monitored and write the +desired threshold and time window. The open file descriptor should be +used to wait for trigger events using select(), poll() or epoll(). +The following format is used: + +