From patchwork Fri Jun 11 17:19:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Tomlin X-Patchwork-Id: 12316359 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,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 2CAE1C48BD1 for ; Fri, 11 Jun 2021 17:19:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B5130613CF for ; Fri, 11 Jun 2021 17:19:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5130613CF 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 315076B0036; Fri, 11 Jun 2021 13:19:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C51F6B006C; Fri, 11 Jun 2021 13:19:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13FC06B006E; Fri, 11 Jun 2021 13:19:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id D3AA36B0036 for ; Fri, 11 Jun 2021 13:19:46 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5A284A8D1 for ; Fri, 11 Jun 2021 17:19:46 +0000 (UTC) X-FDA: 78242105172.27.4219508 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id CE763E000255 for ; Fri, 11 Jun 2021 17:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623431984; 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=LQMTdrZDXFHIZKhVp6aoer1KMD+nKRx3hDZ0SmFf7u8=; b=VI5lmzOeWOb53wrpLxrn9aO4vFxqs7FkU19zdrRUtHN5yr2vzI8S41lUG7zCaOJmzhgc3n daUCQtbnkFH/KSj+pdDhm63FIgsM+s/6NRr6Ql01ASRg9o0AqHU1+u8QhVrBzhVA+YO43E ghzTNkco7V0YUi+TCxgsDPsVwKSI1sk= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-ShKlctBJMf6Gmu_MDbw0wA-1; Fri, 11 Jun 2021 13:19:43 -0400 X-MC-Unique: ShKlctBJMf6Gmu_MDbw0wA-1 Received: by mail-wr1-f70.google.com with SMTP id x9-20020adfffc90000b02901178add5f60so2941105wrs.5 for ; Fri, 11 Jun 2021 10:19:43 -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=LQMTdrZDXFHIZKhVp6aoer1KMD+nKRx3hDZ0SmFf7u8=; b=YyPw7TYSUCGMDdPXwEpt6z0VWHDZSZdp9BbUJRvFCLAmqMqkkkZQqPfIc9zka25Wd5 lUDjhANMSyMTSq3WZflvOHNgsOCMJPMVlxHdcPZFrqHDIoI8AFaF5N5iRnUm61T+n3UP 2lUYNgRzuOsIDOi3+x6IsDQAp6+rkpr2ypB+BDul/x99YtQ/1UmAuiGEtpHE9P91ezZW LAxgzE4/G0ssE8ksOX1MuHhxkbzxTmMKpgStDwAwtcuX/9STYUS5gNvM4LWRcA6hEcCm mkwQ6HerHcRfdhGJ1ycLiBYWnrGs9SOkJWWQF40d0l9FMHqmInhTk/gHBMrgSQcZAIK7 ROKw== X-Gm-Message-State: AOAM530WH1C2BFMkczMjWK9ljGRQAot9DjY6+WQnc9fTkhUmsFDNynFo ARry4+fylGnfwnlW2shm5+SVKibMKw/v5Qb09UW3SwfHRUf3krpMM874yofOa1d71TqZoSVLnkz 0hHhJL7NBoiGICaxTNkyS3kX0LCjoLyYVQsn8LV6VjLyb9XYr6t5rUCP6gCIW X-Received: by 2002:a5d:4e50:: with SMTP id r16mr5330824wrt.124.1623431981732; Fri, 11 Jun 2021 10:19:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOuJlp6OjAomJZ5hmpGIriVy58AXB6nudYEJxJgtGTzxeOibi/0KVJxoiETY9l4oZHLLJkJQ== X-Received: by 2002:a5d:4e50:: with SMTP id r16mr5330796wrt.124.1623431981413; Fri, 11 Jun 2021 10:19:41 -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 d131sm13144458wmd.4.2021.06.11.10.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 10:19:41 -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: [RFC PATCH] mm/oom_kill: show oom eligibility when displaying the current memory state of all tasks Date: Fri, 11 Jun 2021 18:19:40 +0100 Message-Id: <20210611171940.960887-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 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VI5lmzOe; spf=none (imf21.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: pyft748b36wdjhbgemjxn7gj3x8x1asg X-Rspamd-Queue-Id: CE763E000255 X-Rspamd-Server: rspam06 X-HE-Tag: 1623431976-230475 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- mm/oom_kill.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index eefd3f5fde46..70781d681a6e 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 "no: oom score"; + else if (test_bit(MMF_OOM_SKIP, &p->mm->flags) + return "no: oom reaped"; + else if (in_vfork(p)) + return "no: in vfork"; + else + return "yes"; +} + /* 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 %-15s %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 eligible 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);