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: 10644955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 965BB13A4 for ; Wed, 17 Oct 2018 08:03:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87D6C2A201 for ; Wed, 17 Oct 2018 08:03:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78FCC2A216; Wed, 17 Oct 2018 08:03:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCACD2A201 for ; Wed, 17 Oct 2018 08:03:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C074F6B0266; Wed, 17 Oct 2018 04:03:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BB7B86B0269; Wed, 17 Oct 2018 04:03:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A80BD6B026A; Wed, 17 Oct 2018 04:03:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by kanga.kvack.org (Postfix) with ESMTP id 72EFD6B0266 for ; Wed, 17 Oct 2018 04:03:33 -0400 (EDT) Received: by mail-yb1-f197.google.com with SMTP id g194-v6so14347844ybf.5 for ; Wed, 17 Oct 2018 01:03:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :dkim-signature; bh=ynQt3JpL6UcVlULe3g/L1fR5EB/M0ItkbnrVl7SdaTE=; b=fPTPXIK7r4uf0v/RTP3JY5rZGWllcLj2vAlkDmv90RC7jzMzSpdQfFY1YfRonmc2Hy CNfVqBV7G9TNZPkkSvasqugUKAQdp/+NK+4L+Ir8VQ2k+qhb//bQehox5j+ayl0jbE7k 39bUiLUSdQur6X46BAylOeAej7vVT0cSthBauafwQaWQrEY6WRp7yW++4NsHjPRHR+Xa HKNV0UXuiDRGKz/5oDfUWw83HSpIy581Dwn33KAVNe5timpgi9qrcTXWutTXmEE9p7vV WTuKDE7NoJWz3sZ/jo2LGEyFv0omkHiZP7DTWFaMKZJrfD+/TtJLSjo8Zwb1p+yLJgTQ +nTQ== X-Gm-Message-State: ABuFfojzHHmfu82KABc14CH9w2EWkul7XR7Oy04FemOgp8mQwX8nY38v RGJSxqbfmDKD5jHwrKUaUg74Ku3oVgO46yYQzAeoxZN5v/WrBFN0fQPSg5N1M/DONM79WQIF+M8 piT9oaNFzmV7idT0iI54EnbMj0jJGZBMMZTQKZsFhYakg+dPsBIpSgf4Sx8js8AHw3A== X-Received: by 2002:a81:24c1:: with SMTP id k184-v6mr13485901ywk.112.1539763413065; Wed, 17 Oct 2018 01:03:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV62+sduDncdsrN8UmMKZx19gOojA2+ejYT6BbYAxlZtYQDuS6XmSaCwWa7gPrIIU1Q3O5h/o X-Received: by 2002:a81:24c1:: with SMTP id k184-v6mr13485863ywk.112.1539763412357; Wed, 17 Oct 2018 01:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539763412; cv=none; d=google.com; s=arc-20160816; b=A+r6MxeW0Xx4XtRfleDomJzMlo7riKmX8zb8bOoLSoYeyqg7h3BcQTSvdnRfMAFuye 3c7pYUdr5PqaAVTJNx5KOHIAKwCSqGdf7x3sDfA1ChMGe7SCqGAbLAmQiQ1+JDJHDa9i +C2GXKY9Uh6+vQ7vDpE2KxCy6gcr7z8I7c89yNZhHDL/SyazzXlAUsQHw5H6/A9Ey7Id f7yGvFLMjEAU7SkLfnvrQ8YHX0WxfwQu7RXrfK7PfEZTnZNENqPG4noXHR230fdn73zt gMvscrD8gXPoOZ8HEFNSoRxnxiP12RvJeoS2acbe4YG+TGSiHy3axM4do+yD8K3tfhRp lWaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:mime-version:message-id:date:subject:cc:to:from; bh=ynQt3JpL6UcVlULe3g/L1fR5EB/M0ItkbnrVl7SdaTE=; b=FnviYFQY23h2UBUvcWhA3JQfiUgQZ89QQNzqeA8tG9jTapnNVQoTumU3vbOrmcLGlF kZEQWLe2XJ8iz4a+1Ymg9K/HE4W80hU+JRcjM4cyy4f+RrYL8JMspPIzc9y8BgNbGe1q XX9y6+ryeoKptDSLNSYJrREuH8xdDLe4yVF/K/H/dihmptTJC9XHEdulzmb8n9y9gl7e 0zWaY5SnTGYi3LvoQg5TwVhXRz8+utFzaVyo4G7Lem9DNMdT51SF4lORdrwF1BFHje4v EUyQO0pc870EdtdkSjMls6z8GsdEt3KrOO+MOx3LdvxczQYkDpv5RuXKBlCT789MuAFh z51w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=L9WQiaLU; spf=pass (google.com: domain of prpatel@nvidia.com designates 216.228.121.65 as permitted sender) smtp.mailfrom=prpatel@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com. [216.228.121.65]) by mx.google.com with ESMTPS id d2-v6si5227275ybq.469.2018.10.17.01.03.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 01:03:32 -0700 (PDT) Received-SPF: pass (google.com: domain of prpatel@nvidia.com designates 216.228.121.65 as permitted sender) client-ip=216.228.121.65; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=L9WQiaLU; spf=pass (google.com: domain of prpatel@nvidia.com designates 216.228.121.65 as permitted sender) smtp.mailfrom=prpatel@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com 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== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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");