Received: by 10.213.65.68 with SMTP id h4csp1385568imn; Wed, 21 Mar 2018 09:23:37 -0700 (PDT) X-Google-Smtp-Source: AG47ELuneF4mpXcNPayqbkVPu9a7TD8cM68NaVEIWVWNvv0H0R2QjWze0wae8B5t5jkTnx4YBwiW X-Received: by 2002:a17:902:c1:: with SMTP id a59-v6mr21104331pla.284.1521649417062; Wed, 21 Mar 2018 09:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521649417; cv=none; d=google.com; s=arc-20160816; b=bxoEQswQ8b8PY0HzRipjLXFNE1LE7ZJTF48I5YgL4aaFhG1kuRsl688DTutl0n2Cpm RKWhCyXh9mdW1XolT6Q/NG4T1JnftCtk+TqJWKNaVs2fW5bfx6UB7eDOy+dX6n/9u1VQ 6XWN73K8Al8J9mSHJNGBUCBV34qJXT7sO0Gv9KNnWGvaZjSOpXxugjqYoWQV1KvHX/P3 3RKjI5vfhg68pMinCDBtkMgbh804XUTAFp9fr8IY93lkyuvpn8Fh3TfT1m/AffnZdaju c+kr/NursuRaIj/+1kLHPGtOZjr2oL+Rruo0y22SUoSAj/EGOREBgE7BLkzL6JN6NZ95 cQHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=ILYf89dlw7eNxYt6xx/4ZEpX0Lp6XwPdundiPVMh200=; b=U0k7TePstlMd+bE9k3kREqQh9gZ2jtTLpb3zGA7Gf0nX4LRpr3xFIjPl4XdVtBhVQx gCB3MyMCF8DpguU4MXyNR/UUsuazZcNIYgjf3wZxXXrkIBjIdkHT+A1TL75GuSSf98pH YXQwjNMm5XB9WTMn574AK6rjrrz9YlseTEaMINYj5UDqJHo8DKTfMBMIjYZ3gzZF2szc 1f7ckkpr466ZEzidviG1DADaHBkzV1yfD0MrKGrUY2HAsoCd4JJyUHjaaZ81riuJQYxK DVkiF9FSxHJEktMqHGRzPJ4W1oUU68tYqBycN7VnkXQGoXv5q6ttf8QIKfuQgLBS6F5H mE7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Nr9ohil3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o16si2905540pgc.832.2018.03.21.09.23.20; Wed, 21 Mar 2018 09:23:37 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Nr9ohil3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751925AbeCUQWZ (ORCPT + 99 others); Wed, 21 Mar 2018 12:22:25 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50860 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751546AbeCUQWW (ORCPT ); Wed, 21 Mar 2018 12:22:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ILYf89dlw7eNxYt6xx/4ZEpX0Lp6XwPdundiPVMh200=; b=Nr9ohil3XMs7a5FsIOevBNjKh UcaFrEISnRvu034ONoTof595WqDZp0TfeWOgizuHMMR/vws6la5HVNgU5uBv5JPdiUVXZugzx7bwx cEuxHVGAVT8czBveDZRKVeEt0i+gotnL1ZgIti+BAt59J6e1SGrgn9iTOz+bQvY0Yj10e2W5VybX2 wfV7dHcAlyRjBykWMgxFW+TRXNY+CtjJS9WyUT928FBaLuF2PHNGcGfGZQ3GO25eOgS/a7CBvzUcQ N1hb2jInwnMoP9YcKAYAnu2j8fqDPn+pve+PmGk36CYqApZarfOZ0SX+LssP8CW+3/WMJVk5TIYLF xNNNfaiBQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1eygTg-0005Nh-No; Wed, 21 Mar 2018 16:20:40 +0000 Date: Wed, 21 Mar 2018 09:20:39 -0700 From: Matthew Wilcox To: Kirill Tkhai Cc: viro@zeniv.linux.org.uk, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, 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 Subject: Re: [PATCH 03/10] mm: Assign memcg-aware shrinkers bitmap to memcg Message-ID: <20180321162039.GC4780@bombadil.infradead.org> References: <152163840790.21546.980703278415599202.stgit@localhost.localdomain> <152163850081.21546.6969747084834474733.stgit@localhost.localdomain> <20180321145625.GA4780@bombadil.infradead.org> <20180321152647.GB4780@bombadil.infradead.org> <638887a1-35f8-a71d-6e45-4e779eb62dc4@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <638887a1-35f8-a71d-6e45-4e779eb62dc4@virtuozzo.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 21, 2018 at 06:43:01PM +0300, Kirill Tkhai wrote: > On 21.03.2018 18:26, Matthew Wilcox wrote: > > On Wed, Mar 21, 2018 at 06:12:17PM +0300, Kirill Tkhai wrote: > >> On 21.03.2018 17:56, Matthew Wilcox wrote: > >>> Why use your own bitmap here? Why not use an IDA which can grow and > >>> shrink automatically without you needing to play fun games with RCU? > >> > >> Bitmap allows to use unlocked set_bit()/clear_bit() to maintain the map > >> of not empty shrinkers. > >> > >> So, the reason to use IDR here is to save bitmap memory? Does this mean > >> IDA works fast with sparse identifiers? It seems they require per-memcg > >> lock to call IDR primitives. I just don't have information about this. > >> > >> If so, which IDA primitive can be used to set particular id in bitmap? > >> There is idr_alloc_cyclic(idr, NULL, id, id+1, GFP_KERNEL) only I see > >> to do that. > > > > You're confusing IDR and IDA in your email, which is unfortunate. > > > > You can set a bit in an IDA by calling ida_simple_get(ida, n, n, GFP_FOO); > > You clear it by calling ida_simple_remove(ida, n); > > I moved to IDR in the message, since IDA uses global spinlock. It will be > taken every time a first object is added to list_lru, or last is removed. > These may be frequently called operations, and they may scale not good > on big machines. I'm fixing the global spinlock issue with the IDA. Not going to be ready for 4.17, but hopefully for 4.18. > Using IDR will allow us to introduce memcg-related locks, but I'm still not > sure it's easy to introduce them in scalable-way. Simple set_bit()/clear_bit() > do not require locks at all. They're locked operations ... they may not have an explicit spinlock associated with them, but the locking still happens. > > The identifiers aren't going to be all that sparse; after all you're > > allocating them from a global IDA. Up to 62 identifiers will allocate > > no memory; 63-1024 identifiers will allocate a single 128 byte chunk. > > Between 1025 and 65536 identifiers, you'll allocate a 576-byte chunk > > and then 128-byte chunks for each block of 1024 identifiers (*). One of > > the big wins with the IDA is that it will shrink again after being used. > > I didn't read all the way through your patchset to see if you bother to > > shrink your bitmap after it's no longer used, but most resizing bitmaps > > we have in the kernel don't bother with that part. > > > > (*) Actually it's more complex than that... between 1025 and 1086, > > you'll have a 576 byte chunk, a 128-byte chunk and then use 62 bits of > > the next pointer before allocating a 128 byte chunk when reaching ID > > 1087. Similar things happen for the 62 bits after 2048, 3076 and so on. > > The individual chunks aren't shrunk until they're empty so if you set ID > > 1025 and then ID 1100, then clear ID 1100, the 128-byte chunk will remain > > allocated until ID 1025 is cleared. This probably doesn't matter to you. > > Sound great, thanks for explaining this. The big problem I see is > that IDA/IDR add primitives allocate memory, while they will be used > in the places, where they mustn't fail. There is list_lru_add(), and > it's called unconditionally in current kernel code. The patchset makes > the bitmap be populated in this function. So, we can't use IDR there. Maybe we can use GFP_NOFAIL here. They're small allocations, so we're only asking for single-page allocations to not fail, which shouldn't put too much strain on the VM.