From patchwork Thu Jan 24 21:15:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10780147 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 394CE1390 for ; Thu, 24 Jan 2019 21:15:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 286D02F805 for ; Thu, 24 Jan 2019 21:15:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C43C2F83A; Thu, 24 Jan 2019 21:15:44 +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 81FC42F805 for ; Thu, 24 Jan 2019 21:15:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 850588E009B; Thu, 24 Jan 2019 16:15:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7D95C8E0097; Thu, 24 Jan 2019 16:15:42 -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 67B2F8E009B; Thu, 24 Jan 2019 16:15:42 -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 216EF8E0097 for ; Thu, 24 Jan 2019 16:15:42 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id p4so4789989pgj.21 for ; Thu, 24 Jan 2019 13:15:42 -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=xO/xPi1H9RcNh3zL0bmtPchp8X0vIpi2bmKGvABys10=; b=pubLyJenVehK1xm/L1aCA0/OYwHVf2ten6/DaGc44wavsh5zPiylxv6fMz4MgvshSw m1RCN1USVlDE98wwFSIjX5AAx2mKRXf85416ot4Xal5lh1j6AtWBxv+Ky1YFaegqzhkx hxxE3z8yToxK0Mu71KCShsE48vSFIOKb243bSS9q3ARxEeEOlTt257AMbRDyRyLfXMIg F1GLmpmb4VMTdCgNCILVlVNo1fzK5WSVsLUren30Pj/DBj5gzruzwPetxz3cOP6sjOAz 21f1wz4kIqbNQBM8jPAvCtLG2yI0qYJ4p/MqfunBpCiV1xGS73SAQaLXp+AKFQQ4PMg7 JDfA== X-Gm-Message-State: AJcUukfdIYsC2pRL/024KgxG1UtSWCU5BavdNd0xdS9NxY7xdGimmkQa Jm6n+lzC/s049xZYIlA/qKvqkqujLf4Q65wC17Hy5a7Yes/LoOlZj1NBBWwaBDUwAC9qFaXhI9i NTk6Xp3cnTVt+KsELdjabmLwhyo83b92fTXPwhb0oQ1sw1gTB8ChshAzawchIlcDjujKDlP5dMH h6ZFg5enbwdELe+c/cVzV5L/LjvZZ8FLUxelngtmdL72GsPntrQ6mDjHm0wR+ZYQwqxmbt9soS1 zEF4KhPsc2BoMpfe1YyQJRB7+Ts1pgutdy2GetNG61yKQbuV97JbhOlzhxK2QUVgnymeV2h7oZV Z8ygpY9QzwwJnAc5CMJhKIRXLkeFxaMNdIM5/qheRJnP84UKr2WDf9sjEC93aNVq19W3uYtONuq C X-Received: by 2002:a63:cd11:: with SMTP id i17mr7480021pgg.345.1548364541667; Thu, 24 Jan 2019 13:15:41 -0800 (PST) X-Received: by 2002:a63:cd11:: with SMTP id i17mr7479981pgg.345.1548364540780; Thu, 24 Jan 2019 13:15:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548364540; cv=none; d=google.com; s=arc-20160816; b=ixoazy463OWYQ9AJ1cwnIzGqPSm1rm2VIeX4BO/XU83koomdzjap2SQxBhlV7J1PwD fYR6xTtDCRVBgYbioXJzUJ4IEl0y/aGcCV4oQTjwtkY3Ko2YYJsG9HUmPabyUynou8WP wfosAQYlF6u28gvzeJRvIJmfdkK8jruCvftm8X4cEKh3C31J3Y/MibWGpsoEYYdbN0F6 6A1P7TRl+EdbFbFJfJKdk9E8XwXeFaeHLccouEab4EMo93NBHl5S6QPXRvazZhb+m1KW Xb5NCWgoTRwmSs0FCsy4SjF7UrUOVdjcpwt5cqscR1TQ7jhTMkpwXTI97MHGCuWU9m64 g9Hw== 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=xO/xPi1H9RcNh3zL0bmtPchp8X0vIpi2bmKGvABys10=; b=UGTJxFJ5OdXa5kELKeqJZUxt+tJ9rCrBjABVrH6lCzOuYh70TqHhGMwil9Bjf35b1s ZwToXitcbgjHtJHwDyMCOfUeqfJTgrOKQ5dpFMzHAW2xI1BxtMW4XsPXssrUSlm0DWKT DtnIY3SWZArzSHENl5DW8mrPH8dLUETJ0LbW8yDD8U2PY2g2IyAjJDGCs9QEdvvnEV6U wMdpXYOqR9oPrIqL/EKQM08+/vcwEkciNvxHhYwC0qlDav0ZFw+6sZJss/ZZrYIOjW2f xV6eoICBGQiTby0zvoQ6jy8qhCqF1afqOLys6DTzyhrKMHsGqNmhVka0/QEH8puN0c+X o1Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nEU93vo9; 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 i3sor32781977pli.15.2019.01.24.13.15.40 for (Google Transport Security); Thu, 24 Jan 2019 13:15:40 -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=nEU93vo9; 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=xO/xPi1H9RcNh3zL0bmtPchp8X0vIpi2bmKGvABys10=; b=nEU93vo9p1DcR+610e4VL627dSQ3fC1I2asgSaFjUWi4z8xBZmpbzT1frZ2MDGNByX 8posn5i2ohAcTxoWWwj4UvqlcfIFKFCmvAt3kLd01Pk6Dsy1ZF2ID7VJH4Q6CHnzG64i oWOI7QJQwqJ4xz0mOWcXzel1GuFklJ6xYsgj4waaHRSB0B1AU3CvfqF/ow+AqO1ov6kY rNpJ1cPOT1qFOLTVDqxjspdFbVXmmDwk+97A0e4Ut4cJm04TH2EnkPuCxGb/dincba2K pjZqQMLs8h794KA62MZm5LXikOYg7Cb77228LjWdROmB+LoXMm2TSCOxJOEAp7db4pK7 DGKA== X-Google-Smtp-Source: ALg8bN61idbTluJOJwYMGOZ1awTthKG4I4dpmY3hOSMr3gMUs1dElf+ZY2FrGHicAlxE6OKULRh2Ig== X-Received: by 2002:a17:902:4624:: with SMTP id o33mr7963957pld.289.1548364539901; Thu, 24 Jan 2019 13:15:39 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id j197sm29626418pgc.76.2019.01.24.13.15.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 13:15:38 -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 v3 0/5] psi: pressure stall monitors v3 Date: Thu, 24 Jan 2019 13:15:13 -0800 Message-Id: <20190124211518.244221-1-surenb@google.com> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-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 This is respin of: https://lwn.net/ml/linux-kernel/20190110220718.261134-1-surenb@google.com/ 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-4 prepare the psi code for polling support. Patch 5 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-rc7. Johannes Weiner (2): fs: kernfs: add poll file operation kernel: cgroup: add poll file operation 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 | 104 ++++++ 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 | 83 ++++- kernel/cgroup/cgroup.c | 119 +++++- kernel/sched/psi.c | 605 ++++++++++++++++++++++++++++--- 8 files changed, 891 insertions(+), 71 deletions(-) Changes in v3: - Added smp_mb in the slowpath, as per Peter - Changed psi_group.polling flag to atomic_t, as per Peter - Added a comment in the hotpath about implicit smp_wmb in the chmxchg, as per Johannes - Minimized line-breaks wherever possible, as per Peter