Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3566096pxp; Wed, 23 Mar 2022 00:54:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytDzymx/U76SacFfktm4NVRfivvxYLmq1rfWaIHoZHHRw+nB3qWa4Zm0rVG80K+PzZxf0R X-Received: by 2002:a17:902:6b47:b0:150:1f58:44c3 with SMTP id g7-20020a1709026b4700b001501f5844c3mr22874418plt.127.1648022069069; Wed, 23 Mar 2022 00:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648022069; cv=none; d=google.com; s=arc-20160816; b=rPEKJ7P9M1fdmdtm1lOXpMWX7XJ8eVTa0KGCa4DNDSrMu2SHX2AOV1H6WJwB1SdDrQ 4NSdnr2nlAUYKDG1fSTxQZ2gH3HKi5jXmefOMHLs6Ytfma2BTPoNHSMfDkT2He74TNzh vaX1qSoQFgZ6s1FuzD/wTRe8IlJ91JUyyMJutGwkAcbBZTX6TlHyhDKr1spCfAqxCRm+ SUdS9jY6++zq2Elu91D8td4mufuEqwyLiL6FyQL/5dAYwgVvPCEFG3X2zAiXeKF0yWjK zW5ZnN7U9O24waQe1fsMjLT52Dtxo2SQIPaH/aKVEXVmYc0rD1qKqtJfLNeQa0nFWqje 38Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TmS9XqFWOa3npmqi6akNlXoA1MxlQ02g/X1bQSimlGc=; b=CQZangJt2UVQ+bVVYqNfandLFfGBlWwU2Ocrux+8icHkpQnqrqySYzpK9HWrH95KMD fAbpQftv5GQu1BMkf5AFIWHVOvuslQ/JkSM4eXJGN13bxeTRxVB4XGr8FVbsnfXrnCKp G6NgctPMFlgSyo00n+Cz7xQT+J6bGgYHeLSGGTtQgIFjIfjM88xbykMT4y/vaAJgAgwW D+NJnlPzi7jKC7tKgM6LSA2dNVt85jsr/wFjFmqXsjuEFBpw1FQ1FLLhAaISRAjCvhWC ZBzx5o7g8+iBA07n/tqWX+PpHbQmTsOyZvc6ejr82BGCN8J9Sl471DvMn/8eYRdVDb6t OFHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=eTkTfF7g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t21-20020a62ea15000000b004fa3a8e000esi11867951pfh.197.2022.03.23.00.54.15; Wed, 23 Mar 2022 00:54:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=eTkTfF7g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231288AbiCWBJb (ORCPT + 99 others); Tue, 22 Mar 2022 21:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbiCWBJ3 (ORCPT ); Tue, 22 Mar 2022 21:09:29 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB28613F7C for ; Tue, 22 Mar 2022 18:08:00 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id v35so36740101ybi.10 for ; Tue, 22 Mar 2022 18:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TmS9XqFWOa3npmqi6akNlXoA1MxlQ02g/X1bQSimlGc=; b=eTkTfF7gsKMtnFv0vmxEwLrqozg5VjCqWuUXhurTUUzeR+U70FDajhoT65QVvBq2jk +gYcsgOMJ/1DuyZzyUEYPWah83ud2Xu5pv0Lqv7OZo96rCssZtIIVpY7jJcZRE/Jw5OP aaf/roqvZz0TbF5bcE36CTJLbsk+mCqRtidrsLWZowjhS0VvlnIPbnHN46FkiZET02Iu CORiW9OhJPibBlqvEDZYArUrFavapZu5TFLXG3NsIs7vY8IsBJIwPjeVyCYY/ZuFOStW uGnh+eTIOxFP/28ODOJyNjRsJizlUEp4hAXov/29um/mF2h13qzNWzb7QT/lZBftyhfB SzMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TmS9XqFWOa3npmqi6akNlXoA1MxlQ02g/X1bQSimlGc=; b=Z3CW1D9seuYe6wKZ24j1fLzdLGLYLo5S5Tedsa0Rxl66f/IvVfXEoIh1m37600a3sy +nitEghVuV3im2O7IwCSYN4f5gwbZmqnRTD/4nycsrr3d7GfhJp0vlTVx7/+RQ8vq0Gm IVmDwtv6jBkNH0KUlyMk1iU9+yLB8FBbBDkqgcGL9KfapQOCE9OpC8s855et+0DFCjVp H9f/n4jllC3pya5qmdRsUMjCf+3s2AFb1F/UDi0Z/16sP92CKyrIcbYQLwbRIwXfLOQP qM5g9z9MJmWIg0mYhXd8Kl7ADehmfEYd50vh585S8Yro2I3pZuASwQ6qD+GW0pm3bv86 vLuA== X-Gm-Message-State: AOAM531JNuPdZZOX5xF9H4KIog+QMXuNQJcZPE/NqztD4mOLktkAXGSX qFoHiZ/DvMRqAcNuAzpFoeVtyTzCoFQ1HE1gkSVP7g== X-Received: by 2002:a25:24d:0:b0:633:6b37:bea1 with SMTP id 74-20020a25024d000000b006336b37bea1mr29032850ybc.427.1647997680003; Tue, 22 Mar 2022 18:08:00 -0700 (PDT) MIME-Version: 1.0 References: <20220309144000.1470138-1-longman@redhat.com> In-Reply-To: <20220309144000.1470138-1-longman@redhat.com> From: Muchun Song Date: Wed, 23 Mar 2022 09:06:03 +0800 Message-ID: Subject: Re: [PATCH-mm v3] mm/list_lru: Optimize memcg_reparent_list_lru_node() To: Waiman Long Cc: Andrew Morton , Linux Memory Management List , LKML , Roman Gushchin Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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 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. Thanks.