Received: by 10.213.65.68 with SMTP id h4csp839509imn; Thu, 22 Mar 2018 09:40:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELsipg7B0pWyfG98U+3fribSI7Aw7FMl/yTvKRyzxaNpYwpfpBrHZLp0+rnz5xl2OHjHNPFP X-Received: by 2002:a17:902:3225:: with SMTP id y34-v6mr8949341plb.180.1521736831112; Thu, 22 Mar 2018 09:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521736831; cv=none; d=google.com; s=arc-20160816; b=Bj3dy8RFj0lbzbD2682IK0J+JZHwHW9v/n+JxVJb/tWqlr197PJOpEfYwh3yTgf9oZ 5GFakxox9ddHQOLogBvoNWTpPkRwAIOgZxZydrlUmgBxSHDYwDpIrJq6xx11sf0P3bSV Xmj503UXwx7fTrZE07+zKyGZCE2V4xh/fUzvSm39WM1YLtgvFCySTsv0P1LPAYsxhB9C V9kgRIeR6O7x14d4pdnK34FPyybl0ryYCLzAH8WuwxRCtANX21WJ3eWDj8ti97IHBw52 lZ0Rs9IuIEqRkZgImWSGxxJg/o0lYHLlkTZU8Q8pwvCZHUp3N25b7HUADIro/Q5xWhlM dtcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:arc-authentication-results; bh=5TYXSwcMgJbhgrkJ4SZd4y8nfZUXINLbeHUedSN6NxM=; b=WwuUp3Hd6Q0eP3LXPz+S6eN4L0/zdjaSXtiTuAMMPSR1jlol6xWCGeg5zfDp+aUT0H bkm/mlXLRZyStkWZi1A5SdGVFE20jcMw+5y9FFboYOtX1rHNztjPw80xJDbLxZTqozG2 DvTDCX3+2mERqSgCDI82maalCgyAtiftqJZWAVhptAO8BWQfBlKVEVc5k7iEUQZ7H4mp c0beDHEY4PQpX6TB2P8cIHBhDjbwJX5PyVC2F0CnvhaqXoQLthxYVfQKS0N14jxtwzxj Fm8pH3J/9jMRe3ecaIX6zpGqbCvnlACdvXNCfjNt7EyNrXUI5J2nqjJb0v1fhM4PnL8j t0qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=HDq2+a4/; 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=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi1-v6si4606144plb.744.2018.03.22.09.40.16; Thu, 22 Mar 2018 09:40:31 -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=@virtuozzo.com header.s=selector1 header.b=HDq2+a4/; 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=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751843AbeCVQjX (ORCPT + 99 others); Thu, 22 Mar 2018 12:39:23 -0400 Received: from mail-db5eur01on0111.outbound.protection.outlook.com ([104.47.2.111]:8000 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751625AbeCVQjS (ORCPT ); Thu, 22 Mar 2018 12:39:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5TYXSwcMgJbhgrkJ4SZd4y8nfZUXINLbeHUedSN6NxM=; b=HDq2+a4/zpQ9cbiWBYMCh/AY3bjaasqksNyCxaF7VVY4iXd9cuTN8XTMVEJKzz0sS+l0kLozT85BYVgU8ehWBIYf/IQuDjGBounkgnJ01sLCZMS/xEf62E7fmp7dq206IlGczubQ4ZwAPJMxojEruWFFfU+qZ0w+9CmFU4xAgRI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from [172.16.25.196] (195.214.232.6) by HE1PR0801MB1337.eurprd08.prod.outlook.com (2603:10a6:3:39::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.588.14; Thu, 22 Mar 2018 16:39:10 +0000 Subject: Re: [PATCH 03/10] mm: Assign memcg-aware shrinkers bitmap to memcg To: Matthew Wilcox 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 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> <20180321162039.GC4780@bombadil.infradead.org> <20180321175453.GG4780@bombadil.infradead.org> From: Kirill Tkhai Message-ID: Date: Thu, 22 Mar 2018 19:39:06 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180321175453.GG4780@bombadil.infradead.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR05CA0144.eurprd05.prod.outlook.com (2603:10a6:7:28::31) To HE1PR0801MB1337.eurprd08.prod.outlook.com (2603:10a6:3:39::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9dd0ffdf-e337-4c51-0871-08d590137087 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:HE1PR0801MB1337; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1337;3:CAdjHxkBUhPnJwVYDnTngWbptArnwQTH6HkNT5Xa+vLExKh+oKVK/p++T6L3+rOY9GE5H6JF9E1VRYFEnQ2FtwRbmIywzbEUVtQZI0ZI5hObsYvGhF8iM90ttWP7aJUaCfFuwf+CBHbQ5zyuPoWQn2voQXcub+GjajtO1JAlXQ7E24tli4vF+r2biM8wKwnfdB7krw/SHFeAdlxF+wmdHIMHJBkF127719zUJNLcFz6zLagslNTqk2MEAbEIJ3gR;25:0PSvBG0V+keRTvs3j3kuNg98nqBes3P3TvrLu9H3djaW2hluruU/7107+m1YubIBB63WMbyCUw3iDg5ggxz0wG5/DDa4JoBByhV+14+NB7BOkFhR1oxiOj1kJ/bsmqwGduDIeiryRjORBtK7InPLNeBq8GiGhDCcV2KFKmNymwUecEOuyKQGj2Ts0n3Vi+9QJZBSuG5jb1e0WrDT5iCpoiSnfU1EIi/2DHZApE4IcdHN4eSTAgpqOZwVIIPZ/5dNvggUk/+hIU8bebXQAaB+HgRaPf7wBXL+LsOmSQSV6KfRccqFgXttoVzdl94nM64txjbpFakpr2sEdFZxHJuYqg==;31:mfGWBVPBK2ePMEew80jrC56Ih8w5eqAL9qCbSO4bvuDaS0NlbgIYF9RKC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Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(3231221)(944501327)(52105095)(10201501046)(6041310)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011);SRVR:HE1PR0801MB1337;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0801MB1337; X-Forefront-PRVS: 0619D53754 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6049001)(39850400004)(376002)(39380400002)(346002)(396003)(366004)(189003)(199004)(65806001)(58126008)(105586002)(6916009)(65826007)(31686004)(81166006)(6246003)(64126003)(16576012)(77096007)(26005)(31696002)(5660300001)(316002)(36756003)(52116002)(6486002)(50466002)(106356001)(8676002)(68736007)(81156014)(2486003)(59450400001)(55236004)(6666003)(97736004)(76176011)(23676004)(7416002)(229853002)(8936002)(53936002)(7736002)(53546011)(4326008)(25786009)(386003)(93886005)(2906002)(39060400002)(305945005)(86362001)(230700001)(478600001)(52146003)(66066001)(65956001)(3846002)(6116002)(47776003)(186003)(16526019)(446003)(11346002);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0801MB1337;H:[172.16.25.196];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtIRTFQUjA4MDFNQjEzMzc7MjM6dlk2OTJ2c3A2RldWcGU2N1NwVVJQQ2ZZ?= =?utf-8?B?MzNPWVo5cmRjTkVReGRBbUk3bjUrRWlMZURZZFgxbHhPbElzY2JheG9PSlhT?= =?utf-8?B?Z3B1clNZakhDQmVaMnVsWVNST281UTQ4Q3djTUVFaTA5WDJ6eGF3ZGYwUUZG?= =?utf-8?B?QVF5QzFDbk15STBNbEVMVTFMTWFRbGFCTEVQQ0hrdk1vbGd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HRIMRmYMBw/N0+UeICzeoiXNO7LEtviZcuEjbhtcdz195Asl2B1hjgFggZGhG97a1PTwMD4aZQ7cnLchreEsDhqJmWluil SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1337;20:B/EQ9zkXu2I1JWmvDQzfQ2Qf5FAjKzHfNo3xcWOhLML7hmFS1uwRFa+jhEJzzyhFutM/7/BJkvSkgRC31fuvQhW+ZCpeezPw0hQuFl6Fufs0iOdqj5/5AtWEiw0+kxDuhibF2ObjQE6vwl9tOGq/RZkqNO6JwoSkymwW7gKFZbg= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2018 16:39:10.0562 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9dd0ffdf-e337-4c51-0871-08d590137087 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1337 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21.03.2018 20:54, Matthew Wilcox wrote: > On Wed, Mar 21, 2018 at 07:42:38PM +0300, Kirill Tkhai wrote: >> On 21.03.2018 19:20, Matthew Wilcox wrote: >>>> 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. >> >> Oh. I'm not sure about this. Even if each allocation is small, there is >> theoretically possible a situation, when many lists will want to add first >> element. list_lru_add() is called from iput() for example. > > I see. Maybe we could solve this with an IDA_NO_SHRINK flag and an > ida_resize(ida, max); call. But what will be the difference to bitmap, if we allocate maximal map anyway? > You'll also want something like this: > > > diff --git a/include/linux/idr.h b/include/linux/idr.h > index 0f650b90ced0..ee7185354fb2 100644 > --- a/include/linux/idr.h > +++ b/include/linux/idr.h > @@ -273,6 +273,22 @@ static inline void ida_init(struct ida *ida) > ida_alloc_range(ida, start, (end) - 1, gfp) > #define ida_simple_remove(ida, id) ida_free(ida, id) > > +int ida_find(struct ida *, unsigned int id); > + > +/** > + * ida_for_each() - Iterate over all allocated IDs. > + * @ida: IDA handle. > + * @id: Loop cursor. > + * > + * For each iteration of this loop, @id will be set to an allocated ID. > + * No locks are held across the body of the loop, so you can call ida_free() > + * if you want or adjust @id to skip IDs or re-process earlier IDs. > + * > + * On successful loop exit, @id will be less than 0. > + */ > +#define ida_for_each(ida, i) \ > + for (i = ida_find(ida, 0); i >= 0; i = ida_find(ida, i + 1)) > + > /** > * ida_get_new - allocate new ID > * @ida: idr handle > diff --git a/lib/idr.c b/lib/idr.c > index fab3763e8c2a..ba9fae7eb2f5 100644 > --- a/lib/idr.c > +++ b/lib/idr.c > @@ -612,3 +612,54 @@ void ida_free(struct ida *ida, unsigned int id) > spin_unlock_irqrestore(&simple_ida_lock, flags); > } > EXPORT_SYMBOL(ida_free); > + > +/** > + * ida_find() - Find an allocated ID. > + * @ida: IDA handle. > + * @id: Minimum ID to return. > + * > + * Context: Any context. > + * Return: An ID which is at least as large as @id or %-ENOSPC if @id is > + * higher than any allocated ID. > + */ > +int ida_find(struct ida *ida, unsigned int id) > +{ > + unsigned long flags; > + unsigned long index = id / IDA_BITMAP_BITS; > + unsigned bit = id % IDA_BITMAP_BITS; > + struct ida_bitmap *bitmap; > + struct radix_tree_iter iter; > + void __rcu **slot; > + int ret = -ENOSPC; > + > + spin_lock_irqsave(&simple_ida_lock, flags); > +advance: > + slot = radix_tree_iter_find(&ida->ida_rt, &iter, index); > + if (!slot) > + goto unlock; > + bitmap = rcu_dereference_raw(*slot); > + if (radix_tree_exception(bitmap)) { > + if (bit < (BITS_PER_LONG - RADIX_TREE_EXCEPTIONAL_SHIFT)) { > + unsigned long bits = (unsigned long)bitmap; > + > + bits >>= bit + RADIX_TREE_EXCEPTIONAL_SHIFT; > + if (bits) { > + bit += __ffs(bits); > + goto found; > + } > + } > + } else { > + bit = find_next_bit(bitmap->bitmap, IDA_BITMAP_BITS, bit); > + if (bit < IDA_BITMAP_BITS) > + goto found; > + } > + bit = 0; > + index++; > + goto advance; > +found: > + ret = iter.index * IDA_BITMAP_BITS + bit; > +unlock: > + spin_unlock_irqrestore(&simple_ida_lock, flags); > + return ret; > +} > +EXPORT_SYMBOL(ida_find); > diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c > index 6c645eb77d42..a9b5a33a4ef3 100644 > --- a/tools/testing/radix-tree/idr-test.c > +++ b/tools/testing/radix-tree/idr-test.c > @@ -358,8 +358,12 @@ void ida_check_conv(void) > assert(ida_pre_get(&ida, GFP_KERNEL)); > assert(!ida_get_new_above(&ida, i + 1, &id)); > assert(id == i + 1); > + ida_for_each(&ida, id) > + BUG_ON(id != (i + 1)); > assert(!ida_get_new_above(&ida, i + BITS_PER_LONG, &id)); > assert(id == i + BITS_PER_LONG); > + ida_for_each(&ida, id) > + BUG_ON((id != (i + 1)) && (id != (i + BITS_PER_LONG))); > ida_remove(&ida, i + 1); > ida_remove(&ida, i + BITS_PER_LONG); > assert(ida_is_empty(&ida)); > @@ -484,7 +488,7 @@ void ida_simple_get_remove_test(void) > void ida_checks(void) > { > DEFINE_IDA(ida); > - int id; > + int id, id2; > unsigned long i; > > radix_tree_cpu_dead(1); > @@ -496,8 +500,22 @@ void ida_checks(void) > assert(id == i); > } > > + id2 = 0; > + ida_for_each(&ida, id) { > + BUG_ON(id != id2++); > + } > + BUG_ON(id >= 0); > + BUG_ON(id2 != 10000); > + > ida_remove(&ida, 20); > ida_remove(&ida, 21); > + id2 = 0; > + ida_for_each(&ida, id) { > + if (id != id2++) { > + BUG_ON(id != 22 || id2 != 21); > + id2 = 23; > + } > + } > for (i = 0; i < 3; i++) { > assert(ida_pre_get(&ida, GFP_KERNEL)); > assert(!ida_get_new(&ida, &id)); >