From patchwork Fri Oct 12 10:11:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 12182 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4B22F23FB3 for ; Fri, 12 Oct 2012 10:15:06 +0000 (UTC) Received: from mail-ia0-f180.google.com (mail-ia0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id CBBBAA18550 for ; Fri, 12 Oct 2012 10:15:05 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id f6so1916442iag.11 for ; Fri, 12 Oct 2012 03:15:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=+al5T8zrIE0I/rr95lAZGtdwzJm+1JmRLUI5bmyifbM=; b=CSGlciWjLUUuwCrY7hWNeIEgY1UJvSCcOWp+xmO+BYNbHwAj7ap+zepZx0ys2eUres OCQO0QY222uDincQExe0LGzH0yBhuQ2CUm5+OYsORlEQm5ulzAoBd1klS4o14Lfrui6l sdK/67+dx4HKEP4YcwTvGgqThtjcPlNoFFcNGvBIfoIdg/q7+zKUvnWXUGr0njIgaNGM PClstfNlBppmHsgGGKRTs5IhnwhRz4wNZo22wn11fCvFihGPZKKgp3OESUJVqcphbSw6 m8WlGljk5G9oINnhGWCbu3tj0FgIk+czDm8AtXpANAI/hufrUeDa9jOnJguqtNKGg1J3 zL9A== Received: by 10.50.87.134 with SMTP id ay6mr1617393igb.70.1350036905557; Fri, 12 Oct 2012 03:15:05 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp175508igt; Fri, 12 Oct 2012 03:15:05 -0700 (PDT) Received: by 10.68.129.233 with SMTP id nz9mr12115341pbb.136.1350036905012; Fri, 12 Oct 2012 03:15:05 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id s9si10608034pav.59.2012.10.12.03.15.04 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Oct 2012 03:15:05 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id md4so3081182pbc.37 for ; Fri, 12 Oct 2012 03:15:04 -0700 (PDT) Received: by 10.68.129.5 with SMTP id ns5mr12051777pbb.103.1350036904697; Fri, 12 Oct 2012 03:15:04 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id jw14sm4239096pbb.36.2012.10.12.03.15.03 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Oct 2012 03:15:04 -0700 (PDT) From: Anton Vorontsov To: Pekka Enberg Cc: Mel Gorman , Leonid Moiseichuk , KOSAKI Motohiro , Minchan Kim , Bartlomiej Zolnierkiewicz , John Stultz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, patches@linaro.org, kernel-team@android.com Subject: [PATCH 2/3] mm: vmevent: Use value2 for setting vmstat thresholds Date: Fri, 12 Oct 2012 03:11:58 -0700 Message-Id: <1350036719-29031-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <20121012101115.GA11825@lizard> References: <20121012101115.GA11825@lizard> X-Gm-Message-State: ALoCoQmlG//Jtn9Qps74clRNZw3RzU2CJGsi5KwCoMTnrD4XMOw0/rvcZgbmXWA2ZtrrK/15WjnM Attributes that use vmstat can now use attr->value2 to specify an optional accuracy. Based on the provided value, we will setup appropriate vmstat thresholds. Signed-off-by: Anton Vorontsov --- include/linux/vmevent.h | 5 +++++ mm/vmevent.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/linux/vmevent.h b/include/linux/vmevent.h index b1c4016..b8c1394 100644 --- a/include/linux/vmevent.h +++ b/include/linux/vmevent.h @@ -46,6 +46,11 @@ struct vmevent_attr { __u64 value; /* + * Some attributes accept two configuration values. + */ + __u64 value2; + + /* * Type of profiled attribute from VMEVENT_ATTR_XXX */ __u32 type; diff --git a/mm/vmevent.c b/mm/vmevent.c index 8c0fbe6..8113bda 100644 --- a/mm/vmevent.c +++ b/mm/vmevent.c @@ -28,8 +28,13 @@ struct vmevent_watch { /* poll */ wait_queue_head_t waitq; + + struct list_head node; }; +static LIST_HEAD(vmevent_watchers); +static DEFINE_SPINLOCK(vmevent_watchers_lock); + typedef u64 (*vmevent_attr_sample_fn)(struct vmevent_watch *watch, struct vmevent_attr *attr); @@ -259,12 +264,57 @@ out: return ret; } +#ifdef CONFIG_SMP + +static void vmevent_set_thresholds(void) +{ + struct vmevent_watch *w; + struct zone *zone; + u64 thres = ULLONG_MAX; + + spin_lock(&vmevent_watchers_lock); + + list_for_each_entry(w, &vmevent_watchers, node) { + int i; + + for (i = 0; i < w->config.counter; i++) { + struct vmevent_attr *attr = &w->config.attrs[i]; + + if (attr->type != VMEVENT_ATTR_NR_FREE_PAGES) + continue; + if (!attr->value2) + continue; + thres = min(thres, attr->value2); + } + } + + if (thres == ULLONG_MAX) + thres = 0; + + thres = (thres + PAGE_SIZE - 1) / PAGE_SIZE; + + for_each_populated_zone(zone) + set_zone_stat_thresholds(zone, NULL, thres); + + spin_unlock(&vmevent_watchers_lock); +} + +#else +static inline void vmevent_set_thresholds(void) {} +#endif /* CONFIG_SMP */ + static int vmevent_release(struct inode *inode, struct file *file) { struct vmevent_watch *watch = file->private_data; cancel_delayed_work_sync(&watch->work); + spin_lock(&vmevent_watchers_lock); + list_del(&watch->node); + spin_unlock(&vmevent_watchers_lock); + + vmevent_set_thresholds(); + kfree(watch); return 0; @@ -328,6 +378,10 @@ static int vmevent_setup_watch(struct vmevent_watch *watch) watch->sample_attrs = attrs; watch->nr_attrs = nr; + spin_lock(&vmevent_watchers_lock); + list_add(&watch->node, &vmevent_watchers); + spin_unlock(&vmevent_watchers_lock); + return 0; } @@ -363,6 +417,8 @@ SYSCALL_DEFINE1(vmevent_fd, if (err) goto err_free; + vmevent_set_thresholds(); + fd = get_unused_fd_flags(O_RDONLY); if (fd < 0) { err = fd;