From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E5DD1F5834 for ; Fri, 19 Dec 2025 03:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766116564; cv=none; b=MolPraU/KYPX93+BMPEZwMRKEdtwWtrMYSipYZQ17gPQGx4TQ8m7F1PE2j5+2HimqTqIHAe1dX9cXRfdfcV6RHOfquwCI8WWgdK7K1uUbvOmQusRbcWh9SW/ley577hH8tcZSusFyNasTx9Yx0p7+yNRS7gDt6QWjniYQuCkRU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766116564; c=relaxed/simple; bh=tBzt9IV1Wl5MTxV6lep8PjuwLbb78DUv5cJLiCeM/Ms=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VPcUIHTEUwlglTxeaCTtCbpERfF6+bPOcsZcc85pCyLgsV5X2ECuVIFEjBkCgrm+uRQLi/w5EPjY6gxFFRICffQl8rwDJ0vX5lXH6tLtflu9YxI7OG+PTKonIhD2jDWLxsNiMKZiuU6FHgneyCFT0AZIV6XoAtoXOE9zfG6ELk4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=AALuAP+a; arc=none smtp.client-ip=209.85.160.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="AALuAP+a" Received: by mail-qt1-f194.google.com with SMTP id d75a77b69052e-4ed82e82f0fso13581011cf.1 for ; Thu, 18 Dec 2025 19:56:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1766116561; x=1766721361; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VTtfle4/MykGQYtmzDysxCuwpMvHg0hiZkC5ebsS7CQ=; b=AALuAP+aCIiqIz82ecPToGGsjbLaDEaB/p2iIitLaHh6Ob2MjS2p9XQwRBgGrCn9Ey KffYiKvd07IYxn1a8JFz0DFJhWdFs1r/Rg/rk029VBxCVtpXyTkXERJ7Ig7rG/HtKD5D s4LrlCiZ9IWieuuqleumqm7nqhW3qeqEUMKwa+NcgqRtHkQelSLICXbEh+mWpUGZ7Ols bvFiTPL4oOkqn1feNhZu+HLZ7X1ui0RRxrnTWhgQyDhQSP3oJ/nc7wBJxqP0oQ8rYL9O 2mlt/nzGE1gt908IfuMQU0CokGIwiYeIqNvvJSMvR0nbXAuYU5L8EQoscCbx2be4kcDh 4VJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766116561; x=1766721361; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VTtfle4/MykGQYtmzDysxCuwpMvHg0hiZkC5ebsS7CQ=; b=oaww3jzy0af9glZGUGA3tk2jEA6EZW9AwZnyiK+3sLvGqqwpCCp0WqC5mREKtVtXvH KAofM9E/YcpVrxRp3LVc6v8DuTw4oX7npPUXG26lEETo4CmXaH5LAGWsOen304rD8FoH kW8TFG2Cg9Pho79YeIiULW9vL7sN8XxOdmwFEKCGHQ+B2k1q5i+gud7a960EINvnCihq gP9+jLctQmlyxARH8U9/clLrRaaUKw+n0/nymgJNdbYg2jPlqzk7cy1e6ShgZDYFD5ll iBFH6hvenzTLSSax0C4g6baRlLnPxyX9QdCsb2EGK0CA237NQYwi2KXooU7QrPM2bzvp pAyg== X-Forwarded-Encrypted: i=1; AJvYcCVF+ShpQhqbl50rMqLhU34pj8lUYzsR+kfh8GGeg/zM6dLS8waMf6RJRDT953W2C8pY1GCQca3sDnlldBM=@vger.kernel.org X-Gm-Message-State: AOJu0YzKBJmrt48Bq9hWukZx3tfs5gh4SeEc5FoMzBLDZ1uLFeYSteqo n2G12ut0r5fwXYdVGbwY05HzTaB934niaba3rxxXwjstK77iMTUEdi1s5wjG1Jbumto= X-Gm-Gg: AY/fxX6d2pHMMFC7EBHI575HK+GfS9/0v2vg/Bog4CklQMmbMZzyNlgdaiUVVlhkvBz CAXmdV0j9oLnb36DqJx0v8amR2+e6kbxiaefHxhyJHIWtCX0q5+dPXM1dl0BytY9KuaB88P6hc8 O46C82e1sHFThT82zvBpFwALsbFaG3mRQlTbbXAnbIbCOF6hHRr9zLcDOuSKWutxp7YX8TQ361g ofqyRBzfFNDRvFmk3SyVVa0hk39tohelUOrC7bXqRHW8HiSB6PfAMeGEIbRkHMsH9VlmKMI4m2R cco9KyTgoYMvyz6GkQL4XLgFcAez/TsRrpGC2FNO1fDFZ5fDE3Rrb1D71Q0OCpwrEl4MHq5EXxD tcLWLnRbZaEOeeuPXrh2tlhfbNnQM22RVbTGpacG1gif8ekn6XhdnVfAiReUyJbb4FmUBLV2mKQ 5fSwjxTe8QQd6hneZu1vFh X-Google-Smtp-Source: AGHT+IFb5/BXn9GeXqAyeNuOtJbDxjaPRu4NM7Bq86/JmBGVvG42Er/O0lr+BnQiTxNW6EgE2U/MvQ== X-Received: by 2002:a05:622a:2c9:b0:4eb:9df6:5d6f with SMTP id d75a77b69052e-4f4abdbe93cmr23315421cf.74.1766116561499; Thu, 18 Dec 2025 19:56:01 -0800 (PST) Received: from localhost ([2603:7000:c01:2716:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-88d997aed21sm12322946d6.30.2025.12.18.19.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Dec 2025 19:56:00 -0800 (PST) Date: Thu, 18 Dec 2025 22:56:00 -0500 From: Johannes Weiner To: Shakeel Butt Cc: Qi Zheng , hughd@google.com, mhocko@suse.com, roman.gushchin@linux.dev, muchun.song@linux.dev, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, harry.yoo@oracle.com, imran.f.khan@oracle.com, kamalesh.babulal@oracle.com, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, chenridong@huaweicloud.com, mkoutny@suse.com, akpm@linux-foundation.org, hamzamahfooz@linux.microsoft.com, apais@linux.microsoft.com, lance.yang@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Muchun Song , Qi Zheng Subject: Re: [PATCH v2 08/28] mm: memcontrol: prevent memory cgroup release in get_mem_cgroup_from_folio() Message-ID: References: <29e5c116de15e55be082a544e3f24d8ddb6b3476.1765956025.git.zhengqi.arch@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Dec 18, 2025 at 10:53:57PM -0500, Johannes Weiner wrote: > On Thu, Dec 18, 2025 at 06:09:50PM -0800, Shakeel Butt wrote: > > On Wed, Dec 17, 2025 at 04:45:06PM -0500, Johannes Weiner wrote: > > > So starting in patch 27, the tryget can fail if the memcg is offlined, > > > > offlined or on its way to free? It is css_tryget() without online. > > Sorry, I did mean freeing. > > But in the new scheme, they will happen much closer together than > before, since charges don't hold a reference to the css anymore. > > So when css_killed_work_fn() does > > offline_css(css); > css_put(css); > > on rmdir, that's now the css_put() we expect to drop the refcount to 0 > even with folios in circulation. > > The race is then: > > get_mem_cgroup_from_folio() cgroup_rmdir() > memcg = folio_memcg(folio); > folio->objcg->memcg > offline_css() > reparent_objcgs() > objcg->memcg = objcg->memcg->parent > css_put() -> 0 > !css_tryget(&memcg->css) > > and the retry ensures we'll look up objcg->memcg again and find the > live parent and new owner of the folio. But yes, none of this happens until patch 27.