Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1282354imm; Tue, 3 Jul 2018 08:29:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLJ86lUgRs9itXBPw7pvZs2Q9JIKjTjGuzcD/PjuMgUjcmWpAVLOfgLC5V1AV7lAr6J3AF5 X-Received: by 2002:a17:902:5602:: with SMTP id h2-v6mr30837187pli.314.1530631793926; Tue, 03 Jul 2018 08:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530631793; cv=none; d=google.com; s=arc-20160816; b=EZiCDEZzkZRmFpav68McnByZYuRrhKSPmGOHa8gkOxu440aYFzmmv4saqVJoNgPkDq 0XhgHA/KJ/dITKwrcVQzB5+6YuRhkDv7aT5lXDFnDM7KSofaf+KBe2qtSq/rSgdmKdqU E6aICFxofyKCCkXhGIzXt6sOl/nso2lesRzxINFjOC10HQXvUQg5AMVCTAZGanyva8tP FNFEuW4mlQ2h6ZIPpkZyHe/lJFsV5mZUDkP65ZXUun8doto0e3tZYZeC7HrSN7H70ekH 0V5f/z71A/HpsVW5TtCLbxLK1SxA4DRXy3eJqNnKTec/yW809/ZMPE3dNajY2COtPXRu pLDA== 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=h1lpQHZ4BsKbR9GJw1l+EdHj25Ejdim5bn3DVwZG/lA=; b=mL4l6/4vVZGqSFJyN/2PD+wEx6fKHewjM6k+cIsYDFJ1qJLiixmZ51mbtTCbTUnE9+ oqdQEHtv6/ksm4BdklwyrNgQSPQ/x56egLMam4CO5apj+9LsddlU9hK4A32NaJNjdPRy cWZT0i8M+mHExCzmB0EFFhgdTWd8zj9CUN769bDj3FUmQ9Dll8hzox/bweQPMGxDcT+g 7qAhf6oj8i60dyYUJlg2Wvj3WS+dy3dg2XUITOKu1QQmcU2YbmP5gL4BKue6sZWU2ass BVN4cUkF5ScZMFo88tAE6pKMS2EkXnUfrlKqcFaduaiHyW2x9ssqddey5k0grHILS/kb zcEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=WDUnVbJV; 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 s16-v6si1306104pfi.369.2018.07.03.08.29.38; Tue, 03 Jul 2018 08:29:53 -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=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=WDUnVbJV; 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 S932724AbeGCP2G (ORCPT + 99 others); Tue, 3 Jul 2018 11:28:06 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35094 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752745AbeGCP2F (ORCPT ); Tue, 3 Jul 2018 11:28:05 -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=GQ5rpmU5DQJ3Wke4Z+vF7+q6DpMwRy53GSjNlqz+6Dc=; b=WDUnVbJVUxAGaLNUuf18lfFqy SzcUbiWOsZtVYzwScEhaU2oo4l7cuMjfTuC2L55/aKmgBBVsjYfLIui7SVSpDFqhw8DhB/mC1Y2NF H01Z8qiwToUi2G8ExGG9E8726kLP0WyHRIDZ8t75WNMIH908t316Vr4vZfkjkDLnrMMfIM7tj1Xr0 LRvaIoSzr40YbaXHhG8cDXJW/vAI6FLAp8nyNJkj4dOV6Te+l0XbZ4O4LtOYPPfvjtlfojTAUhTQ2 8cjQI5oA6OeS4gd0hn+gKgiclb9NplSvxXz5enbl0XJj73+sWD3d7iXhVSOJrW3lNygB6JTgggxC7 XF8+09S3g==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1faND9-0000vb-SG; Tue, 03 Jul 2018 15:27:23 +0000 Date: Tue, 3 Jul 2018 08:27:23 -0700 From: Matthew Wilcox To: Kirill Tkhai Cc: vdavydov.dev@gmail.com, 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, ying.huang@intel.com, mgorman@techsingularity.net, jbacik@fb.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-mm@kvack.org, lirongqing@baidu.com, aryabinin@virtuozzo.com, akpm@linux-foundation.org Subject: Re: [PATCH v8 03/17] mm: Assign id to every memcg-aware shrinker Message-ID: <20180703152723.GB21590@bombadil.infradead.org> References: <153063036670.1818.16010062622751502.stgit@localhost.localdomain> <153063054586.1818.6041047871606697364.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <153063054586.1818.6041047871606697364.stgit@localhost.localdomain> 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 Tue, Jul 03, 2018 at 06:09:05PM +0300, Kirill Tkhai wrote: > +++ b/mm/vmscan.c > @@ -169,6 +169,49 @@ unsigned long vm_total_pages; > static LIST_HEAD(shrinker_list); > static DECLARE_RWSEM(shrinker_rwsem); > > +#ifdef CONFIG_MEMCG_KMEM > +static DEFINE_IDR(shrinker_idr); > +static int shrinker_nr_max; So ... we've now got a list_head (shrinker_list) which contains all of the shrinkers, plus a shrinker_idr which contains the memcg-aware shrinkers? Why not replace the shrinker_list with the shrinker_idr? It's only used twice in vmscan.c: void register_shrinker_prepared(struct shrinker *shrinker) { down_write(&shrinker_rwsem); list_add_tail(&shrinker->list, &shrinker_list); up_write(&shrinker_rwsem); } list_for_each_entry(shrinker, &shrinker_list, list) { ... The first is simply idr_alloc() and the second is idr_for_each_entry(&shrinker_idr, shrinker, id) { I understand there's a difference between allocating the shrinker's ID and adding it to the list. You can do this by calling idr_alloc with NULL as the pointer, and then using idr_replace() when you want to add the shrinker to the list. idr_for_each_entry() skips over NULL entries. This will actually reduce the size of each shrinker and be more cache-efficient when calling the shrinkers. I think we can also get rid of the shrinker_rwsem eventually, but let's leave it for now.