Received: by 10.192.165.148 with SMTP id m20csp4726352imm; Tue, 24 Apr 2018 07:30:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/IIL+rcCxWgNi25tZ4xiiTd57C0gSwZax3EumwRyrWx0VvaQ+6SxW/dnsi71IjpI5twkKf X-Received: by 2002:a17:902:5710:: with SMTP id k16-v6mr25388596pli.177.1524580204397; Tue, 24 Apr 2018 07:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524580204; cv=none; d=google.com; s=arc-20160816; b=rmlX4kznsErjOzAkWGG5z7PkHwi5qTEbEABYD7JCJrOWSo3qF/O/gSulOxgCuz/XL/ Zn1DOL7NI3IaMzcO4keJdLn2L4Cp9unhQEpTwsWZU8gZOSXpFptL/L0X5+icpLPaOD80 gav0VoV1/nctqKYx2CyARmIaZiLjDhHROM6cPvzUF1v/9rm4ct5kzbAR/pbTytOUtcMJ 44MGFZ3q1GhlQ4BoGARxmLwDO/2Q/29N5r3ViZUBzlj3nIlNLbmLV/pCUuDtcmIbRjva mOzze+ZMICq0vpUhzXHo6tW+LHiPPektc0HnaSqJ7MEkREaagasqJLbTxkW+Nmk7h0rF fmHQ== 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=rwUNgrx3uKnV1/3bPUoFA1as6HycomeltALnNmFiT4w=; b=gKr7PYGvz2f/ThGHF+DJEvOJaygasBk7LoEEm0g7KX5Ocqhqv7jeuqY3w28D9giD/7 CgGSmpjzWfqTglmqvpdHZBcmHPNrCfLOJi9uu/sCOQAlYGAylrgjJyJDlrPxsqVYcjEv V3DZs5YILPycEbKOGKvJWTB2UIsO0+isxu4GBf3jPBBK5hvQwThp7lVRm3YwLtfGT5Wv y5RdDz0XJMt6j+FA5OytcJ+xiE6JoCzvqqFceOgUX4ybvqjhhP6WlWj94/vqHX8hkGHF /KAJ2sj23hF97Z7QGOezZEwJkJfKgeIPZ4OMUukLdordyO8pc3sgCgoMFVRjyZRHHcTA 1nfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XWnMa7v7; 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 b1-v6si13818518plc.403.2018.04.24.07.29.50; Tue, 24 Apr 2018 07:30:04 -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=XWnMa7v7; 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 S1753097AbeDXLIk (ORCPT + 99 others); Tue, 24 Apr 2018 07:08:40 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:39139 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753021AbeDXLIh (ORCPT ); Tue, 24 Apr 2018 07:08:37 -0400 Received: by mail-lf0-f68.google.com with SMTP id p142-v6so19652943lfd.6 for ; Tue, 24 Apr 2018 04:08:36 -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=rwUNgrx3uKnV1/3bPUoFA1as6HycomeltALnNmFiT4w=; b=XWnMa7v7XweAZHYiYBTRlJiznr2YCrmmaO5eMVMZ9Y1uFnZJvm7q3pCk5eUBF85Zlh iiFzK805Rd41nmGzOMuMe/srxhOgFH8n6VmmljJhi3C2HJVc6GqkHvTSZ9v3weeGQOG8 M5uSCttyEnxSssHzJEe4oeh6Ul4YfO5WHZDGtc0H+jdyd2SQYKkN4MsxNBCQ2g3AcqhT lBEiPmNuQI8gX+Iwg7OCjhP+OBdHXm+mWpET3s4EiMjkk6XsyLp4rXe0robjqeEpo5yl XQMZ8QOGZalaOOHSgwc+sxXLinCtdsdFFTosUKrA1oQ5oy4kvVEh8gtkHf2WEfBkWboH R2jg== 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=rwUNgrx3uKnV1/3bPUoFA1as6HycomeltALnNmFiT4w=; b=Dpp5UBNF0vmcn37MdDzn+SY6WwXyuw3/g3oQEV8Mhl2GMCi8t51WapLmlKIf0n2czj QZ80+XV355h2it5HbgGS2kw8f2aHfH93nAofuiJAEPnEYKJVwgOhqSIf4RBYidzaEwkG NKScDQ4wJaRWl2VislDIV1/cf10wRnEtFXMJFtShv4/ZVPyrO2/xbXpesVuXYpkF1/LW 5ZWOgnxXni+oQ31NeJD5TJXJK5RZJiudiUskIylMYfyQ8ht9eTSZeapWxu70xlnjdMYg jKGwQPHsAEQdzVr20/tbo1KEbzjblPqvDYxmCqv70sZYEKS4HUV2Nsx9HL7JVx29G/EF tTuA== X-Gm-Message-State: ALQs6tA9H6VNk4VZ0ACrnfPfzhWx2iFjSGzjcsOi2/MuaoJC271xLeEx 3OJ9YDwmnXUeeshffOC7tZc= X-Received: by 10.46.117.17 with SMTP id q17mr3500234ljc.147.1524568115980; Tue, 24 Apr 2018 04:08:35 -0700 (PDT) Received: from esperanza ([185.6.245.156]) by smtp.gmail.com with ESMTPSA id e19sm2771193ljk.57.2018.04.24.04.08.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Apr 2018 04:08:35 -0700 (PDT) Date: Tue, 24 Apr 2018 14:08:32 +0300 From: Vladimir Davydov To: Kirill Tkhai Cc: akpm@linux-foundation.org, shakeelb@google.com, viro@zeniv.linux.org.uk, hannes@cmpxchg.org, mhocko@kernel.org, tglx@linutronix.de, pombredanne@nexb.com, stummala@codeaurora.org, gregkh@linuxfoundation.org, sfr@canb.auug.org.au, guro@fb.com, mka@chromium.org, penguin-kernel@I-love.SAKURA.ne.jp, chris@chris-wilson.co.uk, longman@redhat.com, minchan@kernel.org, hillf.zj@alibaba-inc.com, ying.huang@intel.com, mgorman@techsingularity.net, jbacik@fb.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, lirongqing@baidu.com, aryabinin@virtuozzo.com Subject: Re: [PATCH v2 04/12] mm: Assign memcg-aware shrinkers bitmap to memcg Message-ID: <20180424110832.barhpnnm5u2shmcu@esperanza> References: <152397794111.3456.1281420602140818725.stgit@localhost.localdomain> <152399121146.3456.5459546288565589098.stgit@localhost.localdomain> <20180422175900.dsjmm7gt2nsqj3er@esperanza> <552aba74-c208-e959-0b4f-4784e68c6109@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <552aba74-c208-e959-0b4f-4784e68c6109@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 23, 2018 at 02:06:31PM +0300, Kirill Tkhai wrote: > >> diff --git a/mm/vmscan.c b/mm/vmscan.c > >> index 4f02fe83537e..f63eb5596c35 100644 > >> --- a/mm/vmscan.c > >> +++ b/mm/vmscan.c > >> @@ -172,6 +172,22 @@ static DECLARE_RWSEM(shrinker_rwsem); > >> #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) > >> static DEFINE_IDR(shrinkers_id_idr); > >> > >> +static int expand_shrinker_id(int id) > >> +{ > >> + if (likely(id < shrinkers_max_nr)) > >> + return 0; > >> + > >> + id = shrinkers_max_nr * 2; > >> + if (id == 0) > >> + id = BITS_PER_BYTE; > >> + > >> + if (expand_shrinker_maps(shrinkers_max_nr, id)) > >> + return -ENOMEM; > >> + > >> + shrinkers_max_nr = id; > >> + return 0; > >> +} > >> + > > > > I think this function should live in memcontrol.c and shrinkers_max_nr > > should be private to memcontrol.c. > > It can't be private as shrink_slab_memcg() uses this value to get the last bit of bitmap. Yeah, you're right, sorry I haven't noticed that. What about moving id allocation to this function as well? IMHO it would make the code flow a little bit more straightforward. I mean, alloc_shrinker_id() { int id = idr_alloc(...) if (id >= memcg_nr_shrinker_ids) memcg_grow_shrinker_map(...) return id; } > > >> static int add_memcg_shrinker(struct shrinker *shrinker) > >> { > >> int id, ret; > >> @@ -180,6 +196,11 @@ static int add_memcg_shrinker(struct shrinker *shrinker) > >> ret = id = idr_alloc(&shrinkers_id_idr, shrinker, 0, 0, GFP_KERNEL); > >> if (ret < 0) > >> goto unlock; > >> + ret = expand_shrinker_id(id); > >> + if (ret < 0) { > >> + idr_remove(&shrinkers_id_idr, id); > >> + goto unlock; > >> + } > >> shrinker->id = id; > >> ret = 0; > >> unlock: > >>