From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 9ED123382CB for ; Sun, 11 Jan 2026 14:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768140389; cv=none; b=mRy2RC/IvG8qzKuuHXHwaZg1FR75Ch7sDzXhYibbo30CWOxpuoHdutgr1rqC9MG0TNB9Sp7mwgC4jL03QBjNATPOWqYy1a39cWmjarDWJSiplKum8KmCGbrkozqtbslljlSdocgY/kOYpTxw22zhrcc1t7L1c4MZ7dLxKyw+CEQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768140389; c=relaxed/simple; bh=ZsjeyQ2BhzOmEdjy0wLmRkk3n3vwdnQg40T0sasLSKc=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=jeP0u+jYFRQnPZ83rM4p3aoqH6JU8Cn3w37V5ytiyuYRd/wdgNNTLNU0Cu+KDMzlyW2q2CvC1oN4YvWIicxMLeJcLk+nHVcjX2RG7QCrUq2ZHzFHZ7wYrY6QbiabuOUzaHmQ0547zOX15NSaKmJuAWQy+kSvZqxlhfV2OpEakFw= 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=NYDj2mlD; arc=none smtp.client-ip=91.218.175.173 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="NYDj2mlD" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768140385; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/zAeMrvMFCoTLAYXTKyzPVZuey3oycGqRnCUj5YJWik=; b=NYDj2mlDQ482dCgWZDLPO5rNZr0rVsfxAlCJRU27shpX8m830U3/7hjvz0QsW2Mr/HQkbU wLTXjYVExOfMStPPjcFQaEFfvOy/wz/L46daNV1C1pLUXVJJqIOLnMfaayuf3ffOwETYgQ P1kXyDTfDTocGqqsMNr62nIVsOA+cAA= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.200.121\)) Subject: Re: [PATCH] mm/page_alloc: Avoid duplicate NR_FREE_PAGES updates in move_to_free_list() X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yajun Deng In-Reply-To: <20260110161048.0aa9c7e32af3e690a671ef8d@linux-foundation.org> Date: Sun, 11 Jan 2026 22:05:40 +0800 Cc: vbabka@suse.cz, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <81F8212D-9C00-4AF2-8D04-79059283B47F@linux.dev> References: <20260109105121.328780-1-yajun.deng@linux.dev> <20260110161048.0aa9c7e32af3e690a671ef8d@linux-foundation.org> To: Andrew Morton X-Migadu-Flow: FLOW_OUT > 2026=E5=B9=B41=E6=9C=8811=E6=97=A5 08:10=EF=BC=8CAndrew Morton = =E5=86=99=E9=81=93=EF=BC=9A >=20 > On Fri, 9 Jan 2026 18:51:21 +0800 Yajun Deng = wrote: >=20 >> In move_to_free_list(), when a page block changes its migration type, >> we need to update free page counts for both the old and new types. >> Originally, this was done by two calls to account_freepages(), which >> updates NR_FREE_PAGES and also type-specific counters. However, this >> causes NR_FREE_PAGES to be updated twice, while the net change is = zero >> in most cases. >>=20 >> This patch introduces a new function account_freepages_both() that >> updates the statistics for both old and new migration types in one = go. >> It avoids the double update of NR_FREE_PAGES by computing the net = change >> only when the isolation status changes. >>=20 >> The optimization avoid duplicate NR_FREE_PAGES updates in >> move_to_free_list(). >=20 > Seems nice and LGTM. >=20 >> +static inline void account_freepages_both(struct zone *zone, int = nr_pages, >> + int old_mt, int new_mt) >> +{ >> + lockdep_assert_held(&zone->lock); >> + >> + bool old_isolated =3D is_migrate_isolate(old_mt); >> + bool new_isolated =3D is_migrate_isolate(new_mt); >=20 > We do permit C99 definition ordering nowadays, but I do think our eyes > and brains prefer the old-school style. >=20 > So here I'd personally prefer >=20 > bool old_isolated =3D is_migrate_isolate(old_mt); > bool new_isolated =3D is_migrate_isolate(new_mt); >=20 > lockdep_assert_held(&zone->lock); >=20 >=20 > Or simply remove the assertion - it doesn't look useful to me. If we > aren't holding zone->lock here then the kernel is so screwed up we > should all just go home. >=20 >=20 Okay, I=E2=80=99ll remove the assertion. Thanks. >=20