From nobody Mon Feb 9 10:57:23 2026 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7F6B338F5B for ; Tue, 28 Oct 2025 14:03:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761660191; cv=none; b=ebM5yh8NfT36B2xxa+68d+vE1wdNJLjWbPNm873BKlwHeW7DF24gSkRyTQmcU8hrFQ3vBwqBMFvjjEM7s72xapLYrp6V/Z/Oi8laiFosdg/A6fti9Z8O9CdDqgORN4RuwZXxtAYfaCaM6sLS3x3LNGjNXQ4RaVyuK+U0eeFxJiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761660191; c=relaxed/simple; bh=d3HGIX+5xqQ3gJbNPVc+GczUi6vw7BKVy2gymVINVFw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ezP+XVD+yUo/Nn8mHs61cZF3iYKSDCcal4qH2dNkJqX6ldwDRJ8ClRXY6+VWTVoI/FcQlY0DKkEC2z8COPAQV0ueFqNf3AhKrFjfgaolrW789R3hB+2oMFRyqKk/VRVBmb06hYSZSKc2kFdds8dGDHs5+CnouOYMNl97Z1p5yuo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=maDouu5c; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="maDouu5c" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1761660182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ul0akWBgQO9d8PYcmieApSptZ1K1m0W1WjLnOQW3EIU=; b=maDouu5ce544NaChXO2olwlSoJjFWIOouCmnASfkFN706sflQURVJ7rfqaMcU+KKGFzR1j b7Gq5siNpsBiC9GDc6Px2VT6uFOE0GtMoXgS/KvQOSx48h4q9XxMHVQ0aMWon1S84m/pky 13xFZW1Z9O3abQIUUWzA2GfMn4SyxBM= From: Qi Zheng To: hannes@cmpxchg.org, hughd@google.com, mhocko@suse.com, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, david@redhat.com, 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, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Muchun Song , Qi Zheng Subject: [PATCH v1 08/26] buffer: prevent memory cgroup release in folio_alloc_buffers() Date: Tue, 28 Oct 2025 21:58:21 +0800 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Muchun Song In the near future, a folio will no longer pin its corresponding memory cgroup. To ensure safety, it will only be appropriate to hold the rcu read lock or acquire a reference to the memory cgroup returned by folio_memcg(), thereby preventing it from being released. In the current patch, the function get_mem_cgroup_from_folio() is employed to safeguard against the release of the memory cgroup. This serves as a preparatory measure for the reparenting of the LRU pages. Signed-off-by: Muchun Song Signed-off-by: Qi Zheng Reviewed-by: Harry Yoo --- fs/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 6a8752f7bbedb..bc93d0b1d0c30 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -925,8 +925,7 @@ struct buffer_head *folio_alloc_buffers(struct folio *f= olio, unsigned long size, long offset; struct mem_cgroup *memcg, *old_memcg; =20 - /* The folio lock pins the memcg */ - memcg =3D folio_memcg(folio); + memcg =3D get_mem_cgroup_from_folio(folio); old_memcg =3D set_active_memcg(memcg); =20 head =3D NULL; @@ -947,6 +946,7 @@ struct buffer_head *folio_alloc_buffers(struct folio *f= olio, unsigned long size, } out: set_active_memcg(old_memcg); + mem_cgroup_put(memcg); return head; /* * In case anything failed, we just free everything we got. --=20 2.20.1