From patchwork Thu Jan 10 22:07:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10756991 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 1BDE617D2 for ; Thu, 10 Jan 2019 22:08:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0891D29EF0 for ; Thu, 10 Jan 2019 22:08:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEBEE29EFB; Thu, 10 Jan 2019 22:08:06 +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 E124E29EF0 for ; Thu, 10 Jan 2019 22:08:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAA198E0003; Thu, 10 Jan 2019 17:08:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D59728E0001; Thu, 10 Jan 2019 17:08:03 -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 C22C78E0003; Thu, 10 Jan 2019 17:08:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 831DB8E0001 for ; Thu, 10 Jan 2019 17:08:03 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id 202so7156413pgb.6 for ; Thu, 10 Jan 2019 14:08:03 -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:in-reply-to:references:mime-version :content-transfer-encoding; bh=6/O3eFualUs49i01Y9nCFMeVAmgaojLv/2MBw+YMFEw=; b=uheeIp1LATtuL3+Z02812fo+60lPolb8k//HRR7rEpceevZSMI2WP1TDiEkt13mBCR 2l26619+FRkaXpK2bIEPD1IiHf5mBYOWa9ZSStAiFtyeryRKJv+wdyEEv1M8cklXASlO FR7FmDmUgck4qUEX8sJ/KrAc5hqxhQK9Z0B5Plg2o0E78R8sAbeFxeudtRNqQWMbWeVf S1PxWzIUv1zh9gRn8oFsXU48n0M+XhOihNNHmh1f5VtsyEEzJOpDjdp6pCBrxFvzgYFX y6kGu1m39lvjm6GWQswfgscnPT9NVrtWjVarMMPNiqGbFJ5FJYtottdJ0vOt+W3s5zo5 B/nA== X-Gm-Message-State: AJcUukd+WGvkhoj9gPVMr60ZIYzNqsdBVITxqZPABTwzbiysdpVD7mum HUSHQJRCBju/9/AE+hyUpVClIdWyYyfj+mLDMsupJ4wDQTLrC7ZwW7bsMGNp2dE1/IhsPo6xYr4 itwKI1xEQnVeTpNzS8tw/IUCc46qRTN+s5/ccNSTYFmMzMMDsk/PgPziSiCqiOqVT86bs9lYssc ZYehCoPh3AL3WBLRdsLYuZD1g9p8IPpyPsI5NIJonj57RnrNLxaV9QR29fI5hm8rOtrT15BXUAj Jbk4xeJXqsTvEhC5Znls5UgOqazTBKvu6DKTzH/vWJYge0CqdqXEZql7U8FVrFe0JbpDdCVfW6D MrsviuNMKW0p1/7jtnLyHlH/rICK3glDu8HLMOgcEX4mNdBC7bf8fP2EwVHVPfxf3xeWFIVM8aP F X-Received: by 2002:a65:514c:: with SMTP id g12mr10914290pgq.169.1547158083168; Thu, 10 Jan 2019 14:08:03 -0800 (PST) X-Received: by 2002:a65:514c:: with SMTP id g12mr10914250pgq.169.1547158082417; Thu, 10 Jan 2019 14:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547158082; cv=none; d=google.com; s=arc-20160816; b=GaxjMjwoYfzgVCoqxlvwebn+cmTyf2SrC4FvND5Y7rXmfUc5bb4x7dB0TP+osOzacg GLOMP1OODkDWwL+m/xe+OMYLDvONE37EuNM4XFkEQm/G7h0CexajvS2tVKpCu6klQFys x7tLCB77U89y5UKaza7WHQeMnvZZtBsJjV/t3T5plndnRmXTr030CF+Nk8sqVSrcpUFG g4Lb6hrDD90kucJefle9XRP1k6hlaikL811lCiC3nLbypgF5NVdISf31+9SqsP5ZWSs4 4zvoIoAUv2pwW3qcjn0W6ukwOYH9o2JltBV9qso1l0hT6M/RE84yIA7cjoy6xkoFaGxc reOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=6/O3eFualUs49i01Y9nCFMeVAmgaojLv/2MBw+YMFEw=; b=DyaUXigMafp2Kan4Jw3P83CNS7ToBWJ7PXcYYM5vQByjuzvHo22LNLrs3yEEIUlp00 Zvrp3Cg9E+V0CjHVnxu2JwAtH4Y6Evm9OCDtnabPyAGH6jmxkvSdOBIcDSCRbu6dRTDp uyJt3IH/anfMjRPOHMX1Rbsy5i3Akzlx5rEy0e/iypGBItZxIEZOvfb3uxzqncykPtwa vXWPJ5AnWLb6fxFHqk59zPdijj7uqmhbJ2sISXDszu+7WMLy2ujf8AM9Sbj14qneyVV0 CB3Nkm4NDVXnfGvA4QhH/XB0hQW2Ka3uEeqxhoeubB3UTz10ir8i2c5zvDU598mtI/jM GgOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZlV37vZt; 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 30sor547374pgz.10.2019.01.10.14.08.02 for (Google Transport Security); Thu, 10 Jan 2019 14:08:02 -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=ZlV37vZt; 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:in-reply-to:references :mime-version:content-transfer-encoding; bh=6/O3eFualUs49i01Y9nCFMeVAmgaojLv/2MBw+YMFEw=; b=ZlV37vZth2xskaz25CzDUgkv2F5IWqrPsLkXq+5WGuLB2x/bp81M8lLF8ZPkjLtZW3 lq4hOdS+fLTm6uWk/RIkdTi3zA+1aFHHEfLWYUGirXTb9rXw6xxvs+LGaUumLrV2P4k7 pITQRvyOn+4dWlNuZ4A4QQcf2n6KmihrQklYYmeAcjKsOM9He4TenXOi36Bn82mU/Ald CTbGvrRA68GVELjzgQyqaSfj5x56VRoBO1LVTm8nyUiVwfH21VV2AV9+O8SDDYmNqkEz D4GgOBYB9F0wlUEkDQspNYjZOL9OuIk4OFAkNhkIxOnxdpi9c0OTdoI4AElmSojoCPxk /hSw== X-Google-Smtp-Source: ALg8bN4VK5/sM3LS/LoPFXFsneMHIR/ap0XXOfEPftIeUw/PbLjRJcIMdlUd4PLfeJM78GtOQw4fEw== X-Received: by 2002:a63:ee0e:: with SMTP id e14mr10793315pgi.8.1547158081876; Thu, 10 Jan 2019 14:08:01 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id p7sm152958019pfj.72.2019.01.10.14.08.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jan 2019 14:08:01 -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 v2 1/5] fs: kernfs: add poll file operation Date: Thu, 10 Jan 2019 14:07:14 -0800 Message-Id: <20190110220718.261134-2-surenb@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190110220718.261134-1-surenb@google.com> References: <20190110220718.261134-1-surenb@google.com> 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 From: Johannes Weiner Kernfs has a standardized poll/notification mechanism for waking all pollers on all fds when a filesystem node changes. To allow polling for custom events, add a .poll callback that can override the default. This is in preparation for pollable cgroup pressure files which have per-fd trigger configurations. Signed-off-by: Johannes Weiner Signed-off-by: Suren Baghdasaryan Reviewed-by: Greg Kroah-Hartman --- fs/kernfs/file.c | 31 ++++++++++++++++++++----------- include/linux/kernfs.h | 6 ++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index dbf5bc250bfd..2d8b91f4475d 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -832,26 +832,35 @@ void kernfs_drain_open_files(struct kernfs_node *kn) * to see if it supports poll (Neither 'poll' nor 'select' return * an appropriate error code). When in doubt, set a suitable timeout value. */ +__poll_t kernfs_generic_poll(struct kernfs_open_file *of, poll_table *wait) +{ + struct kernfs_node *kn = kernfs_dentry_node(of->file->f_path.dentry); + struct kernfs_open_node *on = kn->attr.open; + + poll_wait(of->file, &on->poll, wait); + + if (of->event != atomic_read(&on->event)) + return DEFAULT_POLLMASK|EPOLLERR|EPOLLPRI; + + return DEFAULT_POLLMASK; +} + static __poll_t kernfs_fop_poll(struct file *filp, poll_table *wait) { struct kernfs_open_file *of = kernfs_of(filp); struct kernfs_node *kn = kernfs_dentry_node(filp->f_path.dentry); - struct kernfs_open_node *on = kn->attr.open; + __poll_t ret; if (!kernfs_get_active(kn)) - goto trigger; + return DEFAULT_POLLMASK|EPOLLERR|EPOLLPRI; - poll_wait(filp, &on->poll, wait); + if (kn->attr.ops->poll) + ret = kn->attr.ops->poll(of, wait); + else + ret = kernfs_generic_poll(of, wait); kernfs_put_active(kn); - - if (of->event != atomic_read(&on->event)) - goto trigger; - - return DEFAULT_POLLMASK; - - trigger: - return DEFAULT_POLLMASK|EPOLLERR|EPOLLPRI; + return ret; } static void kernfs_notify_workfn(struct work_struct *work) diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 5b36b1287a5a..0cac1207bb00 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -25,6 +25,7 @@ struct seq_file; struct vm_area_struct; struct super_block; struct file_system_type; +struct poll_table_struct; struct kernfs_open_node; struct kernfs_iattrs; @@ -261,6 +262,9 @@ struct kernfs_ops { ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes, loff_t off); + __poll_t (*poll)(struct kernfs_open_file *of, + struct poll_table_struct *pt); + int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma); #ifdef CONFIG_DEBUG_LOCK_ALLOC @@ -350,6 +354,8 @@ int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, const char *new_name, const void *new_ns); int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); +__poll_t kernfs_generic_poll(struct kernfs_open_file *of, + struct poll_table_struct *pt); void kernfs_notify(struct kernfs_node *kn); const void *kernfs_super_ns(struct super_block *sb); From patchwork Thu Jan 10 22:07:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10756993 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 0BEE117D2 for ; Thu, 10 Jan 2019 22:08:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED18129EF2 for ; Thu, 10 Jan 2019 22:08:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEB5629EFB; Thu, 10 Jan 2019 22:08:12 +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 5153E29EF2 for ; Thu, 10 Jan 2019 22:08:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 608F28E0004; Thu, 10 Jan 2019 17:08:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5B7E28E0001; Thu, 10 Jan 2019 17:08:11 -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 4A98A8E0004; Thu, 10 Jan 2019 17:08:11 -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 0C1228E0001 for ; Thu, 10 Jan 2019 17:08:11 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id a18so7144930pga.16 for ; Thu, 10 Jan 2019 14:08:11 -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:in-reply-to:references:mime-version :content-transfer-encoding; bh=+OULLMuerNEP0alqy6OmnDEtcrB759rW8C6mN7L4vig=; b=pmlhghTOzZNHnfiWJEsBcqODMy/NBP8UsgIIxiURdZ+SKCLS/cyCp1+MGkcrr0PY3n Lu8fFH3aOHCpLz7aWP7Mw4tw26QUexLGRvW61QhBoBblvbHh4Ow/tCb9ZiHJEVTo4cP6 VmNdTp2planJbqnK/AbHd+z71qPRwWOQiMJHLyqyhPUpQUcPq2ozVzKQCP6TvMrMxZWn goHeL8Ao0LRYbjM+fiMkEG6bg3gQJYGmya5e3ATU3JTJhaexGQO1Sa4LB6T8g2ffT25r QFVnjt8+8Z+gqSKjZRYFsP8+8ZhdoVTjM/VmdT331NJlfSEEE1V/MB+NHFa4WCyO6Ak3 8FVA== X-Gm-Message-State: AJcUukex+7xLjd7D/21tQxzCu4M7duZzKUMSmyfhpbViTNR0SPma81p9 orPizRFfwTEVfyVLR7OvNaypScatUQH7j5PVodeGTpVZRD5jdTBZtNIh8ej8j6EPmyGw9oFFZB7 2b++W0LCPQYDXHKuVmgoxk/4oRtgl2b7A/4q126sZurb9TKTOIJrS55Luq4b4DHXW1j+8+10iXV PTaGm16uxOsHpQipPC3rRtcuZdIUx2tpJNfZDIm9vSxZkeWC5cZruO1OLNvW4uCYLMN4NjtbkRb OpJA2t2+YyXU5QNY3Tc6hFr/Djfhq9OMEaowrI5GYX4tr7LRtFh4CyDbYiPz/JJ92ryjnLvCL8E nzHMXU3USRha/MmHpOA8ETm3pmX0XKUbQMYgalI49Vu+bpzjWKPBBR56cZMl/9UnFYDxAcJmMV3 V X-Received: by 2002:a63:d5e:: with SMTP id 30mr11051786pgn.54.1547158090702; Thu, 10 Jan 2019 14:08:10 -0800 (PST) X-Received: by 2002:a63:d5e:: with SMTP id 30mr11051718pgn.54.1547158089440; Thu, 10 Jan 2019 14:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547158089; cv=none; d=google.com; s=arc-20160816; b=F3+p/vkBLkdD0y2qjnVAfVCX7TMXi0pQ9SMVlSG3OZDckUVy4Nn4B4RDmciVub3/e6 KqwdCi3Vd/9DpGZBB+zB514NBHevYY4PwReqpk0ddfc6re2LciPJgVIp0tQCeHZ+t6S0 MAgi5hMzzwooeaPGboK78DMG2B8/QGCwoRpTBbMHCYoPQOyM00pa8Lzezu3zQAuf3Ht6 +Fn6VahJjNrq8IGImhjI3AJ9ArooFtLOOrhgBtCNViEbNhv7JQpBO9/1xhI3SbkR5/dF ktb+XEBWAxEvfeSGIahkBGS70f2K3ECaTc4iMGe/hyKPvl8QxsW6AsZVLzoTjFFH2IY3 WJ+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=+OULLMuerNEP0alqy6OmnDEtcrB759rW8C6mN7L4vig=; b=ib2T2pG1RNg2OLur0nJptqp1UWb/ygWxk24zmzkomi6Khtriew2dzqSg4CIFahvjYq yoKdZcjsNQS/h73z3Mx17eHwtK+uVs+/ejjNgBOHKeY79IhIBjAhhJbVDD96B1EmUKd8 bH1cTJy1GfquZ3yeiEL0+QZOVcBkv2KcHLXbZz6ddaAsbN1fYXrb0V9xZUPD9rKzNmGl WB8b5KPwr6FDaBXLRV/zH80DW/UD82z9K/S4+g1IpR+G4A51YwFVBNziKx9fPmD6AR4a RNQtzSvCkn6iyPG9lFT8Lp+8lujf/RXWFT4PvePeFXnschsd7zjxX0zFBIQ5pTa+8QIi qGWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=srgGXbB+; 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 z188sor53812003pgb.42.2019.01.10.14.08.09 for (Google Transport Security); Thu, 10 Jan 2019 14:08:09 -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=srgGXbB+; 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:in-reply-to:references :mime-version:content-transfer-encoding; bh=+OULLMuerNEP0alqy6OmnDEtcrB759rW8C6mN7L4vig=; b=srgGXbB+MDNra9yHvnpA7JnWGI1yejRbQpFLJdis5RB26UjMRqie4R/aLpnklNN0sS 5MS4o1NN5rAT8Ib1XEseXKu47U1MW3+j8Nkeaj9RrKK9MxEaoeMMi7fVSpRYgDcAjikr RiGmbTb0KnMwV26nPA14fjRBZePi7eM3fcfGCU4Dmom9T1iiwNS+gg622NARdbtZlrdy xTwWjl+Z+99ssFmmYZqRPn7SNQYWzW6GoP30dPpVQv/zuXIAg8wvN0SWhp7AX1FS6eZF oHZ75LY1xssaHYs2FxZ7UEZi6KubW8MBt6CheGcaSE3XdXz9IntU59HFtunkyEXA2Hwk 9keA== X-Google-Smtp-Source: ALg8bN60+69qoUR4ahkci/QfrF0Ij7K44dZKkAyRXtZKwR23+ut1vvrrUADTQ2Xl1Peh8ZO+UT3bSQ== X-Received: by 2002:a63:7e5b:: with SMTP id o27mr10907220pgn.214.1547158088900; Thu, 10 Jan 2019 14:08:08 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id p7sm152958019pfj.72.2019.01.10.14.08.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jan 2019 14:08:08 -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 v2 2/5] kernel: cgroup: add poll file operation Date: Thu, 10 Jan 2019 14:07:15 -0800 Message-Id: <20190110220718.261134-3-surenb@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190110220718.261134-1-surenb@google.com> References: <20190110220718.261134-1-surenb@google.com> 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 From: Johannes Weiner Cgroup has a standardized poll/notification mechanism for waking all pollers on all fds when a filesystem node changes. To allow polling for custom events, add a .poll callback that can override the default. This is in preparation for pollable cgroup pressure files which have per-fd trigger configurations. Signed-off-by: Johannes Weiner Signed-off-by: Suren Baghdasaryan --- include/linux/cgroup-defs.h | 4 ++++ kernel/cgroup/cgroup.c | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 5e1694fe035b..6f9ea8601421 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -32,6 +32,7 @@ struct kernfs_node; struct kernfs_ops; struct kernfs_open_file; struct seq_file; +struct poll_table_struct; #define MAX_CGROUP_TYPE_NAMELEN 32 #define MAX_CGROUP_ROOT_NAMELEN 64 @@ -573,6 +574,9 @@ struct cftype { ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off); + __poll_t (*poll)(struct kernfs_open_file *of, + struct poll_table_struct *pt); + #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lock_class_key lockdep_key; #endif diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 7a8429f8e280..3f533f95acdc 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3499,6 +3499,16 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, return ret ?: nbytes; } +static __poll_t cgroup_file_poll(struct kernfs_open_file *of, poll_table *pt) +{ + struct cftype *cft = of->kn->priv; + + if (cft->poll) + return cft->poll(of, pt); + + return kernfs_generic_poll(of, pt); +} + static void *cgroup_seqfile_start(struct seq_file *seq, loff_t *ppos) { return seq_cft(seq)->seq_start(seq, ppos); @@ -3537,6 +3547,7 @@ static struct kernfs_ops cgroup_kf_single_ops = { .open = cgroup_file_open, .release = cgroup_file_release, .write = cgroup_file_write, + .poll = cgroup_file_poll, .seq_show = cgroup_seqfile_show, }; @@ -3545,6 +3556,7 @@ static struct kernfs_ops cgroup_kf_ops = { .open = cgroup_file_open, .release = cgroup_file_release, .write = cgroup_file_write, + .poll = cgroup_file_poll, .seq_start = cgroup_seqfile_start, .seq_next = cgroup_seqfile_next, .seq_stop = cgroup_seqfile_stop, From patchwork Thu Jan 10 22:07:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10756995 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 9216891E for ; Thu, 10 Jan 2019 22:08:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F77529EF5 for ; Thu, 10 Jan 2019 22:08:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7318D29EFD; Thu, 10 Jan 2019 22:08:18 +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 E6E5429EF5 for ; Thu, 10 Jan 2019 22:08:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA9D68E0005; Thu, 10 Jan 2019 17:08:16 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D59458E0001; Thu, 10 Jan 2019 17:08:16 -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 C485C8E0005; Thu, 10 Jan 2019 17:08:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 85D538E0001 for ; Thu, 10 Jan 2019 17:08:16 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id v2so7007739plg.6 for ; Thu, 10 Jan 2019 14:08:16 -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:in-reply-to:references:mime-version :content-transfer-encoding; bh=gvi1iRKLPW3qMsLI6kumJKUVDFg5NUDF94Fa5S4jUjU=; b=OO6zygfNa4GbTPUdOwSFOdSsbYti5HZyzg9jaPd6GlLCAXywkX8c/iszALxLlf1G3q 4OO02dynZhVDsbegcpvAB8NjhWiOGmSfaJ742p6mW343igCVm/8QarkXjrjKD4PfsIvw Q6M+0Jqrw25eblJuk7uaWqaHr+79/JtmhI5UeHoPRbVOA9e+N50KooB3OR1g4VONbko+ YkkW8AI2L9we36cKbDOMIAXu/2JiDQGebZB18ZmCd95GVe6LzzR0oRY7VGJ4wIsuJR5e zSGasmpGfyLxjgQ6DlCvYoEe+09dCuThEGeyr+GBwpvmTlp04o/vYCdlMXIo5vyb5KEp R3uw== X-Gm-Message-State: AJcUukdCm2zwovfscTAzSHBG1wpP91X4Ia220n13ggHInPFMLO4FF+Bq t3DsRVtzZKDdHP219A4VH0WgmryvPAq8L/kNFGwPlQrEpL/gNndMJ4KN9eQkHscoFpVvhKf1fXm GACqRbaRY75cW7oh52LHD8MIHF5tSHAwwdhfO9ol/5N1Za0RUduMjpAB46b3HOQU58/k1vD8w55 Ggx4joj0CtD16BHu2dYPOvrFiTm89MKTOjj//fAUYZeiv75tyQWSWNl3Dxq/Sefc1iKMSvXUQic mZaf+PgjKpK4odJzd+B9rqzKs5e2LY3p6St/+1qrY/BvNGbKFG70wmt5wJ9/5tBrBocmjJpG4e3 jlx54mgT8UIjvc9Ut8bvM4lMBIY1ob3Xqg0Gx4lRG3ZxWEuxQgbX13tzKHHCeJMP3vjtqwZWype j X-Received: by 2002:a17:902:4624:: with SMTP id o33mr11810098pld.289.1547158096206; Thu, 10 Jan 2019 14:08:16 -0800 (PST) X-Received: by 2002:a17:902:4624:: with SMTP id o33mr11810063pld.289.1547158095487; Thu, 10 Jan 2019 14:08:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547158095; cv=none; d=google.com; s=arc-20160816; b=PIKmsyDASK9FfjAlgKmwlZ2pFjnz+B2oy4olwDdh0n4WUToVrllDMcVxIb++wLd/2J +DCoW4bWqqwfY5jn8kH4RaW9puHyt/kx3z61pVJy3VAVSdnHD4IrQB1ng8oEP+RMGs6E NY9jYADTM/5oLDTo+lOCFmtQfKOKPFqeXqaHO9vFmL9vwJ529A5ud803piLSSkhttvDm R8I45oQc6N21O8S5h/xkbOnXgYwEoOpCIXGeq16PVIPcgx/S9+ID9gBozdeEpoSCprAY 3E9h2m5BDLRJxbvqT5ftSCDy+oL18GKL5rAIVkoPQrL9KG4r8nmCu1AFHGLzyXJTSp9J 0zlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=gvi1iRKLPW3qMsLI6kumJKUVDFg5NUDF94Fa5S4jUjU=; b=fEgSFYfaiEFwU2zjhbjTgqNIoiC9pC/dYAj3kiVkQkDPeUDoevq36RbwYe0oGH8cks I7TszqlnxeM1LhrBkdCqENPBvXa3x7rm0H8DB0NihWGnQvkv2TU4taFM+D+T/Xlw8i5k bFJLHYAWq5KDu09jeknLwEOS2o/6o/ezYC5fsO4/47oOmSc1r1l1sy+AQAaB/aK478uB Y/dM53+KkqIisu20I2RcXjfb0fHapIIRmQEC7BRYhAPKW5nCqN7waiMTq/ono5yd2Dic Ghljvmp0JoSh5zefNVlfc39v0hgIi3Ml4NFSgVYy0IVyL5nlQf5HvWSnKYtGaW3PNXw2 cSag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OdfmzDI9; 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 a83sor569195pfj.39.2019.01.10.14.08.15 for (Google Transport Security); Thu, 10 Jan 2019 14:08:15 -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=OdfmzDI9; 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:in-reply-to:references :mime-version:content-transfer-encoding; bh=gvi1iRKLPW3qMsLI6kumJKUVDFg5NUDF94Fa5S4jUjU=; b=OdfmzDI9CcL+2VXf5ocSTDNyRd9IHxsxjkC2PxQORGPsj0X7psQuS3Umk7pGcF+y1N 2erlFLdCgBeLM6sKPD7UtLOkmNwDY3Q8+bYqlRpPzxYaWaUO9Ku8vgf0RYaWAZcgeQDp +OycaSHT78G3F5f1FH0QvE8CIaRHZ77mkmp4zAhGBT3h+OnHhOI95bD1lAbzndzCJcN8 kAYejfjaXIKLAAr8fN6d+3sQPM/sqCNbQm4TKt/fmoxpEaDlXqQnfBs/W76fh5Si1HRb 2Ywu2dMPM2Aw/LeKx3cXLOODPCznDtA+9g6oDheS4QVxUuvqwreMha9jFWiYakAAlmvd BQvA== X-Google-Smtp-Source: ALg8bN6gohws80ogM6bKIwE/KhY+FsflDzhULCDncx+SgcmmVujJEzOQajCDWV/20rlAO9DnbJk3/Q== X-Received: by 2002:a62:3943:: with SMTP id g64mr12126011pfa.114.1547158094933; Thu, 10 Jan 2019 14:08:14 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id p7sm152958019pfj.72.2019.01.10.14.08.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jan 2019 14:08:14 -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 v2 4/5] psi: rename psi fields in preparation for psi trigger addition Date: Thu, 10 Jan 2019 14:07:17 -0800 Message-Id: <20190110220718.261134-5-surenb@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190110220718.261134-1-surenb@google.com> References: <20190110220718.261134-1-surenb@google.com> 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 Renaming psi_group structure member fields used for calculating psi totals and averages for clear distinction between them and trigger-related fields that will be added next. Signed-off-by: Suren Baghdasaryan --- include/linux/psi_types.h | 15 ++++++++------- kernel/sched/psi.c | 26 ++++++++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h index 762c6bb16f3c..47757668bdcb 100644 --- a/include/linux/psi_types.h +++ b/include/linux/psi_types.h @@ -69,20 +69,21 @@ struct psi_group_cpu { }; struct psi_group { - /* Protects data updated during an aggregation */ - struct mutex stat_lock; + /* Protects data used by the aggregator */ + struct mutex update_lock; /* Per-cpu task state & time tracking */ struct psi_group_cpu __percpu *pcpu; - /* Periodic aggregation state */ - u64 total_prev[NR_PSI_STATES - 1]; - u64 last_update; - u64 next_update; struct delayed_work clock_work; - /* Total stall times and sampled pressure averages */ + /* Total stall times observed */ u64 total[NR_PSI_STATES - 1]; + + /* Running pressure averages */ + u64 avg_total[NR_PSI_STATES - 1]; + u64 avg_last_update; + u64 avg_next_update; unsigned long avg[NR_PSI_STATES - 1][3]; }; diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 2262d920295f..c366503ba135 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -172,9 +172,9 @@ static void group_init(struct psi_group *group) for_each_possible_cpu(cpu) seqcount_init(&per_cpu_ptr(group->pcpu, cpu)->seq); - group->next_update = sched_clock() + psi_period; + group->avg_next_update = sched_clock() + psi_period; INIT_DELAYED_WORK(&group->clock_work, psi_update_work); - mutex_init(&group->stat_lock); + mutex_init(&group->update_lock); } void __init psi_init(void) @@ -277,7 +277,7 @@ static bool update_stats(struct psi_group *group) int cpu; int s; - mutex_lock(&group->stat_lock); + mutex_lock(&group->update_lock); /* * Collect the per-cpu time buckets and average them into a @@ -318,7 +318,7 @@ static bool update_stats(struct psi_group *group) /* avgX= */ now = sched_clock(); - expires = group->next_update; + expires = group->avg_next_update; if (now < expires) goto out; if (now - expires > psi_period) @@ -331,14 +331,14 @@ static bool update_stats(struct psi_group *group) * But the deltas we sample out of the per-cpu buckets above * are based on the actual time elapsing between clock ticks. */ - group->next_update = expires + ((1 + missed_periods) * psi_period); - period = now - (group->last_update + (missed_periods * psi_period)); - group->last_update = now; + group->avg_next_update = expires + ((1 + missed_periods) * psi_period); + period = now - (group->avg_last_update + (missed_periods * psi_period)); + group->avg_last_update = now; for (s = 0; s < NR_PSI_STATES - 1; s++) { u32 sample; - sample = group->total[s] - group->total_prev[s]; + sample = group->total[s] - group->avg_total[s]; /* * Due to the lockless sampling of the time buckets, * recorded time deltas can slip into the next period, @@ -358,11 +358,11 @@ static bool update_stats(struct psi_group *group) */ if (sample > period) sample = period; - group->total_prev[s] += sample; + group->avg_total[s] += sample; calc_avgs(group->avg[s], missed_periods, sample, period); } out: - mutex_unlock(&group->stat_lock); + mutex_unlock(&group->update_lock); return nonidle_total; } @@ -390,8 +390,10 @@ static void psi_update_work(struct work_struct *work) u64 now; now = sched_clock(); - if (group->next_update > now) - delay = nsecs_to_jiffies(group->next_update - now) + 1; + if (group->avg_next_update > now) { + delay = nsecs_to_jiffies( + group->avg_next_update - now) + 1; + } schedule_delayed_work(dwork, delay); } } From patchwork Thu Jan 10 22:07:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10756997 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 D69F517D2 for ; Thu, 10 Jan 2019 22:08:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0E0929EF5 for ; Thu, 10 Jan 2019 22:08:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B41ED29EFD; Thu, 10 Jan 2019 22:08:25 +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 8BA1029EF5 for ; Thu, 10 Jan 2019 22:08:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 174FE8E0006; Thu, 10 Jan 2019 17:08:22 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 124EC8E0001; Thu, 10 Jan 2019 17:08:22 -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 F08DA8E0006; Thu, 10 Jan 2019 17:08:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 9A5868E0001 for ; Thu, 10 Jan 2019 17:08:21 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id v2so7007904plg.6 for ; Thu, 10 Jan 2019 14:08:21 -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:in-reply-to:references:mime-version :content-transfer-encoding; bh=Bksm8QgIpk0mhgRhfImjkl115x47YhafN1AI+7vsErU=; b=eFHjwjpppG2Kj1npy1Ew9VcpInW52tTVzzoa0XOz9mZNdZ61kfAlaIOce2piEq59jY E04+G+zKkK6i+AnoR08Cr+29TupxleEdTOi+lCugpyj6BR98ygvxsPZmp6LNrvNftS2U jkj5Ab1NfxBVW/hxDtNKo6MO9xE7PRoxs+h0OCqEx3xBtrHlfo6E0yzU+1TxQpQDGpe7 c4SdX1y6Z0ihsvWvPT/q4Vs/iLyTcajTOXIDK+3Ao8AQXjG767NOPLcD2TMMzf7Xw4qQ ptYuoUXUCEDcXjFGKFA7RgzSb8bSsNABe4VvGotyhfzSarhmlUDLxypm44NdMnOi3q22 sRXQ== X-Gm-Message-State: AJcUukdVBUtXFmlKIMn0tdB5pqiyphD5vanClSi+1OHykpxSu/udD/V+ cqbYhvDoDfeXbbYo1UluQMhvUln+cSQqekmh44JZQpKNwHf92gOfUsEAKOwvSzf/2LDgoB+Q0oQ SIUfletqJgWLX/eqvRx5VcceX3eVtcZlDTfugRWsR44rSphJyqDOFyWjXHBBPdobdkHDzRaconT 1wyH85WTLn+S+vT4A9JRZXbB+IrhKlDMOOTr01ADuLcDqPQqj8aYB2H9OyRFvlRsyx/1CoY/RXw EpdDJVo1kTiv4RYLUqq9Lv2TTIU6qaSKQ506RIrE2YJQOgUGTQcruP19UkWkCA6FOfzCxGm24/P 6dBpkqEdkWgw23v+hC2zcdKRDHEs960Yc2yllZ4ngB3QbSyCywQMzd/BhUcqK7rltEckt2ozcjg 5 X-Received: by 2002:a63:fe0a:: with SMTP id p10mr8742607pgh.265.1547158101173; Thu, 10 Jan 2019 14:08:21 -0800 (PST) X-Received: by 2002:a63:fe0a:: with SMTP id p10mr8742479pgh.265.1547158098718; Thu, 10 Jan 2019 14:08:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547158098; cv=none; d=google.com; s=arc-20160816; b=mqjixAPvIXYtsjib9kjYyVcgSehkbmL0H6t7nKZVpMRtLa3SOJ229D4eyPYu6LRzLZ r3BBMFschxjHHn48KDYaMdFQ/FsK8IBLeoaylVBayYiHt3Ut7F8LxJsf2HGr048+LmpX /9qUK2KnaFG0dFQQGUmo09E7nnCRHjwqu8l8f3/Lz5WWSDCoNukd0X7UzXYPIqQ1WcbS G/USsPPCI1B1HaehKMRtzTeDNWJm/3+vD9c1Ke38yh+27sXHaNiq/TFX1vwHYA73O+kT p6iZp17j0TNAgNpf9Bx5I5Fg6srdLtsJ7us2ff+cCzfdS7XFFhuteGWe/knQdQq9nl3A aVzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Bksm8QgIpk0mhgRhfImjkl115x47YhafN1AI+7vsErU=; b=hjwwWjdChFDGimAsPbojmfRMYlbxGXktYSHsL9LCjMxCpxtn1K13dDhwLVEk6QiazT ue9A+Ht69tpbjHfgkRETV1+YYta+of+GVfU9B0tgoVG6+bEVXsOiUYhWyrKuTlz8nEYU 7H0k7uXfGa99US+BeWWK4vHWC/IGyQhvjj/ZL0L4OGFZ6gzYUvEzwUXOU8t0htjfWZ/y KYSCwi1S5zphbYGOYq3l5a2CVn+Au+kGYhODPSW+QNy7+hVHoFtXbszeH7KZFDqY9J8k 67D3b3SSGKbWNP64JtykzWwOmUHAotoL3fCGCj4vk6jkkPyqIeO19ReHZbxr9pUoZHMe 2aBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wASq212f; 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 gn15sor490300plb.64.2019.01.10.14.08.18 for (Google Transport Security); Thu, 10 Jan 2019 14:08:18 -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=wASq212f; 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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bksm8QgIpk0mhgRhfImjkl115x47YhafN1AI+7vsErU=; b=wASq212fPJAbSw+wDVzjj4TGxnkBFur8nfdkTP9iLdfs8nl+TPnRkKbu/aoj6sFgtC /t+g1WSA4iZeeNksTjZLTdhVA4w5sFCD03hsISvSFSzO6eTR3/6LKmKAzcLe+uKgXaRg PleSXlF5ESDh4+oHMs/qfZYkPgMVx19FkANmmcmzAyriz/1a9o1443VgvtPcMFpBMwUM GWBVi0J8y9Xl/3V9CSo51itmCCpTl2mrK93bHLAAlGNjw4dy1ZVFXMoXXUwlTmH0+mHN 3HTZrAJiYe49cOueM+mPs3jmD4gJDUhkdcy2AyVMnllbqvUq2XhsnSA+yPDhmqaQcCNY XP2w== X-Google-Smtp-Source: ALg8bN5ga+MMqMuzoOfiJZ44lkbun/HNzvHb8pDsCVfwfOYipzi2bieVhP/zvaJ0UNyREBa+7i1urA== X-Received: by 2002:a17:902:4401:: with SMTP id k1mr12148610pld.307.1547158097575; Thu, 10 Jan 2019 14:08:17 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id p7sm152958019pfj.72.2019.01.10.14.08.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jan 2019 14:08:16 -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 v2 5/5] psi: introduce psi monitor Date: Thu, 10 Jan 2019 14:07:18 -0800 Message-Id: <20190110220718.261134-6-surenb@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190110220718.261134-1-surenb@google.com> References: <20190110220718.261134-1-surenb@google.com> 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 --- Documentation/accounting/psi.txt | 104 ++++++ include/linux/psi.h | 10 + include/linux/psi_types.h | 59 ++++ kernel/cgroup/cgroup.c | 107 +++++- kernel/sched/psi.c | 554 +++++++++++++++++++++++++++++-- 5 files changed, 802 insertions(+), 32 deletions(-) diff --git a/Documentation/accounting/psi.txt b/Documentation/accounting/psi.txt index b8ca28b60215..6b21c72aa87c 100644 --- a/Documentation/accounting/psi.txt +++ b/Documentation/accounting/psi.txt @@ -63,6 +63,107 @@ 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: + +