From patchwork Fri Dec 14 17:15:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10731483 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 18DF1746 for ; Fri, 14 Dec 2018 17:16:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68FF62C807 for ; Fri, 14 Dec 2018 17:16:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C5042D8F5; Fri, 14 Dec 2018 17:16:16 +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 241422C807 for ; Fri, 14 Dec 2018 17:16:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FC578E01F5; Fri, 14 Dec 2018 12:16:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2AE548E01DC; Fri, 14 Dec 2018 12:16:14 -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 1C3078E01F5; Fri, 14 Dec 2018 12:16:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id D10C48E01DC for ; Fri, 14 Dec 2018 12:16:13 -0500 (EST) Received: by mail-pf1-f200.google.com with SMTP id l22so4893493pfb.2 for ; Fri, 14 Dec 2018 09:16:13 -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=yD7OmIaga8bq3vgrhrUeca0ttxxjagifsHLQHNzU5W8=; b=gvaeasxpZIK+Y1XO35GteebPmPHWnHKvNQTdUWJVJM7EkAi3SB1UUFWnAf+nJX5yfG onYcxWhXNyXTgHhlZO3RCadvYmspLuNKG1zNm/Bw+LH+39EgPDQ0Sls5Hs0zZGMN8DPb VOKxEswnTc0v89Rb4OFutEhsRQG1wDm5Gnfwd+EeKVQxm7oqiS661vprk4fEH2mFKHTx 3wy9ldAnXbattSYqDBr4bms4DNJ1PjV5bT07oSkbtJn/k9b6rJbLAxlY6AA5LKxqoc6t G73AngBMy9umaOzh11Yy9gC+soinkbYd1PvlLYebonqbGVulTPObxDWW4OdnuRnP9wpP yjSA== X-Gm-Message-State: AA+aEWZkS6/a3lx63434BNe4BrHFhdVe2kwXxlsJeXpsiAsnQ+OkrOoo fqcsvPvR41rdCaJA8MaSiCrjMZ+jUMW1ekcf3XZrAuqRo9aNLzWAUtEep2Pw0SHujXYC+BaG9pX uXaxZJnXtvJsUBVu4oULrXuGuryAdEb4yaA7f6S75AlLK9doDdjBDQDxLYNt2y0mFtgM8MbECSY L1ZyLHjW3F9BYR03OtaRtThN9Ud5K401wFqcQumdv5FT9Qq6WMlPxSkEqleZV/ccYn0GEWw5ANR bNYng6gkUdMvpYMlVJCi4S2bXHcMjvze5Q1FJKDucqN4mSDaXhyinCMc/5IgAe2rnXq9kEHD8x2 QI8YNconoCtjSOrgjPHZI+Wiayyy6Rm75Z6k+U0d1WDyV5WE3SEashSPPvNw6+QD9YpluqXQHYz 0 X-Received: by 2002:a62:3a04:: with SMTP id h4mr3545429pfa.119.1544807773506; Fri, 14 Dec 2018 09:16:13 -0800 (PST) X-Received: by 2002:a62:3a04:: with SMTP id h4mr3545362pfa.119.1544807772664; Fri, 14 Dec 2018 09:16:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807772; cv=none; d=google.com; s=arc-20160816; b=r/F/ysQMEMDHrUewRuzQEVUsNY+vMjjbJjL4WTlrTaZFHbcg5tt0JrhNe/vazl1w46 k5giVwOjTSPBp9Qga/IO0nrIic4tBUnhn2Jl5LUT1jsvoCg8wh1i7Bi1TI5O44w95Li9 3GG29l8ybUa+PXvmSYjn9HfCz1nNbUkc1EDwWSzddNTBnvTXLrhmXEDwBY152ITUJhdv yOzGkATJLfFBfGaIRAr/ttdw0z3BljA4e41B9+iD/xfGc+RD9utVmyZw5MkP8iWQCXIj NmQqm/f+w6hMwpRs7lY6WZ5A23NJPpIGCi/MM2Jo1N6lYH9Sl0kwRspGK7HCZgBgX3rI 1uFg== 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=yD7OmIaga8bq3vgrhrUeca0ttxxjagifsHLQHNzU5W8=; b=XZRzx+u+HWXbr9U928tD16aMv6/Tf9qJbWjd/bD5cr4w7pNKbpJtsPx0753IOuUKiD i2eyd0WGTovixQhGCIdF9x9L08C1y9kypXQobWE9eJ1wWp3YBMuG/s9FuIJWHaVMhSCl KD4UrLH2kJ/moDk4owuYCt6dYaz4zp2BqCZKXGIKq1sMlb31pO+q+DKm5iMMDSVuzNtR pbMt+Cc9Zv48te3ww0BuLNThlprgylpCZUSKNIp2wpO7DDpJcc/h1HPzX1WEEOXGoh+p LOVYaNK5n2AJAmI97G4ZQ0fzww62mru8H2VlS/Hndw6tiGVrkQkLQjGT8jOiWioX/Bz1 J7FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="q3/CpAxD"; 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 y23sor8848733pga.35.2018.12.14.09.16.12 for (Google Transport Security); Fri, 14 Dec 2018 09:16:12 -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="q3/CpAxD"; 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=yD7OmIaga8bq3vgrhrUeca0ttxxjagifsHLQHNzU5W8=; b=q3/CpAxD8RTwSJRxe5o3byeeJqR4Ch9hUc+/pjXFAQHyESWPfGmuc9y016j2l0B/Xi iS5TEYe/572UOGk6qTUy/EBPF5sohGdF2ZNPjZmHrmtC0RB9p4UAxKf/aEWSyQjYkJGS hiJuNCETCQGWMg6FZL37p47irAMo33zWPoArR1izOd4yzgD00jCUyzX+wnNwImOMELMX JIRZs26qd+A29xirIw3kZtAjP9sNrkRt48cnoTU9mlzvu0BN1GCQ8n+bJvxcYe9LENjh X1AM1EtQrgCaXc+FeG4GR8Bl/R+fbTGdnOAhDXmJyi6z7OK0fAzRpGYZ97xlWT3jUPrL jT4Q== X-Google-Smtp-Source: AFSGD/VXkMTwawtJFy5GzNnm00dKDRrt8F4j6Io6OBC/4OXzLeoNlmGpk0vqxx2kzPbz3iJXYDAwIw== X-Received: by 2002:a63:4c4e:: with SMTP id m14mr3433828pgl.173.1544807772132; Fri, 14 Dec 2018 09:16:12 -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.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16:09 -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 1/6] fs: kernfs: add poll file operation Date: Fri, 14 Dec 2018 09:15:03 -0800 Message-Id: <20181214171508.7791-2-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 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 --- 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 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, From patchwork Fri Dec 14 17:15:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10731487 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 3E7EF746 for ; Fri, 14 Dec 2018 17:16:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D6202CD9E for ; Fri, 14 Dec 2018 17:16:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EA552D8F8; Fri, 14 Dec 2018 17:16:23 +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 CEFF12CD9E for ; Fri, 14 Dec 2018 17:16:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A76148E01F7; Fri, 14 Dec 2018 12:16:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A28138E01DC; Fri, 14 Dec 2018 12:16:21 -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 93DB28E01F7; Fri, 14 Dec 2018 12:16:21 -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 545AD8E01DC for ; Fri, 14 Dec 2018 12:16:21 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id g188so4282874pgc.22 for ; Fri, 14 Dec 2018 09:16: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=0FDvkv6tsCm3cNzadfLexl6yl6Uin8gL5JMahmII+z0=; b=MiOP7GtqqCM3wBwsN7lZ00AhzkZ5Ue2l0p5lpvPIwpKcKmEjHjzRysvToowg6iNOKn eyvuYM//Wiofi7xRi9lM9csFZ024oC8E1Irb5IwR42LDAHsFI73MLxVCEBEPRvTqIU5L sktfl2yQTdFynlNsTblPtyRjkhlHVBVSmhpjze7R59eilYxh1TDwWSQ5lU1vubzqwxLv XGTCh0RVmZTi5VcEnuofP7OWMRk2mvJpcJszb/S3nvNLpIQNWr/3VEmNtnmv12Ng4mQp 3UcJBD+G3iIluaILjURlcmeZqJQGIkoeAoUkOP8Y9ISU0xK8Hr+eUsI9TiHmwhD5hIT4 pDOw== X-Gm-Message-State: AA+aEWY9MwzQeI2gDgKbnbEwJUMwo6cEA+SxtaObRUT4eiTgqjo6KFp0 KMzcotzgiQWXZyjRUiTJwn1W2b5wf4WyEj0Yh8H9ETGC41M2LrT2Ds7nDcJTUbB4NIfPUfhcWhH JybVey21NpJy7wHRv2WhGT+AB4w3sHW0LVjabRi/g8hLIf74lszoCuMp6/uTJq0/N1trQ15Jo+V HhDcuHNSY8x0e3tDyVLipadj5mqFnElwCAbeQ1HpO8fV0JJaQCvzu98j2ZANtxafZ7P+d8r3g5A XgZgAHal+Z2u+xf5IUignfwphIBHHUuzVZgjYllxeYBidTpBwPjNuVGPCXjHTr/4dhSBprsmJa7 zwSN+6wWaei4Oq0jwrrzs2vnYDlRZ6kfXuXuX7BmqsVtN4L0BECz08DP2gQbn5IBzKf3Hmt5x4D W X-Received: by 2002:a62:7796:: with SMTP id s144mr3599010pfc.26.1544807780980; Fri, 14 Dec 2018 09:16:20 -0800 (PST) X-Received: by 2002:a62:7796:: with SMTP id s144mr3598945pfc.26.1544807780116; Fri, 14 Dec 2018 09:16:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807780; cv=none; d=google.com; s=arc-20160816; b=w7TSUurj4k2q6w5H+5C4Bs1I5LsH5voNQ0INGcZeKutlIQlg4o0Jql9pv/ufOi09YY uLk+iFAZ+qBz26vFI0KX2Jls4BUlzTk8PPYIeoxTTbCyZedclj7gOgdWZ2QbgsyQM2rb qQWaTzbKAvnSu0L50femMRlo7bX4SK8llAOkh6oQVTHUzxr+VZ/cLvOxp+lZ0vmO7SEJ 1SSJEZxzC9aRYJJ8LKvOYz9EDzo/HVjZf08K3UWV+HyzV79FyzDZ4CunNK8uufcggEBQ wMbSYRWFwmH5g1LtTpFqW8DSHQxZmFNEMUsLbzmMYfDlH5/56CCWl/TXAZE31FMm/B8v 4yMg== 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=0FDvkv6tsCm3cNzadfLexl6yl6Uin8gL5JMahmII+z0=; b=BYmbTf5/sHVO6kJ2JiUDRpIv0TjE4nrzTh5zl6c4BRISJuzX1cMwKFTZio5pYP61Ae kOir5SlObURSxjMsUsiQw/1VzqrwdltSVWlqblLyBSk9VxORUGemomJinDL8EbK41pMN yUYlpZGqC72T4h6GKYcP6SqBRhG1d6cLNZ1txQljkSDqbrt++ajkSzh8duwrTaOVrhQz 6kMB99n64xUyEW+/PRKgWjoaVmaGvmvwtHxsKKxjkhoJv7KOLyV2fqF1FgGLX36pmB49 3DFO6cfH4GZdQ7WX84BuKGZIMw3IOAlejDJOxhpTd242U1yvQW0lJpd80afD6EPgXkAn XeEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=U7EhDtis; 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 f15sor8962239pgh.59.2018.12.14.09.16.19 for (Google Transport Security); Fri, 14 Dec 2018 09:16:20 -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=U7EhDtis; 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=0FDvkv6tsCm3cNzadfLexl6yl6Uin8gL5JMahmII+z0=; b=U7EhDtislcgtKwumTakwNlDb98xcrJsvjaV6Zryr6uh98v/X4ttIUEcIfmGS4+Clob Dq6lSfqfmvQnITixqwh8F/5sm+iIWl1DSGD5CgvrrossRO68btMuVKtwGATCwSMPjpVE MAgpvb/UKiyUxWqpcsTITxFdMr6goCKyPPbvVM5p9b5fm3pvQENuWmy7H48Q67WduI/w Bqd+0fjT0cLR0fmX3zJ8lEgyzzpQx46+/E88TCgOmEFUKMYDOi6ZLJ3EikAkgW4hhZ+S FLs4OCUrn7/Z8F98XEPUqRXkLstLrZtJ7PB8fzd2XH0wASjNIodngZXI5XpdA6vNibsN BuLQ== X-Google-Smtp-Source: AFSGD/XxvjRonJ8g4MyFx01iXwrNYJuQQi0FMNBwa7K0SFsZMf2wrlu6z7ySWVpaogG9SwMJ4PpVhA== X-Received: by 2002:a63:d604:: with SMTP id q4mr3363458pgg.175.1544807779468; Fri, 14 Dec 2018 09:16:19 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16:17 -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 3/6] psi: eliminate lazy clock mode Date: Fri, 14 Dec 2018 09:15:05 -0800 Message-Id: <20181214171508.7791-4-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 psi currently stops its periodic 2s aggregation runs when there has not been any task activity, and wakes it back up later from the scheduler when the system returns from the idle state. The coordination between the aggregation worker and the scheduler is minimal: the scheduler has to nudge the worker if it's not running, and the worker will reschedule itself periodically until it detects no more activity. The polling patches will complicate this, because they introduce another aggregation mode for high-frequency polling that also eventually times out if the worker sees no more activity of interest. That means the scheduler portion would have to coordinate three state transitions - idle to regular, regular to polling, idle to polling - with the worker's timeouts and self-rescheduling. The additional overhead from this is undesirable in the scheduler hotpath. Eliminate the idle mode and keep the worker doing 2s update intervals at all times. This eliminates worker coordination from the scheduler completely. The polling patches will then add it back to switch between regular mode and high-frequency polling mode. Signed-off-by: Johannes Weiner Signed-off-by: Suren Baghdasaryan --- kernel/sched/psi.c | 55 +++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index fe24de3fbc93..d2b9c9a1a62f 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -248,18 +248,10 @@ static void get_recent_times(struct psi_group *group, int cpu, u32 *times) } } -static void calc_avgs(unsigned long avg[3], int missed_periods, - u64 time, u64 period) +static void calc_avgs(unsigned long avg[3], u64 time, u64 period) { unsigned long pct; - /* Fill in zeroes for periods of no activity */ - if (missed_periods) { - avg[0] = calc_load_n(avg[0], EXP_10s, 0, missed_periods); - avg[1] = calc_load_n(avg[1], EXP_60s, 0, missed_periods); - avg[2] = calc_load_n(avg[2], EXP_300s, 0, missed_periods); - } - /* Sample the most recent active period */ pct = div_u64(time * 100, period); pct *= FIXED_1; @@ -268,10 +260,9 @@ static void calc_avgs(unsigned long avg[3], int missed_periods, avg[2] = calc_load(avg[2], EXP_300s, pct); } -static bool update_stats(struct psi_group *group) +static void update_stats(struct psi_group *group) { u64 deltas[NR_PSI_STATES - 1] = { 0, }; - unsigned long missed_periods = 0; unsigned long nonidle_total = 0; u64 now, expires, period; int cpu; @@ -321,8 +312,6 @@ static bool update_stats(struct psi_group *group) expires = group->next_update; if (now < expires) goto out; - if (now - expires > psi_period) - missed_periods = div_u64(now - expires, psi_period); /* * The periodic clock tick can get delayed for various @@ -331,8 +320,8 @@ 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->next_update = expires + psi_period; + period = now - group->last_update; group->last_update = now; for (s = 0; s < NR_PSI_STATES - 1; s++) { @@ -359,18 +348,18 @@ static bool update_stats(struct psi_group *group) if (sample > period) sample = period; group->total_prev[s] += sample; - calc_avgs(group->avg[s], missed_periods, sample, period); + calc_avgs(group->avg[s], sample, period); } out: mutex_unlock(&group->stat_lock); - return nonidle_total; } static void psi_update_work(struct work_struct *work) { struct delayed_work *dwork; struct psi_group *group; - bool nonidle; + unsigned long delay = 0; + u64 now; dwork = to_delayed_work(work); group = container_of(dwork, struct psi_group, clock_work); @@ -383,17 +372,12 @@ static void psi_update_work(struct work_struct *work) * go - see calc_avgs() and missed_periods. */ - nonidle = update_stats(group); - - if (nonidle) { - unsigned long delay = 0; - u64 now; + update_stats(group); - now = sched_clock(); - if (group->next_update > now) - delay = nsecs_to_jiffies(group->next_update - now) + 1; - schedule_delayed_work(dwork, delay); - } + now = sched_clock(); + if (group->next_update > now) + delay = nsecs_to_jiffies(group->next_update - now) + 1; + schedule_delayed_work(dwork, delay); } static void record_times(struct psi_group_cpu *groupc, int cpu, @@ -480,9 +464,6 @@ static void psi_group_change(struct psi_group *group, int cpu, groupc->tasks[t]++; write_seqcount_end(&groupc->seq); - - if (!delayed_work_pending(&group->clock_work)) - schedule_delayed_work(&group->clock_work, PSI_FREQ); } static struct psi_group *iterate_groups(struct task_struct *task, void **iter) @@ -619,6 +600,8 @@ int psi_cgroup_alloc(struct cgroup *cgroup) if (!cgroup->psi.pcpu) return -ENOMEM; group_init(&cgroup->psi); + schedule_delayed_work(&cgroup->psi.clock_work, PSI_FREQ); + return 0; } @@ -761,12 +744,18 @@ static const struct file_operations psi_cpu_fops = { .release = single_release, }; -static int __init psi_proc_init(void) +static int __init psi_late_init(void) { + if (static_branch_likely(&psi_disabled)) + return 0; + + schedule_delayed_work(&psi_system.clock_work, PSI_FREQ); + proc_mkdir("pressure", NULL); proc_create("pressure/io", 0, NULL, &psi_io_fops); proc_create("pressure/memory", 0, NULL, &psi_memory_fops); proc_create("pressure/cpu", 0, NULL, &psi_cpu_fops); + return 0; } -module_init(psi_proc_init); +module_init(psi_late_init); From patchwork Fri Dec 14 17:15:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10731489 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 C744F746 for ; Fri, 14 Dec 2018 17:16:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2335A2C807 for ; Fri, 14 Dec 2018 17:16:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1754F2D8F5; Fri, 14 Dec 2018 17:16:27 +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 826032C807 for ; Fri, 14 Dec 2018 17:16:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E34E8E01F8; Fri, 14 Dec 2018 12:16:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5BA248E01DC; Fri, 14 Dec 2018 12:16:25 -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 4D2178E01F8; Fri, 14 Dec 2018 12:16:25 -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 0F35F8E01DC for ; Fri, 14 Dec 2018 12:16:25 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id 82so4851036pfs.20 for ; Fri, 14 Dec 2018 09:16:25 -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=YwSYAI43KM10GrnM4hZ3Qtd3y6BkTcR7ZHO9M+skX2s=; b=B26J0xHp3RAjTbQCtXuTyVUZILuMq1e58iwiTnKk6YFhk9BS752ej1FaPQ/pmUPn+X JLgGJeEmbFbRhGIxsih8cqUpLT5i+6ai8GZCTnamcysPPTYT+GAkP9DeBD3M7FxIYppU 0PVZEfi30tG5+5zw5qLKZAVceFZNhXvl4GFNgwpdlxSzCC+3XAmaLjsZGv6G5dPim0LN DPKEFcUBxvpfOH/wxB0UHLkAuSXCGS5iFIp0YM/Z73EHBEFBLa9P071sZQZhuHC7LJtt zJqfXPNB+UHbiPmi09OtRWTmCx9BmupLAsUf2fLFVqA/tH1ZRwhdOhu6fsKLFNVhId9E f/Nw== X-Gm-Message-State: AA+aEWYTIM/ZCEmomc++0WfVXSGXNCkD7ppOtSF90ZapKNJaGvd6X3As nDuce8aajMzpMcciiN1u/Lr6kzTly3PVJsk9EON5LkIbfAFmla6Hg3+P2rQQPyoDv58zCIEXrtl EUwadBbC0Zr5LrGgB4ko19MyjfRrWzpRae0akPfCBNn5jCqMA+CzW8c6ZmNDrEQubnNRofmRGHx OrhKbIPiOvrvsxPEe0CidGwFJB5u//zIRdUNCD0K/SttaTtYPZ0NyVAG5RUxLVXpFyzkX6dU6Jt GbAEfNWuDEM97IpHfnyKCGNHdqg5kbPQMJQQ/MLpnpXTu6zKvjiHcyf3qkADTyc/QIbsmng6+kc YBa1t/WbU7VAleci1NuUt10DpEOfgH6M0z4VOPInZ3B5nyliYjYjgKM8HbNrnJYe3MpeKNJygn2 E X-Received: by 2002:a63:85c6:: with SMTP id u189mr3303831pgd.156.1544807784730; Fri, 14 Dec 2018 09:16:24 -0800 (PST) X-Received: by 2002:a63:85c6:: with SMTP id u189mr3303771pgd.156.1544807783877; Fri, 14 Dec 2018 09:16:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807783; cv=none; d=google.com; s=arc-20160816; b=OR3T4mZVsB3Pa5RrFP43CY9HefVV6SH4ysHrvXXoKyyBbUhQuB9vAsQGF1X0yNbT0h mkP/UQlBqsSay0Tn1sDKMftYJjSuQ2PYH5qBG78RYQeY2oLpsnU6KMooLR2ocXBG597X P29CN7d+wlvPoRaREbVXFmV5wR7bWDDJ+mnOB2i5sCNtJDRyMkWyNYGfS0rvx+T+GFzb qK+xocTrVNiJV2H71ujm6wmxPB5O5XFAPQrlY88USziJAPoWSzN9xhHUVqyGZUqV0OvB DTiZ3Y2Y5d8lDHLa6ZR3VrsImm9WCR1sSeW9ZNYV21cunllpVUrqwuKmjWJnqsZBdALp 36Ug== 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=YwSYAI43KM10GrnM4hZ3Qtd3y6BkTcR7ZHO9M+skX2s=; b=ZfgF34L9/xveIVOQwUxh3HBHq+62m0K259Ju5KfI3EMIis2GYm9znqpW4VT/D8hntJ ztYqjURqgc2fGmRq6QkLQ5/mC6Rif7pTY+bEpQoJtWaMs671BakGPWQDCwHl737ZSMel 7sLmDaY/y7IJnQYAcQTP5GvXn9cMkV8hYarbXdtAqMjVsv3pyfSa/yjBOcW0Srsi1Gr7 xJEpMBkaYypA/3Zu3nJ/Kl05wF357l/iBLdo9f1FLsy1Jg5eihURz0by51YS9x4Ssx1U xtciLxc8amyoYu2j21egZr3YfV3Q+gle9yppg/oRpz2IcPm97CxJ3lcS85gdFMRPOj+P OpOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=akXIWndi; 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 w11sor8347559ply.14.2018.12.14.09.16.23 for (Google Transport Security); Fri, 14 Dec 2018 09:16:23 -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=akXIWndi; 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=YwSYAI43KM10GrnM4hZ3Qtd3y6BkTcR7ZHO9M+skX2s=; b=akXIWndiUHaos9TbyNLP3xeaC0ZtOOtr3cSf/ilsoUM7WywehoLoqyXEZzuFIORB9M OvxzyeHc32Q4lx447L/4jMQROuD8Tpifnb+eTjanco+ff7o+IwZScCVw5XFu71NXZHQx h65SJNlG1uCZ+LcxQFWTzPj27rLKDsz7X5nBwYOPjf33icL9nUeUcN8H4DxeA2dJ2CoJ u04GoPkgs3B2NaoDOzsMLnvT61RyHEVW0r29CnBfMfhJUd+xuXxPuur/lVVYkfCIPun7 /axdZ+sXYAdccL5hZ+AL8HqqFeX7QG3R9jGqHbyBu5W6pW9dZ01ISpGwMqGQkIolMen/ 1COA== X-Google-Smtp-Source: AFSGD/UnqpC986vJpvC7OunDuj94mE83rlw4ebocm39rs/p+lo9QYqHHDyqOGddBMnR+LPZQxbTwJQ== X-Received: by 2002:a17:902:b20e:: with SMTP id t14mr3653918plr.128.1544807783288; Fri, 14 Dec 2018 09:16:23 -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.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16:21 -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 4/6] psi: introduce state_mask to represent stalled psi states Date: Fri, 14 Dec 2018 09:15:06 -0800 Message-Id: <20181214171508.7791-5-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 The psi monitoring patches will need to determine the same states as record_times(). To avoid calculating them twice, maintain a state mask that can be consulted cheaply. Do this in a separate patch to keep the churn in the main feature patch at a minimum. Signed-off-by: Suren Baghdasaryan --- include/linux/psi_types.h | 3 +++ kernel/sched/psi.c | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h index 2cf422db5d18..2c6e9b67b7eb 100644 --- a/include/linux/psi_types.h +++ b/include/linux/psi_types.h @@ -53,6 +53,9 @@ struct psi_group_cpu { /* States of the tasks belonging to this group */ unsigned int tasks[NR_PSI_TASK_COUNTS]; + /* Aggregate pressure state derived from the tasks */ + u32 state_mask; + /* Period time sampling buckets for each state of interest (ns) */ u32 times[NR_PSI_STATES]; diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index d2b9c9a1a62f..153c0624976b 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -212,17 +212,17 @@ static bool test_state(unsigned int *tasks, enum psi_states state) static void get_recent_times(struct psi_group *group, int cpu, u32 *times) { struct psi_group_cpu *groupc = per_cpu_ptr(group->pcpu, cpu); - unsigned int tasks[NR_PSI_TASK_COUNTS]; u64 now, state_start; + enum psi_states s; unsigned int seq; - int s; + u32 state_mask; /* Snapshot a coherent view of the CPU state */ do { seq = read_seqcount_begin(&groupc->seq); now = cpu_clock(cpu); memcpy(times, groupc->times, sizeof(groupc->times)); - memcpy(tasks, groupc->tasks, sizeof(groupc->tasks)); + state_mask = groupc->state_mask; state_start = groupc->state_start; } while (read_seqcount_retry(&groupc->seq, seq)); @@ -238,7 +238,7 @@ static void get_recent_times(struct psi_group *group, int cpu, u32 *times) * (u32) and our reported pressure close to what's * actually happening. */ - if (test_state(tasks, s)) + if (state_mask & (1 << s)) times[s] += now - state_start; delta = times[s] - groupc->times_prev[s]; @@ -390,15 +390,15 @@ static void record_times(struct psi_group_cpu *groupc, int cpu, delta = now - groupc->state_start; groupc->state_start = now; - if (test_state(groupc->tasks, PSI_IO_SOME)) { + if (groupc->state_mask & (1 << PSI_IO_SOME)) { groupc->times[PSI_IO_SOME] += delta; - if (test_state(groupc->tasks, PSI_IO_FULL)) + if (groupc->state_mask & (1 << PSI_IO_FULL)) groupc->times[PSI_IO_FULL] += delta; } - if (test_state(groupc->tasks, PSI_MEM_SOME)) { + if (groupc->state_mask & (1 << PSI_MEM_SOME)) { groupc->times[PSI_MEM_SOME] += delta; - if (test_state(groupc->tasks, PSI_MEM_FULL)) + if (groupc->state_mask & (1 << PSI_MEM_FULL)) groupc->times[PSI_MEM_FULL] += delta; else if (memstall_tick) { u32 sample; @@ -419,10 +419,10 @@ static void record_times(struct psi_group_cpu *groupc, int cpu, } } - if (test_state(groupc->tasks, PSI_CPU_SOME)) + if (groupc->state_mask & (1 << PSI_CPU_SOME)) groupc->times[PSI_CPU_SOME] += delta; - if (test_state(groupc->tasks, PSI_NONIDLE)) + if (groupc->state_mask & (1 << PSI_NONIDLE)) groupc->times[PSI_NONIDLE] += delta; } @@ -431,6 +431,8 @@ static void psi_group_change(struct psi_group *group, int cpu, { struct psi_group_cpu *groupc; unsigned int t, m; + enum psi_states s; + u32 state_mask = 0; groupc = per_cpu_ptr(group->pcpu, cpu); @@ -463,6 +465,13 @@ static void psi_group_change(struct psi_group *group, int cpu, if (set & (1 << t)) groupc->tasks[t]++; + /* Calculate state mask representing active states */ + for (s = 0; s < NR_PSI_STATES; s++) { + if (test_state(groupc->tasks, s)) + state_mask |= (1 << s); + } + groupc->state_mask = state_mask; + write_seqcount_end(&groupc->seq); } From patchwork Fri Dec 14 17:15:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10731491 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 88AFC6C5 for ; Fri, 14 Dec 2018 17:16:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7FF52C807 for ; Fri, 14 Dec 2018 17:16:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB8E12D8F5; Fri, 14 Dec 2018 17:16:30 +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 45D632C807 for ; Fri, 14 Dec 2018 17:16:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EDB48E01F9; Fri, 14 Dec 2018 12:16:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 19C8C8E01DC; Fri, 14 Dec 2018 12:16:29 -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 0B37C8E01F9; Fri, 14 Dec 2018 12:16:29 -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 BF0ED8E01DC for ; Fri, 14 Dec 2018 12:16:28 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id f69so4882333pff.5 for ; Fri, 14 Dec 2018 09:16:28 -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=1K/9jxBUhr3ZKbGV/xGf2bm9+2dhfv3m9ZmKXLf2XLM=; b=jL7yZNW/PMH0Me8oznMUni9Gi8FiqE7N0DGCUCY6kERhpMEZvUJlOkPjIDtHy7FfX5 p3cpvAGJXJzsxn8B94cDdCyEUs5OYKUbwAuYCUY8whBCXbtJ+EVYIfE8MRkT9+nJ2dVB wvOjJmHmL70tM0yR7ixyq5lhQq7HzZ0YlRIN93vymWW1UYXBy7p2JfXA8v0FUZp/Yoxh OgWiK3kvHDiFWNbWSs2ObjJpBdTelUnPOZfyJ2s1/Zp9t5h3wYqXi91d+L+U7SWk/ZuS 6lWLOcM2JVhZGPPD5ZQCvvxc2B6qNzJP+gd2xf/Ic6wlreDCQgD+MZnrw8GndjVI6uu2 igMg== X-Gm-Message-State: AA+aEWZ3NN6dspKSA0md0V5mdMvrp+Q8UJAHZumBSsuVV0meqMgQNezq rirIfDCiKF5m2lpFVWlBQHS7U8ZCr20ps9lPGZcm5RgK9imsAP2g9Wc0Osy+REVqY5LCo9TlrXg z6EaDgIN+v52DXPImwbkD1Bi0fRIHr/T5eknU/SWu2Hn3sUImA8Yf/YtptSegFucdrznoibZgnh xZid1mAFVsGZe1/gmaXrhXR7Gj5KmWUfZ5lWDI5opFck7OKhGMpi3tjKgMeghjpGWBdXR6RSVcD umF4d66FbIuL/mA/gUHTCG3h90Mw2RWCGUQdLAiHYcaF2kUrqJ7lI4XIqmANUFYX8QOoYQBig4H /u8QWpwN/Rwu8TfDRnsevQs1PZ3+zA6DKBFsWcJUP8bhSzFWIOh34EXHn9QKlJ3BVoD+sj1qymM B X-Received: by 2002:a17:902:22f:: with SMTP id 44mr3571297plc.137.1544807788434; Fri, 14 Dec 2018 09:16:28 -0800 (PST) X-Received: by 2002:a17:902:22f:: with SMTP id 44mr3571244plc.137.1544807787754; Fri, 14 Dec 2018 09:16:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807787; cv=none; d=google.com; s=arc-20160816; b=i8DE3SLF7AgBi9xlGPUZRSQal30lBluvjAw+LnCWVvGxiDy8E+8WNPQKGqA0OtlUgI N0AWFQF5x3hg941ehtAYO7h75B3d/dlg0MjAOG3CzG0fGTALmf8Cy5wCzDXpQQXjZ7i9 2NbAdhnztJjg2dhYHDw84DQruuD4/mwBFHOrAq7/Lc+f1Oq2QchyiUpw91s8u9A1JG17 zPaMYqK9OZZ/P0Y2cS+ttXewgAyXNv7LdV2HY0RIPl9BxD5+YVN8VY9MRh5aNHS5h56V FdIMzR84IbyM8fqfgjz1/GCkCKIPS4q0iQe0QAAZNoA0fj+GAT8oWdmJPPrJqRWazb1g uQTw== 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=1K/9jxBUhr3ZKbGV/xGf2bm9+2dhfv3m9ZmKXLf2XLM=; b=mqBgGSPQWq5YRnyTxr/V5irRzuAiECNNAIJ9vVPVSJPCTqZyrPvuJp4alNll8RGcJ2 fJgJpXpfSlwZtWSs/AI0zRgOVsbnzxivRwh2a3SAvjr6zarL9UugOHP0Xk6xRf3EMafx X2MPyJvgL2VJhimo2zjoVbzIfImAELUIfDDVOdkeqoR9yx0KYOO28Zlzsngh9uVq7wKa 2BDvc7HqLHLpM2i5cAQjUlYBw+9TLSM+4BRwhesDCvork92qlk9zuRYu1jfdK6sUDtHc ITK82192I1v8ci1flAnUz9KoAevJ/WgjYQAyhNmYXGKtZWFF9JtbzuH/u8JnvagAdrJj MISw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fdbSosqk; 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 a33sor3694174pla.29.2018.12.14.09.16.27 for (Google Transport Security); Fri, 14 Dec 2018 09:16:27 -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=fdbSosqk; 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=1K/9jxBUhr3ZKbGV/xGf2bm9+2dhfv3m9ZmKXLf2XLM=; b=fdbSosqkmOy+GOJSWJ6aOnhR9OK/6rV7BapjvJttxkHBRPlyq0NYeMod4uZFvdSdmT YuqAwToioC5aXk49M7de1ONOHk9gEsqA7b40kGqvGCau9bMzwLC+BfUXeXcvoRoXY/6z hgN9QIykNobCdulmez5DFg6uIyyRfq7Fv1vwvgOPGumapbEOiO4sslYg8YcjTvKfeWK+ Q14G6m3ZKlkUIUwWpyj24NjsPl7ZP6FsYoj8aqWhtBb9nh7IrV5WHsNgYb40G4jcArqC 8EpvQKL679AjqTo4JLW8cTKtzZMHTArygO9acydjH0zI5ExKr4x7CG85JKpbMTXGdASU 5w/w== X-Google-Smtp-Source: AFSGD/UAxdLH6HoIs+mnW869kAVAqSMJdTBnZfNTiYAZJdKFhswZe4dHVAjkbuZrTEVtGTcbSwoN2Q== X-Received: by 2002:a17:902:4c85:: with SMTP id b5mr3446926ple.226.1544807787259; Fri, 14 Dec 2018 09:16:27 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16:24 -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 5/6] psi: rename psi fields in preparation for psi trigger addition Date: Fri, 14 Dec 2018 09:15:07 -0800 Message-Id: <20181214171508.7791-6-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 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 2c6e9b67b7eb..11b32b3395a2 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 153c0624976b..694edefdd333 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) @@ -268,7 +268,7 @@ static void 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 @@ -309,7 +309,7 @@ static void update_stats(struct psi_group *group) /* avgX= */ now = sched_clock(); - expires = group->next_update; + expires = group->avg_next_update; if (now < expires) goto out; @@ -320,14 +320,14 @@ static void 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 + psi_period; - period = now - group->last_update; - group->last_update = now; + group->avg_next_update = expires + psi_period; + period = now - group->avg_last_update; + 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, @@ -347,11 +347,11 @@ static void 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], sample, period); } out: - mutex_unlock(&group->stat_lock); + mutex_unlock(&group->update_lock); } static void psi_update_work(struct work_struct *work) @@ -375,8 +375,10 @@ static void psi_update_work(struct work_struct *work) update_stats(group); 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 Fri Dec 14 17:15:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10731493 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 269EB746 for ; Fri, 14 Dec 2018 17:16:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C94D2CD9E for ; Fri, 14 Dec 2018 17:16:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DB5A2D8F8; Fri, 14 Dec 2018 17:16:38 +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 7BE0F2C807 for ; Fri, 14 Dec 2018 17:16:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 324218E01FA; Fri, 14 Dec 2018 12:16:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2FB9A8E01DC; Fri, 14 Dec 2018 12:16:35 -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 1C48E8E01FA; Fri, 14 Dec 2018 12:16:35 -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 BBDCC8E01DC for ; Fri, 14 Dec 2018 12:16:34 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id m16so4350485pgd.0 for ; Fri, 14 Dec 2018 09:16:34 -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=Nn1Ue314+SswAOf+vuY6es4gTIX1DYSVA06c4QWx+Js=; b=HbE6Ip+aXuA745ajf/4ILRRogjc66AGpdUD7HPexJ526enO84ZFgwEaIg7Mevj5Azn pMHnpuwl4e3s5nj1ShdRKR/rSv+0BwuebrjCgzWRATS+5dyMqUh2CB7QEj4ODlay5fxu M2Db+vG3h/JetFBaRuP5y2xP41z8InUbpu9ZooTK7C5x+jdYLor1Ync9Ib8X6gU5IPPp vUq6Rpe/9VNA8xhF260QSjw+sq4GRzmYNqpZnbq5DCgFVnpfCiz6FDjZ2p9nww4YptWY ikjtbwilPYTkxsGGROvrmzaaTJGsBPi/pFnkCcpalbk/GUBrVqfuXuXlhPnN0bcUHfwM 55zw== X-Gm-Message-State: AA+aEWYprCjlYN7AWRUESghF6uRAbkZFM+7pkQuy5kR0dQREfYrYACSa 9o64Rov/+1SnXO+QD+pfuqETvGRrDc9LsrabTIPvZ10ne14DSWgrUjHVgTOWhYbILwo2oeSN6wJ C0/5bN70uAVc2IxjKXFSOWPwhO5/KZaWoYdRa8DnQhzRLo6bCEf1yh3osR/Lfn3EtL/QK9GH4vh NaJmQ0ZVmRpdIufyWqsjl3Mk5LR9dF/FDiPVNReNwHAzV15hmlT9cSevGLgAAZcS0oo6W3zrLYN ybTFhOD8Al735cQFCOfz3EK03ORIW9Fma0As+DtQuAjj+4HucVqow1GPRc7PwdZUmAtgh413zTE nIL2Z5qxvHqoaZT5KALjgxH0CiFCOhX/vnZDl7A1d3ZWYUcB7f3AuctxeVU1LyIZXkNo7n2vfcR o X-Received: by 2002:a17:902:f091:: with SMTP id go17mr3690654plb.235.1544807794270; Fri, 14 Dec 2018 09:16:34 -0800 (PST) X-Received: by 2002:a17:902:f091:: with SMTP id go17mr3690464plb.235.1544807791812; Fri, 14 Dec 2018 09:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807791; cv=none; d=google.com; s=arc-20160816; b=JhGgDU3rC+ClGUExorJ9e/TuFslJ8rq1uqxN+IZJNLcLPh1JJ4QVLn5CbAX+Ld87jW yuV5ZTDZzGnM81h3s5vQF3skvlFQnbJLnwd5Tdj+0d0IEkWtjWqCfaxiR7NVHQQ5Io42 9D+HwnQH29wWHyW1PkZCKuzHLZ6l1icmCAVo1r2JQv4azaqD5WzWaMsoZoIuMf/LpR7I 3vjJ9LsdNUVzYZ7i57s2u3R3L4w7AOr7jZSmfWEgFyZvPbaDghqdVF1L5GeCZLCE6ZQE 0yow3kJAUGSzngTYhujt/txo6YREflg05TPsW14uM4nOM99aj1XcXBeNLuZuQrQEnB7N 9Axw== 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=Nn1Ue314+SswAOf+vuY6es4gTIX1DYSVA06c4QWx+Js=; b=nH3FAxfNKKXg9Jf/wu3IzGrSbgnqXQjUQD3TjOsKcVRDcnw11YB7I0/nrS9vPqFRPL VDUWTQbeixNmAx2lV6cbSJxitDZgZpwMRG2Ih8QzDSUKGx+8DtjYZ3gBwhVsdTveSQYJ nPc/DZ2Va/6d3Ef7t711+tVoKIjoo8PNA8M20sYmdpCES88ee3Cm0oOym5GWTB1T2Wbb Hv6DuYAVGGdZPnL+GfPyiaNzANa10EY4F10d4Sv2UNvmtcWxllI7PXKGYRCs1AW9/IhW PYI37MEP6Il2R43JpUjD7qRFHydYWRjxiW3tFoVxB4ef3bVseoGQ9fm9qsVLSgQOj7o2 FtkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tGiGcMHC; 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 p22sor9050510pfi.50.2018.12.14.09.16.31 for (Google Transport Security); Fri, 14 Dec 2018 09:16:31 -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=tGiGcMHC; 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=Nn1Ue314+SswAOf+vuY6es4gTIX1DYSVA06c4QWx+Js=; b=tGiGcMHCsDgHZsibAW6sAWf/+Rm39sMWc9MZsmiT0YP2QTv8F/vKO78Zq7xBDlFVkT qfwF8qJOn6J2Sazm9+qrPDsyRQWqPGYC4Az/EXSlixdSVPLx8qE785Djmu9+6N5fLsEr c2T2kCphP5DbvzPMjiIXmrYYliVwROp0ATUNGJHohc2KxoetApyu+FngwQ70bpoxnoHE ncSrXfAGWuSdskRjyJsCwvYJTL3D9Ma3j/s3KciEpNjgWYBEyQ7F+YLhCkGIg2VzOGu2 8sWwAV+bshSPo43Zv0ncsTZ/Prg1V2IbyE5IRSAOgemRx/0V6rscKkgFNgqIP4THUr+y eEpg== X-Google-Smtp-Source: AFSGD/ViMDG0O+AhMhqckGp7fTYuzr0B6jw0GK8VDwFnvYjAbS86oGJY733jEqTJCnD6+K5jz/mo8w== X-Received: by 2002:a62:1c96:: with SMTP id c144mr3555511pfc.129.1544807790658; Fri, 14 Dec 2018 09:16:30 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16:29 -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 6/6] psi: introduce psi monitor Date: Fri, 14 Dec 2018 09:15:08 -0800 Message-Id: <20181214171508.7791-7-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 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 is expressed in usecs and threshold can be expressed in usecs or percentages of the tracking window. 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 --- Documentation/accounting/psi.txt | 105 +++++++ include/linux/psi.h | 10 + include/linux/psi_types.h | 72 +++++ kernel/cgroup/cgroup.c | 107 ++++++- kernel/sched/psi.c | 510 +++++++++++++++++++++++++++++-- 5 files changed, 774 insertions(+), 30 deletions(-) diff --git a/Documentation/accounting/psi.txt b/Documentation/accounting/psi.txt index b8ca28b60215..b006cc84ad44 100644 --- a/Documentation/accounting/psi.txt +++ b/Documentation/accounting/psi.txt @@ -63,6 +63,108 @@ 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: + +