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 7AE2DC43334 for ; Mon, 20 Jun 2022 07:14:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0760A6B0071; Mon, 20 Jun 2022 03:14:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 025436B0073; Mon, 20 Jun 2022 03:14:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2E728E0001; Mon, 20 Jun 2022 03:14:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D0BF26B0071 for ; Mon, 20 Jun 2022 03:14:33 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9CDC8347D0 for ; Mon, 20 Jun 2022 07:14:33 +0000 (UTC) X-FDA: 79597751226.10.952308F Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf31.hostedemail.com (Postfix) with ESMTP id B4A8920015 for ; Mon, 20 Jun 2022 07:14:32 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id y6so8977344plg.0 for ; Mon, 20 Jun 2022 00:14:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=eje5eCQ8r99TF3Jk0Qo8Mipd7vUdFeKKOC/KwGU7LYo=; b=5rjycCsWpc48JYQSoB4UcNVOmG+xAyesyo1mdm5rRUN994NyEiZ9k1gWuZ8JtZpRMP +t2ea1U2dv3RAM5uPoEEheqmZOFdxYojQE4qK1jJiWODWj7qtMc9qreieOw7jgRi3Gru CPQKm469WxG0mK9uHF8ugLNBD9vNZqHP0iscnj9b6MT52CKIda2e4NasxL+5tUKOxTOh NyfiZR36HKx1Bor2GxITw1ZyRLZ4XW+Qdtc42fjrzuFgzmH9UkQ5/fN/NQv2MgLO8+mA ssZzqrrmOpBYjTaya8uuD4A6lIQrGOXoCTbtrCcSo3ZV+2R4u94IGcyvAyggnunAWW9a Pc/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eje5eCQ8r99TF3Jk0Qo8Mipd7vUdFeKKOC/KwGU7LYo=; b=fNleGeCI9ePqT/LsUw+FlTY3fMKkTRgKzENhhN4o5JO9wnZajDV7+HgowpZ8YbSfz7 N5cJqN9YY+NaGoL+0C+FGuz/ir2YwN83o3ArlTMK1GuU/QbH4+oGakhTN0DJOH3XzbsN fWqq9bqypkLis2V2N6vLPlaYpmMvFOVzH33lUHvlv83JxiTyzEsqCbGulXqXtPTBo5Nd aTd0viQKJUbhajBr+HcIoqihWj2BpWkmkv/lw5ab5ESkDwlcJRiy8+DO7SetiIYile0B uYFRCHF6LuOcP6kLTVmA1njzKBkJExWcjzIteSXhD87559xwF2GdgnHRfwC21gYNtnwb sd8A== X-Gm-Message-State: AJIora85c3P9E1yMTN74Qm37TU4Feo1OOZlk/7k504DXocGkgefZUUiq RrXcUQm17j1J+X+mDCFo3cBN5w== X-Google-Smtp-Source: AGRyM1tSD/PcZEEst4MVznqWWeY3KmDeC0shEVp/6sGC9nq7iORMis0MpgAxZTqLlpVES7+Lm1YvQw== X-Received: by 2002:a17:90b:38c8:b0:1e8:5202:f6d4 with SMTP id nn8-20020a17090b38c800b001e85202f6d4mr25245023pjb.149.1655709271470; Mon, 20 Jun 2022 00:14:31 -0700 (PDT) Received: from localhost ([139.177.225.239]) by smtp.gmail.com with ESMTPSA id j3-20020a170903024300b001624965d83bsm7892935plh.228.2022.06.20.00.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 00:14:31 -0700 (PDT) Date: Mon, 20 Jun 2022 15:14:27 +0800 From: Muchun Song To: Roman Gushchin Cc: hannes@cmpxchg.org, mhocko@kernel.org, shakeelb@google.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, longman@redhat.com Subject: Re: [PATCH v5 08/11] mm: memcontrol: introduce memcg_reparent_ops Message-ID: References: <20220530074919.46352-1-songmuchun@bytedance.com> <20220530074919.46352-9-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655709273; a=rsa-sha256; cv=none; b=ep1gZc+fdjcA9z9HbH4SK6jKdhiti3uZUBsTm8rgb1ImGDCzZ6In5cCpvcXpvG8NAaAQYr 3mIcf7tTwp6p7x0GPmF5z0aNbzHKUT2u6MKRO0VpLv2rpZpfy/kMCjwdHqct/Tf1yOlxDF n0I7Qq412Rcnn0oiLZjoB3x0dYRURQ0= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5rjycCsW; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf31.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655709273; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eje5eCQ8r99TF3Jk0Qo8Mipd7vUdFeKKOC/KwGU7LYo=; b=RL1WVM9ZNetXI2/iBXFgbXPXkbDjHxZv383HnGzAcf5fB+RU49oaUqBpUD374IsWtODAJ8 TffLVf6xQU1cVpzb8ZDkmcazxJ1iZHyErbYYzqTjL7rxB0kHYcdwmP7JEnKVFmKFevJhQx WZoTxErSqJORww7H9EO9kjRmeCqP2YE= X-Rspamd-Queue-Id: B4A8920015 X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5rjycCsW; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf31.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspamd-Server: rspam06 X-Stat-Signature: fiobu7f8ygzesdj81xn9wt3y3j5cnrff X-HE-Tag: 1655709272-934290 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 Sun, Jun 19, 2022 at 12:47:39PM -0700, Roman Gushchin wrote: > On Mon, May 30, 2022 at 03:49:16PM +0800, Muchun Song wrote: > > In the previous patch, we know how to make the lruvec lock safe when LRU > > pages are reparented. We should do something like following. > > > > memcg_reparent_objcgs(memcg) > > 1) lock > > // lruvec belongs to memcg and lruvec_parent belongs to parent memcg. > > spin_lock(&lruvec->lru_lock); > > spin_lock(&lruvec_parent->lru_lock); > > > > 2) relocate from current memcg to its parent > > // Move all the pages from the lruvec list to the parent lruvec list. > > > > 3) unlock > > spin_unlock(&lruvec_parent->lru_lock); > > spin_unlock(&lruvec->lru_lock); > > > > Apart from the page lruvec lock, the deferred split queue lock (THP only) > > also needs to do something similar. So we extract the necessary three steps > > in the memcg_reparent_objcgs(). > > > > memcg_reparent_objcgs(memcg) > > 1) lock > > memcg_reparent_ops->lock(memcg, parent); > > > > 2) relocate > > memcg_reparent_ops->relocate(memcg, reparent); > > > > 3) unlock > > memcg_reparent_ops->unlock(memcg, reparent); > > > > Now there are two different locks (e.g. lruvec lock and deferred split > > queue lock) need to use this infrastructure. In the next patch, we will > > use those APIs to make those locks safe when the LRU pages reparented. > > > > Signed-off-by: Muchun Song > > I've mixed feelings about this: it looks nice, but maybe too nice. I wonder > if it's better to open-code it. Not very confident, I wonder what others are > thinking. > I also thought about this. Open-code is not simplified than this since memcg_reparent_ops can be used for 3 locks which simplifies code a lot. I also want to hear others' thoughts on this. > 1) Because the lock callback is first called for all ops, then relocate, then > unlock, implicit lock dependencies are created. Now it depends on the order > of elements in the memcg_reparent_ops array, which isn't very obvious. Maybe we can add some comments explaining the lock dependency depends on the element order in array. > 2) Unlikely there will be a lot of new ops added in the future. > Yep. I think so. Thanks. > The code looks correct though. > > Thanks! >