From patchwork Fri Dec 14 17:15:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10731481 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 E2B1C6C5 for ; Fri, 14 Dec 2018 17:16:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F4682C807 for ; Fri, 14 Dec 2018 17:16:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 322EC2D8F5; Fri, 14 Dec 2018 17:16:10 +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 9E92D2C807 for ; Fri, 14 Dec 2018 17:16:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D84DE8E01F4; Fri, 14 Dec 2018 12:16:08 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D34D08E01DC; Fri, 14 Dec 2018 12:16:08 -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 C4B728E01F4; Fri, 14 Dec 2018 12:16:08 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 86EA28E01DC for ; Fri, 14 Dec 2018 12:16:08 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id f125so4303849pgc.20 for ; Fri, 14 Dec 2018 09:16:08 -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=SQH8taIQkjdsZM4vXe8YuYSXfYbFmiDD/sxQ2CNRa+Q=; b=i6KsxibJ3kKVMFBm4qXmO1t99/TAvxdT/3HY2qYPtJzEQbpUNex84MabaKxnJ6CHzR Q5NnoT06a0oetHi806XpZLON1sE6+Z3a+0jv5AsEGg2qFHPsO3437VRIl1MtkwrvD68l shoz2m4y6g7YfGYNlcti2yrYF+Ip31Q9sA5UwPJdPLbtNkFAnODd/rlBA1d4nybwG4KW VpnT75pukWmfgIFzwtPD0qdsYG3G+G3/geQp7s/c8vlcJnG8EtM5ViVKxuBzySyVw4cF zbSlMeaIEuGsVSiW9gBw+42FfjchN4CbRrXNhLF1USTB6l1AXifd0cl1y5eGVGWEuj09 cUmw== X-Gm-Message-State: AA+aEWZINYWgfh+Kg0bqlXkiH1bOPSS4U5qHsfoTMVcnUXzFOVyzdRsY TLRQxRHnt2g+CQSpBzgFkKMjmOUJ0hs9JQ1yXWkMHZzwnbiR8y90yRXP5pES/RsXDrWeN8gfMfH /+ROLJebVgydIqtCca5k0TNBkHYxhSzuJU9S8d8NEYcMKy9JHAJKOK/UCUGWUNfDpwHAhrCK11p xRyVjYHOqxNZJYl9/4OlStUQOUiJ7Ay9EasXhdKmXPIESO8wnWGLbMZijJWsoSrNUHdjDVNsZ7B o1VE5VZFteHd+9ghyeqm4yVq8wfZGsPncRCP/8G0FKCyDmQEN+mlpe1xN2/d3gDQ6vPOcc4JK84 FSOGJjjo0XBMEwmJim4/Z4EwcogDwbdgn2OVc0rSAVrumx2xFiHdUMKjOgFud63ofbs8K6OCyy9 L X-Received: by 2002:a63:b94c:: with SMTP id v12mr3395978pgo.221.1544807768033; Fri, 14 Dec 2018 09:16:08 -0800 (PST) X-Received: by 2002:a63:b94c:: with SMTP id v12mr3395922pgo.221.1544807767205; Fri, 14 Dec 2018 09:16:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807767; cv=none; d=google.com; s=arc-20160816; b=UarmUim3hSh126KiJEJcFUqRa7iY2PnYao1PNBh3rAA9twlgmv7HHBrfBb4jrCBv0c +jhu4Rtz6efc98fl0J1erX7XDbPktdfboyKlDwDOSpMxcKWK5xBNCYRu0o68qiPzWMki hdazkcdW9HfzZdiTeBvyooMlW7F1elCMJXfFQpI9jJLOdYEiDpjbgiSXon1vruEKvC4S Ft1DPMuN1J80EbWkvbH+IrlftOsSLDrZT8LINmi8jxtHyoRr+PzoSbWJnE1LZHGikmyP PxbwjakJYQiqIgZZQMN+m+bgidrQ3YTDseiCAcjTQV0FZmF1tK2bkJBbQ59Qr/f7zXPD tYLw== 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=SQH8taIQkjdsZM4vXe8YuYSXfYbFmiDD/sxQ2CNRa+Q=; b=Nhw3p/79I/+EetkNpqj8SVxN5mko1dL/FyeC2M+V/ZhcmRA//IcZ5en0MnobJZJKv+ w2e8xz1oCAi36PhS2cnq33NMkknh2yVns3h5amLsamCfcUqZm2Gzo7Rlsy622XXCKDS/ gfLDAijabLYlY0iZd+omjHiE0ImeltVb/ueXyTZpPIPcbF9/Y77bkr70BkAVaYq8ZVRd ZJBv6//5Dlw0g3nSz9aCBSxtyviWigKKTG5JTgoxoa2Q6/Wuc9hHuwKOgbJln49BpkkT hpxJxrFa+CQ1rA0A4Dx2KOS1Jv4UbpG1fGegnteo5Hifl8z1SN/XB34KC6c+tifZPM5E iN/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VMlcDc6p; 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 t7sor8209003plo.3.2018.12.14.09.16.07 for (Google Transport Security); Fri, 14 Dec 2018 09:16:07 -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=VMlcDc6p; 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=SQH8taIQkjdsZM4vXe8YuYSXfYbFmiDD/sxQ2CNRa+Q=; b=VMlcDc6pBbefgdLgbx3BcKdCAoBNsxf/QXyvozcie1dZ7JHxwPkvj+fpOcvPhlxdCD Aor+gaWOgpUb/+t5BxoCW1Zf56LnakBSXB7vCmyXudReJIdR5rm+k6CPIo6E1inL/Aw3 V9g8MO/sbuDMPNP0PILBab5iuBBuV1+hKwsVbnihgRz5ZZDffEC4ejVIYBcIw3FghUM1 2htQ844fjf/54XM5IWxGpdqSuvJLtBNhNuZePcROUtK8iuWon/vjfh1Q4sTGuotxzZ1t PVEfrcG8EQoRG9WQ4mzZy8YmG7coFYwxA1htS7YNPMyoSZojqhCZsFpNhgLPcZwc8nSE Cn1A== X-Google-Smtp-Source: AFSGD/VISB3dsALFF4TyZc+/KZMs0SYYeof/RgIJi+hcr7RmBwliOILzFmC7LQbu0KhL/8UaPsVDoQ== X-Received: by 2002:a17:902:70c6:: with SMTP id l6mr3733729plt.30.1544807766604; Fri, 14 Dec 2018 09:16:06 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id g185sm7605761pfc.174.2018.12.14.09.16.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16:04 -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 0/6] psi: pressure stall monitors Date: Fri, 14 Dec 2018 09:15:02 -0800 Message-Id: <20181214171508.7791-1-surenb@google.com> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85-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 Android is adopting psi to detect and remedy memory pressure that results in stuttering and decreased responsiveness on mobile devices. Psi gives us the stall information, but because we're dealing with latencies in the millisecond range, periodically reading the pressure files to detect stalls in a timely fashion is not feasible. Psi also doesn't aggregate its averages at a high-enough frequency right now. This patch series extends the psi interface such that users can configure sensitive latency thresholds and use poll() and friends to be notified when these are breached. As high-frequency aggregation is costly, it implements an aggregation method that is optimized for fast, short-interval averaging, and makes the aggregation frequency adaptive, such that high-frequency updates only happen while monitored stall events are actively occurring. With these patches applied, Android can monitor for, and ward off, mounting memory shortages before they cause problems for the user. For example, using memory stall monitors in userspace low memory killer daemon (lmkd) we can detect mounting pressure and kill less important processes before device becomes visibly sluggish. In our memory stress testing psi memory monitors produce roughly 10x less false positives compared to vmpressure signals. Having ability to specify multiple triggers for the same psi metric allows other parts of Android framework to monitor memory state of the device and act accordingly. The new interface is straight-forward. The user opens one of the pressure files for writing and writes a trigger description into the file descriptor that defines the stall state - some or full, and the maximum stall time over a given window of time. E.g.: /* Signal when stall time exceeds 100ms of a 1s window */ char trigger[] = "full 100000 1000000" fd = open("/proc/pressure/memory") write(fd, trigger, sizeof(trigger)) while (poll() >= 0) { ... }; close(fd); When the monitored stall state is entered, psi adapts its aggregation frequency according to what the configured time window requires in order to emit event signals in a timely fashion. Once the stalling subsides, aggregation reverts back to normal. The trigger is associated with the open file descriptor. To stop monitoring, the user only needs to close the file descriptor and the trigger is discarded. Patches 1-5 prepare the psi code for polling support. Patch 6 implements the adaptive polling logic, the pressure growth detection optimized for short intervals, and hooks up write() and poll() on the pressure files. The patches were developed in collaboration with Johannes Weiner. The patches are based on 4.20-rc6. Johannes Weiner (3): fs: kernfs: add poll file operation kernel: cgroup: add poll file operation psi: eliminate lazy clock mode Suren Baghdasaryan (3): psi: introduce state_mask to represent stalled psi states psi: rename psi fields in preparation for psi trigger addition psi: introduce psi monitor Documentation/accounting/psi.txt | 105 ++++++ fs/kernfs/file.c | 31 +- include/linux/cgroup-defs.h | 4 + include/linux/kernfs.h | 6 + include/linux/psi.h | 10 + include/linux/psi_types.h | 90 ++++- kernel/cgroup/cgroup.c | 119 ++++++- kernel/sched/psi.c | 586 +++++++++++++++++++++++++++---- 8 files changed, 865 insertions(+), 86 deletions(-)