Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5658932pxb; Mon, 28 Mar 2022 15:37:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWSinqWwsErg0cxqLzMexRQZu6e/ydLhTAa4GjUYQkJ0uI3e5EOi6bj1LoRu72LujB47El X-Received: by 2002:a05:6130:85:b0:351:3b2:7f34 with SMTP id x5-20020a056130008500b0035103b27f34mr14309623uaf.66.1648507054563; Mon, 28 Mar 2022 15:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648507054; cv=none; d=google.com; s=arc-20160816; b=Om0MfLxl0U1JTjpoxwxidCpdMy/XDcRuZKjdmzIjGwSlDC6sKQqtm8pMNyY7jKOTXD zyU1Esk1c+LqsqW+slQtw607UlDWPR574Vq93Qgeeje8rRKsAevAXjoboyLbJXn1fuP9 CHw0bmVrJkE4Me1UKO2rojr0fsh1Rm+d83PJApymjlKcebm6hhTPgtS48Q5zcvFBc6QC Foz+04tpQLayQe+lbMmIt7E4Mmkn7dGryydTyFIAXjfnUQyl5vOZbthIeBf8Sgeh+SZe QAYnP9grbURq8hjQNR1QsZIva/YuLuZyiAA+CCiNRkYB9IB3izt9hzd1J3m5E6EbnFXJ 8Caw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=CSJN++S6R+1y8yPPjj83792q6MSLXlCqzDvFYFEsGEo=; b=nGvreYXl8f+Z5SYzQs99OJ1bTJiwi1ebJs7bOe6SHLLEft2Dxl3fvormxbpjApYiOy TDtGQprTw2J6j5cf919KagjRNlrLRXv9WA8wShVkHRugPOCpgljBGXQR9vXBqNsaEdcX ueOueEQysJeLLJzfnfH+rhgWaS3tt9kp5ZjXpfb63khM1XBpLk1PvoaV27v7QtpwFLyT Y6OibxhD055XMdeOXGsf2lRQtJAW/PDtdbRat9AFA3cPBZ9+8SbtsIUsnyzkCpnpiQZO vNi/xN2q19rqQ1dqSNvtlFm0V/7SBbICjNd3lftjHW9lsWdFPubcy6NTsutDweOOQ4a0 YOSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="iOJhwpD/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u22-20020ac5cdd6000000b0033e831701dcsi3040062vkn.70.2022.03.28.15.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 15:37:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="iOJhwpD/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE7FA1E1128; Mon, 28 Mar 2022 14:45:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245521AbiC1TOr (ORCPT + 99 others); Mon, 28 Mar 2022 15:14:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245522AbiC1TOq (ORCPT ); Mon, 28 Mar 2022 15:14:46 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3360766CB3 for ; Mon, 28 Mar 2022 12:13:05 -0700 (PDT) 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 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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!