Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp6321443imm; Sun, 20 May 2018 00:09:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoGWMhYGSESj/N0w7JQH4vrViqOK9VqhSLkBi1pm/h0eGr4vy9twKyarcsjBfqYBxuyqfZM X-Received: by 2002:a17:902:b585:: with SMTP id a5-v6mr16144218pls.53.1526800169820; Sun, 20 May 2018 00:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526800169; cv=none; d=google.com; s=arc-20160816; b=Tk8k1CGmjLIZj0qyKFnXSftneAl7BetO4l/8CaMvSIwPX4F2XRgt0Hv05Alo01QK9E oTyu21X8bPsDY+hm9s4dARwMBOGiY2elkX00bT/NlpRXEbwAhbWlBPuctKVGU9g/rSY7 CLZDGeJZ9hRTrgcE3bY+lmjMBC88Wvt8eeO6tptZ9B6W92QYf8eIlxVSXASmAanBzgr/ GtRpk5V8MbjQvViKoKEMf8XIwhwk3DgW3p/n6GKCxLOWCjJZnc64lXljWrSZs3H0lSU7 RTCg++XMPimwH231AxuDmit2RUDWbHKwGrDgtDOCVRKS45P/AAfAWaiQRFzuIIzotwhF 8p3w== 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=AV+Xm8lWfRJQWRJe+MFO86ST9NxbJSCp4wvcUfVYKE8=; b=KrRk4pBo9RBsjEDZkFrt02pz3k+fio0eV0NXMGw8cL0QqsTtmK/6ju+Xs0uQrRMo87 Z1wkqvgCqdtQs/QlNgCPJNdHCzgrgfi+VNYAgWloBAHxK+O7WaIUTFakQdixobbQFGyA YyZViSm2sMWjmxyDh2UHlHEHd+OevwAEOoyAdhS43gUy83n0yFQgqt0qGqZPiqXGfqf3 TAAALzrWpXUKwX5pA7Zna+HsjHwBtwPyAHmCURf1fJ+gT9oI9b3YWrtq1Hk0+p/uabzC YGB+IR5ixLBjE+M8oZgWtJjS7VnWXdI57uWaWEJ5Ae+8RK2EgLBM9wGOoq70dtlaOn2M wwpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jVGrZQ8m; 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 c1-v6si11070209plz.307.2018.05.20.00.09.03; Sun, 20 May 2018 00:09:29 -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=jVGrZQ8m; 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 S1751162AbeETHIx (ORCPT + 99 others); Sun, 20 May 2018 03:08:53 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:34860 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbeETHIv (ORCPT ); Sun, 20 May 2018 03:08:51 -0400 Received: by mail-lf0-f68.google.com with SMTP id y72-v6so19586684lfd.2 for ; Sun, 20 May 2018 00:08:50 -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=AV+Xm8lWfRJQWRJe+MFO86ST9NxbJSCp4wvcUfVYKE8=; b=jVGrZQ8my8pO4wlsyKWH5bfO+zcqrbdpgZlPUqwp7LD4gjMvNngbrl9/K2tAnLENdy CyutjMnwGGOnJK/AhppV3+Ic/g464jOp4Qy+SmS/VaCctquqCpqLNxGRRDBDbVzMzZCF SzeVI+KO3iDaXvcb7tiiWke82he8hPQP0/0BADZ0KNiuDFKhGAZQC8/HQfazuSrMmzwI CfUhNq/7jfuQxuf5f6QgeqAiT3vVasTGdMNZnSmDUoJxY4G2ipDxtEroVHvk7G2ezo/Z 2Nq03ThijnpOFDDIcZVComBtsZE0R6sPufosVWjy8ffQR/Jo1VFbYPvy7Ps53VrR0L7u NbpQ== 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=AV+Xm8lWfRJQWRJe+MFO86ST9NxbJSCp4wvcUfVYKE8=; b=cle2bM7v82L775/xTbfg7afxWkIdnjmYvg6q0VweZaKKbM2VUhS1o9Pn1h3K3vm7l0 t0OMJMVhEm2/ukRma808ZCB+M/7XEOybJuCj5MccsIu5u8F37lN6Gc2KBg1nplsGN6jn RTzu9GAbNY0BJmw1daF8mEJJqCh92avdt38/Dt0HF50KaIeKxVgNsT4vKe/o+sy0FHV2 NtqHm0r60yueXVbccFkc4FT4/QXiqkodrzYxAAkLvSKwXkJ2JefAzqyrvoOQaThGCE0l +yU43UGQCOWw2HzdqSlrghlE26+19j9pTokq2rkeLbTX/E0O34/riw7+BDqMCIxQ1XSW aU6A== X-Gm-Message-State: ALKqPweG8ZcxZ7LZp+ULPXHSVjogkr0GRLoSbyUogO2v48v9/322lcVm S7d41AQnjnCPz35IUhn8jVQ= X-Received: by 2002:a19:6356:: with SMTP id x83-v6mr20573095lfb.104.1526800129570; Sun, 20 May 2018 00:08:49 -0700 (PDT) Received: from esperanza (81.5.110.211.dhcp.mipt-telecom.ru. [81.5.110.211]) by smtp.gmail.com with ESMTPSA id q78-v6sm525902lfg.66.2018.05.20.00.08.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 May 2018 00:08:48 -0700 (PDT) Date: Sun, 20 May 2018 10:08:46 +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, 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 v6 03/17] mm: Assign id to every memcg-aware shrinker Message-ID: <20180520070846.jfgfl23ionghevlw@esperanza> References: <152663268383.5308.8660992135988724014.stgit@localhost.localdomain> <152663292827.5308.15476497557507652648.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152663292827.5308.15476497557507652648.stgit@localhost.localdomain> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Kirill, Generally, all patches in the series look OK to me, but I'm going to do some nitpicking before I ack them. See below. On Fri, May 18, 2018 at 11:42:08AM +0300, Kirill Tkhai wrote: > The patch introduces shrinker::id number, which is used to enumerate > memcg-aware shrinkers. The number start from 0, and the code tries > to maintain it as small as possible. > > This will be used as to represent a memcg-aware shrinkers in memcg > shrinkers map. > > Since all memcg-aware shrinkers are based on list_lru, which is per-memcg > in case of !CONFIG_MEMCG_KMEM only, the new functionality will be under > this config option. > > Signed-off-by: Kirill Tkhai > --- > include/linux/shrinker.h | 4 +++ > mm/vmscan.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 64 insertions(+) > > diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h > index 6794490f25b2..7ca9c18cf130 100644 > --- a/include/linux/shrinker.h > +++ b/include/linux/shrinker.h > @@ -66,6 +66,10 @@ struct shrinker { > > /* These are for internal use */ > struct list_head list; > +#ifdef CONFIG_MEMCG_KMEM > + /* ID in shrinker_idr */ > + int id; > +#endif > /* objs pending delete, per node */ > atomic_long_t *nr_deferred; > }; > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 50055d72f294..3de12a9bdf85 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -169,6 +169,48 @@ unsigned long vm_total_pages; > static LIST_HEAD(shrinker_list); > static DECLARE_RWSEM(shrinker_rwsem); > > +#ifdef CONFIG_MEMCG_KMEM > +static DEFINE_IDR(shrinker_idr); > + > +static int prealloc_memcg_shrinker(struct shrinker *shrinker) > +{ > + int id, ret; > + > + shrinker->id = -1; > + down_write(&shrinker_rwsem); > + ret = id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); > + if (ret < 0) > + goto unlock; > + shrinker->id = id; > + ret = 0; > +unlock: > + up_write(&shrinker_rwsem); > + return ret; > +} > + > +static void unregister_memcg_shrinker(struct shrinker *shrinker) > +{ > + int id = shrinker->id; > + > + if (id < 0) > + return; Nit: Please replace this with BUG_ON(id >= 0) - this function can only be called for a memcg-aware shrinker that has been fully initialized (prealloc_shrinker() sets nr_deferred after id; unregister_shrinker() returns immediately if nr_deferred is NULL). > + > + down_write(&shrinker_rwsem); > + idr_remove(&shrinker_idr, id); > + up_write(&shrinker_rwsem); > + shrinker->id = -1; Nit: I'd move this under shrinker_rwsem as you set it with the rwsem taken. > +} > +#else /* CONFIG_MEMCG_KMEM */ > +static int prealloc_memcg_shrinker(struct shrinker *shrinker) > +{ > + return 0; > +} > + > +static void unregister_memcg_shrinker(struct shrinker *shrinker) > +{ > +} > +#endif /* CONFIG_MEMCG_KMEM */ > + > #ifdef CONFIG_MEMCG > static bool global_reclaim(struct scan_control *sc) > { > @@ -306,6 +348,7 @@ unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone > int prealloc_shrinker(struct shrinker *shrinker) > { > size_t size = sizeof(*shrinker->nr_deferred); > + int ret; > > if (shrinker->flags & SHRINKER_NUMA_AWARE) > size *= nr_node_ids; > @@ -313,11 +356,26 @@ int prealloc_shrinker(struct shrinker *shrinker) > shrinker->nr_deferred = kzalloc(size, GFP_KERNEL); > if (!shrinker->nr_deferred) > return -ENOMEM; > + > + if (shrinker->flags & SHRINKER_MEMCG_AWARE) { > + ret = prealloc_memcg_shrinker(shrinker); > + if (ret) > + goto free_deferred; Nit: 'ret' is not really needed here. > + } > + > return 0; > + > +free_deferred: > + kfree(shrinker->nr_deferred); > + shrinker->nr_deferred = NULL; > + return -ENOMEM; > } > > void free_prealloced_shrinker(struct shrinker *shrinker) > { > + if (shrinker->flags & SHRINKER_MEMCG_AWARE) > + unregister_memcg_shrinker(shrinker); > + > kfree(shrinker->nr_deferred); > shrinker->nr_deferred = NULL; > } > @@ -347,6 +405,8 @@ void unregister_shrinker(struct shrinker *shrinker) > { > if (!shrinker->nr_deferred) > return; > + if (shrinker->flags & SHRINKER_MEMCG_AWARE) > + unregister_memcg_shrinker(shrinker); > down_write(&shrinker_rwsem); > list_del(&shrinker->list); > up_write(&shrinker_rwsem); >