Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3478099rwe; Sun, 16 Apr 2023 21:23:48 -0700 (PDT) X-Google-Smtp-Source: AKy350bUj492u1Q7WbKFvbNACUrKXicGmlmc7OoJbk2BIHx6W2fk3HC8bkwzrUeJlfgNBrI6gaqy X-Received: by 2002:a17:90a:638e:b0:247:6ec8:7e9b with SMTP id f14-20020a17090a638e00b002476ec87e9bmr4942909pjj.44.1681705428674; Sun, 16 Apr 2023 21:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681705428; cv=none; d=google.com; s=arc-20160816; b=eoE3ZiO4mhfcibRsWhtrSRYn7AOI32PPUVZE5ikulKy+pCOezHT0L2z1AkhP6rIL6H OHl5qaylwqRSBSJ2kVYzQrmUaHHy8GFROp0T+q0hBUPlnEzLOB8lQmH0CI1UU/HiWIQe 5sBLxSqchWzpt9eWI3Abtxwu/Qy+RxjQDueOJOVqy7jhlwBMtEJ9bNIn3hOaGRxCgE6j UKTyiVnaf4rHc4ZNbbCmU/u2BIfPEKaRxyEnfa/xN6Ynwbgxc2eXyPN5SJYEDGJwa0Vb A4/YBOKZN213DFkerde+Xf2C3SoXIUsRxxfb07zg4LjUHwPntJKedYW6LD3uR+r1Mqs/ u0Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=N1rIn34+I9+LMC5x+RgqWpX2I7AwIm2eyZEXSYzzQWE=; b=GtbUaWCbyPiyD3boGi+NCflIuL/ls89hbxXkVqwEMLKp3EJ0TKddW67y6j9qVnTy7L xAVWc+3tWuB5PgR9VIk3KpYmmO8PkbzDTdBh0N1P//6U66PopJokJsaasZmyb2TLWaBN 1dXERM+X1Co6nVH65x70xVRTS5EibovxanHhBKGYt00nJmvz1adnH73Geo0nZj6p3Xg6 6X3Y3oHjmbs4FaQQPfD0NRdCu/iiIHyrEUv14VRXKl6/U+vmNqFSttUuNlksVSQhSYSy lZru6K5yuuutpY+5/Qrm0VrF8asM7/Qv3e42Q7gu2GqFJ6448hu9p+h0coXPwZ85HxhS 4ReQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=bRJ70dly; 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 on11-20020a17090b1d0b00b0023adb22068csi11630418pjb.81.2023.04.16.21.23.37; Sun, 16 Apr 2023 21:23:48 -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=bRJ70dly; 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 S230225AbjDQDwt (ORCPT + 99 others); Sun, 16 Apr 2023 23:52:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbjDQDwr (ORCPT ); Sun, 16 Apr 2023 23:52:47 -0400 Received: from out-20.mta1.migadu.com (out-20.mta1.migadu.com [95.215.58.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81372A4 for ; Sun, 16 Apr 2023 20:52:45 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1681703561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=N1rIn34+I9+LMC5x+RgqWpX2I7AwIm2eyZEXSYzzQWE=; b=bRJ70dlyX4rS4tJEJU7dR4YfnCkk4eXbdUlgcIo9FX8iGh7GFxItdrdzozlfUkkI5Jy0+T Uzal4FJNdETzepC7uKDOz3XX/Xzhw273vNF3201SUXanEY2N8Hn4GXYwB2kkfvj+2x36uj 8Qa8YzKxlyXhD/HZ54cZUmRvobMvwqw= From: Yajun Deng To: hannes@cmpxchg.org, vbabka@suse.cz, mhocko@suse.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH] lib/show_mem.c: Use for_each_populated_zone() simplify code Date: Mon, 17 Apr 2023 11:52:26 +0800 Message-Id: <20230417035226.4013584-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 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 --- 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); -- 2.25.1