From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no 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 7BA54C2BA19 for ; Mon, 6 Apr 2020 14:10:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 38628239EF for ; Mon, 6 Apr 2020 14:10:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F3H0ts5M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38628239EF 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 AEDE88E002C; Mon, 6 Apr 2020 10:10:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A76E78E000D; Mon, 6 Apr 2020 10:10:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93E008E002C; Mon, 6 Apr 2020 10:10:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id 773808E000D for ; Mon, 6 Apr 2020 10:10:33 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 304224857 for ; Mon, 6 Apr 2020 14:10:33 +0000 (UTC) X-FDA: 76677615546.21.oil66_21e3a910c7b06 X-HE-Tag: oil66_21e3a910c7b06 X-Filterd-Recvd-Size: 4464 Received: from mail-il1-f196.google.com (mail-il1-f196.google.com [209.85.166.196]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Mon, 6 Apr 2020 14:10:32 +0000 (UTC) Received: by mail-il1-f196.google.com with SMTP id i75so14709943ild.13 for ; Mon, 06 Apr 2020 07:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=siOFHZwsJ0/l26O+2+A0oymT1z06rj+kgcTP1md2w3Y=; b=F3H0ts5MKgGLa+P3LhtwBzzaF7FILDbsirGF/VKBJ8zCtTbhDLGt9vTLJn9JtzD3ei hitTKr0WR0LojOyZukx7t/0C3rFBlwpYOg4A/QqCKkxSmdHrUpkBkO0rf6nxAC0WB17Z UxyM56D15tFjY9s88wOYabXDmqTCIX/ZRe1yYOAC4FwE4lDTMZqPZBGXe4LtQDcF2tIo am0M9g3FuN/NXw2Aelr0Dc4cuErG/WXg6+fTwARwQz2JKLaXrO5Z0fUIfFHnOh5101ub sCHK1D4zDflmvqS3MgBZ0+uvUPTZhUrjgCUdFzFD9OoFg6zuLBHpK+gjYItRrA/A33c8 o2jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=siOFHZwsJ0/l26O+2+A0oymT1z06rj+kgcTP1md2w3Y=; b=E2juC8pRHjV93tVYD6/TKs1+TUJCovWRWSLFncJBO4OlWBM5OZnsKmi45EL71F4K+1 7I6f+SPIEcf+/tgVj4wE6TGxBxZA0EraLz2xyb7GH5WHPzM/xm6ljHuEyQTtgGBPxWZs rKKoxeGr26hIZPuR3XTfm3NaN0TOn0XKLcnHCT99EwaQWTKE978gsdRp3YRAzXUoPnHi LaXePd16FeDh9Yi79/PTSE/tVhuxeuK/Hst6Bs+6ABjpLKlFO8K3vnADqphSv8zq8MYJ e1GSyFcCEgRP9qQiafO1gvAPSHyOGOn3YyU3Q8XhEx5SRTZMk0DPoFPYu9B4Xc9Gs2h8 eLKg== X-Gm-Message-State: AGi0PubnR19CoA3QGRItGdeqZ896lNPNr2Z8i/RMgOhcCecbTndYFfw6 HlT7tiO8VpHswggDCAfiX3VlIJ4wuFfCbFv49hU= X-Google-Smtp-Source: APiQypIQOdqXuokYPrrlGJh9OZkgDjKqTFiQCHAnc+/lmZ6varAyeMCgJpNNR5hA618qAmfzJIAkAeKUpM/pCBriPs0= X-Received: by 2002:a92:bb9d:: with SMTP id x29mr21775414ilk.137.1586182231986; Mon, 06 Apr 2020 07:10:31 -0700 (PDT) MIME-Version: 1.0 References: <1586177647-11889-1-git-send-email-laoar.shao@gmail.com> <20200406130533.GZ21484@bombadil.infradead.org> In-Reply-To: From: Yafang Shao Date: Mon, 6 Apr 2020 22:09:55 +0800 Message-ID: Subject: Re: [PATCH] mm, memcg: fix error return value of mem_cgroup_alloc() To: Matthew Wilcox Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Linux MM Content-Type: text/plain; charset="UTF-8" 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: On Mon, Apr 6, 2020 at 9:30 PM Yafang Shao wrote: > > On Mon, Apr 6, 2020 at 9:05 PM Matthew Wilcox wrote: > > > > On Mon, Apr 06, 2020 at 08:54:07AM -0400, Yafang Shao wrote: > > > 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(). > > > > I think idr_alloc() is wrong. I think the right errno to return here is > > EBUSY "Device or resource busy". > > > > Agree with you that EBUSY is better. > I will correct it. > Hi Matthew, What about ida_alloc_range() ? Should we correct it as well ? * Return: The allocated ID, or %-ENOMEM if memory could not be allocated, * or %-ENOSPC if there are no free IDs. */ int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, gfp_t gfp) If there're no free IDs, ida_alloc_range() also returns ENOSPC. > > > -static struct mem_cgroup *mem_cgroup_alloc(void) > > > +static struct mem_cgroup *mem_cgroup_alloc(long *error) > > > > The normal way to do this is to return an ERR_PTR(). See > > include/linux/err.h. > > > > Thanks for your advise. I will take a look at it. > > Thanks Yafang