Received: by 10.213.65.68 with SMTP id h4csp306000imn; Wed, 28 Mar 2018 04:05:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/4DeJ52Gtt47lNaDr2VoQ+zZreQcs04oID082FjteKEw3c6z8eQgA3MarOTihfJj+xEjQQ X-Received: by 2002:a17:902:778e:: with SMTP id o14-v6mr3389501pll.160.1522235104067; Wed, 28 Mar 2018 04:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522235104; cv=none; d=google.com; s=arc-20160816; b=uiDclGoao8HalnPJL7Fbykz7nSfMEND1SX4bPTmI2PLF7fArSwYrcB7MjKL40Wo6B0 thfXOdlX2XG6x5z/2lSFRmqi/ZYMcovIuNDD+IOnIg+M/kPH7YnzVgBVhwvaZED1A6xu CoOeKjR9uP2CF6DkqpPeT2XSdPe3aAi9/7l1yq3iiuDbj06aFT1yXND8dWibXumPFme8 qLghWKz4xdIJ/3tcOGOl/M+wcofhxJaa2hyEMoCoNvQWn7IPK4A5WXxgXRRnFe5GK1Fx FWtDA6IMJbgoHQWXZYASVrpZzoY0P4WMkspYznUL/rNU6WGLiyFA3ExVf6YZB2ZFK4Oq wluA== 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=I7z03aN7o54iOjTct1aVNAMWe5IVxzDI9plbMhl2kd4=; b=JyBDq9U6A3SYR2YRLRcRIpzsUUfFtuNTY1yELwNZUscSbej+eP4SftS3u9XzbFLB7e ocnsn0Ian0hCSNVYNM7G0AVxiBNk3jEm/rYTCJ5dYOzL9Vyo15kDZpqNtUE6d+T9iura enimc3XG6xKRlETPle8qSYVaZVJirhYVTCmxbBgOhwjcNC0geNRCTpUDqZsh/2KrtG6b runTY2lphoNPoEoYh9uPgjtslAdscHFR9QJ2ci8z+Zw4ug2olEpjhMIgs8fgiShKsBAc sfErCxbnfPkVWZ9ukpMurjNV4jdhG1Q7BvCMjyjyMLqvm6tE0CtTK2yJ8jCJgutwzGge +N7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ncmmt1bT; 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 g1-v6si3214586plo.250.2018.03.28.04.04.21; Wed, 28 Mar 2018 04:05: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=Ncmmt1bT; 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 S1752219AbeC1LC5 (ORCPT + 99 others); Wed, 28 Mar 2018 07:02:57 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:43008 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751223AbeC1LC4 (ORCPT ); Wed, 28 Mar 2018 07:02:56 -0400 Received: by mail-lf0-f66.google.com with SMTP id v207-v6so2846119lfa.10 for ; Wed, 28 Mar 2018 04:02:55 -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=I7z03aN7o54iOjTct1aVNAMWe5IVxzDI9plbMhl2kd4=; b=Ncmmt1bTO/kDRkY12O/ggTinxPr9ZpN6Kl0Qtm010ypLTH5k+VPxhFACJOafD4/ea1 ehRekj7i6VOoMmiB4A4Yx5xpOQisBz1daiHFcKc2xNiktAP0CB/t55nLQesIxxwyBqjl /tmVKskPFrjm+wh21p+WXlg7EUnAmpHhCz1dSr/ZLiTKwCGrEfbk2N2tiHPJ9rGVPOBb 5wDR9beCa6JKQJG1cMbi7h8OqGLSPxp5/xqXnTi51osNR0298UFFQ6ZP+P39BxtrQW+v dDivzLRB3sSyb1H9beD39n7IEG5BNpmGiYxqfuHzg1eW0BQwMJUkFjwh2zwFCx14xT7P Zbxg== 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=I7z03aN7o54iOjTct1aVNAMWe5IVxzDI9plbMhl2kd4=; b=Ah3EqG4NC67l7ElFna9dXLSCdv3C2WLMOY1cM6CnJK2scUqVhhs0kYChJr8FxHE2sO OX6D8b1vxkHDp9YzPHwXGRsAOmPGrYXsfjaqIsLev5KR53H03ww3ynEEtD7q/7KavPYZ gBGlZuNYwEc2EtlqWJEt2ApOtlpZOsYwBFvPu9Re7jVQXT0QbODwhwIEM98QqrcjerJ+ LXBiqgKV7UXtwFIoQ9DtfypgbC9hVwRplD0uRQfVGPlruQZU4qtpjzed+4vagjox7Q00 mtflTXA49HhK1brbAcQVe2BpPCWDEzp6EybaQOI33DBXG4JQLUlixd+RR/9bCmfduj1g EwIg== X-Gm-Message-State: AElRT7F6QeeNpDDV0CjYjOvJrWUzFCV/mlgSSZOciddKy96Yql54VY5m VFHMKL27O1YEkVe2F5WC5sQ= X-Received: by 2002:a19:cf89:: with SMTP id f131-v6mr2025346lfg.130.1522234974850; Wed, 28 Mar 2018 04:02:54 -0700 (PDT) Received: from esperanza ([185.6.245.156]) by smtp.gmail.com with ESMTPSA id b186-v6sm573451lfb.47.2018.03.28.04.02.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Mar 2018 04:02:54 -0700 (PDT) Date: Wed, 28 Mar 2018 14:02:51 +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: <20180328110251.5wl3kwjhcuizyz6n@esperanza> References: <152163840790.21546.980703278415599202.stgit@localhost.localdomain> <152163847740.21546.16821490541519326725.stgit@localhost.localdomain> <20180324184009.dyjlt4rj4b6y6sz3@esperanza> <0db2d93f-12cd-d703-fce7-4c3b8df5bc12@virtuozzo.com> <20180327091504.zcqvr3mkuznlgwux@esperanza> <5828e99c-74d2-6208-5ec2-3361899dd36a@virtuozzo.com> <20180327154828.udezpkwkwzcftnqn@esperanza> <635e8bdf-9280-c872-49c3-d3e293e1b332@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <635e8bdf-9280-c872-49c3-d3e293e1b332@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 28, 2018 at 01:30:20PM +0300, Kirill Tkhai wrote: > On 27.03.2018 18:48, Vladimir Davydov wrote: > > On Tue, Mar 27, 2018 at 06:09:20PM +0300, Kirill Tkhai wrote: > >>>>>> 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). > >> > >> We take bitmap_rwsem for writing to expand shrinkers maps. If we replace > >> it with shrinker_rwsem and the memory allocation get into reclaim, there > >> will be deadlock. > > > > Hmm, AFAICS we use down_read_trylock() in shrink_slab() so no deadlock > > would be possible. We wouldn't be able to reclaim slabs though, that's > > true, but I don't think it would be a problem for small allocations. > > > > That's how I see this. We use shrinker_rwsem to protect IDR mapping > > shrink_id => shrinker (I still insist on IDR). It may allocate, but the > > allocation size is going to be fairly small so it's OK that we don't > > call shrinkers there. After we allocated a shrinker ID, we release > > shrinker_rwsem and call mem_cgroup_grow_shrinker_map (or whatever it > > will be called), which checks if per-memcg shrinker bitmaps need growing > > and if they do it takes its own mutex used exclusively for protecting > > the bitmaps and reallocates the bitmaps (we will need the mutex anyway > > to synchronize css_online vs shrinker bitmap reallocation as the > > shrinker_rwsem is private to vmscan.c and we don't want to export it > > to memcontrol.c). > > But what the profit of prohibiting reclaim during shrinker id allocation? > In case of this is a IDR, it still may require 1 page, and still may get > in after fast reclaim. If we prohibit reclaim, we'll fail to register > the shrinker. > > It's not a rare situation, when all the memory is occupied by page cache. shrinker_rwsem doesn't block page cache reclaim, only dcache reclaim. I don't think that dcache can occupy all available memory. > So, we will fail to mount something in some situation. > > What the advantages do we have to be more significant, than this disadvantage? The main advantage is code simplicity.