Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp812670imm; Sat, 26 May 2018 11:52:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZonfVKxF4WhUl+nAlDwUb9jS4PGLAGpMMst4P2VSWbWffEPw5XJvzfM+O69Vl3q/sUWK7FG X-Received: by 2002:a17:902:7149:: with SMTP id u9-v6mr7363826plm.356.1527360762606; Sat, 26 May 2018 11:52:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527360762; cv=none; d=google.com; s=arc-20160816; b=pcyeCn2MeXx0QCvAa/eis4rjOQLLB5MsvD4tR//rA0w65ZvIOeUQj7NIaN1lEj53n+ 3Z3NLW6dC/kBOfAQdWgduACsRywBX+s1Hz68xthCC97T7MbzRVHtv3GZkmsoprVrurWd CtJH8u/RcmWb9XL5mb3gpdtb9oSg7I3c+GLgfgDxLDbQ/Q2rj7UvLpFECyFMr3oQydAz PWWwqbwVMD+3a8h5ZsOdOIKq7uDYto9EtAV3wxI4KADfWSdNOEw5WGMNcjyfbJJDRPUq 1PP+m9h+aClwVRQr6WsIO6cTOK/Ugb+SXSLbhF+B6qvw++rSGuLmwmBe9zjdjf0nIT7I H1SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=iNL4kxrCaSEntuQJhwPEATyXyItKqBo7oCsUbKz+fMI=; b=RG7OYsc9GE2VVN+0xRkk1lRUIo3/dZGS3OV7WjKeyPJh643jGOCqSxTQUv3qGhXZjI qn9veShrYygEiXNN+Fx6V2SL+5EB+RN6ZVNjxFmymoI3Axbp8MhpD2p/qvK5VSyiX0nx 0ivC2bZSJRldoAT+B3a/RzQJ1+l1br0vfaYkMrxTXr0RAREo+7Z/NvC7YhIxlf6eZkd8 42ze7UVQskex+pmea2UzS1OXPTOXkni5ErTrp+EYnf4pashLbf5J/vn6nGPfc1gYpnap 1gTnuIM8F3avbaMX1c/tkDlqmNe6GlyG6WX5QC/Iu/GKBguf/wRqDPe+jOSXnn6rsHQY EKqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DZw8U7WY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k14-v6si21211312pgs.418.2018.05.26.11.51.59; Sat, 26 May 2018 11:52:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DZw8U7WY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032314AbeEZSvu (ORCPT + 99 others); Sat, 26 May 2018 14:51:50 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33328 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032234AbeEZSvt (ORCPT ); Sat, 26 May 2018 14:51:49 -0400 Received: by mail-wr0-f195.google.com with SMTP id a15-v6so14224349wrm.0; Sat, 26 May 2018 11:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=iNL4kxrCaSEntuQJhwPEATyXyItKqBo7oCsUbKz+fMI=; b=DZw8U7WYxDaAnIpArdI67LqMaEHn6frouzGjrBU79phvhIXGMaEs4yC7jfH+gOXWNV Yr28vuQWT1k8eo06EgMGK3mmlIqex9/tXjuoW13dXZ1/wqePhKTv+Re1XFIRojSBt+NT GglCNqVpyMneoxjEbnP4fAbl2y3cuDrY7hxiRKf4nHHiqwTmdQ2As7I/2uCtHBCiPJf0 Lvqat5td0vGK5r9Krqq1cWSklKtmPE6kB9Z47NIbu3quHkU9mKCZ+P8d3C3pHWxGOtBA pnDbmidB4HATb3/ESi3idYGIhZPcppp9mRvm8VK2fDpTbNFGwmJBWgSNi/le5G4NeuuU HuBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iNL4kxrCaSEntuQJhwPEATyXyItKqBo7oCsUbKz+fMI=; b=ex0Kw0kypxNrJeoKh8+w/AlvSX3Bn4E+3lobMWpGzMpDsN0y1DYSshPiyp2JAo2yVp CAhV7HSwrHVWcIwgCi+DqWXtKNTL9ER0QkSyMa0a4Mn70jrTh2ctXeCV/45JRi3MlfHG 396i0eSmsYXXC3aR/D3/cNb6inSqxCf3cM+Q39oiRjhI8CX6Us8yXWhsGMVDbWk714IQ H/ONt15ToHHvTezavPsUN0TjlzYdvxdIBJAW2DMFcyzOYet4Q7UNimsd6XIAbMkcTsZh 4vnAUZ2Ajkd7FfFomJGzclc1BVZKK/rMApbXc/LdgYc2B4XEXqqH6FmqOs3c76fYbw23 UUkw== X-Gm-Message-State: ALKqPwdpYktj3XDVERv6U4L8S/l2nxFvlAeDzStkX9uQss4+f0fn0qVM 9LeE0Mg2jca+wiVr8zcTU48= X-Received: by 2002:a19:9a10:: with SMTP id c16-v6mr4024086lfe.60.1527360707697; Sat, 26 May 2018 11:51:47 -0700 (PDT) Received: from esperanza (81.5.110.211.dhcp.mipt-telecom.ru. [81.5.110.211]) by smtp.gmail.com with ESMTPSA id s24-v6sm1283741lfg.4.2018.05.26.11.51.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 May 2018 11:51:46 -0700 (PDT) Date: Sat, 26 May 2018 21:51:44 +0300 From: Vladimir Davydov To: Shakeel Butt Cc: Michal Hocko , Andrew Morton , Greg Thelen , Johannes Weiner , Linux MM , cgroups@vger.kernel.org, LKML Subject: Re: [PATCH] memcg: force charge kmem counter too Message-ID: <20180526185144.xvh7ejlyelzvqwdb@esperanza> References: <20180525185501.82098-1-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180525185501.82098-1-shakeelb@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 25, 2018 at 11:55:01AM -0700, Shakeel Butt wrote: > Based on several conditions the kernel can decide to force charge an > allocation for a memcg i.e. overcharge memcg->memory and memcg->memsw > counters. Do the same for memcg->kmem counter too. In cgroup-v1, this > bug can cause a __GFP_NOFAIL kmem allocation fail if an explicit limit > on kmem counter is set and reached. memory.kmem.limit is broken and unlikely to ever be fixed as this knob was deprecated in cgroup-v2. The fact that hitting the limit doesn't trigger reclaim can result in unexpected behavior from user's pov, like getting ENOMEM while listing a directory. Bypassing the limit for NOFAIL allocations isn't going to fix those problem. So I'd suggest to avoid setting memory.kmem.limit instead of trying to fix it or, even better, switch to cgroup-v2. > > Signed-off-by: Shakeel Butt > --- > mm/memcontrol.c | 21 +++++++++++++++++++-- > 1 file changed, 19 insertions(+), 2 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index ab5673dbfc4e..0a88f824c550 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -1893,6 +1893,18 @@ void mem_cgroup_handle_over_high(void) > current->memcg_nr_pages_over_high = 0; > } > > +/* > + * Based on try_charge() force charge conditions. > + */ > +static inline bool should_force_charge(gfp_t gfp_mask) > +{ > + return (unlikely(tsk_is_oom_victim(current) || > + fatal_signal_pending(current) || > + current->flags & PF_EXITING || > + current->flags & PF_MEMALLOC || > + gfp_mask & __GFP_NOFAIL)); > +} > + > static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, > unsigned int nr_pages) > { > @@ -2008,6 +2020,8 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, > * The allocation either can't fail or will lead to more memory > * being freed very soon. Allow memory usage go over the limit > * temporarily by force charging it. > + * > + * NOTE: Please keep the should_force_charge() conditions in sync. > */ > page_counter_charge(&memcg->memory, nr_pages); > if (do_memsw_account()) > @@ -2331,8 +2345,11 @@ int memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order, > > if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && > !page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) { > - cancel_charge(memcg, nr_pages); > - return -ENOMEM; > + if (!should_force_charge(gfp)) { > + cancel_charge(memcg, nr_pages); > + return -ENOMEM; > + } > + page_counter_charge(&memcg->kmem, nr_pages); > } > > page->mem_cgroup = memcg;