From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D9FE328F5 for ; Sun, 11 Jan 2026 00:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768090249; cv=none; b=p6mvVSogqi5t4mRbKsUlgnJIbL6WmfFGszraDst3VG0kQzBMJ92miEs5XGD8twSW6YLID4+hQy/bYbilnbRjpilUj0Jj+yXP8JKxyyHPGzskxFw5ljqTQEhkU+DZr/LvZzniRxl7m+IPt68yc9oaEv4rQPVb6fXhF1V4pwblgTI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768090249; c=relaxed/simple; bh=+X7k0urrtvloUeDzhx+e+wj1OrtJld0n/M0L6ssw5uU=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=hSHFmZyiC/wa5nUWHytwoM1PDvmhCdYDUiO6/B2g7MHPnA53Z6IbAMKP1dXvXBVOEwSnBEZRCj3e1bcdVcjuQ4zKIH3WKt9n4P1kJlBfhmePsZZMaAhJqDIs5WB8lvMX7QaOgC7IuF5JqVKWqJYlpKpVZcjmLARib26irdGW8bw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=mDD/LtFC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="mDD/LtFC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3883AC4CEF1; Sun, 11 Jan 2026 00:10:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1768090249; bh=+X7k0urrtvloUeDzhx+e+wj1OrtJld0n/M0L6ssw5uU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=mDD/LtFCP7BwHFx8iqSO0ctIoObmagUS5/tOknktDPa1Xyj/H8vii2/vY8tykuuKv pn4SHjkrGTrofwnL6S9STuZFh3s8R4ztaIH93Nd2mHphrEk3yjEZu0XVWaB5CP8x7+ FvNN7HlydnI3O7bSCyEauU1GSTKWMsU6sMpPWtMo= Date: Sat, 10 Jan 2026 16:10:48 -0800 From: Andrew Morton To: Yajun Deng 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 Subject: Re: [PATCH] mm/page_alloc: Avoid duplicate NR_FREE_PAGES updates in move_to_free_list() Message-Id: <20260110161048.0aa9c7e32af3e690a671ef8d@linux-foundation.org> In-Reply-To: <20260109105121.328780-1-yajun.deng@linux.dev> References: <20260109105121.328780-1-yajun.deng@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Fri, 9 Jan 2026 18:51:21 +0800 Yajun Deng wrote: > 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. > > 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. > > The optimization avoid duplicate NR_FREE_PAGES updates in > move_to_free_list(). Seems nice and LGTM. > +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 = is_migrate_isolate(old_mt); > + bool new_isolated = is_migrate_isolate(new_mt); We do permit C99 definition ordering nowadays, but I do think our eyes and brains prefer the old-school style. So here I'd personally prefer bool old_isolated = is_migrate_isolate(old_mt); bool new_isolated = is_migrate_isolate(new_mt); lockdep_assert_held(&zone->lock); 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.