Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp136011pxb; Tue, 17 Aug 2021 21:34:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaszTR3i2YuQVIHh/2WD4QlA9QuswvXQp5ffWUL9GA4EsRN1PD5EEmELN422uhrdx8+Dly X-Received: by 2002:a17:906:3699:: with SMTP id a25mr7668096ejc.452.1629261243647; Tue, 17 Aug 2021 21:34:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629261243; cv=none; d=google.com; s=arc-20160816; b=g8rwCVqwKRgC5uF4EJ00b96mbbN2FrmqfDEyPIpvlJ715irbSouKEUQM4NzdorskD8 MFyH8EmHaGR+9oO4Z6zWjRAWV2oZiEKH7W+NiIjB1cEb8z3XOJyberTF3rKYMkBIqKJB vIHqBT08/8b32vHziN+7iIXOEqIZdCLdaCh+8GdZ9VvH5u6cvOmuHk+O1ggez5vb1y2P A4BE2M6tRY2EDHE19kdkDa9Kig6Oa+T/LhDdardmiUk9r9OYjjL8FOeFw2RFWRq7C6M+ p3G2uIvCvqxuz2KII93swhYLIePpsUP1lGwVyi9KmIZP0qf/ymNBzonVENjKsUIJpOlF cz6g== 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=M4OMUrZpxJEGBppNP6I6AWvsCoN2WAaAil0LMMI5r7w=; b=S546MQnQ82sIOX5PGIfYa0wLWLRT2NEMbuTWax+A2GUDru0GSHI9wCeLJxSM/HT2uV ChptzPeI/PZh7FJdcVXeP4z0tYm78/J0QktJMw3srNqxghK/E6N6cwxcL0p6rUlORJVk peO9Tb9ieTyX3XVf1V+G3u1kVRM415RwofbD7YLIHeWRZcLr20wIx/64caLPMjuE/H/P WJ5HxhwrpV5L2G4UxPAD8GrKRcaCgYyO+wpIgyjm6gydMFzFFsRgB/0UVeXEjfyqD2sD 9aRrVX0cM4fMumMOlslfALvBenzXxeb2emmiYUb0l+oyC7v4SdMHKafya9sWQPARgpxB f57A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=YGtvo4t4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si4490620edt.448.2021.08.17.21.33.40; Tue, 17 Aug 2021 21:34:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=YGtvo4t4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231853AbhHRE3Q (ORCPT + 99 others); Wed, 18 Aug 2021 00:29:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbhHRE3P (ORCPT ); Wed, 18 Aug 2021 00:29:15 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 106B9C061764 for ; Tue, 17 Aug 2021 21:28:41 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id x4so930681pgh.1 for ; Tue, 17 Aug 2021 21:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=M4OMUrZpxJEGBppNP6I6AWvsCoN2WAaAil0LMMI5r7w=; b=YGtvo4t4xs4zqvtZ50FJJp/fthSkuSt28mL+68Mg+C6c/viofJiHvmRcp0QO3rdzof 1/4droGy6AFsOeCm6LjfKInmaKmO7NCUzWuuAjKbuKqhKBBLmf3f2xRinXEp7GnSqEZs TqNHxqK8YnzTBGYxzn9imexx5V9BncTlx1ettwwtFd4mu+ji3j4QCC/CNLNG5A4ppnsW nvRMCrbGZWdoqH+bweKmgW0+G6GZrX30zfNZY6wabsy2SrdUppH5p/L9mgg49/MY2nER 5awbSp50/gfxfQKlhJMvNa4RE9IPiQVYMdz5Vaqn4lY3usCmoKW8edO4QhMPT9I7kgYV hH6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=M4OMUrZpxJEGBppNP6I6AWvsCoN2WAaAil0LMMI5r7w=; b=JMkgJK5j3qeBingPSXuTum5tBmDmEbnpLgCQNDiZHX0JEY2WaJdqfGng+nMo+E1+C1 bxt+NR5Sl3O9Ps5NQDtzeoXYSs8CkXrKd6oIHORKHQATwtoCIXaGaeMnzBlAONiVMICA a3UFZ7aA4LK7jFMS4msr3Rk7nYobeOXU+U3wxRthjvNNNCzLbLTK+b0FaxOYh6yXmb9l zHr3TCean1XZdZ/wsFQ8dl8FTQqNxf4yKcuNDsbm4BeXm/BnMugv9PCWa5qd4jjOPdbZ G+npE9ODvjJcwMzGJuzMi5KNTTSWVXPh0L65lNqOgfNqV5NjvweR3nZ/1sTdOE0ZfV3V Y/Jg== X-Gm-Message-State: AOAM5334WbQHc3wOw+jVA3LvVrcpEGsiTxDmj2hbDccZf+bf9PqEj++X mMCcQihO59gQW3rHedrXHBjQlLjA1wL1RfJggjtbOg== X-Received: by 2002:a63:f804:: with SMTP id n4mr6884502pgh.341.1629260920403; Tue, 17 Aug 2021 21:28:40 -0700 (PDT) MIME-Version: 1.0 References: <20210814052519.86679-1-songmuchun@bytedance.com> <20210814052519.86679-4-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Wed, 18 Aug 2021 12:28:02 +0800 Message-ID: Subject: Re: [PATCH v1 03/12] mm: memcontrol: make lruvec lock safe when LRU pages are reparented To: Roman Gushchin Cc: Johannes Weiner , Michal Hocko , Andrew Morton , Shakeel Butt , Vladimir Davydov , LKML , Linux Memory Management List , Xiongchun duan , fam.zheng@bytedance.com, "Singh, Balbir" , Yang Shi , Alex Shi , Muchun Song , Qi Zheng Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 18, 2021 at 11:18 AM Roman Gushchin wrote: > > On Sat, Aug 14, 2021 at 01:25:10PM +0800, Muchun Song wrote: > > The diagram below shows how to make the folio lruvec lock safe when LRU > > pages are reparented. > > > > folio_lruvec_lock(folio) > > retry: > > lruvec = folio_lruvec(folio); > > > > // The folio is reparented at this time. > > spin_lock(&lruvec->lru_lock); > > > > if (unlikely(lruvec_memcg(lruvec) != folio_memcg(folio))) > > // Acquired the wrong lruvec lock and need to retry. > > // Because this folio is on the parent memcg lruvec list. > > goto retry; > > > > // If we reach here, it means that folio_memcg(folio) is stable. > > > > memcg_reparent_objcgs(memcg) > > // lruvec belongs to memcg and lruvec_parent belongs to parent memcg. > > spin_lock(&lruvec->lru_lock); > > spin_lock(&lruvec_parent->lru_lock); > > > > // Move all the pages from the lruvec list to the parent lruvec list. > > > > spin_unlock(&lruvec_parent->lru_lock); > > spin_unlock(&lruvec->lru_lock); > > > > After we acquire the lruvec lock, we need to check whether the folio is > > reparented. If so, we need to reacquire the new lruvec lock. On the > > routine of the LRU pages reparenting, we will also acquire the lruvec > > lock (will be implemented in the later patch). So folio_memcg() cannot > > be changed when we hold the lruvec lock. > > > > Since lruvec_memcg(lruvec) is always equal to folio_memcg(folio) after > > we hold the lruvec lock, lruvec_memcg_debug() check is pointless. So > > remove it. > > > > This is a preparation for reparenting the LRU pages. > > > > Signed-off-by: Muchun Song > > Acked-by: Roman Gushchin > > Maybe it's mostly s/page/folio, but the patch looks quite differently > in comparison to the version I did ack. In general, please, drop acks > when there are significant changes between versions. Got it. I'll drop all acks in the next version. Thanks. > > Thanks!