From patchwork Thu Jan 16 16:24:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 3499501 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 73415C02DC for ; Thu, 16 Jan 2014 16:26:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7079620170 for ; Thu, 16 Jan 2014 16:26:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5308420165 for ; Thu, 16 Jan 2014 16:26:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752157AbaAPQYn (ORCPT ); Thu, 16 Jan 2014 11:24:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26496 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbaAPQYm (ORCPT ); Thu, 16 Jan 2014 11:24:42 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0GGOTUP014864 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 16 Jan 2014 11:24:30 -0500 Received: from localhost (ovpn-113-136.phx2.redhat.com [10.3.113.136]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0GGOTBG028530; Thu, 16 Jan 2014 11:24:29 -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 2/4] vmpressure in-kernel: hack Date: Thu, 16 Jan 2014 11:24:03 -0500 Message-Id: <1389889445-3855-3-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.68 on 10.5.11.25 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: Luiz capitulino 1. Allow drivers to register private data 2. Allow drivers to pass css=NULL 3. Pass level to the callback Signed-off-by: Luiz capitulino --- include/linux/vmpressure.h | 3 ++- mm/vmpressure.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h index 9102e53..de416b6 100644 --- a/include/linux/vmpressure.h +++ b/include/linux/vmpressure.h @@ -42,7 +42,8 @@ extern int vmpressure_register_event(struct cgroup_subsys_state *css, struct eventfd_ctx *eventfd, const char *args); extern int vmpressure_register_kernel_event(struct cgroup_subsys_state *css, - void (*fn)(void)); + void (*fn)(void *data, int level), + void *data); 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 730e7c1..4ed0e85 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -132,9 +132,10 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned, struct vmpressure_event { union { struct eventfd_ctx *efd; - void (*fn)(void); + void (*fn)(void *data, int level); }; enum vmpressure_levels level; + void *data; bool kernel_event; struct list_head node; }; @@ -152,7 +153,7 @@ static bool vmpressure_event(struct vmpressure *vmpr, list_for_each_entry(ev, &vmpr->events, node) { if (ev->kernel_event) { - ev->fn(); + ev->fn(ev->data, level); } else if (vmpr->notify_userspace && level >= ev->level) { eventfd_signal(ev->efd, 1); signalled = true; @@ -352,21 +353,25 @@ int vmpressure_register_event(struct cgroup_subsys_state *css, * well-defined cgroup aware interface. */ int vmpressure_register_kernel_event(struct cgroup_subsys_state *css, - void (*fn)(void)) + void (*fn)(void *data, int level), void *data) { - struct vmpressure *vmpr = css_to_vmpressure(css); + struct vmpressure *vmpr; struct vmpressure_event *ev; + vmpr = css ? css_to_vmpressure(css) : memcg_to_vmpressure(NULL); + ev = kzalloc(sizeof(*ev), GFP_KERNEL); if (!ev) return -ENOMEM; ev->kernel_event = true; + ev->data = data; ev->fn = fn; mutex_lock(&vmpr->events_lock); list_add(&ev->node, &vmpr->events); mutex_unlock(&vmpr->events_lock); + return 0; }