From patchwork Thu Jan 16 16:24:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 3499481 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 413859F2E9 for ; Thu, 16 Jan 2014 16:25:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1BC120171 for ; Thu, 16 Jan 2014 16:25:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A5E7920165 for ; Thu, 16 Jan 2014 16:25:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752701AbaAPQZV (ORCPT ); Thu, 16 Jan 2014 11:25:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:2359 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752171AbaAPQYn (ORCPT ); Thu, 16 Jan 2014 11:24:43 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0GGOTXv023466 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 16 Jan 2014 11:24:29 -0500 Received: from localhost (ovpn-113-136.phx2.redhat.com [10.3.113.136]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0GGOSZL009246; Thu, 16 Jan 2014 11:24:28 -0500 From: Luiz Capitulino To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, riel@redhat.com, aarcange@redhat.com, aquini@redhat.com, mst@redhat.com, rusty@rustcorp.com.au, vdavydov@parallels.com, amit.shah@redhat.com, dfediuck@redhat.com, agl@us.ibm.com Subject: [RFC PATCH 1/4] vmpressure: in-kernel notifications Date: Thu, 16 Jan 2014 11:24:02 -0500 Message-Id: <1389889445-3855-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1389889445-3855-1-git-send-email-lcapitulino@redhat.com> References: <1389889445-3855-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Glauber Costa During the past weeks, it became clear to us that the shrinker interface we have right now works very well for some particular types of users, but not that well for others. The latter are usually people interested in one-shot notifications, that were forced to adapt themselves to the count+scan behavior of shrinkers. To do so, they had no choice than to greatly abuse the shrinker interface producing little monsters all over. During LSF/MM, one of the proposals that popped out during our session was to reuse Anton Voronstsov's vmpressure for this. They are designed for userspace consumption, but also provide a well-stablished, cgroup-aware entry point for notifications. This patch extends that to also support in-kernel users. Events that should be generated for in-kernel consumption will be marked as such, and for those, we will call a registered function instead of triggering an eventfd notification. Please note that due to my lack of understanding of each shrinker user, I will stay away from converting the actual users, you are all welcome to do so. Signed-off-by: Glauber Costa Signed-off-by: Vladimir Davydov Acked-by: Anton Vorontsov Acked-by: Pekka Enberg Reviewed-by: Greg Thelen Cc: Dave Chinner Cc: John Stultz Cc: Andrew Morton Cc: Joonsoo Kim Cc: Michal Hocko Cc: Kamezawa Hiroyuki Cc: Johannes Weiner Signed-off-by: Luiz capitulino --- include/linux/vmpressure.h | 5 +++++ mm/vmpressure.c | 53 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h index 3f3788d..9102e53 100644 --- a/include/linux/vmpressure.h +++ b/include/linux/vmpressure.h @@ -19,6 +19,9 @@ struct vmpressure { /* Have to grab the lock on events traversal or modifications. */ struct mutex events_lock; + /* False if only kernel users want to be notified, true otherwise. */ + bool notify_userspace; + struct work_struct work; }; @@ -38,6 +41,8 @@ extern int vmpressure_register_event(struct cgroup_subsys_state *css, struct cftype *cft, struct eventfd_ctx *eventfd, const char *args); +extern int vmpressure_register_kernel_event(struct cgroup_subsys_state *css, + void (*fn)(void)); extern void vmpressure_unregister_event(struct cgroup_subsys_state *css, struct cftype *cft, struct eventfd_ctx *eventfd); diff --git a/mm/vmpressure.c b/mm/vmpressure.c index e0f6283..730e7c1 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -130,8 +130,12 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned, } struct vmpressure_event { - struct eventfd_ctx *efd; + union { + struct eventfd_ctx *efd; + void (*fn)(void); + }; enum vmpressure_levels level; + bool kernel_event; struct list_head node; }; @@ -147,12 +151,15 @@ static bool vmpressure_event(struct vmpressure *vmpr, mutex_lock(&vmpr->events_lock); list_for_each_entry(ev, &vmpr->events, node) { - if (level >= ev->level) { + if (ev->kernel_event) { + ev->fn(); + } else if (vmpr->notify_userspace && level >= ev->level) { eventfd_signal(ev->efd, 1); signalled = true; } } + vmpr->notify_userspace = false; mutex_unlock(&vmpr->events_lock); return signalled; @@ -222,7 +229,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, * we account it too. */ if (!(gfp & (__GFP_HIGHMEM | __GFP_MOVABLE | __GFP_IO | __GFP_FS))) - return; + goto schedule; /* * If we got here with no pages scanned, then that is an indicator @@ -239,8 +246,15 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, vmpr->scanned += scanned; vmpr->reclaimed += reclaimed; scanned = vmpr->scanned; + /* + * If we didn't reach this point, only kernel events will be triggered. + * It is the job of the worker thread to clean this up once the + * notifications are all delivered. + */ + vmpr->notify_userspace = true; spin_unlock(&vmpr->sr_lock); +schedule: if (scanned < vmpressure_win) return; schedule_work(&vmpr->work); @@ -324,6 +338,39 @@ int vmpressure_register_event(struct cgroup_subsys_state *css, } /** + * vmpressure_register_kernel_event() - Register kernel-side notification + * @css: css that is interested in vmpressure notifications + * @fn: function to be called when pressure happens + * + * This function register in-kernel users interested in receiving notifications + * about pressure conditions. Pressure notifications will be triggered at the + * same time as userspace notifications (with no particular ordering relative + * to it). + * + * Pressure notifications are a alternative method to shrinkers and will serve + * well users that are interested in a one-shot notification, with a + * well-defined cgroup aware interface. + */ +int vmpressure_register_kernel_event(struct cgroup_subsys_state *css, + void (*fn)(void)) +{ + struct vmpressure *vmpr = css_to_vmpressure(css); + struct vmpressure_event *ev; + + ev = kzalloc(sizeof(*ev), GFP_KERNEL); + if (!ev) + return -ENOMEM; + + ev->kernel_event = true; + ev->fn = fn; + + mutex_lock(&vmpr->events_lock); + list_add(&ev->node, &vmpr->events); + mutex_unlock(&vmpr->events_lock); + return 0; +} + +/** * vmpressure_unregister_event() - Unbind eventfd from vmpressure * @css: css handle * @cft: cgroup control files handle