From patchwork Mon Apr 6 15:48:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11475769 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E76A1392 for ; Mon, 6 Apr 2020 16:02:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1075724910 for ; Mon, 6 Apr 2020 16:02:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qPL8E59m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1075724910 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 432FD8E0040; Mon, 6 Apr 2020 12:02:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3E2638E000D; Mon, 6 Apr 2020 12:02:30 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31FC08E0040; Mon, 6 Apr 2020 12:02:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0025.hostedemail.com [216.40.44.25]) by kanga.kvack.org (Postfix) with ESMTP id 1C1BC8E000D for ; Mon, 6 Apr 2020 12:02:30 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C48C0181AEF23 for ; Mon, 6 Apr 2020 16:02:29 +0000 (UTC) X-FDA: 76677897618.21.light00_8a2797c8cc25a X-Spam-Summary: 2,0,0,18ee5e5a2c341492,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:968:973:988:989:1260:1345:1437:1535:1542:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:3871:3872:3874:4385:5007:6119:6261:6653:7514:7903:8603:9413:10004:11026:11473:11658:11914:12043:12048:12114:12296:12297:12438:12517:12519:12555:12679:12691:12737:12895:12986:13161:13229:14093:14096:14181:14394:14687:14721:14819:21080:21444:21451:21611:21627:21666:21990:30054:30080,0,RBL:209.85.215.194:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: light00_8a2797c8cc25a X-Filterd-Recvd-Size: 5551 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Mon, 6 Apr 2020 16:02:29 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id g32so125352pgb.6 for ; Mon, 06 Apr 2020 09:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ldRoNWazQa+t+hdSFtBYrKyLuEWhR9w5SNuNbM/9YUU=; b=qPL8E59mMkWU+QHOU0qFLwarXOYPrXq23A7rHzVjBc2i2VPEHutJUBKXzfjABIl0BE bq1hDxrRGEdjlcJ0otKPLxUOtCApi6Q8XWP8i0lQ1LbC0KthxUrrnLlv15cWBBIptGlN 5obqXV8CYNpSsqziz9oUST6xyxC2zWA1EjWIRxkOsatkJ356qvXf/+1uexTKP81k7fW4 6w1V9M8f6C0kVbxYjVPboA3gA31ajtESlW1j5bojJTEA5cSoIGT+4zRIbUKYoEcBcoj6 Y92tzgAHH+h6BTAKxzbDYyCEaTODCfFdX6gnaSuZPX6yrF9N9ejTehJA1w6IjdG5bGwC Z5sQ== 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; bh=ldRoNWazQa+t+hdSFtBYrKyLuEWhR9w5SNuNbM/9YUU=; b=is5RnVdhrW8x8aDEQhOsoh+1TD9sYmWc7hGOaIsb26B+4cCJNlUE/qeYELIl5q4uK0 sk7qN5LxagxONmtsB2UIOAc67+Q4Ls07li0kz33v62tqbIlER+OhwOTHlR4gjEp40w5a w/1pmOcs+mCLzgCbNJBklzoJ+BRkVWQ2Hdk9am0v0p0DVOF6n7qSKOld37qR1TbANC+4 NHBIHPBcWCH3dkIOHwp0+GV+h04OK9hE2fMdxoTn/kt/D3A8nFCv7BiBT80PApkYbGdG mlcGT/GU2XS9SheFMpoChQgtrFXZ4HakIiSXp00j0jOHBvuey3+uPf5JnI/lXDtLrvr8 jGMw== X-Gm-Message-State: AGi0Pua5uHLBXHPapDjI4wcSt1fqlstKD5RKDVMvTsPUbinzrr1gcMOY N8lc5CBCKCgoPNbm5T65R3w= X-Google-Smtp-Source: APiQypJdRcUFWfDIFCUjIW98BDFaU7epHnnxocSXU7eD1Pffec5lecacPeBhTKHSuAbrKk6F/WzaIA== X-Received: by 2002:a63:5023:: with SMTP id e35mr21350494pgb.165.1586188948204; Mon, 06 Apr 2020 09:02:28 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id 1sm32775pjo.10.2020.04.06.09.02.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2020 09:02:27 -0700 (PDT) From: Yafang Shao To: willy@infradead.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao Subject: [PATCH v2] mm, memcg: fix error return value of mem_cgroup_css_alloc() Date: Mon, 6 Apr 2020 23:48:54 +0800 Message-Id: <1586188134-17038-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.7.1 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: When I run my memcg testcase which creates lots of memcgs, I found there're unexpected out of memory logs while there're still enough available free memory. The error log is, mkdir: cannot create directory 'foo.65533': Cannot allocate memory The reason is when we try to create more than MEM_CGROUP_ID_MAX memcgs, an -ENOMEM errno will be set by mem_cgroup_css_alloc(), but the right errno should be -EBUSY "Device or resource busy". That is same with memcg_alloc_cache_id(). As the errno really misled me, we should make it right. After this patch, the error log will be, mkdir: cannot create directory 'foo.65533': Device or resource busy Suggested-by: Matthew Wilcox Signed-off-by: Yafang Shao --- mm/memcontrol.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ca194864d802..94319e4dd1bd 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2717,8 +2717,12 @@ static int memcg_alloc_cache_id(void) id = ida_simple_get(&memcg_cache_ida, 0, MEMCG_CACHES_MAX_SIZE, GFP_KERNEL); - if (id < 0) + if (id < 0) { + if (id == -ENOSPC) + id = -EBUSY; + return id; + } if (id < memcg_nr_cache_ids) return id; @@ -4986,19 +4990,26 @@ static struct mem_cgroup *mem_cgroup_alloc(void) unsigned int size; int node; int __maybe_unused i; + long error = -ENOMEM; size = sizeof(struct mem_cgroup); size += nr_node_ids * sizeof(struct mem_cgroup_per_node *); memcg = kzalloc(size, GFP_KERNEL); if (!memcg) - return NULL; + return ERR_PTR(error); memcg->id.id = idr_alloc(&mem_cgroup_idr, NULL, 1, MEM_CGROUP_ID_MAX, GFP_KERNEL); - if (memcg->id.id < 0) + if (memcg->id.id < 0) { + if (memcg->id.id == -ENOSPC) + error = -EBUSY; + else + error = memcg->id.id; + goto fail; + } memcg->vmstats_local = alloc_percpu(struct memcg_vmstats_percpu); if (!memcg->vmstats_local) @@ -5042,7 +5053,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void) fail: mem_cgroup_id_remove(memcg); __mem_cgroup_free(memcg); - return NULL; + return ERR_PTR(error); } static struct cgroup_subsys_state * __ref @@ -5053,8 +5064,8 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) long error = -ENOMEM; memcg = mem_cgroup_alloc(); - if (!memcg) - return ERR_PTR(error); + if (IS_ERR(memcg)) + return ERR_CAST(memcg); WRITE_ONCE(memcg->high, PAGE_COUNTER_MAX); memcg->soft_limit = PAGE_COUNTER_MAX; @@ -5104,7 +5115,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) fail: mem_cgroup_id_remove(memcg); mem_cgroup_free(memcg); - return ERR_PTR(-ENOMEM); + return ERR_PTR(error); } static int mem_cgroup_css_online(struct cgroup_subsys_state *css)