Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6427625rwr; Mon, 24 Apr 2023 20:40:01 -0700 (PDT) X-Google-Smtp-Source: AKy350YWlyzqiechNSwzXjRJGpufKiPktdklbRRu01TOXAe3qcq+ObxFSvsH2BhWBcLNW019KtjH X-Received: by 2002:a17:90a:6e46:b0:247:70ff:b45f with SMTP id s6-20020a17090a6e4600b0024770ffb45fmr16341358pjm.37.1682394000928; Mon, 24 Apr 2023 20:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682394000; cv=none; d=google.com; s=arc-20160816; b=QM1nKjEk6CcLFeui2hlWZSoIveeS26Oi8FWwUO69fSwilAy+jZiyW4KD4aypCWs/nh TCe1rDFObUaAFHYGwygBx03VXb7M2IGFcBFoCIOQSz7S38z05wAR2+Lz9kC4v5fqI9cF i5I+kuA+gUpVV+xYYiRkv2Hd9Jrl68y/k1FdwFhgT5Wlr+ECugtRAMy+K+kUxP+VD8bH asq7Bea/iLNb94ap6D34kJ1Buj/lhPpd5MUGn3eb0VOkSqNxnVWH6I/UVeCDgg1k5juU qRhEKWtkRqnrwNR2wUs5L7kOjRaCUmZLZn+WJmirk11Yooyh2NiVg/D1HQHuS1uOLCBt 55gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TDZKORwzEt+eX2u0tCokEp9eJLCllrYXgwK+Hx7Vcpk=; b=Tub4J9FdLhf4dNX23XIp7S4z8sU/B6Spbn7IToE79Uu4YQInkj5KyxDepzhGLacgHg uylDl78MNhWAyE5e2SbCwBB1XMyyAoNSOBgoECFqdoCHW3M7sUy/fKTFUopEoaXSqERl 2qhsKG/WHE4w8VyaK0nRVyO7tRPmnRYHBt4ZguSP9wbJj8YaV+AWSNU++B+c9QqW0nrh RXvqlaZPW2wsoTKDrYIoFa0viNE0lOAeSQCj2i36RTzL7MRV/KWgwYWiq+uxeWsj7UYO /vhSnqNzzRY8ydxb84VBDUOK9GgwsUgBdGB+pkBFR/wXTO6oWVEHnAaupk6QH/clk6dH b06w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="GefC/jvF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ie2-20020a17090b400200b002472cd8ded6si13535008pjb.103.2023.04.24.20.39.42; Mon, 24 Apr 2023 20:40:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="GefC/jvF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233139AbjDYDXi (ORCPT + 99 others); Mon, 24 Apr 2023 23:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbjDYDXg (ORCPT ); Mon, 24 Apr 2023 23:23:36 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA1C9A8; Mon, 24 Apr 2023 20:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=TDZKORwzEt+eX2u0tCokEp9eJLCllrYXgwK+Hx7Vcpk=; b=GefC/jvFTqeaTIMWQN69ufb2Me sAIXG1NtP1yjyItvIAQpV0D4kpWWMhKNhQ1j7uhKMIIODYwXfUda7IdDsaBIhpXIsyyQw26Sif0xU GJZGrm/HqpFBiMyB/OCvROv64NNHzEONcn4r9rYmrzYE8JEe1lhDl64E/NbQHEVVgLEYVLDf7XKAi 0SpwJfGx2NfwRrdjwnDsO45GmhdvYbJzPdco38YI9bjf7cE5XFGQ42/LX9kwn2tJodQ+6PsDqbShV 5rAe0q8HQVGBAIm743Vmp0GETWCgQXfu4wG2x7rWLxS4ZB1Xz+HQWvzswUlMKnTru3B82Q7Q7VY0C FT4X0aWw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pr9Gx-0014cq-LB; Tue, 25 Apr 2023 03:23:19 +0000 Date: Tue, 25 Apr 2023 04:23:19 +0100 From: Matthew Wilcox To: Andrew Morton Cc: Yajun Deng , david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] mmzone: Introduce for_each_populated_zone_pgdat() Message-ID: References: <20230424030756.1795926-1-yajun.deng@linux.dev> <20230424145823.b8e8435dd3242614371be6d5@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230424145823.b8e8435dd3242614371be6d5@linux-foundation.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 24, 2023 at 02:58:23PM -0700, Andrew Morton wrote: > On Mon, 24 Apr 2023 04:50:37 +0100 Matthew Wilcox wrote: > > > On Mon, Apr 24, 2023 at 11:07:56AM +0800, Yajun Deng wrote: > > > Instead of define an index and determining if the zone has memory, > > > introduce for_each_populated_zone_pgdat() helper that can be used > > > to iterate over each populated zone in pgdat, and convert the most > > > obvious users to it. > > > > I don't think the complexity of the helper justifies the simplification > > of the users. > > Are you sure? > > > > +++ b/include/linux/mmzone.h > > > @@ -1580,6 +1580,14 @@ extern struct zone *next_zone(struct zone *zone); > > > ; /* do nothing */ \ > > > else > > > > > > +#define for_each_populated_zone_pgdat(zone, pgdat, max) \ > > > + for (zone = pgdat->node_zones; \ > > > + zone < pgdat->node_zones + max; \ > > > + zone++) \ > > > + if (!populated_zone(zone)) \ > > > + ; /* do nothing */ \ > > > + else > > > + > > But each of the call sites is doing this, so at least the complexity is > now seen in only one place. But they're not doing _that_. They're doing something normal and obvious like: for (zone = pgdat->node_zones; zone < pgdat->node_zones + max; zone++) { if (!populated_zone(zone) continue; ... } which clearly does what it's supposed to. But with this patch, there's macro expansion involved, and it's not a nice simple macro, it has a loop _and_ an if-condition, and there's an else, and now I have to think hard about whether flow control is going to do the right thing if the body of the loop isn't simple. > btw, do we need to do the test that way? Why won't this work? > > #define for_each_populated_zone_pgdat(zone, pgdat, max) \ > for (zone = pgdat->node_zones; \ > zone < pgdat->node_zones + max; \ > zone++) \ > if (populated_zone(zone)) I think it will work, except that this is now legal: for_each_populated_zone_pgdat(zone, pgdat, 3) else i++; and really, I think that demonstrates why we don't want macros that are that darn clever.