From patchwork Wed Oct 17 08:03:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prateek Patel X-Patchwork-Id: 985194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nvidia.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nvidia.com header.i=@nvidia.com header.b="L9WQiaLU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Zl6x40XPz9sCW for ; Wed, 17 Oct 2018 19:03:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727194AbeJQP6A (ORCPT ); Wed, 17 Oct 2018 11:58:00 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:14465 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbeJQP6A (ORCPT ); Wed, 17 Oct 2018 11:58:00 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 17 Oct 2018 01:03:35 -0700 Received: from HQMAIL103.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Wed, 17 Oct 2018 01:03:31 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Wed, 17 Oct 2018 01:03:31 -0700 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL103.nvidia.com (172.20.187.11) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 17 Oct 2018 08:03:31 +0000 Received: from HQMAIL102.nvidia.com (172.18.146.10) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 17 Oct 2018 08:03:30 +0000 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by HQMAIL102.nvidia.com (172.18.146.10) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Wed, 17 Oct 2018 08:03:30 +0000 Received: from prpatel-System-Product-Name.nvidia.com (Not Verified[10.24.229.63]) by hqnvemgw02.nvidia.com with Trustwave SEG (v7, 5, 8, 10121) id ; Wed, 17 Oct 2018 01:03:30 -0700 From: Prateek Patel To: CC: , , , , , , , , "Sri Krishna chowdary" Subject: [PATCH] kmemleak: Add config to select auto scan Date: Wed, 17 Oct 2018 13:33:28 +0530 Message-ID: <1539763408-22085-1-git-send-email-prpatel@nvidia.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1539763415; bh=ynQt3JpL6UcVlULe3g/L1fR5EB/M0ItkbnrVl7SdaTE=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Type; b=L9WQiaLUwkcN3ygi9lz46ZPqxDRyCpHOf1S86zkM3WTGTroWvKY2jvd6v1/xvD+ut kig6l+NOaP0dUyotTKAEZiBvQYMN5a6BBISq5mkGXbGfdiT8oX9Ygik7q94vG6MVJD gdl0hGcSosVcVDjPMnwbJqVkmcKABziHZO+SH7oa9AXQfJJdTpU95kfGkxp+Yn2hEz jJWAYPoWIKLxaGf2dHPD9ZBDciWFyXvOGYkgD8Oe1b6EG3Wce24/Y2OFC72PuHxQRf sFRa1C2geT8DnEuh1tL/FSE3OyxDvgfYNX/6ikXSIJlPWxUeMlpAD1G9jvplvLKJKQ WKGtxyzDX8L6A== Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Sri Krishna chowdary Kmemleak scan is cpu intensive and can stall user tasks at times. To prevent this, add config DEBUG_KMEMLEAK_SCAN_ON to enable/disable auto scan on boot up. Also protect first_run with CONFIG_DEBUG_KMEMLEAK_SCAN_ON as this is meant for only first automatic scan. Signed-off-by: Sri Krishna chowdary Signed-off-by: Sachin Nikam Signed-off-by: Prateek --- lib/Kconfig.debug | 11 +++++++++++ mm/kmemleak.c | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index e5e7c03..9542852 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -593,6 +593,17 @@ config DEBUG_KMEMLEAK_DEFAULT_OFF Say Y here to disable kmemleak by default. It can then be enabled on the command line via kmemleak=on. +config DEBUG_KMEMLEAK_SCAN_ON + bool "Enable kmemleak auto scan thread on boot up" + default y + depends on DEBUG_KMEMLEAK + help + Kmemleak scan is cpu intensive and can stall user tasks at times. + This option enables/disables automatic kmemleak scan at boot up. + + Say N here to disable kmemleak auto scan thread to stop automatic + scanning. + config DEBUG_STACK_USAGE bool "Stack utilization instrumentation" depends on DEBUG_KERNEL && !IA64 diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 877de4f..ac53678 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1647,11 +1647,14 @@ static void kmemleak_scan(void) */ static int kmemleak_scan_thread(void *arg) { +#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON static int first_run = 1; +#endif pr_info("Automatic memory scanning thread started\n"); set_user_nice(current, 10); +#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON /* * Wait before the first scan to allow the system to fully initialize. */ @@ -1661,6 +1664,7 @@ static int kmemleak_scan_thread(void *arg) while (timeout && !kthread_should_stop()) timeout = schedule_timeout_interruptible(timeout); } +#endif while (!kthread_should_stop()) { signed long timeout = jiffies_scan_wait; @@ -2141,9 +2145,11 @@ static int __init kmemleak_late_init(void) return -ENOMEM; } +#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON mutex_lock(&scan_mutex); start_scan_thread(); mutex_unlock(&scan_mutex); +#endif pr_info("Kernel memory leak detector initialized\n");