From patchwork Tue Aug 31 08:38:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 12466753 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.8 required=3.0 tests=BAYES_00, 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 DE93DC432BE for ; Tue, 31 Aug 2021 08:38:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 88BE36023E for ; Tue, 31 Aug 2021 08:38:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 88BE36023E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C75546B0071; Tue, 31 Aug 2021 04:38:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C254F6B0072; Tue, 31 Aug 2021 04:38:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B14458D0001; Tue, 31 Aug 2021 04:38:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id A3B246B0071 for ; Tue, 31 Aug 2021 04:38:10 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 62E93274D0 for ; Tue, 31 Aug 2021 08:38:10 +0000 (UTC) X-FDA: 78534723540.12.5200275 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf27.hostedemail.com (Postfix) with ESMTP id 83B4C700009D for ; Tue, 31 Aug 2021 08:38:09 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10092"; a="218474320" X-IronPort-AV: E=Sophos;i="5.84,365,1620716400"; d="scan'208";a="218474320" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2021 01:38:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,365,1620716400"; d="scan'208";a="600844367" Received: from shbuild999.sh.intel.com ([10.239.146.151]) by fmsmga001.fm.intel.com with ESMTP; 31 Aug 2021 01:38:06 -0700 From: Feng Tang To: linux-mm@kvack.org, Andrew Morton , Michal Hocko , Christian Brauner Cc: linux-kernel@vger.kernel.org, Feng Tang Subject: [RFC PATCH] mm/oom: detect and kill task which has allocation forbidden by cpuset limit Date: Tue, 31 Aug 2021 16:38:05 +0800 Message-Id: <1630399085-70431-1-git-send-email-feng.tang@intel.com> X-Mailer: git-send-email 2.7.4 Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf27.hostedemail.com: domain of feng.tang@intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=feng.tang@intel.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 83B4C700009D X-Stat-Signature: rg39u4seufrp1b3duhqjit664smzet97 X-HE-Tag: 1630399089-62835 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: There was report that starting an Ubuntu in docker while using cpuset to bind it to movlabe nodes (a node only has movable zone, like a node for hotplug or a PMEM node in normal usage) will fail due to memory allocation failure, and then OOM is involved and many other innocent processes got killed. It can be reproduced with command: $docker run -it --rm --cpuset-mems 4 ubuntu:latest bash -c "grep Mems_allowed /proc/self/status" (node 4 is a movable node) The reason is, in the case, the target cpuset nodes only have movable zone, while the creation of an OS in docker sometimes needs to allocate memory in non-movable zones (dma/dma32/normal) like GFP_HIGHUSER, and the cpuset limit forbids the allocation, then out-of-memory killing is involved even when normal nodes and movable nodes both have many free memory. We've posted patches to LKML trying to make the usage working by loosening the check, which is not agreed as the cpuset binding should be respected, and should not be bypassed [1] But still there is another problem, that when the usage fails as it's an mission impossible due to the cpuset limit, the allocating should just be killed first, before any other innocent processes get killed. Add detection for cases like this, and kill the allocating task only. [1].https://lore.kernel.org/lkml/1604470210-124827-1-git-send-email-feng.tang@intel.com/ Signed-off-by: Feng Tang --- include/linux/oom.h | 1 + mm/oom_kill.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/oom.h b/include/linux/oom.h index 2db9a1432511..bf470d8cc421 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -18,6 +18,7 @@ struct task_struct; enum oom_constraint { CONSTRAINT_NONE, CONSTRAINT_CPUSET, + CONSTRAINT_CPUSET_NONE, /* no available zone from cpuset's mem nodes */ CONSTRAINT_MEMORY_POLICY, CONSTRAINT_MEMCG, }; diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 431d38c3bba8..021ec8954279 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -247,6 +247,7 @@ long oom_badness(struct task_struct *p, unsigned long totalpages) static const char * const oom_constraint_text[] = { [CONSTRAINT_NONE] = "CONSTRAINT_NONE", [CONSTRAINT_CPUSET] = "CONSTRAINT_CPUSET", + [CONSTRAINT_CPUSET_NONE] = "CONSTRAINT_CPUSET_NONE", [CONSTRAINT_MEMORY_POLICY] = "CONSTRAINT_MEMORY_POLICY", [CONSTRAINT_MEMCG] = "CONSTRAINT_MEMCG", }; @@ -275,6 +276,14 @@ static enum oom_constraint constrained_alloc(struct oom_control *oc) if (!oc->zonelist) return CONSTRAINT_NONE; + + if (cpusets_enabled() && (oc->gfp_mask & __GFP_HARDWALL)) { + z = first_zones_zonelist(oc->zonelist, + highest_zoneidx, &cpuset_current_mems_allowed); + if (!z->zone) + return CONSTRAINT_CPUSET_NONE; + } + /* * Reach here only when __GFP_NOFAIL is used. So, we should avoid * to kill current.We have to random task kill in this case. @@ -1093,7 +1102,9 @@ bool out_of_memory(struct oom_control *oc) oc->nodemask = NULL; check_panic_on_oom(oc); - if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task && + if (!is_memcg_oom(oc) && + (sysctl_oom_kill_allocating_task || + oc->constraint == CONSTRAINT_CPUSET_NONE) && current->mm && !oom_unkillable_task(current) && oom_cpuset_eligible(current, oc) && current->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) {