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,