From patchwork Mon Apr 6 12:54:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11475511 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 01ACF112C for ; Mon, 6 Apr 2020 12:54:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B82E320769 for ; Mon, 6 Apr 2020 12:54:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ulrILbWW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B82E320769 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 02C9B8E0010; Mon, 6 Apr 2020 08:54:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 002CD8E000D; Mon, 6 Apr 2020 08:54:23 -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 E83498E0010; Mon, 6 Apr 2020 08:54:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id D30658E000D for ; Mon, 6 Apr 2020 08:54:23 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 944EC8019DD5 for ; Mon, 6 Apr 2020 12:54:23 +0000 (UTC) X-FDA: 76677423606.08.power73_6083d5c8af350 X-Spam-Summary: 2,0,0,7f53b49a6fb4f786,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:3871:3872:4321:4385:5007:6119:6261:6653:7514:7903:8603:9413:10004:11026:11473:11658:11914:12048:12296:12297:12438:12517:12519:12555:12679:12691:12737:12895:12986:13069:13161:13229:13311:13357:14096:14181:14384:14394:14687:14721:14819:21080:21444:21451:21627:21666:21990:30054,0,RBL:209.85.214.194:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.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:23,LUA_SUMMARY:none X-HE-Tag: power73_6083d5c8af350 X-Filterd-Recvd-Size: 4446 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Mon, 6 Apr 2020 12:54:23 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id s23so5853689plq.13 for ; Mon, 06 Apr 2020 05:54:22 -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=0MatIwaf0tV+g448eXLQcOJOWFagO+EgD7PmSHekb1U=; b=ulrILbWWTEbWtgGbXYOR5v/Lhp0obtodyC/fX7ouoMQGXuItmKrx5+dJAThUhZ6lY8 mVOgAWWWeWfUsthMtgPlppiKLpXf/1KjlMw9ChW3ZU7qzPpyySdzTpLsO+LsU4k37Lio gpevi/KqWcn/JmOShK+qkVjvijEq2FDN5fsLvkaPKpZnLckzZ+iiH4IC7XGIN4QwDIN7 DBI9XOu49Ikfi14Tr/bQ5c23UdlVmVBdkpiHT82HvUjAeRJIozo+Yualw51CnA3YlcY7 Rv0h7qyPMSzI1a4Lh4mb/CfGYNZ8zvTAJCyF8hNIbCT6+VsIJy8ZyEZeZUrCm2IkM7oI XyoA== 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=0MatIwaf0tV+g448eXLQcOJOWFagO+EgD7PmSHekb1U=; b=ot2LEk/sMDqN8O0LDPMDi5U0ZuWFTSam20yDcI7rKGMxcBiPJV3JZ3yaI63qTQjZdq f1bQE3xavBzsQU1Qc2UL8WzRL4VgxJmGxic9aRHiYbqSJf8p/9gEIwjhHgXwhD8UU24k GEV+SK3DN7sCWBx2tAIUfhnUCiIqKeqfDMfii9mSLVf3SMpvAMSyL4DUJCRWfSSeZ/p5 kVbw1mBIiW0ugWJ5Y29iHyF8YY8Za7ctnL7iimVUSO6tGNhI9Ie3/ZQcbicWw1zMNYkz bd0jAiJ4GkopVpkCYGp7NrVCYmwjhLSsO6vA73k17B6egdW5gYaX4xVWKuDIsACFgds2 bCxg== X-Gm-Message-State: AGi0PuYiAloPFvxgQcQ1W8NgRRCVIEwQRTE+sCllShR/wITVk7VavlN4 CXnImKBjbCdEU9viBBqibBU= X-Google-Smtp-Source: APiQypKyEqr87yyn6oT4AElu1xXecH9Vb9btMt/XA2RsXL/FSjdaRx8a86l7NfGDrAdQen8SiHVYeQ== X-Received: by 2002:a17:90a:218b:: with SMTP id q11mr25820852pjc.163.1586177662059; Mon, 06 Apr 2020 05:54:22 -0700 (PDT) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id z30sm11563286pfq.84.2020.04.06.05.54.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2020 05:54:21 -0700 (PDT) From: Yafang Shao To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao Subject: [PATCH] mm, memcg: fix error return value of mem_cgroup_alloc() Date: Mon, 6 Apr 2020 08:54:07 -0400 Message-Id: <1586177647-11889-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.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 -ENOSPC, as explained above the function idr_alloc(). 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': No space left on device Signed-off-by: Yafang Shao --- mm/memcontrol.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ca19486..9c85470 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4980,7 +4980,7 @@ static void mem_cgroup_free(struct mem_cgroup *memcg) __mem_cgroup_free(memcg); } -static struct mem_cgroup *mem_cgroup_alloc(void) +static struct mem_cgroup *mem_cgroup_alloc(long *error) { struct mem_cgroup *memcg; unsigned int size; @@ -4997,8 +4997,10 @@ static struct mem_cgroup *mem_cgroup_alloc(void) 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) { + *error = memcg->id.id; goto fail; + } memcg->vmstats_local = alloc_percpu(struct memcg_vmstats_percpu); if (!memcg->vmstats_local) @@ -5052,7 +5054,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void) struct mem_cgroup *memcg; long error = -ENOMEM; - memcg = mem_cgroup_alloc(); + memcg = mem_cgroup_alloc(&error); if (!memcg) return ERR_PTR(error);