Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4711596ybl; Mon, 26 Aug 2019 14:49:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzi0smc9jt+TOFXu0OxVGIsla9PrgMOdJrk4k3+p1UjsZbx14TP5I1pFTtf6hP6z52ravQs X-Received: by 2002:a17:902:5a09:: with SMTP id q9mr20993336pli.191.1566856167761; Mon, 26 Aug 2019 14:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566856167; cv=none; d=google.com; s=arc-20160816; b=N+Qv0wqChF18j2ay7Me1wG9a8Sx2O9CyoL+8xyPt7Imy/Ayw+7sJjfzOccEWFnePTl K3+8dawITyHw9wU/4Onet448LUdh/d2yfCQggfowpgdJMRdGVlokwI8qgUPTfAAF10cF Rav70pAsMxRYTtPGR++SHyP66ifTjRWDFpjoEMlHNcgh/dlxqxCt2lIX16igGOhk7Iqp 74leHzjN+kjflAQ/RJhPWzcuu+pBN+9cnePg2l/m25t1/wBJua9d7hMR9taufvd2xI8r zq+eFgoFnES/ZG6U677yV7OpBiNheDxXJsCtZtpyEYgke7ZRkv+0+iSAGy369uRYiciY DXHA== 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=yZeSIo1yMzeevCoZoSFenzyCHvBSamWsDJbpHlAcw0g=; b=zKU4rbOOt8QbXU4QtnDislWEh78obe6RVbAKXBsMlZ2WXgsHfBIIpM9D5rYlZ88WgE ubmnWQ/V2LBnXIl7oQL5JWtHRGRVXJ/D46BsEgaalUpU+InknFzSVVujLGJ8Tk2Lbw+I WgS4yteFxfCsZA9fdNrvJP78Bo415KorG3P4MgV1YjfPZH7jYGiL+BV9hDlXoKe0R2uc eBoJkt3xok82hnjv437w7BGUJT3VK1GCxS6TeKhAG6wRJ93iZdnnqkDBf1Usr4SKsYvV 9fqQC99j3m1t0QvIxgDoeHevAE69rJ8Ug8xLIuv++DtDgws6x0/KQimlTg7dvw7TIrAt QILQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=Arista-A header.b=hzGobiGn; 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 h65si11303616pfe.216.2019.08.26.14.49.12; Mon, 26 Aug 2019 14:49:27 -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=hzGobiGn; 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 S2387771AbfHZThE (ORCPT + 99 others); Mon, 26 Aug 2019 15:37:04 -0400 Received: from mx.aristanetworks.com ([162.210.129.12]:32317 "EHLO smtp.aristanetworks.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387580AbfHZTgz (ORCPT ); Mon, 26 Aug 2019 15:36:55 -0400 Received: from smtp.aristanetworks.com (localhost [127.0.0.1]) by smtp.aristanetworks.com (Postfix) with ESMTP id B9C8342A6B7; Mon, 26 Aug 2019 12:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=Arista-A; t=1566848260; bh=yZeSIo1yMzeevCoZoSFenzyCHvBSamWsDJbpHlAcw0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hzGobiGnNRcU+IfgJBe3DjCKRQJdhh6XWzw/725isqWDirZKKqGTE/XjGfsZiE5Vx q1emrBguNlHiK5kyzx/zr0+HZRRGEosJccej8pId9BH55BYGydjHGeS+3mbxRLKcw8 m3vi4IiZsHecHB1Y8JkN2TRxzXfkr/GUTa9Yfnb23WbL8AlihVdHDTXN0etnf1oT4J l7R8AXNc7IKa6m3cszsL9G1ez57IDRbDFX1ZL497rCgrFw9GV3TmDnkxiTWzMVz7ty GTUTAjGgb2rhBQgk6iPt7A/ZtM23D4gEMHIK2FzZyo4oFNMIT8IoP+sOiu3oMDHAna tbYjL5r5b8Lpw== Received: from egc101.sjc.aristanetworks.com (unknown [172.20.210.50]) by smtp.aristanetworks.com (Postfix) with ESMTP id A7DDC42AD87; Mon, 26 Aug 2019 12:37:40 -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 07/10] mm/oom_debug: Add Select Process Entries Print Date: Mon, 26 Aug 2019 12:36:35 -0700 Message-Id: <20190826193638.6638-8-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 Add OOM Debug code to selectively print an entry for each user process that was considered for OOM selection at the time of an OOM event. Limiting the processes to print is done by specifying a minimum amount of memory that must be used to be eligible to be printed. Note: memory usage for oom processes includes RAM memory as well as swap space. The value totalpages is actually used as the memory size for determining percentage of "memory" used. Configuring this OOM Debug Option (DEBUG_OOM_PROCESS_SELECT_PRINT) ------------------------------------------------------------------ To configure this option it needs to be selected in the OOM Debugging configure menu. The kernel configuration entry for this option can be found in the config file at: Kernel hacking, Memory Debugging, OOM Debugging the DEBUG_OOM_PROCESS_SELECT config entry. Two dynamic OOM debug settings for this option: enable, tenthpercent -------------------------------------------------------------------- The oom debugfs base directory is found at: /sys/kernel/debug/oom. The oom debugfs for this option is: process_select_print_ and for select options there are two files, the enable file and the tenthpercent file are the debugfs files. Dynamic disable or re-enable this OOM Debug option -------------------------------------------------- This option may be disabled or re-enabled using the debugfs entry for this OOM debug option. The debugfs file to enable this entry is found at: /sys/kernel/debug/oom/process_select_print_enabled where the enabled file's value determines whether the facility is enabled or disabled. A value of 1 is enabled (default) and a value of 0 is disabled. Specifying the minimum entry size (0-1000) in the tenthpercent file ------------------------------------------------------------------- For DEBUG_OOM_PROCESS_SELECT_PRINT the processes printed can be limited by specifying the minimum percentage of memory usage to be eligible to be printed. By default if the DEBUG_OOM_PROCESS_SELECT config option is enabled only OOM considered processes that use 1% or more of memory are printed. This can be adjusted to be entries as small as 0.1% of memory or as large as 100% of memory in which case only a summary line is printed, as no process could possibly consume 100% of the memory. Adjustments are made through the debugfs file found at: /sys/kernel/debug/oom/procs_select_print_tenthpercent valid values include values 1 through 1000 which represent memory usage of 0.1% of memory to 100% of totalpages. Also specifying a value of zero is a valid value and when specified it prints an entry for all OOM considered processes even if they use essentially no memory. Sample Output ------------- Output produced consists of one line of standard Linux OOM process entry output for each process that is equal to or larger than the minimum entry size specified by the percent_totalpages_print_limit (0% to 100.0%) followed by one line of summary output. Summary print line output (minsize = 0.1% of totalpages): Aug 13 20:16:30 yourserver kernel: Summary: OOM Tasks considered:245 printed:33 minimum size:32576kB total-pages:32579084kB Signed-off-by: Edward Chron --- include/linux/oom.h | 1 + mm/Kconfig.debug | 34 ++++++++++++++++++++++++++++++++++ mm/oom_kill.c | 39 +++++++++++++++++++++++++++++++-------- mm/oom_kill_debug.c | 22 ++++++++++++++++++++++ mm/oom_kill_debug.h | 3 +++ 5 files changed, 91 insertions(+), 8 deletions(-) diff --git a/include/linux/oom.h b/include/linux/oom.h index c696c265f019..f37af4772452 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -49,6 +49,7 @@ struct oom_control { unsigned long totalpages; struct task_struct *chosen; unsigned long chosen_points; + unsigned long minpgs; /* Used to print the constraint info. */ enum oom_constraint constraint; diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index ea3465343286..0c5feb0e15a9 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -247,3 +247,37 @@ config DEBUG_OOM_VMALLOC_SELECT_PRINT print limit value of 10 or 1% of memory. If unsure, say N. + +config DEBUG_OOM_PROCESS_SELECT_PRINT + bool "Debug OOM Select Process Print" + depends on DEBUG_OOM + help + When enabled, allows OOM considered process OOM information + to be print rate limited based on the amount of memory the + considered process is consuming. The number of processes that + were considered for OOM selection, the number of processes + that were actually printed and the minimum memory usage + percentage that was used to select to which processes are + printed is printed in a summary line after printing the + selected tasks. + + If the option is configured it is enabled/disabled by setting + the value of the file entry in the debugfs OOM interface at: + /sys/kernel/debug/oom/process_select_print_enabled + A value of 1 is enabled (default) and a value of 0 is disabled. + + When enabled entries are print limited by the amount of memory + they consume. The setting value defines the minimum memory + size consumed and are represented in tenths of a percent. + Values supported are 0 to 1000 where 0 allows all OOM considered + processes to be printed, 1 would allow entries using 0.1% or + more to be printed, 10 would allow entries using 1% or more of + memory to be printed. + + If configured and enabled the rate limiting OOM process selection + is specified by setting a value in the debugfs OOM interface at: + /sys/kernel/debug/oom/process_select_print_tenthpercent + If configured the default settings are set to enabled and + print limit value of 10 or 1% of memory. + + If unsure, say N. diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 9022297fa2ba..4b37318dce4f 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -380,6 +380,7 @@ static void select_bad_process(struct oom_control *oc) static int dump_task(struct task_struct *p, void *arg) { + unsigned long rsspgs, swappgs, pgtbl; struct oom_control *oc = arg; struct task_struct *task; @@ -400,17 +401,29 @@ static int dump_task(struct task_struct *p, void *arg) return 0; } + rsspgs = get_mm_rss(task->mm); + swappgs = get_mm_counter(p->mm, MM_SWAPENTS); + pgtbl = mm_pgtables_bytes(p->mm); + +#ifdef CONFIG_DEBUG_OOM_PROCESS_SELECT_PRINT + if ((oc->minpgs > 0) && + ((rsspgs + swappgs + pgtbl / PAGE_SIZE) < oc->minpgs)) { + task_unlock(task); + return 0; + } +#endif + pr_info("[%7d] %5d %5d %8lu %8lu %8ld %8lu %5hd %s\n", task->pid, from_kuid(&init_user_ns, task_uid(task)), - task->tgid, task->mm->total_vm, get_mm_rss(task->mm), - mm_pgtables_bytes(task->mm), - get_mm_counter(task->mm, MM_SWAPENTS), + task->tgid, task->mm->total_vm, rsspgs, pgtbl, swappgs, task->signal->oom_score_adj, task->comm); task_unlock(task); - return 0; + return 1; } +#define K(x) ((x) << (PAGE_SHIFT-10)) + /** * dump_tasks - dump current memory state of all system tasks * @oc: pointer to struct oom_control @@ -423,19 +436,31 @@ static int dump_task(struct task_struct *p, void *arg) */ static void dump_tasks(struct oom_control *oc) { + u32 total = 0; + u32 prted = 0; + pr_info("Tasks state (memory values in pages):\n"); pr_info("[ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name\n"); +#ifdef CONFIG_DEBUG_OOM_PROCESS_SELECT_PRINT + oc->minpgs = oom_kill_debug_min_task_pages(oc->totalpages); +#endif + if (is_memcg_oom(oc)) mem_cgroup_scan_tasks(oc->memcg, dump_task, oc); else { struct task_struct *p; rcu_read_lock(); - for_each_process(p) - dump_task(p, oc); + for_each_process(p) { + ++total; + prted += dump_task(p, oc); + } rcu_read_unlock(); } + + pr_info("Summary: OOM Tasks considered:%u printed:%u minimum size:%lukB totalpages:%lukB\n", + total, prted, K(oc->minpgs), K(oc->totalpages)); } static void oom_kill_unreclaimable_slabs_print(void) @@ -492,8 +517,6 @@ static DECLARE_WAIT_QUEUE_HEAD(oom_victims_wait); static bool oom_killer_disabled __read_mostly; -#define K(x) ((x) << (PAGE_SHIFT-10)) - /* * task->mm can be NULL if the task is the exited group leader. So to * determine whether the task is using a particular mm, we examine all the diff --git a/mm/oom_kill_debug.c b/mm/oom_kill_debug.c index d5e37f8508e6..66b745039771 100644 --- a/mm/oom_kill_debug.c +++ b/mm/oom_kill_debug.c @@ -232,6 +232,12 @@ static struct oom_debug_option oom_debug_options_table[] = { .option_name = "vmalloc_select_print_", .support_tpercent = true, }, +#endif +#ifdef CONFIG_DEBUG_OOM_PROCESS_SELECT_PRINT + { + .option_name = "process_select_print_", + .support_tpercent = true, + }, #endif {} }; @@ -255,6 +261,9 @@ enum oom_debug_options_index { #endif #ifdef CONFIG_DEBUG_OOM_VMALLOC_SELECT_PRINT SELECT_VMALLOC_STATE, +#endif +#ifdef CONFIG_DEBUG_OOM_PROCESS_SELECT_PRINT + SELECT_PROCESS_STATE, #endif OUT_OF_BOUNDS }; @@ -415,6 +424,19 @@ bool oom_kill_debug_unreclaimable_slabs_print(void) } #endif /* CONFIG_DEBUG_OOM_SLAB_SELECT_PRINT */ +#ifdef CONFIG_DEBUG_OOM_PROCESS_SELECT_PRINT +unsigned long oom_kill_debug_min_task_pages(unsigned long totalpages) +{ + u16 pct; + + if (!oom_kill_debug_enabled(SELECT_PROCESS_STATE)) + return 0; + + pct = oom_kill_debug_tenthpercent(SELECT_PROCESS_STATE); + return (totalpages * pct) / 1000; +} +#endif /* CONFIG_DEBUG_OOM_PROCESS_SELECT_PRINT */ + #ifdef CONFIG_DEBUG_OOM_TASKS_SUMMARY static void oom_kill_debug_tasks_summary_print(void) { diff --git a/mm/oom_kill_debug.h b/mm/oom_kill_debug.h index 549b8da179d0..7eec861a0009 100644 --- a/mm/oom_kill_debug.h +++ b/mm/oom_kill_debug.h @@ -9,6 +9,9 @@ #ifndef __MM_OOM_KILL_DEBUG_H__ #define __MM_OOM_KILL_DEBUG_H__ +#ifdef CONFIG_DEBUG_OOM_PROCESS_SELECT_PRINT +extern unsigned long oom_kill_debug_min_task_pages(unsigned long totalpages); +#endif #ifdef CONFIG_DEBUG_OOM_SLAB_SELECT_PRINT extern bool oom_kill_debug_unreclaimable_slabs_print(void); #endif -- 2.20.1