From patchwork Thu Jan 24 21:15: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: 10780151 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 372401390 for ; Thu, 24 Jan 2019 21:15:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 265F32F810 for ; Thu, 24 Jan 2019 21:15:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1722F2F876; Thu, 24 Jan 2019 21:15:50 +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 8EC8B2F810 for ; Thu, 24 Jan 2019 21:15:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B93F8E009D; Thu, 24 Jan 2019 16:15:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EE3588E0097; Thu, 24 Jan 2019 16:15:47 -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 CE5EF8E009D; Thu, 24 Jan 2019 16:15:47 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 8B2328E0097 for ; Thu, 24 Jan 2019 16:15:47 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id l76so5724660pfg.1 for ; Thu, 24 Jan 2019 13:15:47 -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=hQMXtShjYz4LIok46DuN+DSpcNGcRKZs3McroLRrGJw=; b=CFEif2lIKLIa28DL3OGg9/fm9oY/SepTNwuP77/J9EfuR/oT0S2xvtDoh6vF7UWZy+ it4SZOkKLsxhZ4gG8sc1h/vJESF140n0TBuEhChyhYw1j//L2U8X3sDjVXXvmfjOdcAz /iURsRwOz8Ewk51Jftl7GPCnZ7VUmkm6ToAPyJ4Oc0D9OlMharjzkJuvsG6JEHv6lY3g Hg7TmlGXVXWRWKU4sPfn0NNK63DEkgWeVO11X2Qe9XrXAYuKWPyh4UwzWpDDhW3yBZys Anlk8YeVCIhn+58C+qP1EEt5X0xtyhUrW4fOK85yV0QOHXWtCp9r2WK08S84dToSAMoW d/mg== X-Gm-Message-State: AJcUukfa8LLcm4uBGnfyeUbXgm0P6zsqKEqVmqDka8opiq9nrcipgWwO wXRy2wVCK+Ra/aksHkhZO6tQ3WhiJwDTzM1YeI8Fuh+6KtKI1i9wOVDvdidxf/gkx6IqNPHKqbg G4xCnbvqN0CSZUSvqp5YINwt3TI5NIXQfFkmc7gifRtrW7dgzIQhewnx3A9UNWRNVkLn2sKe5RS 4nMwJr1GmjIKErXdSjWnTMHURcuC4qQxK/MVdWLEzz6Fq6sZOtvMK0NqCVigTO3+Kj/KPQDZejl c/wCbMr2BNwJ/PpZ1umq1G+BgH2YF0Oxr65t6BkpfJzI7dhzQ5JhBFC3YoE2UUHeg1M90QMRe6Z 9SFJU3YNt6xuhMWxGl4sWWtzdaBm1GTpVgsTg/a5ZDBPV7KODDa5FebkeNSerHOl8pKxq1yzbm2 M X-Received: by 2002:aa7:8758:: with SMTP id g24mr7991278pfo.250.1548364547213; Thu, 24 Jan 2019 13:15:47 -0800 (PST) X-Received: by 2002:aa7:8758:: with SMTP id g24mr7991234pfo.250.1548364546371; Thu, 24 Jan 2019 13:15:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548364546; cv=none; d=google.com; s=arc-20160816; b=qQjv8gXqQbs7YVLrx4nRzYSeXnFUiaFD/AthoGkBIZFfudCC/GrC2jDrWyxlnO9I6k yIbDM2JV2qffs7EBZQeObvX57lvVtK5xQgPl/3vihjTQLJ9S/2BHQy/mx4+VS+I6s+RV ONQZSu45XJBvNW2T5zGrt77Vj/598h9jGis3Lr5cnOA7MMQBLCJqHXcO/OF9qGy/9nkn P0by0QnQOP6fU0NpuyT68zul+5BtylvbZ2spdig08e1j3YKAddjqT05y6qnFBSpiA5h0 ge54FB5VeKBgeolh3iJlSKDR1SUvJQ+cgAYMMHTbReLr1dE2Pw8sFHRtS2OC4Bc6GgZy QdSw== 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=hQMXtShjYz4LIok46DuN+DSpcNGcRKZs3McroLRrGJw=; b=eH96APQGzQsnxmtrw+aKCcwSDDYg1edlBhnz8UBMnv3/REGRXb0WlpNb3C7MK7j48x fohF2XIxMKnbs1X2AmMG1oyMJHSvukW+0OqkKKPRrKQuEDbOH/MRV4TPYEmbT3+FDi+9 EjisRJ0duQx3ToAAMdaI1yHroKTaN6uNarQ21jDuZpn/LBzpmImpdQ1449JwHABImuCH aQZobJwEvu0sRAHx6vYiDzojoenxnGuloa5iGscMT7QceuLVnH7hGXR0hqZYVsl9o7M9 i1km8VQHmc6jBUSnpV1ppqJcXQG+6STB/KmzQQQLDTsCf00dP/UFzwq4cilgAFh3bfcb /7zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=j20YsKHG; 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 p3sor32892617plo.56.2019.01.24.13.15.46 for (Google Transport Security); Thu, 24 Jan 2019 13:15:46 -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=j20YsKHG; 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=hQMXtShjYz4LIok46DuN+DSpcNGcRKZs3McroLRrGJw=; b=j20YsKHGwaT+e7qtfX+pJMn7EqgnnAg98DHCtEKAcNNAthLRLG8JE/6hRv7KyQ5Iiz g0cQdc6pIJoSNiXlKr5WinqrLgPEyyyT3ueTy2KBOv5V7YP+cZAFTlF+rB9CIxSpQJxG r43vq8LUoKlLqhCQAloIuMQU+cSFgagDdDNtqJu/3gx84lgakSYZqN2brhiwObjRTIf1 X++KVwfttX10Q5Dwj4X55d7C4wtHOvzDch/8RmJjhBu2y0rDPFeIHjbFfjE540Fv/dvd jBcaZipg2xsJp2QnwLiTyYtSLmwgKypskSEK4EcIDc/gjPZnGZm3zMY3OayW//GIfrhe DCuQ== X-Google-Smtp-Source: ALg8bN7nCufI9BYh2GZ0ogHwAUMbkmGJZbvBktdzlwXxc4JpxluUrMJcb20Y/QlbwgK+in4KOP50ww== X-Received: by 2002:a17:902:d697:: with SMTP id v23mr8003217ply.261.1548364545767; Thu, 24 Jan 2019 13:15:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 13:15:45 -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 2/5] kernel: cgroup: add poll file operation Date: Thu, 24 Jan 2019 13:15:15 -0800 Message-Id: <20190124211518.244221-3-surenb@google.com> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190124211518.244221-1-surenb@google.com> References: <20190124211518.244221-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 8fcbae1b8db0..aad3babef007 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 @@ -574,6 +575,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 f31bd61c9466..e8cd12c6a553 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3533,6 +3533,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); @@ -3571,6 +3581,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, }; @@ -3579,6 +3590,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,