From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F4FCC54E58 for ; Fri, 15 Mar 2024 11:09:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F03A98011E; Fri, 15 Mar 2024 07:09:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB44A800B4; Fri, 15 Mar 2024 07:09:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7B878011E; Fri, 15 Mar 2024 07:09:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C98F7800B4 for ; Fri, 15 Mar 2024 07:09:33 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 952F7A14AA for ; Fri, 15 Mar 2024 11:09:33 +0000 (UTC) X-FDA: 81899002626.25.63F0C9A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf26.hostedemail.com (Postfix) with ESMTP id 30BA014001C for ; Fri, 15 Mar 2024 11:09:30 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="Z/cIie2T"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=jg0DSH4p; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="Z/cIie2T"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=jg0DSH4p; dmarc=none; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710500971; h=from:from:sender: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:dkim-signature; bh=OjoX9b3TBaI+zz4wUVXKNc/j5Lf3cTQPsLzjI7O3xWY=; b=69qz6QZrRyF7hOpxTLUzYLaIRWZ+aITZGXhDm8b54agAuGLdpvWBZnTPWrIb+PTV8IEtV3 Wp2JHz9PhF580iV8w4bAu0zVzeuQZa6drFpPY6xvjROYu5A5cctoFr2FEtLwuvUuLGSxXi IXZ8Yeu4N3W8DBRMri4kCX4dYxS9d5c= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="Z/cIie2T"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=jg0DSH4p; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="Z/cIie2T"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=jg0DSH4p; dmarc=none; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710500971; a=rsa-sha256; cv=none; b=SQFBu+Z84fQJSM+eN9TcIdftXgX4AhryYZmXBeQqMSS/bxUXCQazE2MkdWDI3Y0n31+OKl glZvHmkoAOslLCA23U9Knpt2E8RlKyQzt/1r9m7MM0VMU5Pdn7+eM0geN8vMim26pS3Tma xveNUgJnQ6jZ6vQdnn89sEB7CI4x1zQ= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8359921DD2; Fri, 15 Mar 2024 11:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710500969; h=from:from:reply-to: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=OjoX9b3TBaI+zz4wUVXKNc/j5Lf3cTQPsLzjI7O3xWY=; b=Z/cIie2Te5X9Kp4fXdLx9VJljlR+FUnG++OqIR6d8s/A+i8r5oP8Pbgym0Gf5vG6eo3Mxi 92xwybZ3Oo/JZTqjnBMYlZfEMCxN4+f5BayjBHoC0Z6LSyl8+/+wmWQfu829g5Hfgs98zu W3MKFWSGcYRGdvAhZwOhOkgO2RINnAg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710500969; h=from:from:reply-to: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=OjoX9b3TBaI+zz4wUVXKNc/j5Lf3cTQPsLzjI7O3xWY=; b=jg0DSH4p1kvYN4EkpifnfW4VfdHHRC19/uKsoMtx/3YVmbF3u5jFuZx/E23t7/XcZkkDs1 4Hfw30ax9+BavJDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710500969; h=from:from:reply-to: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=OjoX9b3TBaI+zz4wUVXKNc/j5Lf3cTQPsLzjI7O3xWY=; b=Z/cIie2Te5X9Kp4fXdLx9VJljlR+FUnG++OqIR6d8s/A+i8r5oP8Pbgym0Gf5vG6eo3Mxi 92xwybZ3Oo/JZTqjnBMYlZfEMCxN4+f5BayjBHoC0Z6LSyl8+/+wmWQfu829g5Hfgs98zu W3MKFWSGcYRGdvAhZwOhOkgO2RINnAg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710500969; h=from:from:reply-to: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=OjoX9b3TBaI+zz4wUVXKNc/j5Lf3cTQPsLzjI7O3xWY=; b=jg0DSH4p1kvYN4EkpifnfW4VfdHHRC19/uKsoMtx/3YVmbF3u5jFuZx/E23t7/XcZkkDs1 4Hfw30ax9+BavJDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6AB75137E8; Fri, 15 Mar 2024 11:09:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 5ya9GWks9GW+egAAD6G6ig (envelope-from ); Fri, 15 Mar 2024 11:09:29 +0000 Message-ID: <532c9e93-e8cc-4f6f-bf08-b5625022dd4f@suse.cz> Date: Fri, 15 Mar 2024 12:09:29 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] mm/compaction: add and use for_each_populated_zone_pgdat() helper Content-Language: en-US To: Luis Chamberlain , Baolin Wang Cc: akpm@linux-foundation.org, jhubbard@nvidia.com, mgorman@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave@stgolabs.net, p.raghav@samsung.com, da.gomez@samsung.com References: <20240314005436.2962962-1-mcgrof@kernel.org> <20240314005436.2962962-3-mcgrof@kernel.org> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 30BA014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WyGG1 UlID0LsA n0HOu43cUYF8nmTI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 3/15/24 06:38, Luis Chamberlain wrote: > On Thu, Mar 14, 2024 at 03:19:45PM +0800, Baolin Wang wrote: >> >> >> On 2024/3/14 08:54, Luis Chamberlain wrote: >> > We can just wrap most of the work done on fragmentation_score_node() >> > into a pgdat helper for populated zones. Add the helper and use it. >> > >> > Signed-off-by: Luis Chamberlain >> > --- >> > include/linux/mmzone.h | 8 ++++++++ >> > mm/compaction.c | 9 ++------- >> > 2 files changed, 10 insertions(+), 7 deletions(-) >> > >> > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h >> > index a497f189d988..1fd74c7100ec 100644 >> > --- a/include/linux/mmzone.h >> > +++ b/include/linux/mmzone.h >> > @@ -1597,6 +1597,14 @@ extern struct zone *next_zone(struct zone *zone); >> > ; /* do nothing */ \ >> > else >> > +#define for_each_populated_zone_pgdat(zone, pgdat) \ >> > + for (zone = pgdat->node_zones; \ >> > + zone; \ >> > + zone = next_zone(zone)) \ >> > + if (!populated_zone(zone)) \ >> > + ; /* do nothing */ \ >> > + else >> >> I think this will break the original logics, since the next_zone() will >> iterate over all memory zones, instead of only the memory zones of the >> specified node. > > Definitely, thanks, so we'd need something like this in addition: IMHO that's unnecessarily complex, why not just do the iteration all inline without this next_zone_pgdat() helper? Also maybe you could find more users if you created just a for_each_zone_pgdat() and left the populated_zone() in the user? Otherwise it's quite a specific helper with just one user. > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index 34b729fc751b..bd11d33ea14d 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -1568,6 +1568,7 @@ static inline struct pglist_data *NODE_DATA(int nid) > extern struct pglist_data *first_online_pgdat(void); > extern struct pglist_data *next_online_pgdat(struct pglist_data *pgdat); > extern struct zone *next_zone(struct zone *zone); > +extern struct zone *next_zone_pgdat(struct zone *zone, struct pglist_data *pgdat); > > /** > * for_each_online_pgdat - helper macro to iterate over all online nodes > @@ -1600,7 +1601,7 @@ extern struct zone *next_zone(struct zone *zone); > #define for_each_populated_zone_pgdat(zone, pgdat) \ > for (zone = pgdat->node_zones; \ > zone; \ > - zone = next_zone(zone)) \ > + zone = next_zone_pgdat(zone, pgdat)) \ > if (!populated_zone(zone)) \ > ; /* do nothing */ \ > else > diff --git a/mm/compaction.c b/mm/compaction.c > index 015126803017..96434f6fc1ad 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -2152,7 +2152,6 @@ static unsigned int fragmentation_score_node(pg_data_t *pgdat) > { > unsigned int score = 0; > struct zone *zone; > - int zoneid; > > for_each_populated_zone_pgdat(zone, pgdat) > score += fragmentation_score_zone_weighted(zone); > diff --git a/mm/mmzone.c b/mm/mmzone.c > index c01896eca736..043a6dc16c05 100644 > --- a/mm/mmzone.c > +++ b/mm/mmzone.c > @@ -43,6 +43,18 @@ struct zone *next_zone(struct zone *zone) > return zone; > } > > +/* > + * next_zone_pgdat - helper magic for for_each_zone() per node > + */ > +struct zone *next_zone_pgdat(struct zone *zone, struct pglist_data *pgdat) > +{ > + if (!zone || !pgdat) > + return NULL; > + if (zone < pgdat->node_zones + MAX_NR_ZONES - 1) > + return ++zone; > + return NULL; > +} > + > static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes) > { > #ifdef CONFIG_NUMA