From patchwork Mon Oct 22 18:08:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prateek Patel X-Patchwork-Id: 10652339 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 3877914BB for ; Mon, 22 Oct 2018 18:09:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22053291D9 for ; Mon, 22 Oct 2018 18:09:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 127AA291DB; Mon, 22 Oct 2018 18:09:04 +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 75C52291D9 for ; Mon, 22 Oct 2018 18:09:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DF716B0003; Mon, 22 Oct 2018 14:09:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 492126B0005; Mon, 22 Oct 2018 14:09:02 -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 357AE6B0008; Mon, 22 Oct 2018 14:09:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id 0990B6B0003 for ; Mon, 22 Oct 2018 14:09:02 -0400 (EDT) Received: by mail-yb1-f200.google.com with SMTP id p18-v6so25576962ybe.0 for ; Mon, 22 Oct 2018 11:09:02 -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=gUUILHBVOLMP9cQJM58PswCXRezagqDyQqQND/HH+NE=; b=YD2RMNOcV1faS+EccoFrIhYNy6/rXS+BxOV9uWO/H4k5vsGhlTZClwHHR006xZB1KV TjRWUgpCVCOKvUrrzvI7k1JuiKCs11HOoYsMWZsmF6rxs/cGW4jlZ34QJKem9r7FEh5x 975qL7d4XENsoN51FFgeW8Rx2Sz95r5PUTpA/OuluG178f9KeObsQ0RQLA6ZPwXRzQFk UTm0oZWJWeobTXEMNUyW5y6DC0yLxew887VQWo6eEcqSgNvCUZYIfyFyHq0A5Yusplrb FWRrc9KFs0HNqN56f4d/ng1awLqYXbVMpGuqxz4NCb6giQdxesWRAQeFayTTFIkiXB7P wRdw== X-Gm-Message-State: ABuFfoiKXpu/zAc00hSWUxs8QoDmQDqr5C+EKMMwWBwLh4hGH8yCQ0ml DZ68nCYICUzhTE/fYZaCBLorvc3/n5x+gQSllMEsVoRNnHn9lC4bp0AoIk3J2LlD8RVW+otSTMb ljTJ5EYN8SwU2Qub8A+xJ0/zFhN0ExeqS9U5UA/tmgNHKLwKjLQ8sQj73jg33maJwSQ== X-Received: by 2002:a81:a286:: with SMTP id z128-v6mr34016796ywg.480.1540231741645; Mon, 22 Oct 2018 11:09:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV63p38HP0+nl12zFr3YX86CtpTAwBsT2r00/vbj6vJ/QnW1QH8cVdd9OyHCaRw1gx/wWJoiz X-Received: by 2002:a81:a286:: with SMTP id z128-v6mr34016739ywg.480.1540231740794; Mon, 22 Oct 2018 11:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540231740; cv=none; d=google.com; s=arc-20160816; b=pec/Gy4owW+rr7Sacosn+snP54OhQU9fLTa32nscaEjwwdaUSO8p1S/eCt2HRptU2G sgdE+mKfQHKcakqnbCmtxi3Kemq34O/R7P16Hpw16Agg8KuLmxzvbPCD2q34jpadiNFZ s3NSwtFuJcDsExVT3IxeKdnV6AjgoOgcp630yBE5jJh8q8A1ytzbJl6BQGMsWQoXgfwf 9nWbkr3VjqHaMsxlhnfmyZA5dUIA7kKKIzvnOr2L53DN13/wKxEQN2EK+g7EeNJmgDnT xJQ6BZurK4x9sXgI+oS7A5gyGAcEJRCZnJZZbICwxgUhX1cwaZ0WJ8rpoZRyVpQkvOii fczA== 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=gUUILHBVOLMP9cQJM58PswCXRezagqDyQqQND/HH+NE=; b=F96I5RfuIT/6BSJvIe1+/oOhzb0CTWNuyOdAnxRkag1cdtNgGyYO6PgeCXrKp5hOtK wmrpC8dk74KSzr9or+LBYRTwgpnDUbcXfADUhZjkFJvl5Amg9xNAweeXQrNBL5pgZCT/ 3adOt6ecNPaK95BdJ+apLgG/xqr77WYObs0xk3uH9hEqxEHuu/FPtZeRjfpMGeJDEBSP PKmPPb1bE4UILwMwJx3rj/9KHAWOCLbdcyM9lyB7cEOquRcoUFNBFgQbFbZHqIlqVpt7 S3X8uYmm5JVOJQP+1rXJHfGvpZfbixcNZxFzIUjIjDTP5GvuEYFGrmgMCGeIdbhbab/4 Aoxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=SRKtTg9A; spf=pass (google.com: domain of prpatel@nvidia.com designates 216.228.121.64 as permitted sender) smtp.mailfrom=prpatel@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate15.nvidia.com (hqemgate15.nvidia.com. [216.228.121.64]) by mx.google.com with ESMTPS id a15-v6si4214299ybs.443.2018.10.22.11.09.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Oct 2018 11:09:00 -0700 (PDT) Received-SPF: pass (google.com: domain of prpatel@nvidia.com designates 216.228.121.64 as permitted sender) client-ip=216.228.121.64; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=SRKtTg9A; spf=pass (google.com: domain of prpatel@nvidia.com designates 216.228.121.64 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 hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 22 Oct 2018 11:08:52 -0700 Received: from HQMAIL105.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 22 Oct 2018 11:08:59 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 22 Oct 2018 11:08:59 -0700 Received: from HQMAIL108.nvidia.com (172.18.146.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 22 Oct 2018 18:08:59 +0000 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by HQMAIL108.nvidia.com (172.18.146.13) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Mon, 22 Oct 2018 18:08:59 +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 ; Mon, 22 Oct 2018 11:08:59 -0700 From: Prateek Patel To: CC: , , , , , , , , Sri Krishna chowdary Subject: [PATCH V2] kmemleak: Add config to select auto scan Date: Mon, 22 Oct 2018 23:38:43 +0530 Message-ID: <1540231723-7087-1-git-send-email-prpatel@nvidia.com> X-Mailer: git-send-email 2.1.4 X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1540231732; bh=gUUILHBVOLMP9cQJM58PswCXRezagqDyQqQND/HH+NE=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: X-NVConfidentiality:MIME-Version:Content-Type; b=SRKtTg9Aep7PEy5+fYnCwtGIRiek1mII8Aed7pKbye0fg2btgER4iW3ukD0VOHoiV Xj63dwSXkLCYZVyv42W92ai+wYR0wXEMmN3KCvQcHacb3qSrcUQiDkUSfpqVdaZ5A6 qXPhFfmgqYAkqoXdQ2mhzyixT8FAiucC7vWGW44KwMgytNqGWb5Zs6olEKjsiVqjYW m0ij0J+b0G1xDn4gzDyBXjxgIMrc19rTcJ5baUikCn0J1rvg3PwSYdgHNVTLwCVtlg X439OJdFFXMHaenz+YIqw2rJuGIZLorrKV2ALlMTye18Zk0vKfKOdKEkw4hPaH2A6T jqSHaDCZAwMxA== 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 can be cpu intensive and can stall user tasks at times. To prevent this, add config DEBUG_KMEMLEAK_AUTO_SCAN to enable/disable auto scan on boot up. Also protect first_run with DEBUG_KMEMLEAK_AUTO_SCAN as this is meant for only first automatic scan. Signed-off-by: Sri Krishna chowdary Signed-off-by: Sachin Nikam Signed-off-by: Prateek Reviewed-by: Catalin Marinas Acked-by: Catalin Marinas --- v2: * change config name to DEBUG_KMEMLEAK_AUTO_SCAN from DEBUG_KMEMLEAK_SCAN_ON * use IS_ENABLED(...) instead of #ifdef ... * update commit message according to config name --- lib/Kconfig.debug | 15 +++++++++++++++ mm/kmemleak.c | 10 ++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index c958013..a14166d 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -593,6 +593,21 @@ 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_AUTO_SCAN + bool "Enable kmemleak auto scan thread on boot up" + default y + depends on DEBUG_KMEMLEAK + help + Depending on the cpu, kmemleak scan may be 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. Disabling this option disables automatic reporting of + memory leaks. + + If unsure, say Y. + 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..a614930 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1647,7 +1647,7 @@ static void kmemleak_scan(void) */ static int kmemleak_scan_thread(void *arg) { - static int first_run = 1; + static int first_run = IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN); pr_info("Automatic memory scanning thread started\n"); set_user_nice(current, 10); @@ -2141,9 +2141,11 @@ static int __init kmemleak_late_init(void) return -ENOMEM; } - mutex_lock(&scan_mutex); - start_scan_thread(); - mutex_unlock(&scan_mutex); + if (IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN)) { + mutex_lock(&scan_mutex); + start_scan_thread(); + mutex_unlock(&scan_mutex); + } pr_info("Kernel memory leak detector initialized\n");