Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3622578rwe; Mon, 17 Apr 2023 00:32:12 -0700 (PDT) X-Google-Smtp-Source: AKy350YHzR4nEiVm1xgqzmE1+a1TUPrh7rKozi7oyu6SE7XkAEViWXxTQ+/GfWEchR5b6lwZ2H4x X-Received: by 2002:a17:90a:ad94:b0:247:25d6:b849 with SMTP id s20-20020a17090aad9400b0024725d6b849mr13128606pjq.8.1681716732114; Mon, 17 Apr 2023 00:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681716732; cv=none; d=google.com; s=arc-20160816; b=fuZCM3ZselSIqpI/X8tvrqtkFROgRFg4WQMMjkL7VUfGfkWYmSa2haIgmfbCBIEJ0E fND3u9U87qb2WYM6TFqqcnBxqb4tqkLEoa24tWvwzFAObLHK6O1Lj7S4CZHhm6iVsAKW xu6dI5TiTxG6fG9cvivatoZGP19gPbiOpnmFiLCBy5xkDpd2KGZt2XuTxaOBj+GnoTQ+ 90CubtJ2nCd7m0sOSmppVzujfzub00uR+PiT0khaLeEHC3iT6Og3ehBvmglHZPBdYLGy qptTnKBzfT+ug+dlwXQI2KuRtXs2XUxViVIpS8z+knhfBr/TLdPILFGeXhMq/ThUZGXg CpzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=WQ1R4sZvD1Du39W5RTulU4BAsSwlbCyckcS5wsqWjl0=; b=uOUog26RQtU1AOY13EJTscetqMQYjXcR6kaQx6cfeL/TYnwDWBJdMFDpjgeeXR6i5n GrGt3Ruv7LkKA09qr7YxzBHKoPX621lDuPW8WZw1I/ffJ2hQanRR0Y+LRNChyjBIpkdF 3EhDNb8V/1ByPs1xozpMmpJzpNraCtq6iROfyuhYiTxCd5Ho5rqvhsdukMT7BNO8YoDK t5P9ePB5qjzB6zkrg93vdOvbCo/HIxaLP10QX3gFmQIGUw9sJfcRtX43GIvM1rSLQdAp XaZlNEhHxE2fzVvbpSAOrL0/IKlRD+P9L5aJQFJI5Uv/ETTG5UCeWV3mbiWGhiX+Fq5u 7Q2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=cfmkvv25; dkim=neutral (no key) header.i=@suse.cz header.b=W5QLXKEq; 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 s32-20020a17090a2f2300b00240d7509eb8si12515459pjd.114.2023.04.17.00.31.59; Mon, 17 Apr 2023 00:32:12 -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=@suse.cz header.s=susede2_rsa header.b=cfmkvv25; dkim=neutral (no key) header.i=@suse.cz header.b=W5QLXKEq; 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 S230309AbjDQH2y (ORCPT + 99 others); Mon, 17 Apr 2023 03:28:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbjDQH2m (ORCPT ); Mon, 17 Apr 2023 03:28:42 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D6E530C6 for ; Mon, 17 Apr 2023 00:28:03 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1267421A46; Mon, 17 Apr 2023 07:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1681716478; 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=WQ1R4sZvD1Du39W5RTulU4BAsSwlbCyckcS5wsqWjl0=; b=cfmkvv25zNgiKJq6AOdiBFoS6/TgJZACH3uGf2koIfOprJcCsuoLLV0HQL0hBoxJHFnrj4 JhhUUCt3syIwh5rDFn9emXtzTcvLrswa+Hd7O3/+uoJDiG06YdFZ6JWg+VD7gm7de3uyvZ Kfi2fJIbdrIGWb3Fp9gaRFdM7YcnxFE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1681716478; 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=WQ1R4sZvD1Du39W5RTulU4BAsSwlbCyckcS5wsqWjl0=; b=W5QLXKEq944ybE5GqdoMHBrt5hoebhZ4R2faxEs0VUmc3AZtYnUlHdyv4am9DA5OqruYDn AqsN6BiKHXsNMhDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E62B013319; Mon, 17 Apr 2023 07:27:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0DwyN/30PGRQIAAAMHmgww (envelope-from ); Mon, 17 Apr 2023 07:27:57 +0000 Message-ID: Date: Mon, 17 Apr 2023 09:27:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH] lib/show_mem.c: Use for_each_populated_zone() simplify code Content-Language: en-US To: Yajun Deng , hannes@cmpxchg.org, mhocko@suse.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org References: <20230417035226.4013584-1-yajun.deng@linux.dev> From: Vlastimil Babka In-Reply-To: <20230417035226.4013584-1-yajun.deng@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE 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 4/17/23 05:52, Yajun Deng wrote: > The __show_mem() needs to iterate over all zones that have memory, we can > simplify the code by using for_each_populated_zone(). > > Signed-off-by: Yajun Deng Acked-by: Vlastimil Babka > --- > lib/show_mem.c | 19 ++++++------------- > 1 file changed, 6 insertions(+), 13 deletions(-) > > diff --git a/lib/show_mem.c b/lib/show_mem.c > index 0d7585cde2a6..1485c87be935 100644 > --- a/lib/show_mem.c > +++ b/lib/show_mem.c > @@ -10,26 +10,19 @@ > > void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx) > { > - pg_data_t *pgdat; > unsigned long total = 0, reserved = 0, highmem = 0; > + struct zone *zone; > > printk("Mem-Info:\n"); > __show_free_areas(filter, nodemask, max_zone_idx); > > - for_each_online_pgdat(pgdat) { > - int zoneid; > + for_each_populated_zone(zone) { > > - for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { > - struct zone *zone = &pgdat->node_zones[zoneid]; > - if (!populated_zone(zone)) > - continue; > + total += zone->present_pages; > + reserved += zone->present_pages - zone_managed_pages(zone); > > - total += zone->present_pages; > - reserved += zone->present_pages - zone_managed_pages(zone); > - > - if (is_highmem_idx(zoneid)) > - highmem += zone->present_pages; > - } > + if (is_highmem(zone)) > + highmem += zone->present_pages; > } > > printk("%lu pages RAM\n", total);