From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31575C433F5 for ; Thu, 31 Mar 2022 15:18:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77EA26B0072; Thu, 31 Mar 2022 11:18:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 705166B0073; Thu, 31 Mar 2022 11:18:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A63C6B0074; Thu, 31 Mar 2022 11:18:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 4A0D96B0072 for ; Thu, 31 Mar 2022 11:18:32 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0FB3F21DA5 for ; Thu, 31 Mar 2022 15:18:31 +0000 (UTC) X-FDA: 79305038022.09.D0984C5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 636C620019 for ; Thu, 31 Mar 2022 15:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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; bh=I1ivG9NRVVOIvA3ZPKM+gIMrRc3A4IUWwLKDETjpzMc=; b=nmphzON5aRX1gVVs+kcWI+9gnm FxFJVvwZF+8lpX53dCZiA59vjQ/4MhaTldkSSN+oz2JfvAGRoPR0urkBcSQ/OKGcuOk5aNGoRclp2 rp4OKUjZEEiESuwJq/ehxBoXmD45sbaVaaDkmit/NFXHr/qRz+t0eoeUFGHiX735Ocq3Wz2nf2eEi T/o73agCDMnNsjFCeyYv6Ba9dLnIIwe9LopsnNHiY/EzL73yI9PnIPN9xzWWi4TKetKV+5pWsm+3Q n4z9iJqNQ4YcHFhwDYTGngZIHpkF+qPBoWTJ9iQSHuBGzN+WKkfk85jnTbZX4mSrcvT64LHJ/GTfQ rdv4BqLg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nZwIz-002LNx-Nu; Thu, 31 Mar 2022 15:01:45 +0000 Date: Thu, 31 Mar 2022 16:01:45 +0100 From: Matthew Wilcox To: Muchun Song Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, shakeelb@google.com, roman.gushchin@linux.dev, shy828301@gmail.com, alexs@kernel.org, richard.weiyang@gmail.com, david@fromorbit.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, jaegeuk@kernel.org, chao@kernel.org, kari.argillander@gmail.com, vbabka@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, zhengqi.arch@bytedance.com, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, smuchun@gmail.com Subject: Re: [PATCH v6 12/16] mm: list_lru: replace linear array with xarray Message-ID: References: <20220228122126.37293-1-songmuchun@bytedance.com> <20220228122126.37293-13-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220228122126.37293-13-songmuchun@bytedance.com> X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=nmphzON5; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 636C620019 X-Stat-Signature: 35mz1yzfii1bj8azakett1xnia7fzyqq X-HE-Tag: 1648739906-557192 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Feb 28, 2022 at 08:21:22PM +0800, Muchun Song wrote: > @@ -586,27 +508,48 @@ int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru, > } > } > > + xas_lock_irqsave(&xas, flags); > while (i--) { > + int index = READ_ONCE(table[i].memcg->kmemcg_id); > struct list_lru_per_memcg *mlru = table[i].mlru; > > + xas_set(&xas, index); > +retry: > + if (unlikely(index < 0 || xas_error(&xas) || xas_load(&xas))) { > kfree(mlru); > + } else { > + xas_store(&xas, mlru); > + if (xas_error(&xas) == -ENOMEM) { > + xas_unlock_irqrestore(&xas, flags); > + if (xas_nomem(&xas, gfp)) > + xas_set_err(&xas, 0); > + xas_lock_irqsave(&xas, flags); > + /* > + * The xas lock has been released, this memcg > + * can be reparented before us. So reload > + * memcg id. More details see the comments > + * in memcg_reparent_list_lrus(). > + */ > + index = READ_ONCE(table[i].memcg->kmemcg_id); > + if (index < 0) > + xas_set_err(&xas, 0); > + else if (!xas_error(&xas) && index != xas.xa_index) > + xas_set(&xas, index); > + goto retry; > + } > + } > } > + /* xas_nomem() is used to free memory instead of memory allocation. */ > + if (xas.xa_alloc) > + xas_nomem(&xas, gfp); > + xas_unlock_irqrestore(&xas, flags); > kfree(table); > > + return xas_error(&xas); > } This is really unidiomatic. And so much more complicated than it needs to be. while (i--) { do { int index = READ_ONCE(table[i].memcg->kmemcg_id); struct list_lru_per_memcg *mlru = table[i].mlru; xas_set(&xas, index); xas_lock_irqsave(&xas, flags); if (index < 0 || xas_load(&xas)) xas_set_err(&xas, -EBUSY); xas_store(&xas, mlru); if (!xas_error(&xas)) break; xas_unlock_irqrestore(&xas, flags); } while (xas_nomem(&xas, gfp)); if (xas_error(&xas)) kfree(mlru); } kfree(table); return xas_error(&xas); (you might want to mask out the EBUSY error here)