Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4711138ybl; Mon, 26 Aug 2019 14:48:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8pkAeeFZodEk2m4LHqx1lnv7gE8nvy3s8kQ+V65/RBd081dyEjRF3Ge1wvX0MjnaM7iwf X-Received: by 2002:a62:2ac4:: with SMTP id q187mr22012415pfq.242.1566856130519; Mon, 26 Aug 2019 14:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566856130; cv=none; d=google.com; s=arc-20160816; b=yays7P0kvPcnv0lvDN+Hh9j7D/P7HH2ZCPC8/f3jC4k/SzCVQYQwhl1IL6jQ/z32v5 kAhheoZGeNfFY08dYNiDJbMRIj+jFhYmcznMaHRWPnj3RI9Aga7yVqtNJv04ZaphWfVo ww8lVFPNY4hksKyIP75ebmc8pZc4EW8JnTU1Zyk3WnPjg/0RJmyJ8VR8ekI6nvj5tYHH VmIiBBxt5badZBNcjaXWhfIGNPnPy+f+jtFUm6wtUscmzT1MYL/Lq0RHG1Ga+GfJ3RHb uswwUp1d8aFNlsr+wCgmgJ8Ugb0gpII3flwIMmqYr3gGXKEUMTNxy09zsmqL+m+BcsPg lLLg== 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=geOwB3duci2zbNvoXfDx+5+x5VtXw6E+x8+dOFZDgKM=; b=C0JUL7GaATEFUqAU3t6a4B5BwmdbNA25wV3pVe+hDwFnXLVJufO7UAImNuECHrWKFa HD8++/YVP7UopO00L6VUt6z1At/vZTEAcIb4PUcPLKnJN1qMkfbLHI8vdzII0YSccDxl zeioIS0fkSFKG6PB14jERydPwSK8KUh1q3raU3PbdZ+Q+QwEl1Buq9/RFg9WSserBElu qEbAKDXYKw62gSZFOJ/b1/+RmdKp2GD3VFvxm3wXawkewNwsoTda4sj3AI4350xEflj0 FuGvEhUMz8HQ3/mjE4WnlGB/WfaoNKR/hd/9JsnX0pZ3EO89Hw3epkZvmLf1U2FJEfcz CX3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=Arista-A header.b=1IEjogex; 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 u38si10372933pgn.79.2019.08.26.14.48.35; Mon, 26 Aug 2019 14:48:50 -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=1IEjogex; 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 S2387549AbfHZTgx (ORCPT + 99 others); Mon, 26 Aug 2019 15:36:53 -0400 Received: from mx.aristanetworks.com ([162.210.129.12]:2700 "EHLO smtp.aristanetworks.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387417AbfHZTgv (ORCPT ); Mon, 26 Aug 2019 15:36:51 -0400 Received: from smtp.aristanetworks.com (localhost [127.0.0.1]) by smtp.aristanetworks.com (Postfix) with ESMTP id 931FE42A6BB; Mon, 26 Aug 2019 12:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=Arista-A; t=1566848255; bh=geOwB3duci2zbNvoXfDx+5+x5VtXw6E+x8+dOFZDgKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1IEjogexzuQCB3SP38md7Eq7OAtVIB9hqKIwzdhXq9OKGIHvWKGuRq1zmfcN7hdXv fPd7SXHgFSThKuZJr8a5ZvI8CZib+v+FLCIf1jki8OhLBtTVx/ytVRHydiqzEaPagh JPZXB4AOFk4EUCpl73dyFdgL2f8/acMUXaPoGgYh99S7RPizNVGNqNcD82fpBjgmca flazzOdVEDUXatpff0Du/hlvWUAogblxYEhvPR1WAgw69bV/xHozqclJwsUctRMTH8 4pRu4ak3SRjysHQc1ZDP3Z1ZnImD5ycT13vKdxOJltNyRZ12aXw0jyWapP9IW4qwY+ ArpNl8dESBAlg== Received: from egc101.sjc.aristanetworks.com (unknown [172.20.210.50]) by smtp.aristanetworks.com (Postfix) with ESMTP id 8537F42A6B7; Mon, 26 Aug 2019 12:37:35 -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 02/10] mm/oom_debug: Add System State Summary Date: Mon, 26 Aug 2019 12:36:30 -0700 Message-Id: <20190826193638.6638-3-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 When selected, prints the number of CPUs online at the time of the OOM event. Also prints nodename, domainname, machine type, kernel release and version, system uptime, total memory and swap size. Produces a single line of output holding this information. This information is useful to help determine the state the system was in when the event was triggered which is helpful for debugging, performance measurements and security issues. Configuring this Debug Option (DEBUG_OOM_SYSTEM_STATE) ------------------------------------------------------ To enable the option it needs to be configured in the OOM Debugging configure menu. The kernel configuration entry can be found in the config at: Kernel hacking, Memory Debugging, OOM Debugging the DEBUG_OOM_SYSTEM_STATE config entry. 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: system_state_summary_ and the file for this option is the enable file. This option may be disabled or re-enabled using the debugfs enable file for this OOM debug option. The debugfs file to enable this entry is found at: /sys/kernel/debug/oom/system_state_summary_enabled where the enabled file's value determines whether the facility is enabled or disabled. A value of 1 is enabled and a value of 0 is disabled. When configured the default setting is set to enabled. Content and format of System State Summary Output ------------------------------------------------- One line of output that includes: - Uptime (days, hour, minutes, seconds) - Number CPUs - Machine Type - Node name - Domain name - Kernel Release - Kernel Version Sample Output: ------------- Sample System State Summary message: Jul 27 10:56:46 yoursystem kernel: System Uptime:0 days 00:17:27 CPUs:4 Machine:x86_64 Node:yoursystem Domain:localdomain Kernel Release:5.3.0-rc2+ Version: #49 SMP Mon Jul 27 10:35:32 PDT 2019 Signed-off-by: Edward Chron --- mm/Kconfig.debug | 15 +++++++++ mm/oom_kill_debug.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index 5610da5fa614..dbe599b67a3b 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -132,3 +132,18 @@ config DEBUG_OOM option is a prerequisite for selecting any OOM debugging options. If unsure, say N + +config DEBUG_OOM_SYSTEM_STATE + bool "Debug OOM System State" + depends on DEBUG_OOM + help + When enabled, provides one line of output on an oom event to + document the state of the system when the oom event occurred. + Prints: uptime, # threads, # processes, system memory size in KiB + and swap space size in KiB, nodename, domainname, machine type, + kernel release and version. If configured it is enabled/disabled + by setting the enabled file entry in the debugfs OOM interface + at: /sys/kernel/debug/oom/system_state_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 af07e662c808..6eeaad86fca8 100644 --- a/mm/oom_kill_debug.c +++ b/mm/oom_kill_debug.c @@ -144,6 +144,14 @@ #include #include "oom_kill_debug.h" +#ifdef CONFIG_DEBUG_OOM_SYSTEM_STATE +#include +#include +#include +#include +#include +#endif + #define OOMD_MAX_FNAME 48 #define OOMD_MAX_OPTNAME 32 @@ -169,11 +177,20 @@ struct oom_debug_option { /* Table of oom debug options, new options need to be added here */ static struct oom_debug_option oom_debug_options_table[] = { +#ifdef CONFIG_DEBUG_OOM_SYSTEM_STATE + { + .option_name = "system_state_summary_", + .support_tpercent = false, + }, +#endif {} }; /* Option index by name for order one-lookup, add new options entry here */ enum oom_debug_options_index { +#ifdef CONFIG_DEBUG_OOM_SYSTEM_STATE + SYSTEM_STATE, +#endif OUT_OF_BOUNDS }; @@ -244,10 +261,74 @@ u32 oom_kill_debug_oom_event(void) return oom_kill_debug_oom_events; } +#ifdef CONFIG_DEBUG_OOM_SYSTEM_STATE +/* + * oom_kill_debug_system_summary_prt - provides one line of output to document + * some of the system state at the time of an oom event. + * Output line includes: uptime, # threads, # processes, + * system memory size in KiB and swap space size in KiB, + * nodename, domainname, machine type, kernel release + * and version. + */ +static void oom_kill_debug_system_summary_prt(void) +{ + struct new_utsname *p_uts; + char domainname[256]; + unsigned long upsecs; + unsigned short hours; + struct timespec64 tp; + unsigned short days; + unsigned short mins; + unsigned short secs; + char nodename[256]; + size_t nodesize; + char *p_wend; + long uptime; + int procs; + + p_uts = utsname(); + + memset(nodename, 0, sizeof(nodename)); + memset(domainname, 0, sizeof(domainname)); + + p_wend = strchr(p_uts->nodename, '.'); + if (p_wend != NULL) { + nodesize = p_wend - p_uts->nodename; + ++p_wend; + strncpy(nodename, p_uts->nodename, nodesize); + strcpy(domainname, p_wend); + } else { + strcpy(nodename, p_uts->nodename); + strcpy(domainname, "(none)"); + } + + procs = nr_processes(); + + ktime_get_boottime_ts64(&tp); + uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0); + + days = uptime / 86400; + upsecs = uptime - (days * 86400); + hours = upsecs / 3600; + upsecs = upsecs - (hours * 3600); + mins = upsecs / 60; + secs = upsecs - (mins * 60); + + pr_info("System Uptime:%hu days %02hu:%02hu:%02hu CPUs:%u Machine:%s Node:%s Domain:%s Kernel Release:%s Version:%s\n", + days, hours, mins, secs, num_online_cpus(), p_uts->machine, + nodename, domainname, p_uts->release, p_uts->version); +} +#endif /* CONFIG_DEBUG_OOM_SYSTEM_STATE */ + u32 oom_kill_debug_oom_event_is(void) { ++oom_kill_debug_oom_events; +#ifdef CONFIG_DEBUG_OOM_SYSTEM_STATE + if (oom_kill_debug_enabled(SYSTEM_STATE)) + oom_kill_debug_system_summary_prt(); +#endif + return oom_kill_debug_oom_events; } -- 2.20.1