Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6566814rwr; Mon, 24 Apr 2023 23:50:56 -0700 (PDT) X-Google-Smtp-Source: AKy350a4v5azXYYkoRFhAw+kQRb42SwELXqEuP6MlLs7tbs1I3NY6D5a9u3X3z4NU9G4OFV6yVdW X-Received: by 2002:a17:90a:9a97:b0:247:862d:a224 with SMTP id e23-20020a17090a9a9700b00247862da224mr16291695pjp.27.1682405456527; Mon, 24 Apr 2023 23:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682405456; cv=none; d=google.com; s=arc-20160816; b=D3UhPJvzJrZGkUn2cuMGtHN54PvxjU4vZCk72cbz4Oi9Caj07TkNZJ1ybk8Bo9PopS Gi2szXWznCsWP6djQbAiTHK6U+rXd5dXVRvBptO5WsmSj0yJEEu2xB6tZ33NUg+fCl2P vOoSeHaTvJLGyYp/MccwEsTor7qMyfZwl1ZAMrFP2SRP1EZbC1/vdmn+EFC7BjcQ7sJW 6SgmMTNVRTVutnxgDNNtN1bhSpGMe1SPfhP4t26bjAnTZ2pDPQSgtBNK8u/coQ+K3fy2 39HexdQOEAYP/cKnOJr8YQ3v93kkTv6u8QupP8BjDg3skBSPSVbiuC6pp/mT62nQXH6j c6FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:cc:to:subject:message-id :from:content-transfer-encoding:date:dkim-signature:mime-version; bh=G0Sw1HF+tb0ME16TauipdBUqsBMcXzjj7/tJbiHX/1s=; b=YOa10EM6Yfk09lpi2kJJ+lmvZwZ949iQ2qHNj6xYCXKD9tDwgS77lKlWCD3mqQXnir Om8XDVgeF9V39XnxJjkDPycG6YpfLKnke0MhSRyx+qlLNSgX+BQss+GzXmG+/QvxVMy3 U0iMERL24ClKHfm+VacnSMy7C93cl4Jz1IPny9jDJugw2R3zXw+S4lJNr1hG/57yZiGO GXcjeNHSNfN4ohM3/YCzA64P5fwSIr7WQiD3dbmglOtG/0/RJCCX7p4HOnx6eOKeHqpn 9KDImPPSWIaqcPsXYmhegK7W2TOEGD0CVhwZsS6zhXq5Eu60m2+6u3K6HVBDzyNR+TVA JRew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Waxpik0M; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d63-20020a17090a6f4500b00247304b4a27si12816079pjk.173.2023.04.24.23.50.40; Mon, 24 Apr 2023 23:50:56 -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=@linux.dev header.s=key1 header.b=Waxpik0M; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233466AbjDYGi1 (ORCPT + 99 others); Tue, 25 Apr 2023 02:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233461AbjDYGiZ (ORCPT ); Tue, 25 Apr 2023 02:38:25 -0400 Received: from out-49.mta1.migadu.com (out-49.mta1.migadu.com [95.215.58.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5658A4EF7 for ; Mon, 24 Apr 2023 23:38:21 -0700 (PDT) MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1682404699; 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=G0Sw1HF+tb0ME16TauipdBUqsBMcXzjj7/tJbiHX/1s=; b=Waxpik0MqJXy4sXV9FTSarf+6yE6iLfbA5xW066NmLPSnwiydD2Fo6Bmj1v0lb/pBAGcgI rLzA9EJRZD2KJqeI6HeSp6aQgasrBIU7bx7Tm+8Qhc11S2W7IazEP5JY+nBrydwV4ic13k WhGhE8O4Ia/nEpLKkJps7kSxKYwr7Uo= Date: Tue, 25 Apr 2023 06:38:18 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Yajun Deng" Message-ID: Subject: Re: [PATCH] mmzone: Introduce for_each_populated_zone_pgdat() To: "Huang, Ying" , "Andrew Morton" Cc: "Matthew Wilcox" , 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 In-Reply-To: <875y9kfr0o.fsf@yhuang6-desk2.ccr.corp.intel.com> References: <875y9kfr0o.fsf@yhuang6-desk2.ccr.corp.intel.com> <20230424030756.1795926-1-yajun.deng@linux.dev> <20230424145823.b8e8435dd3242614371be6d5@linux-foundation.org> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 April 25, 2023 1:51 PM, "Huang, Ying" wrote:=0A=0A= > Andrew Morton writes:=0A> =0A>> On Mon, 24 = Apr 2023 04:50:37 +0100 Matthew Wilcox wrote:=0A>> = =0A>>> On Mon, Apr 24, 2023 at 11:07:56AM +0800, Yajun Deng wrote:=0A>>>>= Instead of define an index and determining if the zone has memory,=0A>>>= > introduce for_each_populated_zone_pgdat() helper that can be used=0A>>>= > to iterate over each populated zone in pgdat, and convert the most=0A>>= >> obvious users to it.=0A>>> =0A>>> I don't think the complexity of the = helper justifies the simplification=0A>>> of the users.=0A>> =0A>> Are yo= u sure?=0A>> =0A>>>> +++ b/include/linux/mmzone.h=0A>>>> @@ -1580,6 +1580= ,14 @@ extern struct zone *next_zone(struct zone *zone);=0A>>>> ; /* do n= othing */ \=0A>>>> else=0A>>>> =0A>>>> +#define for_each_populated_zone_p= gdat(zone, pgdat, max) \=0A>>>> + for (zone =3D pgdat->node_zones; \=0A>>= >> + zone < pgdat->node_zones + max; \=0A>>>> + zone++) \=0A>>>> + if (!p= opulated_zone(zone)) \=0A>>>> + ; /* do nothing */ \=0A>>>> + else=0A>>>>= +=0A>> =0A>> But each of the call sites is doing this, so at least the c= omplexity is=0A>> now seen in only one place.=0A>> =0A>> btw, do we need = to do the test that way? Why won't this work?=0A>> =0A>> #define for_each= _populated_zone_pgdat(zone, pgdat, max) \=0A>> for (zone =3D pgdat->node_= zones; \=0A>> zone < pgdat->node_zones + max; \=0A>> zone++) \=0A>> if (p= opulated_zone(zone))=0A>> =0A>> I suspect it was done the original way in= order to save a tabstop,=0A>> which is no longer needed.=0A> =0A> This m= ay cause unexpected effect when used with "if" statement. For=0A> example= ,=0A> =0A> if (something)=0A> for_each_populated_zone_pgdat(zone, pgdat, = max)=0A> total +=3D zone->present_pages;=0A> else=0A> pr_info("something = is false!\n");=0A> =0A=0AThanks Huang, Ying for the example.=0A=0AYes, th= is macros with multiple statements but doesn't have a do - while loop,=0A= It needs if and else together.=0A=0A> Best Regards,=0A> Huang, Ying