From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D61FD2C326F; Tue, 26 May 2026 11:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779793523; cv=none; b=d63xHmhj31i2J+6JCZ9f7Dq/oZZ5F7oRfciQ9I0BZe/z8c5F7X5kJGdJeYNyptT+il+eDR3JgGMIbpqMU4FHpFgW/Uhy5FrhsRzHOkpqY3GM+cJrZdK3jwUsp7JoYojIEOs+uYWFCFnuFZIONcAhLZW8+DrKThzXfd1eNg8JLHA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779793523; c=relaxed/simple; bh=o2irwX7EG6I+YJ0FvIT9HckDmEnpR+ox2VKp9/aKOyk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Od+DmgC6QkYNlW78chZLzLlcTrqlhAgKYRtXMBIlzZ2Z7MN1jArG7nUmeXfntqqf4LH78FIIcPX8b1rUOJxh05uj3MwQ28fQldBV1jC1ED4DMyCr7beR5p0CR/TESPWuhBmiaxJmRx8BLw+bLq5/RSVwk47YYOMw8fea873gpPA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i+2Dh7MF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i+2Dh7MF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55E4B1F000E9; Tue, 26 May 2026 11:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779793522; bh=qk40xgulls2bsEySJ0d4/5IyTPrAc0LfClUBUzlGCjE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=i+2Dh7MFEtK74+pZLmmNLDVqGWGe2BE+kd3pDCqQXGbpTjL7Logl9E6fmQ0ubku+1 nyOjwqL+o0m5Ts5cROkskSsx8BBovl9L8IyPmf5m4cF5bkx26ThEevbfbn5KNW9ygl yXWTAuQX9CmIwRFZUksstdZwplvejzDeV1LunwDhE+WlkkWABJoU4quxu4Aa6r1l9s EKOxiCJ0cQvS3yULxl9RIkuNSKc0fB5rcyvNUYLxymB/EWdGPLZ09F6aUnfWem9QML xeIJ6Kzi3M/GWTMKKHZ0SypcJlgX7NGSp7a2OopiPU5ihCB+0KREcp481g6H5y5p9w 2mUtT7NpMbH4A== Date: Tue, 26 May 2026 12:05:15 +0100 From: Lorenzo Stoakes To: Yin Tirui Cc: Andrew Morton , David Hildenbrand , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Yang Shi , wangkefeng.wang@huawei.com, chenjun102@huawei.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] mm/huge_memory: update file PMD counter before folio_put() Message-ID: References: <20260526101337.1984081-1-yintirui@huawei.com> Precedence: bulk X-Mailing-List: stable@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: <20260526101337.1984081-1-yintirui@huawei.com> On Tue, May 26, 2026 at 06:13:37PM +0800, Yin Tirui wrote: > __split_huge_pmd_locked() updates the file/shmem RSS counter after > dropping the PMD mapping's folio reference. If folio_put() drops the > last reference, mm_counter_file() can later read freed folio state via > folio_test_swapbacked(). > > Move the counter update before folio_put(). > > Fixes: fadae2953072 ("thp: use mm_file_counter to determine update which rss counter") That's an old commit :) I mean I suspect we're probably not actually ever dropping the folio ref to 0 here since we never had a report since ~2018. The page cache keeping a reference I guess? But doesn't mean we shouldn't fix this on principal/there being some way this could happen. > Cc: > Signed-off-by: Yin Tirui LGTM, so: Reviewed-by: Lorenzo Stoakes > --- > mm/huge_memory.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 0135c29a4372..a5f4a48b7b77 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -3145,7 +3145,9 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, > if (!folio_test_referenced(folio) && pmd_young(old_pmd)) > folio_set_referenced(folio); > folio_remove_rmap_pmd(folio, page, vma); > + add_mm_counter(mm, mm_counter_file(folio), -HPAGE_PMD_NR); > folio_put(folio); > + return; Hmm, sucks to duplicate like this, but for purposes of backport and getting this resolved fine, we can clean it up later. > } > add_mm_counter(mm, mm_counter_file(folio), -HPAGE_PMD_NR); > return; > -- > 2.43.0 > Cheers, Lorenzo