Received: by 10.213.65.68 with SMTP id h4csp444716imn; Tue, 27 Mar 2018 02:16:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx484dqIKGmmLa8DSJQNPpl4zPsGRty+eWOEWlD5xhRIyjryoazqFaK+ru8jq47OAv9WRT+hb X-Received: by 10.101.99.129 with SMTP id h1mr2463807pgv.27.1522142183570; Tue, 27 Mar 2018 02:16:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522142183; cv=none; d=google.com; s=arc-20160816; b=hirws9Kso7L+QDQBKQ3IBzqbEIvu+UmbRhzEMUO1eWdyAIAuvbdfMbkpuKjoa75cpb 6vik8dd8sGZoB/iBbFarNaV1pjXFaredTFm6Su8sVNBzmup5w+kpX/whYkGJ2QLxmbCF +OGLabMT4zRYKxSrTC8MKgaWeoATidjSui9LGvu6BGBk9UtKjzePYmAj0fu+a8aB44c6 Z53KpDNU/djz31K7hQBZ34goW698Tl/AIca824xzuiTHAjZ7fJBwvMrD5seGIyjPpG/8 GQBTEpFT9MjPiRWePwv3ifPevsR0Q/mYCGm40JM9Pu4yWZCO7Dok1XFgnfLiNpxxfU6k hS4w== 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=IP/5640eGTm+lrGD5tbDl1YAcA61UWl2gH7Q5QFclp4=; b=x0wuhAp+Swe8ozN539N8ONfqaZJYRX4EP5h8DsaLuEHzYWV42IFs9/f9hFyiVuDYHB Yrk4RqHyySKej+b2/4GAtsATbltrO+ntxZzcDAVv/eWlpuAuW1GXGm+0mlZxpDEQmj+C I/BEC/1h8QrBezzdeNLJcie/dwdj/zSeaPmVOrLK8K4IaLQAhob55h+i40MfmvPSljzL F6YG6wY+xiNeIl89NWLdbbpZtqkecV6FXegvGzD1U8rcdSUAp0zUFCMMwHosNTxLXW4i SFVYGfrVIrzgoaqmmOQh8AlVtWvefBWCmeEfgYfJ0++rN4PN/FVVDNIsIjc0GwacBlGt zDAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BGbmCrXw; 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 z2si568591pgz.328.2018.03.27.02.16.07; Tue, 27 Mar 2018 02:16:23 -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=BGbmCrXw; 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 S1751964AbeC0JPK (ORCPT + 99 others); Tue, 27 Mar 2018 05:15:10 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:33816 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750937AbeC0JPJ (ORCPT ); Tue, 27 Mar 2018 05:15:09 -0400 Received: by mail-lf0-f67.google.com with SMTP id c78-v6so27570716lfh.1 for ; Tue, 27 Mar 2018 02:15:08 -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=IP/5640eGTm+lrGD5tbDl1YAcA61UWl2gH7Q5QFclp4=; b=BGbmCrXwxl/rTJWHNtSehSeQvwYjwF7rPYI+r4c/uBq5XTIqbGZmQqJp11o5TFSaqO qbxNQFwnMJs10UcFnydjjWkWNtSGKNxgAgyPvGofXhnhrbneW7pVtNWjspKz2kCbm2WM IdBo2UF1SuMM0MH/qy0+k27gqT6jNgubljJ+GyfXj3maGVsHMncIZdWzrhYXhVA+g1yk P9v12e4+2b9Deaj0OG7YK+oEc4/gBtI5If1V2uixioKffpnJxse7X52EcxPDJluepkeb z+lDjzbBCpbqgULz02n2jUBpAT4ZU7OB3O7DIBRujj83zS/m9mhxz+tUnualYVwACUqH Gg2A== 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=IP/5640eGTm+lrGD5tbDl1YAcA61UWl2gH7Q5QFclp4=; b=Sr884fWub0MqHy3yTXAuUH82NOLRcYDMu2LunVKWnhFjhkwUmkui0SrAEEoDRL763l v6P3/6vbWjxMdeW66CtkkeB1mnWGstbb8ktJu+bAJkz8rdaxhUk4ZMmygyErKiB4cjTY gGrSxjx24TOL1yUTBb8lQ/7VjntuI+/I9wuCldotSr/X/mhxg79tlCA5Q9op5WI67Ohz p+QI76vi4jrY8/IKW8sfODxGHLvTGUtjJz06F4kUAAfW7KjFOtr9aW9R3ecGJcFlb+LV vbHLqd8RFNdi1GgPagP/T8CyXYvF4yfKKqo6ND0Q+kRcmFLIDbc8kmh6uP5rr7lg71o4 HvLQ== X-Gm-Message-State: AElRT7FtTtMVhHD55/PDMN5oPZUpaTrkmKzLra6BgW8zZ6D6NBvhFNdc 8+oi1IZh4wG/16zMXWqPsOc= X-Received: by 10.46.23.70 with SMTP id l67mr27775497lje.132.1522142107505; Tue, 27 Mar 2018 02:15:07 -0700 (PDT) Received: from esperanza ([185.6.245.156]) by smtp.gmail.com with ESMTPSA id 200sm141457ljf.12.2018.03.27.02.15.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Mar 2018 02:15:06 -0700 (PDT) Date: Tue, 27 Mar 2018 12:15:04 +0300 From: Vladimir Davydov To: Kirill Tkhai Cc: viro@zeniv.linux.org.uk, hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.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, shakeelb@google.com, jbacik@fb.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org Subject: Re: [PATCH 01/10] mm: Assign id to every memcg-aware shrinker Message-ID: <20180327091504.zcqvr3mkuznlgwux@esperanza> References: <152163840790.21546.980703278415599202.stgit@localhost.localdomain> <152163847740.21546.16821490541519326725.stgit@localhost.localdomain> <20180324184009.dyjlt4rj4b6y6sz3@esperanza> <0db2d93f-12cd-d703-fce7-4c3b8df5bc12@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0db2d93f-12cd-d703-fce7-4c3b8df5bc12@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 26, 2018 at 06:09:35PM +0300, Kirill Tkhai wrote: > Hi, Vladimir, > > thanks for your review! > > On 24.03.2018 21:40, Vladimir Davydov wrote: > > Hello Kirill, > > > > I don't have any objections to the idea behind this patch set. > > Well, at least I don't know how to better tackle the problem you > > describe in the cover letter. Please, see below for my comments > > regarding implementation details. > > > > On Wed, Mar 21, 2018 at 04:21:17PM +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 | 1 + > >> mm/vmscan.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ > >> 2 files changed, 60 insertions(+) > >> > >> diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h > >> index a3894918a436..738de8ef5246 100644 > >> --- a/include/linux/shrinker.h > >> +++ b/include/linux/shrinker.h > >> @@ -66,6 +66,7 @@ struct shrinker { > >> > >> /* These are for internal use */ > >> struct list_head list; > >> + int id; > > > > This definition could definitely use a comment. > > > > BTW shouldn't we ifdef it? > > Ok > > >> /* objs pending delete, per node */ > >> atomic_long_t *nr_deferred; > >> }; > >> diff --git a/mm/vmscan.c b/mm/vmscan.c > >> index 8fcd9f8d7390..91b5120b924f 100644 > >> --- a/mm/vmscan.c > >> +++ b/mm/vmscan.c > >> @@ -159,6 +159,56 @@ unsigned long vm_total_pages; > >> static LIST_HEAD(shrinker_list); > >> static DECLARE_RWSEM(shrinker_rwsem); > >> > >> +#if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) > >> +static DEFINE_IDA(bitmap_id_ida); > >> +static DECLARE_RWSEM(bitmap_rwsem); > > > > Can't we reuse shrinker_rwsem for protecting the ida? > > I think it won't be better, since we allocate memory under this semaphore. > After we use shrinker_rwsem, we'll have to allocate the memory with GFP_ATOMIC, > which does not seems good. Currently, the patchset makes shrinker_rwsem be taken > for a small time, just to assign already allocated memory to maps. AFAIR it's OK to sleep under an rwsem so GFP_ATOMIC wouldn't be necessary. Anyway, we only need to allocate memory when we extend shrinker bitmaps, which is rare. In fact, there can only be a limited number of such calls, as we never shrink these bitmaps (which is fine by me). > > >> +static int bitmap_id_start; > >> + > >> +static int alloc_shrinker_id(struct shrinker *shrinker) > >> +{ > >> + int id, ret; > >> + > >> + if (!(shrinker->flags & SHRINKER_MEMCG_AWARE)) > >> + return 0; > >> +retry: > >> + ida_pre_get(&bitmap_id_ida, GFP_KERNEL); > >> + down_write(&bitmap_rwsem); > >> + ret = ida_get_new_above(&bitmap_id_ida, bitmap_id_start, &id); > > > > AFAIK ida always allocates the smallest available id so you don't need > > to keep track of bitmap_id_start. > > I saw mnt_alloc_group_id() does the same, so this was the reason, the additional > variable was used. Doesn't this gives a good advise to ida and makes it find > a free id faster? As Matthew pointed out, this is rather pointless.