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 E3DE8C433EF for ; Mon, 20 Jun 2022 06:13:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 038C18E0002; Mon, 20 Jun 2022 02:13:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2B858E0001; Mon, 20 Jun 2022 02:13:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF2008E0002; Mon, 20 Jun 2022 02:13:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CD8C28E0001 for ; Mon, 20 Jun 2022 02:13:51 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9FB8533A80 for ; Mon, 20 Jun 2022 06:13:51 +0000 (UTC) X-FDA: 79597598262.27.4E3BEFD Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf28.hostedemail.com (Postfix) with ESMTP id A9A10C0020 for ; Mon, 20 Jun 2022 06:13:49 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id a11-20020a17090acb8b00b001eca0041455so1567811pju.1 for ; Sun, 19 Jun 2022 23:13:49 -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=YkPqpfUX+L0hoB9Kerf1NXcOCvW4O6Wrp9vBOyavaFk=; b=Sppa+cznksmSnBN0Hb4tnd39OxbExYMGS14dgliIM6xPRw/js90Q5vuen3RaccDVM5 +QsuOAQ6T9HD8irEpLB3MO7T0xKMmuoJJ0WLppjaITPcl7icv0Bq2MVpw1ms1v3D/HMS jJt2W+zx39RpJMloaVl7FFXL++y0Pn4GxUjeX9dHHQuFeo000sEeq5s3rvlYAO0WagjC SjwvH+1PBzGF1nb56G64rpo33emu3MTDoVT7HEKIq2Iz6jFVnjESTWXXB6o6tMApC3Bw E8zzdoHnBmgYPoiJ3VaklC+iP71Uk1xULCza4MWM+Z+egAVv/pu9bQcMgLXW83rHwh+A nRtQ== 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=YkPqpfUX+L0hoB9Kerf1NXcOCvW4O6Wrp9vBOyavaFk=; b=eCbJ+OuiqexgoR/2bT9F6kwDNpbPyTb56EEbk84upTqX1iOZLbRofTJFuTmuqP2e8c B63Pd6DFcF0PWO4gB4sszsh6Qbh2vGqeQbDCnvlHCHV8zaGnsAJR7U9+X1O/57cPjY+y TrFnYXgRJGh7za6RwT47NiwcMn30turPmdfWTJTuE5DPRnhErhDEdBklVRaTKhUOBNGt VQc8m230e+55t+WEDoZmSCeE1SP7FQrRmaOllEuAQ8rAmTlcK7VBoa35j62meQBCPYkg FJOHtNykt2gyYs1Gvxa8HjAxbb/LkYN7jbd64FdUeisAZec7bfZeWpNadpPFmDa2RktS wo6w== X-Gm-Message-State: AJIora/Ktr34qF0ctilJ/UgInqXo9bj7JajRifRQ2ickt9ysgZfKJK9F XVlE+hTvEO6CS8+gk4V7E4SmFw== X-Google-Smtp-Source: AGRyM1vb+i5Qz13vCcA6u03mQcnnNFh6BLT1nElkzwn7cdTPYhep/s6hfBC6ak+0NcZXC8GxZkB7/g== X-Received: by 2002:a17:902:a58b:b0:168:b680:c769 with SMTP id az11-20020a170902a58b00b00168b680c769mr23332488plb.32.1655705628395; Sun, 19 Jun 2022 23:13:48 -0700 (PDT) Received: from localhost ([139.177.225.239]) by smtp.gmail.com with ESMTPSA id x19-20020a63b213000000b0040c9df2b060sm2363931pge.30.2022.06.19.23.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jun 2022 23:13:48 -0700 (PDT) Date: Mon, 20 Jun 2022 14:13:43 +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 07/11] mm: memcontrol: make all the callers of {folio,page}_memcg() safe Message-ID: References: <20220530074919.46352-1-songmuchun@bytedance.com> <20220530074919.46352-8-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=1655705630; a=rsa-sha256; cv=none; b=HnFTk5mR5DWWp5w+rBKfD7+QxFn6mGWESX0DsmA8RM7Jg1r9a3i4XFndiIKhA0sJM22Bn3 Mx2mORhgbOCUOvtkX3QoFl9V3gnBN5CAldsTY2GTrgp/x0K+q5k+7c2DEq4nBGq166050D hr35VwaD46S50QTeFXy4Kl9eZjfI4TQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Sppa+czn; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf28.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.53 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=1655705630; 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=YkPqpfUX+L0hoB9Kerf1NXcOCvW4O6Wrp9vBOyavaFk=; b=gSq7f75rAtMVKg+oSCas1/QZnbk59wf2WBasHrljHgcbxzXermEqLKndTnyi31afn9Er9H BpyKPUTezVdP4xvxMWn2xWCvyux6BzTbv3OaZn/LbetUT44KOPx/zjrTbjFF9yIIg+xg+X 5J0IZsngbQCg9s1mDim5CRQRpG65RQw= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A9A10C0020 X-Stat-Signature: j3ryfpb4rtw4axsjthsr3xiiyf6nzuo9 X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Sppa+czn; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf28.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1655705629-501156 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:37:32PM -0700, Roman Gushchin wrote: > On Mon, May 30, 2022 at 03:49:15PM +0800, Muchun Song wrote: > > When we use objcg APIs to charge the LRU pages, the page will not hold > > a reference to the memcg associated with the page. So the caller of the > > {folio,page}_memcg() should hold an rcu read lock or obtain a reference > > to the memcg associated with the page to protect memcg from being > > released. So introduce get_mem_cgroup_from_{page,folio}() to obtain a > > reference to the memory cgroup associated with the page. > > > > In this patch, make all the callers hold an rcu read lock or obtain a > > reference to the memcg to protect memcg from being released when the LRU > > pages reparented. > > > > We do not need to adjust the callers of {folio,page}_memcg() during > > the whole process of mem_cgroup_move_task(). Because the cgroup migration > > and memory cgroup offlining are serialized by @cgroup_mutex. In this > > routine, the LRU pages cannot be reparented to its parent memory cgroup. > > So {folio,page}_memcg() is stable and cannot be released. > > > > This is a preparation for reparenting the LRU pages. > > > > Signed-off-by: Muchun Song > > Acked-by: Roman Gushchin > Thanks for your review. > The locking seems to be correct. I'm slightly worried about a potential > perf degradation, especially on dying cgroups, where css_get() is relatively > expensive. I hope getting it into mm-unstable will help to determine > whether it's actually a problem. > I'll send a new version based on mm-unstable ASAP. Thanks. > Thanks! >