From patchwork Wed Aug 20 12:10:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chintan Pandya X-Patchwork-Id: 4750441 Return-Path: X-Original-To: patchwork-linux-arm-msm@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 A7F669F344 for ; Wed, 20 Aug 2014 12:14:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6CE6620179 for ; Wed, 20 Aug 2014 12:14:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1999E201BC for ; Wed, 20 Aug 2014 12:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752308AbaHTMLT (ORCPT ); Wed, 20 Aug 2014 08:11:19 -0400 Received: from smtp.codeaurora.org ([198.145.11.231]:39239 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753432AbaHTMLQ (ORCPT ); Wed, 20 Aug 2014 08:11:16 -0400 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id AB67913F663; Wed, 20 Aug 2014 12:11:15 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id 9B83013F666; Wed, 20 Aug 2014 12:11:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (unknown [202.46.23.54]) (using TLSv1.1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: cpandya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 43EF513F663; Wed, 20 Aug 2014 12:11:13 +0000 (UTC) From: Chintan Pandya To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Chintan Pandya , Thomas Gleixner , John Stultz , Peter Zijlstra , Ingo Molnar , Hugh Dickins Subject: [PATCH v4 2/2] ksm: provide support to use deferrable timers for scanner thread Date: Wed, 20 Aug 2014 17:40:28 +0530 Message-Id: <1408536628-29379-2-git-send-email-cpandya@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1408536628-29379-1-git-send-email-cpandya@codeaurora.org> References: <1408536628-29379-1-git-send-email-cpandya@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP KSM thread to scan pages is scheduled on definite timeout. That wakes up CPU from idle state and hence may affect the power consumption. Provide an optional support to use deferrable timer which suites low-power use-cases. Typically, on our setup we observed, 10% less power consumption with some use-cases in which CPU goes to power collapse frequently. For example, playing audio on Soc which has HW based Audio encoder/decoder, CPU remains idle for longer duration of time. This idle state will save significant CPU power consumption if KSM don't wakes them up periodically. Note that, deferrable timers won't be deferred if any CPU is active and not in IDLE state. By default, deferrable timers is enabled. To disable deferrable timers, $ echo 0 > /sys/kernel/mm/ksm/deferrable_timer Signed-off-by: Chintan Pandya Cc: Thomas Gleixner Cc: John Stultz Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Hugh Dickins Acked-by: Hugh Dickins --- Changes: V3-->V4: - Use deferrable timers by default V2-->V3: - Handled error case properly - Corrected indentation in Documentation - Fixed build failure - Removed left over process_timeout() V1-->V2: - allowing only valid values to be updated as use_deferrable_timer - using only 'deferrable' and not 'deferred' - moved out schedule_timeout code for deferrable timer into timer.c Documentation/vm/ksm.txt | 6 ++++++ mm/ksm.c | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Documentation/vm/ksm.txt b/Documentation/vm/ksm.txt index f34a8ee..23e26c3 100644 --- a/Documentation/vm/ksm.txt +++ b/Documentation/vm/ksm.txt @@ -87,6 +87,12 @@ pages_sharing - how many more sites are sharing them i.e. how much saved pages_unshared - how many pages unique but repeatedly checked for merging pages_volatile - how many pages changing too fast to be placed in a tree full_scans - how many times all mergeable areas have been scanned +deferrable_timer - whether to use deferrable timers or not + e.g. "echo 1 > /sys/kernel/mm/ksm/deferrable_timer" + Default: 1 (means, we are using deferrable timers. Users + might want to clear deferrable_timer option if they want + ksm thread to wakeup CPU to carryout ksm activities thus + loosing on battery while gaining on memory savings.) A high ratio of pages_sharing to pages_shared indicates good sharing, but a high ratio of pages_unshared to pages_sharing indicates wasted effort. diff --git a/mm/ksm.c b/mm/ksm.c index fb75902..af90e30 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -223,6 +223,9 @@ static unsigned int ksm_thread_pages_to_scan = 100; /* Milliseconds ksmd should sleep between batches */ static unsigned int ksm_thread_sleep_millisecs = 20; +/* Boolean to indicate whether to use deferrable timer or not */ +static bool use_deferrable_timer = 1; + #ifdef CONFIG_NUMA /* Zeroed when merging across nodes is not allowed */ static unsigned int ksm_merge_across_nodes = 1; @@ -1725,8 +1728,13 @@ static int ksm_scan_thread(void *nothing) try_to_freeze(); if (ksmd_should_run()) { - schedule_timeout_interruptible( - msecs_to_jiffies(ksm_thread_sleep_millisecs)); + signed long to; + + to = msecs_to_jiffies(ksm_thread_sleep_millisecs); + if (use_deferrable_timer) + schedule_timeout_deferrable_interruptible(to); + else + schedule_timeout_interruptible(to); } else { wait_event_freezable(ksm_thread_wait, ksmd_should_run() || kthread_should_stop()); @@ -2175,6 +2183,29 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr, } KSM_ATTR(run); +static ssize_t deferrable_timer_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return snprintf(buf, 8, "%d\n", use_deferrable_timer); +} + +static ssize_t deferrable_timer_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + unsigned long enable; + int err; + + err = kstrtoul(buf, 10, &enable); + if (err < 0) + return err; + if (enable >= 1) + return -EINVAL; + use_deferrable_timer = enable; + return count; +} +KSM_ATTR(deferrable_timer); + #ifdef CONFIG_NUMA static ssize_t merge_across_nodes_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) @@ -2287,6 +2318,7 @@ static struct attribute *ksm_attrs[] = { &pages_unshared_attr.attr, &pages_volatile_attr.attr, &full_scans_attr.attr, + &deferrable_timer_attr.attr, #ifdef CONFIG_NUMA &merge_across_nodes_attr.attr, #endif