Received: by 10.213.65.68 with SMTP id h4csp790488imn; Tue, 27 Mar 2018 08:49:54 -0700 (PDT) X-Google-Smtp-Source: AG47ELtE/TWYY3pSWOF3pIP4xB9hYmOTAVC1EgQHDVTs8I7WvOVMVNd8kG2Y2ezs0++7N4JX2P4m X-Received: by 10.167.129.195 with SMTP id c3mr37141732pfn.14.1522165794636; Tue, 27 Mar 2018 08:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522165794; cv=none; d=google.com; s=arc-20160816; b=aXTjrCfzxWqU+jOxWWJJUCeS6/UH7XB7hZqw5pMdRLltnNm8EsejlTzlSdtC1PeEEz 36Q3N3YoVsr70HMzEXe1V/DcN4mJPdj2NN+wGDMJbQs2dS2pLAzToBT9RuObjC2Nq/ij JO5Qn+nYTDuZ8vxEubQwKMPnyh7M9fdjXeI5JiP9DFGjccetBtTd3e4x/nALNmmO7EdT 23HqdMHUI4+hk8uKHlcEJAF3aCSLPhQrI7MKD8cQoNi/+EZD+OKt2ypo3N8qCfbZB30O Ll7Hwzd5N8VuMVpeTrjaQDE+bDNKiJi1sml1bC/elu4NvlZtSoEFdYX6i8FZL01dAgVp xeBw== 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=Tw0xQ8FRqT8mt68rEnCOm1ZdznUJ0tycw0HWjlTOlNA=; b=oNtbnSWLfbdm2F0t2hW7HED6YeCaWbdjOGseYZU/J7M7LNWtftoyl/Uygg64UWUjic e+nPOrYN0GogfAjW2apePcz5EQC7eNIZ2FzFUBpjPcZjdC+F9lx4GDEusPBIaX+J0tBz IZS+JH38PsojG8PAikrFrI178oLkMQEynI+lsKcywZ4whU4UkbCpUfr/zOMOg5G7NAp1 HXgRpMidIEiouOKLbE9xK/KRDCFbEnE6HR53DvDEzPZFI7mrunUpdNL/ShoKIBF5IMhz 8RSpRlLZPJacZpmBp8Ewe86U/8gDN0Mu34WBHmBXtpvTF/tvKgQleFPk58DADgke2JeV cazA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UznMGanZ; 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 b92-v6si1517310plb.514.2018.03.27.08.49.39; Tue, 27 Mar 2018 08:49:54 -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=UznMGanZ; 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 S1752683AbeC0Psf (ORCPT + 99 others); Tue, 27 Mar 2018 11:48:35 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:43806 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752161AbeC0Psd (ORCPT ); Tue, 27 Mar 2018 11:48:33 -0400 Received: by mail-lf0-f66.google.com with SMTP id v207-v6so34011324lfa.10 for ; Tue, 27 Mar 2018 08:48:32 -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=Tw0xQ8FRqT8mt68rEnCOm1ZdznUJ0tycw0HWjlTOlNA=; b=UznMGanZY99P7yfYqJTU8zIFLivuDYRhgWBPIaCIIH3hb6YsnOx5yu9l2xmzB+urpw ev1+lxycdp9kQsK4Wqr4iIzAgEVCirnE0hB5ss/YIyWnaTpmDImwvb2nsHxes72Q+998 WGApgXenmR/njo0cm00eVYz1uANwT9vo1oF1e0yPNy2qfIPMBQpo+yIMDnUYRTV9NcTU 0OBDmXr5hSBtLMAGYm8SseDoY+boEJz8sPk4P6wHG/igJIS08YShpED1zlJIzTa77xWx 56j1pJdjk9v6Wfybf22k60URCPK3lB3ti/GV4omUKvjxUB3J7TK6uDIBTG0LdmDc8Ne/ BMgQ== 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=Tw0xQ8FRqT8mt68rEnCOm1ZdznUJ0tycw0HWjlTOlNA=; b=EUDlEaO3SawRVNgIDls8xyR4TBotbTaQOgxNBTepvY0QUatqJA6bDZUZDGTHwUghcU ifpCJKP5hqBVUkUqJhbGN+LH+mP3Iic3lTSo9S1ON/hMTQX4Jwu6544QIET/fq2JGiQO 0AQN05joj/KURCDHzIITjgie+PpzQc38v9FEqz9nnxiEDn+fRn1c+4V0yQLuNiS27ezz GJzUfB1v2J15ZggGpIOepgbopbBE9gbpZHt8h/L/NoLS/DjkDZ8q240j5uG3CnuysB60 Xt2+miHVwDjI0aH/tc/+qy/VWj8aN0un+n4VzhJR4t2AbaBQTs1JWs4cKgCC3czX48md mc5Q== X-Gm-Message-State: AElRT7F7zVuWLivowBAisiyq+w9pSE65Yq7wbs4YBmbHhpnzo8v0tXhM TT1KJBE4iSIgLN1QlilsBFg= X-Received: by 2002:a19:1668:: with SMTP id m101-v6mr31295599lfi.27.1522165711980; Tue, 27 Mar 2018 08:48:31 -0700 (PDT) Received: from esperanza ([185.6.245.156]) by smtp.gmail.com with ESMTPSA id g192-v6sm283237lfg.86.2018.03.27.08.48.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Mar 2018 08:48:31 -0700 (PDT) Date: Tue, 27 Mar 2018 18:48:28 +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: <20180327154828.udezpkwkwzcftnqn@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5828e99c-74d2-6208-5ec2-3361899dd36a@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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).