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 468D6C433F5 for ; Mon, 28 Mar 2022 19:13:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5DBF8D0002; Mon, 28 Mar 2022 15:13:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0E528D0001; Mon, 28 Mar 2022 15:13:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFE918D0002; Mon, 28 Mar 2022 15:13:05 -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 B276C8D0001 for ; Mon, 28 Mar 2022 15:13:05 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 82BDA228C3 for ; Mon, 28 Mar 2022 19:13:05 +0000 (UTC) X-FDA: 79294742730.12.D93010F Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf03.hostedemail.com (Postfix) with ESMTP id ED77D20034 for ; Mon, 28 Mar 2022 19:13:04 +0000 (UTC) Date: Mon, 28 Mar 2022 12:12:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1648494783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CSJN++S6R+1y8yPPjj83792q6MSLXlCqzDvFYFEsGEo=; b=iOJhwpD/QsCM5J5Q/uDpzEWgOTG5feFqbnxhAGLtKWfIruNdOhuzlQkNh/pem1gs031yI8 +vvLMbYInGjdd8RBYIrpO9893GbJaVC129NfdOqb0ZGGeroKVPFKD39u7i38g3Y9HA/ZIT EFxaSiXnxwddimLH/4mYTuKfyiINRxE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Muchun Song Cc: Waiman Long , Andrew Morton , Linux Memory Management List , LKML Subject: Re: [PATCH-mm v3] mm/list_lru: Optimize memcg_reparent_list_lru_node() Message-ID: References: <20220309144000.1470138-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="iOJhwpD/"; spf=pass (imf03.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: ED77D20034 X-Stat-Signature: 7y49q4t47stzyxf58xqf1711idhpe3dz X-HE-Tag: 1648494784-123354 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 Wed, Mar 23, 2022 at 09:06:03AM +0800, Muchun Song wrote: > On Wed, Mar 9, 2022 at 10:40 PM Waiman Long wrote: > > > > Since commit 2c80cd57c743 ("mm/list_lru.c: fix list_lru_count_node() > > to be race free"), we are tracking the total number of lru > > entries in a list_lru_node in its nr_items field. In the case of > > memcg_reparent_list_lru_node(), there is nothing to be done if nr_items > > is 0. We don't even need to take the nlru->lock as no new lru entry > > could be added by a racing list_lru_add() to the draining src_idx memcg > > at this point. > > Hi Waiman, > > Sorry for the late reply. Quick question: what if there is an inflight > list_lru_add()? How about the following race? > > CPU0: CPU1: > list_lru_add() > spin_lock(&nlru->lock) > l = list_lru_from_kmem(memcg) > memcg_reparent_objcgs(memcg) > memcg_reparent_list_lrus(memcg) > memcg_reparent_list_lru() > memcg_reparent_list_lru_node() > if (!READ_ONCE(nlru->nr_items)) > // Miss reparenting > return > // Assume 0->1 > l->nr_items++ > // Assume 0->1 > nlru->nr_items++ > > IIUC, we use nlru->lock to serialise this scenario. Thank you for bringing this up, really cool race!