From patchwork Sat Jun 12 20:46:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Tomlin X-Patchwork-Id: 12317231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17622C48BCF for ; Sat, 12 Jun 2021 20:46:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7CB3E61164 for ; Sat, 12 Jun 2021 20:46:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7CB3E61164 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A551F6B006C; Sat, 12 Jun 2021 16:46:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DDF96B006E; Sat, 12 Jun 2021 16:46:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8308A6B0070; Sat, 12 Jun 2021 16:46:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 4C5516B006C for ; Sat, 12 Jun 2021 16:46:40 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E1DADC5B4 for ; Sat, 12 Jun 2021 20:46:39 +0000 (UTC) X-FDA: 78246255318.11.E93EBCC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 072A2C00CBC0 for ; Sat, 12 Jun 2021 20:46:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623530798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+9nkcAASg28WXColzX7UZg8LwsE297V2tiWAYMADEZg=; b=jJHm9jvQIbPFPh9NvI+B9O/3K3OC60xuKf9Xeh+5yB1YcsNKG6aCQvSkAB4l3khsUB2mGa optRtDsCdb34oc5lbnOanl/FQDNi2SNvzEQV4Du2gETxHNHY1y7XpDssKp0xJRUvyWRSaX 45r7ZtydsKZ8PMSvezE3tAMTuNaJ5Og= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-224-UVkl_NplOy65gIcUX51n8w-1; Sat, 12 Jun 2021 16:46:37 -0400 X-MC-Unique: UVkl_NplOy65gIcUX51n8w-1 Received: by mail-wr1-f71.google.com with SMTP id m27-20020a056000025bb0290114d19822edso4589339wrz.21 for ; Sat, 12 Jun 2021 13:46:37 -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 :content-transfer-encoding; bh=+9nkcAASg28WXColzX7UZg8LwsE297V2tiWAYMADEZg=; b=jedBIu8kvvlaJRB5366AwVHbFtra9L0W+6XEO+AQ+ptbpa5NZVAD3nn/m3yNWzOl8k 8lE+i6VB3Kybiztlmb2jSzNDbyCvt6IHZlHpgTSnd1nIjBdg2H08S8yjs7HkNPYWnvLa BWNarzJNgZ50h2YkvzzPjdqzVfZogTQC6hZjgtbv7NHhJGt4aUJikc2kIC5EckLpFjmv sh62a3RzlRZhvkldhkxkywKCfcf8UYgnBnIn8Mf30nw8XHackHAOS8g1rsPvfi2jkzbb 1rcUwEDANroNpFfz0gIFIoKfaNXsLwhKm1o1mOw8V1UkFBVIunpIeW6ORp2iyJ9Tqtia urTw== X-Gm-Message-State: AOAM530fwWelCckv25IYexpODS9Ff0FFDuaCnMhMT7/X/qP1hyqpyVKL 1zBbxVmmOEyiBiHrhB/FnvzJfWwYF6Aus6g1LntHvgYeBlLRAx06beMJUkxDXu3wLiKo8Fvaaen Nk2ZdEXJOTToPBlAA8YuibxUYD8dWWKIk2VrHIlxpyXz0AWSJr8Rq4GG730Jl X-Received: by 2002:a5d:4291:: with SMTP id k17mr10949319wrq.40.1623530796194; Sat, 12 Jun 2021 13:46:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2aLWGp0+5W7LeQkPgVCM54EHR6a+rX/1sZm4i4lSirw4qDm8GxATKPZjB3C90aHCUypU1hA== X-Received: by 2002:a5d:4291:: with SMTP id k17mr10949300wrq.40.1623530795890; Sat, 12 Jun 2021 13:46:35 -0700 (PDT) Received: from localhost (cpc111743-lutn13-2-0-cust979.9-3.cable.virginm.net. [82.17.115.212]) by smtp.gmail.com with ESMTPSA id g21sm12030748wrb.46.2021.06.12.13.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Jun 2021 13:46:35 -0700 (PDT) From: Aaron Tomlin To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, penguin-kernel@i-love.sakura.ne.jp, llong@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm/oom_kill: show oom eligibility when displaying the current memory state of all tasks Date: Sat, 12 Jun 2021 21:46:34 +0100 Message-Id: <20210612204634.1102472-1-atomlin@redhat.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 072A2C00CBC0 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jJHm9jvQ; spf=none (imf22.hostedemail.com: domain of atomlin@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=atomlin@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: gw9wz1y6xf7y3imajhrn5puuicqja9o1 X-HE-Tag: 1623530791-666412 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: Changes since v2: - Use single character (e.g. 'R' for MMF_OOM_SKIP) as suggested by Tetsuo Handa - Add new header to oom_dump_tasks documentation At the present time, when showing potential OOM victims, we do not exclude tasks which already have MMF_OOM_SKIP set; it is possible that the last OOM killable victim was already OOM killed, yet the OOM reaper failed to reclaim memory and set MMF_OOM_SKIP. This can be confusing/or perhaps even misleading, to the reader of the OOM report. Now, we already unconditionally display a task's oom_score_adj_min value that can be set to OOM_SCORE_ADJ_MIN which is indicative of an "unkillable" task i.e. is not eligible. This patch provides a clear indication with regard to the OOM eligibility of each displayed task. Signed-off-by: Aaron Tomlin --- Documentation/admin-guide/sysctl/vm.rst | 5 ++-- mm/oom_kill.c | 31 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index 586cd4b86428..123be642bc7e 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -658,8 +658,9 @@ oom_dump_tasks Enables a system-wide task dump (excluding kernel threads) to be produced when the kernel performs an OOM-killing and includes such information as pid, uid, tgid, vm size, rss, pgtables_bytes, swapents, oom_score_adj -score, and name. This is helpful to determine why the OOM killer was -invoked, to identify the rogue task that caused it, and to determine why +score, oom eligibility status and name. This is helpful to determine why +the OOM killer was invoked, to identify the rogue task that caused it, and +to determine why the OOM killer chose the task it did to kill. If this is set to zero, this information is suppressed. On very diff --git a/mm/oom_kill.c b/mm/oom_kill.c index eefd3f5fde46..094b7b61d66f 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -160,6 +160,27 @@ static inline bool is_sysrq_oom(struct oom_control *oc) return oc->order == -1; } +/** + * is_task_eligible_oom - determine if and why a task cannot be OOM killed + * @tsk: task to check + * + * Needs to be called with task_lock(). + */ +static const char * is_task_oom_eligible(struct task_struct *p) +{ + long adj; + + adj = (long)p->signal->oom_score_adj; + if (adj == OOM_SCORE_ADJ_MIN) + return "S"; + else if (test_bit(MMF_OOM_SKIP, &p->mm->flags) + return "R"; + else if (in_vfork(p)) + return "V"; + else + return ""; +} + /* return true if the task is not adequate as candidate victim task. */ static bool oom_unkillable_task(struct task_struct *p) { @@ -401,12 +422,13 @@ static int dump_task(struct task_struct *p, void *arg) return 0; } - pr_info("[%7d] %5d %5d %8lu %8lu %8ld %8lu %5hd %s\n", + pr_info("[%7d] %5d %5d %8lu %8lu %8ld %8lu %5hd %13s %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->signal->oom_score_adj, task->comm); + task->signal->oom_score_adj, is_task_oom_eligible(task), + task->comm); task_unlock(task); return 0; @@ -420,12 +442,13 @@ static int dump_task(struct task_struct *p, void *arg) * memcg, not in the same cpuset, or bound to a disjoint set of mempolicy nodes * are not shown. * State information includes task's pid, uid, tgid, vm size, rss, - * pgtables_bytes, swapents, oom_score_adj value, and name. + * pgtables_bytes, swapents, oom_score_adj value, oom eligibility status + * and name. */ static void dump_tasks(struct oom_control *oc) { 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"); + pr_info("[ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj oom eligible? name\n"); if (is_memcg_oom(oc)) mem_cgroup_scan_tasks(oc->memcg, dump_task, oc);