Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4711801ybl; Mon, 26 Aug 2019 14:49:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyI6vji87/uffUjxRezJIW+K4tks28pc314Tg9H/WR9e5Ctt47VR+sWZYu+Fg78hgUlG3Ma X-Received: by 2002:a17:90a:ad86:: with SMTP id s6mr20998429pjq.53.1566856184172; Mon, 26 Aug 2019 14:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566856184; cv=none; d=google.com; s=arc-20160816; b=dUntCErSV9hQFtSR9qNfgAim4wkndelCp0Z87hefl5ODdC8GzvkpZ5gHKx4q8xPGTA eahe0pClJpLzdYlC+14sj4TMXU7VCxOafI3O4P1c2SRRu1JhYfqqCFAlKSPwFllTWDGr jTmNo3pG5HIA3miAv9RpPd3NEx0bQTVA+bSVJRKxNTfVOVXVW5YPDq1wuJG9uxN+MUPL 1UkNE/9LTpl76tvC60zS4EHCLFxMH2OQSxJZOs7DxqJAsnSDI/evb0WtqCqhZ6fT98PL 2xInMzRQ8NI6quC0XW4O9cAYPnLhVDkuP6aDOpaogxbpnK1fhjxbXmI4sYcR0b1r/dJI 4TNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V/mOhY7XhS1f/Jh8Iiul8CdPIyA7jYqIKAUZG/uvnLY=; b=uvJVxqE9J2LwV1b0q6fq4WO3kTTGhBQWh/mpl4+Gz/Vh1iVpkNqPh1KDuJLxst1u7u vK5lfZ8os5vKi5FG8CMrbKe68ZlPkU8Ko0DUK9s/8sOAdRdX/17FIGMv7tj30FqxpZWX KFX3rKRHkEAeZaWo+l23qp3MBkpmN7LmYxQgdhGZ7hLCTkJu5XbH+Co8z46mOOiAHhKO 4ofq67sNWKV51hHAb26/BT36CUdScB/7lof0ZH6Gae6Pa7423zioGyJnSazvR68PmsZG PakFRsBGuEIwRbwP4am0RXQcMsl4ohf9t+vRrqEWXzRoyze1LuAdwbeSUj0/IJUSd7r/ T49A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=Arista-A header.b=SkUBMpm0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v40si737333pjb.7.2019.08.26.14.49.29; Mon, 26 Aug 2019 14:49:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=Arista-A header.b=SkUBMpm0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387850AbfHZThY (ORCPT + 99 others); Mon, 26 Aug 2019 15:37:24 -0400 Received: from mx.aristanetworks.com ([162.210.129.12]:60727 "EHLO smtp.aristanetworks.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727504AbfHZTgw (ORCPT ); Mon, 26 Aug 2019 15:36:52 -0400 Received: from smtp.aristanetworks.com (localhost [127.0.0.1]) by smtp.aristanetworks.com (Postfix) with ESMTP id 8E35842A6BC; Mon, 26 Aug 2019 12:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=Arista-A; t=1566848256; bh=V/mOhY7XhS1f/Jh8Iiul8CdPIyA7jYqIKAUZG/uvnLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SkUBMpm0614z4oh4Ou9RV1ZU4w8JPkL5Ew0hBhOK7lcaxxLe9Xd4qD5/Rz/ZiWcY6 uq4GUTStXzVIAr+hAAqjXhFaAZAJip064kT3YHQz8mI1sXmMB1okUll8is5jtiUM0w 8/WmdCPVtmgix0tSpJWQubuSF4D+ug99DItgnVD9dK26z8dHDPC627LWZukaHmgiWq Ngfw11gQ12y0SEp1SjpTY8DpuOyQm2MbD8jpv5PFw3xtgFMToxXkb1x9DoQRkDlKyg 19FmT5ae959jy/s+yLPIFzxD3I+URuSO6ThZFZDMZw8UUz4rUqdK/HaJ/w+3IPktPa hd8EImz/dnIpg== Received: from egc101.sjc.aristanetworks.com (unknown [172.20.210.50]) by smtp.aristanetworks.com (Postfix) with ESMTP id 8168442A6B7; Mon, 26 Aug 2019 12:37:36 -0700 (PDT) From: Edward Chron To: Andrew Morton Cc: Michal Hocko , Roman Gushchin , Johannes Weiner , David Rientjes , Tetsuo Handa , Shakeel Butt , linux-mm@kvack.org, linux-kernel@vger.kernel.org, colona@arista.com, Edward Chron Subject: [PATCH 03/10] mm/oom_debug: Add Tasks Summary Date: Mon, 26 Aug 2019 12:36:31 -0700 Message-Id: <20190826193638.6638-4-echron@arista.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190826193638.6638-1-echron@arista.com> References: <20190826193638.6638-1-echron@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adds config option and code to support printing a Process / Thread Summary of process / thread activity when an OOM event occurs. The information provided includes the number of process and threads active, the number of oom eligible and oom ineligible tasks, the total number of forks that have happened since the system booted and the number of runnable and I/O blocked processes. All values are at the time of the OOM event. Configuring this Debug Option (DEBUG_OOM_TASKS_SUMMARY) ------------------------------------------------------- To get the tasks information summary this option must be configured. The Tasks Summary option uses the CONFIG_DEBUG_OOM_TASKS_SUMMARY kernel config option which is found in the kernel config under the entry: Kernel hacking, Memory Debugging, OOM Debugging entry. The config option to select is: DEBUG_OOM_TASKS_SUMMARY. Dynamic disable or re-enable this OOM Debug option -------------------------------------------------- The oom debugfs base directory is found at: /sys/kernel/debug/oom. The oom debugfs for this option is: tasks_summary_ and there is just one file for this option, the enable file. The option may be disabled or re-enabled using the debugfs entry for this OOM debug option. The debugfs file to enable this option is found at: /sys/kernel/debug/oom/tasks_summary_enabled The option's enabled file value determines whether the facility is enabled or disabled. A value of 1 is enabled (default) and a value of 0 is disabled. When configured the default setting is set to enabled. Content and format of Tasks Summary Output ------------------------------------------ One line of output that includes: - Number of Threads - Number of processes - Forks since boot - Processes that are runnable - Processes that are in iowait Sample Output: ------------- Sample Tasks Summary message output: Aug 13 18:52:48 yoursystem kernel: Threads: 492 Processes: 248 forks_since_boot: 7786 procs_runable: 4 procs_iowait: 0 Signed-off-by: Edward Chron --- mm/Kconfig.debug | 16 ++++++++++++++++ mm/oom_kill_debug.c | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index dbe599b67a3b..fcbc5f9aa146 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -147,3 +147,19 @@ config DEBUG_OOM_SYSTEM_STATE A value of 1 is enabled (default) and a value of 0 is disabled. If unsure, say N. + +config DEBUG_OOM_TASKS_SUMMARY + bool "Debug OOM System Tasks Summary" + depends on DEBUG_OOM + help + When enabled, provides a kernel process/thread summary recording + the system's process/thread activity at the time an OOM event. + The number of processes and of threads, the number of runnable + and I/O blocked threads, the number of forks since boot and the + number of oom eligible and oom ineligble tasks are provided in + the output. If configured it is enabled/disabled by setting the + enabled file entry in the debugfs OOM interface at: + /sys/kernel/debug/oom/tasks_summary_enabled + A value of 1 is enabled (default) and a value of 0 is disabled. + + If unsure, say N. diff --git a/mm/oom_kill_debug.c b/mm/oom_kill_debug.c index 6eeaad86fca8..395b3307f822 100644 --- a/mm/oom_kill_debug.c +++ b/mm/oom_kill_debug.c @@ -152,6 +152,10 @@ #include #endif +#ifdef CONFIG_DEBUG_OOM_TASKS_SUMMARY +#include +#endif + #define OOMD_MAX_FNAME 48 #define OOMD_MAX_OPTNAME 32 @@ -182,6 +186,12 @@ static struct oom_debug_option oom_debug_options_table[] = { .option_name = "system_state_summary_", .support_tpercent = false, }, +#endif +#ifdef CONFIG_DEBUG_OOM_TASKS_SUMMARY + { + .option_name = "tasks_summary_", + .support_tpercent = false, + }, #endif {} }; @@ -190,6 +200,9 @@ static struct oom_debug_option oom_debug_options_table[] = { enum oom_debug_options_index { #ifdef CONFIG_DEBUG_OOM_SYSTEM_STATE SYSTEM_STATE, +#endif +#ifdef CONFIG_DEBUG_OOM_TASKS_SUMMARY + TASKS_STATE, #endif OUT_OF_BOUNDS }; @@ -320,6 +333,15 @@ static void oom_kill_debug_system_summary_prt(void) } #endif /* CONFIG_DEBUG_OOM_SYSTEM_STATE */ +#ifdef CONFIG_DEBUG_OOM_TASKS_SUMMARY +static void oom_kill_debug_tasks_summary_print(void) +{ + pr_info("Threads:%d Processes:%d forks_since_boot:%lu procs_runable:%lu procs_iowait:%lu\n", + nr_threads, nr_processes(), + total_forks, nr_running(), nr_iowait()); +} +#endif /* CONFIG_DEBUG_OOM_TASKS_SUMMARY */ + u32 oom_kill_debug_oom_event_is(void) { ++oom_kill_debug_oom_events; @@ -329,6 +351,11 @@ u32 oom_kill_debug_oom_event_is(void) oom_kill_debug_system_summary_prt(); #endif +#ifdef CONFIG_DEBUG_OOM_TASKS_SUMMARY + if (oom_kill_debug_enabled(TASKS_STATE)) + oom_kill_debug_tasks_summary_print(); +#endif + return oom_kill_debug_oom_events; } -- 2.20.1