Received: by 10.192.165.148 with SMTP id m20csp2590955imm; Sun, 22 Apr 2018 10:18:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx4//usrfhsXFMPc90cZVB93WkSNc5OKcpu03ksbV/edQKStp4reF3ovKnXWXHUDiG4IAi/VY X-Received: by 2002:a17:902:8646:: with SMTP id y6-v6mr17605292plt.86.1524417496872; Sun, 22 Apr 2018 10:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524417496; cv=none; d=google.com; s=arc-20160816; b=OI2hAJgyN78ggIa0doOWa6CsFs5ZdjGT0eUghHKJlZbFPpcJhCWmCcspJsgzJ90Umq 2bLAw5GKFwPL/aqdegWZkxxbN7CIMHhZnMKkVas3BS39H9f/xuhwemoQhGQ58htlu8LD AxO9mcislCc5lIFc1lxDvsgMu4OuCI9l4JEW2gZ5VHSn74ZNF5igOAJb7kwmtlPElzhU pENitQbuxERqYt6OMYEOvQ9aMrEXtLRJUF7gx2FoAIAhMxecVUzkh9/ufxd7PBfuTFoe Kn+9Vr4ek6tfUbIvhYeoVdqmciwXJ9ErbusRpJlXedVYLWM9Hi35dkafKDwuu7En+sgG 5QMg== 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=gOkJNJoboUwDuK4tSeSyXPB0tEPGmMaeZyBU9yb1CeI=; b=PNBxzusTITSP8VZPR+cdYASr41CNenWo30BAuonJkuZv9R50mLC6KAzqipUi+Mn7lh 3AL1O/rOvF0fsWwweT9TvefKMcGTfV/ddcOVnfpUrc9UBdEm/EC3mbPG+lW3QsdSXQZK XPkUk82xqwdtNXPRPN+MRnC1bHSg2a+etJxv+T5aZJ4BfXyZn6AB3dY1msY6jVaPFBOb TgCV61zc3/OYib52gM6bk+PkjlE3jLAZQQOyjWBvEMMttGft5QgrsHjbiyoSfqMfq8vO gK9wL96hCaLDQdThFiZphdIg9ouraFtwxzfoXopxaOuQnGxtKfPbZUdxjM/nex66//2H /9gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F9LMKekE; 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 t14-v6si10386800plm.588.2018.04.22.10.18.02; Sun, 22 Apr 2018 10:18:16 -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=F9LMKekE; 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 S1753404AbeDVRRD (ORCPT + 99 others); Sun, 22 Apr 2018 13:17:03 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:33950 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751564AbeDVRRB (ORCPT ); Sun, 22 Apr 2018 13:17:01 -0400 Received: by mail-lf0-f67.google.com with SMTP id r7-v6so11608024lfr.1 for ; Sun, 22 Apr 2018 10:17:00 -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=gOkJNJoboUwDuK4tSeSyXPB0tEPGmMaeZyBU9yb1CeI=; b=F9LMKekEX/6BGrDXOhX9biiQ0km18PipLcA4/r+RFjPculPcSNuPVIxZ/HOvFU0gSX xfEpeMafvZZKdzYIDvB0I/JSYe8Izu4J2u+Sx/ozjCPXVcklEi3TnDvVpkhEY14DCrBT ZZiPVawrwHUZET3GzHkS7PE4No9WlUeJvuzO5GplES95/7ry4u6KmUVhTpcePwADmQu3 j23G1DVR/rNS2yIXK4R+/OdyY4eys2u/S3/x7UDvNjyNCOD3/LOiBy/ltiWgfxSneUTW wR6VC2Gq2R/Sdn7waQc0ddqtubqLoiEpjjkwrc4iwRUVi1Xgr5eLIOK7MavaHS0wSbEp 0Jxg== 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=gOkJNJoboUwDuK4tSeSyXPB0tEPGmMaeZyBU9yb1CeI=; b=JCUCcH4Sa3Ie4aLTFQUpTnGcPvEZ5T3h2jgbrMV/u3GjWfwR1NNK6nDVdLtAlEEein XX3mxs7PDPsZWMhYkSxDm55TlYt0tb14n89kgJNkqi+PcaSittC+/tUwSqGLUWyAWMqq fC0Urv4EAj29KDxmLe9dJemVSFJimBvx0PAkDs5GxdDq0PkboeiIvUfaTq/86cp1MavX pf3RZgDaNz6z+Y7fRONvwEgoSccGbV15I5yAsvgEBYW7yz6XJ1Q81oGwEaEH1127CFCE vp5g44XH67iBCTzhaAV55rFqmPagbNJedY3vnVeu293AjIEBEm6JGe9sz7v5+bPXq4El Txaw== X-Gm-Message-State: ALQs6tApe4bsbHfKN7cjUDOApa8pmQkJ/8d4zwqKTuLw8OwdOpll735T yevTe8nmnMM2NZwz8ZsOdOM= X-Received: by 2002:a19:4c46:: with SMTP id z67-v6mr6896164lfa.141.1524417419385; Sun, 22 Apr 2018 10:16:59 -0700 (PDT) Received: from esperanza (81.5.110.211.dhcp.mipt-telecom.ru. [81.5.110.211]) by smtp.gmail.com with ESMTPSA id g13sm1980767ljk.0.2018.04.22.10.16.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Apr 2018 10:16:58 -0700 (PDT) Date: Sun, 22 Apr 2018 20:16:55 +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 01/12] mm: Assign id to every memcg-aware shrinker Message-ID: <20180422171655.llxowifnxzpf5hee@esperanza> References: <152397794111.3456.1281420602140818725.stgit@localhost.localdomain> <152399118252.3456.17590357803686895373.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152399118252.3456.17590357803686895373.stgit@localhost.localdomain> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 17, 2018 at 09:53:02PM +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. > > Signed-off-by: Kirill Tkhai > --- > include/linux/shrinker.h | 2 ++ > mm/vmscan.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 53 insertions(+) > > diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h > index a3894918a436..86b651fa2846 100644 > --- a/include/linux/shrinker.h > +++ b/include/linux/shrinker.h > @@ -66,6 +66,8 @@ struct shrinker { > > /* These are for internal use */ > struct list_head list; > + /* ID in shrinkers_id_idr */ > + int id; This should be under ifdef CONFIG_MEMCG && CONFIG_SLOB. > /* objs pending delete, per node */ > atomic_long_t *nr_deferred; > }; > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 8b920ce3ae02..4f02fe83537e 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -169,6 +169,43 @@ unsigned long vm_total_pages; > static LIST_HEAD(shrinker_list); > static DECLARE_RWSEM(shrinker_rwsem); > > +#if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) > +static DEFINE_IDR(shrinkers_id_idr); IMO shrinker_idr would be a better name. > + > +static int add_memcg_shrinker(struct shrinker *shrinker) > +{ > + int id, ret; > + > + down_write(&shrinker_rwsem); > + ret = id = idr_alloc(&shrinkers_id_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 del_memcg_shrinker(struct shrinker *shrinker) > +{ > + int id = shrinker->id; > + > + down_write(&shrinker_rwsem); > + idr_remove(&shrinkers_id_idr, id); > + up_write(&shrinker_rwsem); > +} > +#else /* CONFIG_MEMCG && !CONFIG_SLOB */ > +static int add_memcg_shrinker(struct shrinker *shrinker) > +{ > + return 0; > +} > + > +static void del_memcg_shrinker(struct shrinker *shrinker) > +{ > +} > +#endif /* CONFIG_MEMCG && !CONFIG_SLOB */ > + > #ifdef CONFIG_MEMCG > static bool global_reclaim(struct scan_control *sc) > { > @@ -306,6 +343,7 @@ unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone > int register_shrinker(struct shrinker *shrinker) > { > size_t size = sizeof(*shrinker->nr_deferred); > + int ret; > > if (shrinker->flags & SHRINKER_NUMA_AWARE) > size *= nr_node_ids; > @@ -314,10 +352,21 @@ int register_shrinker(struct shrinker *shrinker) > if (!shrinker->nr_deferred) > return -ENOMEM; > > + if (shrinker->flags & SHRINKER_MEMCG_AWARE) { > + ret = add_memcg_shrinker(shrinker); > + if (ret) > + goto free_deferred; > + } > + This doesn't apply anymore, not after commit 8e04944f0ea8a ("mm,vmscan: Allow preallocating memory for register_shrinker()"). Please rebase. I guess now you have to allocate an id in prealloc_shrinker and set the pointer (with idr_replace) in register_shrinker_prepared. > down_write(&shrinker_rwsem); > list_add_tail(&shrinker->list, &shrinker_list); > up_write(&shrinker_rwsem); > return 0; > + > +free_deferred: > + kfree(shrinker->nr_deferred); > + shrinker->nr_deferred = NULL; > + return -ENOMEM; > } > EXPORT_SYMBOL(register_shrinker); > > @@ -328,6 +377,8 @@ void unregister_shrinker(struct shrinker *shrinker) > { > if (!shrinker->nr_deferred) > return; > + if (shrinker->flags & SHRINKER_MEMCG_AWARE) > + del_memcg_shrinker(shrinker); > down_write(&shrinker_rwsem); > list_del(&shrinker->list); > up_write(&shrinker_rwsem); >