From patchwork Fri Dec 14 17:15:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10731485 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 35E3A746 for ; Fri, 14 Dec 2018 17:16:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 865D82C807 for ; Fri, 14 Dec 2018 17:16:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 797D82D8F5; Fri, 14 Dec 2018 17:16:19 +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 0497F2C807 for ; Fri, 14 Dec 2018 17:16:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E463E8E01F6; Fri, 14 Dec 2018 12:16:17 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DF76B8E01DC; Fri, 14 Dec 2018 12:16:17 -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 D0F098E01F6; Fri, 14 Dec 2018 12:16:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 8D89F8E01DC for ; Fri, 14 Dec 2018 12:16:17 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id u17so4289048pgn.17 for ; Fri, 14 Dec 2018 09:16:17 -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=sCRWYoNU0VkVJ/z3jhqejq2doYZrQjVc/bE8fLkqY2M=; b=sNeEojoG771AG1yjW2FiYKfvDcPKd/7nl2BQ/WQaTO/+NScn+H0JqmDfkXe1UZif0K b7Ypf21K9dXOVlVwpBur6lAcQM1tcn6KAlVQwQlOjCVS0ijhskgui9SXmVTc0h93tm8w 5NlgeAO2HrEk4gHZReI/3hCk42k/iSpjeNIQ39YykipVKLSqJnZB7drI8w9dld7VwcDF /vZyYObDYB0D7/MiNrqMc5yKQ4mv4Bv8IV1lBA37dfkA/tMJs0v/okSOhk5f1vFxBYPw EX6UkRS6MiBlt7huCR5nDTdsdvpFCqLFnrQXjBmEN7xR1CNEIZQQ/7GPhLVHDk3QA7t/ y4Lw== X-Gm-Message-State: AA+aEWawB4sMBS3P8exxxK0BqXaopUTypkRYdhic9kSnrNOFOcIdeu4Q e757rORl+nfzmYGkja9FEPlc6BFYnFKnbMelI2HSiMQmzZ80ZfpAjz07IgR95lbr3MdgRZ/wCvx XED3nxgCIGCnmneVVPFYVTHUIJ8yjzGczF47pvEnVHgm9mp81Z/Gp0nve0Re7pG9NH+90kk0mvO XZ/h+8GOyTcE+GdZ6IEJEjxyY/ln9LQyEvR0yZonRjgASt1VrLHasmfV5IXBd3ARPgOLwpKZLcv DKMUHOGZXNgGW+EtymTuI43GFYX5gat2JPMGyk9eNXW+MySzQBmBesEcY2NuKcgHy7B2IwyLhvV wzrUZfm/VtNeaVdfOfPLC8ls7iCfpKTdP8K91PI2tI0r5oKYq1sWxZ4Ht1bPkMujJsfp9saZy+t F X-Received: by 2002:a63:6704:: with SMTP id b4mr3470732pgc.100.1544807777252; Fri, 14 Dec 2018 09:16:17 -0800 (PST) X-Received: by 2002:a63:6704:: with SMTP id b4mr3470682pgc.100.1544807776562; Fri, 14 Dec 2018 09:16:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807776; cv=none; d=google.com; s=arc-20160816; b=zSZDjAiQBd5U/25Q2UlFq27wBcjHgQxSUiT/d7MBksGkj6+8ljM5bcGePtZ4JyaD0+ RmPmsZptuK7NnHXArqZdJ6+cFSM86ddRekjJtsYCpwA7i0i46ccTUP6I4biU7YcsLfUU Dgj5tNcX90sl3mefvwRmVOr1tP7OxFHYXoVOaOkjQxN20QXLFvSUCAHtzeVUrl/ppYW+ vM0WMGRJM1yxT3Z2FBPUZQPeAaU3L9OD0+kzkHgUZ0mBWLHgA+Xam7KN2gt7cf8wo8s5 TX8TXI8Q4McZ9Uame5YyIEwUgib8rXo2yWdV7rfnyS6ppU1AGjJuWsuhZRSVDJpsuvpZ 2MGg== 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=sCRWYoNU0VkVJ/z3jhqejq2doYZrQjVc/bE8fLkqY2M=; b=ULvzGRxhfIfoJu/cCx1VP2H5Z7c7NkMktEnqgCtvsg5IXZM1NE10bPQuZjBpGUyzly 76lA1aw8kyp5QS6s1rp/lEIKbDXpQOcYqU+mBbJ6OLFv47DVtASotY6QO69WvZhoJUEC TtUAe5JDGN6DaysGnuqkGDZhNlhDJi64aUhnI3/KIrd/urYSuUMKOCdO62bNxwhHjXaC nuTS0eRZm8qF3qmLXmli3p/j1Erx0HyR36jdE+0RCfd2p/Qag8iBLGvEto8ZMRzjE72U Xa8JUejzvR4HmkD/lwAtbH0QG/i1R95Aw7MonfpjMZG0jsAxE1wD/0+uI/TvF2aqdkwQ yt7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qtqDt0yW; 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 y64sor9074266pgd.38.2018.12.14.09.16.16 for (Google Transport Security); Fri, 14 Dec 2018 09:16:16 -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=qtqDt0yW; 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=sCRWYoNU0VkVJ/z3jhqejq2doYZrQjVc/bE8fLkqY2M=; b=qtqDt0yWn90HRTU+TjV+hv+Nm4vyH6Oihs6UoQLIHJzjQGDbObJpGMIW9v+FkBaVLR Uj8Mr9R6Rg0Sz1w7z3mYjuvKfxqj1KpIz5MHIF71R3JSGS6DuFPN+gh6/j1qi+lTThBZ bUtMX2GGllNQNpMM1hWDtA8Jb3e/DqguXh/VMkUbYokl1bHIab0fSzpccYMg5XIsFgtL cwNrvkofLgF/3zHa+CdOYBv8XhaIjPY6MX6VtZTlE9YX5+0piu/xcN/kY9kPUOGsU1hx /NMZB+XqLjN8gHVlZLBzkM9TnJZ0KARCM0+BSoqoytH9MUyVZtILnhGsikxNDrCX2BIa cXWQ== X-Google-Smtp-Source: AFSGD/WwBkLtx/2+rsJz8EKva+zOAw3UYuj7OIEVEXnn41gItTDoWAgGJfWYfZ3NqfogZ0YiSy18Ow== X-Received: by 2002:a63:b34f:: with SMTP id x15mr3471723pgt.243.1544807776049; Fri, 14 Dec 2018 09:16:16 -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.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16: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 2/6] kernel: cgroup: add poll file operation Date: Fri, 14 Dec 2018 09:15:04 -0800 Message-Id: <20181214171508.7791-3-surenb@google.com> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85-goog In-Reply-To: <20181214171508.7791-1-surenb@google.com> References: <20181214171508.7791-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 6aaf5dd5383b..ffcd7483b8ee 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,