Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2622517iog; Mon, 20 Jun 2022 00:40:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sZ0E0wyDOod5Na+aLEqimKrqZY0SBmhe8SAEcOJ0yASNRVi/v3eZaeW3MDsSZ4/8Fp2ZXv X-Received: by 2002:a17:903:2308:b0:167:6bfe:a800 with SMTP id d8-20020a170903230800b001676bfea800mr22187676plh.100.1655710812525; Mon, 20 Jun 2022 00:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655710812; cv=none; d=google.com; s=arc-20160816; b=QUlblSFn3bVr8BqIUGwZ11YQy3vpjPgTS1aTcwb8p5+xfXQ0js+0K88MRsdGrRjqU0 YT8J0Q7l+JAtDvRV6IaSvDpmD4JW12esaTJsM46M4YmE2+u36eeki1D/a0bSw2GEJOqs iZE9C/trq9Zbb4mk8o9IBGCEOiw90mmq4KEVSOdaNT0qvl5jMOhxXR1EZ2suyCEXjDLa xes9AT/pnvWt8I8PEjFBrQIRa7cnhyArFeRrTvp1ArcXjIUBNZkjkoR4Dll+LeXZ8NSI 4rJKIvwzoD3ikVGMRvOCULdMC2OCH8Z1cjeQo3vwuioD6HXkYKSbNsLrpVITNj+RlFhR TFhg== 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:date:dkim-signature; bh=eje5eCQ8r99TF3Jk0Qo8Mipd7vUdFeKKOC/KwGU7LYo=; b=kinQEQNTV+F1bzxYFLBZYKNi3twUZ8rfsy0YWHCOW8T+uKku2iBCS3tF+Ed/ZIwG2F vpo77EY30jpSI2K5e4aWgaJ1foZ+9cfxXsUxmJyeBxM8dWt14gnL6PlTFXJN3qJ2QK53 UN+S6BotOitbsfSPTWf/f69YYo8ZR1BWjGiG94TrkXQKEKBzuJaxdjRwGkfkSDGqoMJQ JDRssfjwTugcgADer5yzI6+k3TkNiApyJbyttYm3knRhXaKQA3VKSShZsn6WB8sOTYEH OzO6ufz3/HdZhls1uqs8rDbsnoUvR99aWCOLa2k/tSNNwfi6FjsGSK6jD0OMImFAmXZP up8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5rjycCsW; 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 f12-20020a056a0022cc00b0050dd6ccf178si15350008pfj.381.2022.06.20.00.40.00; Mon, 20 Jun 2022 00:40:12 -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=5rjycCsW; 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 S239216AbiFTHOj (ORCPT + 99 others); Mon, 20 Jun 2022 03:14:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239199AbiFTHOd (ORCPT ); Mon, 20 Jun 2022 03:14:33 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29F18E036 for ; Mon, 20 Jun 2022 00:14:32 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id k7so8957587plg.7 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=vK5/xyz0jLqqgGRjbGpMY0z31WFNTBJP2//u3AtTVB/mqEyqfkjwTCh6hRNjuCtBRk Dcebz/kmiqy6cf1R/TvCj7BfytnxgltPvSD6RL295xFrU0t9d9bYH2LRoN0HF9tao/RV pTqp80QcUTJExg/h7Z2r3VmLoyNljvpheVZSERgFPRHYoMHkk1h0X5HqM5suvyZzZSER yJrfTDQmUva1LN+1CyA/Dm6vugz69CkvZxGnUumoSUxMT4dYuwx6g5p2mZbLUTSEdJgi kgjIo0Fg1n/nc0C7Kw5oAMcY1EM82TQfgiqKXXNa6eqqqtlbfrjm8nRqA5tDmAWRvaEI ViXQ== X-Gm-Message-State: AJIora8CfNwyH8+cf2/tKLrsYw7e9ga6PUJxacGACS/wAqlBLZKrgxDt 7RJKj0cYrrxwAcM99jdNLrJwHg== 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: 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_PASS, 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 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! >