From patchwork Fri Oct 12 10:11:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 12183 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 D5CC623FB3 for ; Fri, 12 Oct 2012 10:15:08 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 6D342A183E7 for ; Fri, 12 Oct 2012 10:15:08 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so4411576iej.11 for ; Fri, 12 Oct 2012 03:15:07 -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 :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=AKjTJIhWaYvvLP1R6QnMgZ4/Ii5g5UPpfcI8I7mItNE=; b=pGys9IdqEv4AFfaadVFIemo91Gy0WmSAYXcC8n94QNeub26luBp54SIES3NZsaqf1M ckd8jooIRnSWVt882Gxf95CnqMHv3idvbDMn5HtWSI89hdnoVhlWym857oJ88gvtKsHL yPKAtaZ3tTto25H/BAJGdDi1R8lyMescyue4qzCsDGHjrdiFL6/W9KxNrHDp9t+GL8aF HPsSlVHmLk6JCRyD7dyT9RVojZfzRHTtad13Exebs7lvPiKETEna7qTQ//unQVB6Zx5J PJfzSuz5TnEl4O4NjdUBBVXcwXhqSJZSoPYWmstZkpb3on0IHECtFo+qAH7M0dWx00ZX XXGg== Received: by 10.42.57.10 with SMTP id b10mr83063ich.54.1350036907852; Fri, 12 Oct 2012 03:15:07 -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 n20csp175510igt; Fri, 12 Oct 2012 03:15:07 -0700 (PDT) Received: by 10.68.224.132 with SMTP id rc4mr11974590pbc.155.1350036907258; Fri, 12 Oct 2012 03:15:07 -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 t9si10586571paz.142.2012.10.12.03.15.07 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Oct 2012 03:15:07 -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 md4so3081219pbc.37 for ; Fri, 12 Oct 2012 03:15:07 -0700 (PDT) Received: by 10.68.240.36 with SMTP id vx4mr12120515pbc.89.1350036907020; Fri, 12 Oct 2012 03:15:07 -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 kc4sm538528pbc.23.2012.10.12.03.15.05 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Oct 2012 03:15:06 -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: =?UTF-8?q?=5BPATCH=203/3=5D=20mm=3A=20vmevent=3A=20Sum=20per=20cpu=20pagesets=20stats=20asynchronously?= Date: Fri, 12 Oct 2012 03:11:59 -0700 Message-Id: <1350036719-29031-3-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> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkKZbaX4edX52km9goZjVWOWNeM0/E9KUXYAfBDRnj5xy2gJNlrgWuzJMAVk9yuOBPv2ElF Currently vmevent relies on the global page state stats, which is updated once per stat_interval (1 second) or when the per CPU pageset stats hit their threshold. We can sum the vm_stat_diff values asynchronously: they will be possibly a bit inconsistent, but overall this should improve accuracy, since with previous scheme we would always use worst-case scenario (i.e. we'd wait for threshold to hit or 1 second delay), but now we use somewhat average accuracy. The idea is very similar to zone_page_state_snapshot(). Note that this might cause more pressure on CPU caches, so we only use this when userland explicitly asks for accuracy, plus since we gather stats outside of any fastpath, this should be OK in general. Signed-off-by: Anton Vorontsov --- mm/vmevent.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/mm/vmevent.c b/mm/vmevent.c index 8113bda..a059bed 100644 --- a/mm/vmevent.c +++ b/mm/vmevent.c @@ -52,10 +52,51 @@ static u64 vmevent_attr_swap_pages(struct vmevent_watch *watch, #endif } +/* + * In the worst case, this is inaccurate by + * + * ±(pcp->stat_threshold * zones * online_cpus) + * + * For say 4-core 2GB setup that would be ~350 KB worst case inaccuracy, + * but to reach this inaccuracy, CPUs would all need have to keep + * allocating (or freeing) pages from all the zones at the same time, and + * all their current vm_stat_diff values would need to be pretty close to + * pcp->stat_threshold. + * + * The larger the system, the more inaccurare vm_stat is (but at the same + * time, on large systems we care much less about small chunks of memory). + * When a more predicted behaviour is needed, userland can set a desired + * accuracy via attr->value2. + */ +static ulong vmevent_global_page_state(struct vmevent_attr *attr, + enum zone_stat_item si) +{ + ulong global = global_page_state(si); +#ifdef CONFIG_SMP + struct zone *zone; + + if (!attr->value2) + return global; + + for_each_populated_zone(zone) { + uint cpu; + + for_each_online_cpu(cpu) { + struct per_cpu_pageset *pcp; + + pcp = per_cpu_ptr(zone->pageset, cpu); + + global += pcp->vm_stat_diff[si]; + } + } +#endif + return global; +} + static u64 vmevent_attr_free_pages(struct vmevent_watch *watch, struct vmevent_attr *attr) { - return global_page_state(NR_FREE_PAGES); + return vmevent_global_page_state(attr, NR_FREE_PAGES); } static u64 vmevent_attr_avail_pages(struct vmevent_watch *watch,