From patchwork Mon Apr 17 03:52:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 83987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1875119vqo; Sun, 16 Apr 2023 21:23:54 -0700 (PDT) X-Google-Smtp-Source: AKy350YblXg+zO4ttMKJzTnXSSllKdgXWd3roB1BJbvUGbxe2T4PxBADr0WtKiWvuvxyjaVNTgTf X-Received: by 2002:a05:6a20:5489:b0:f0:110b:bf9b with SMTP id i9-20020a056a20548900b000f0110bbf9bmr984600pzk.16.1681705434502; Sun, 16 Apr 2023 21:23:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681705434; cv=none; d=google.com; s=arc-20160816; b=aNUr8wjR2fWQFxM36nn21iUIOsjTHhrQpQlm6oDs8mXpDOI3/kzsBMBih+4SwP+QxE jdiKUaXJ07Vq27ZzDiCV97DfzgFMZ2GjvCqVtsG3LYXIH4xF06tYPr3K9vnsmrtOfARx 5RozR8aX3lPaLIV2nNuZJvPBEin+CfXHEO1JKbHgnwXEfwya8j2MZEjT/KVcYEqPW7rK WENY+6Ebt3cB/tGbS2oP7I+R8UN4sfXzb+11m/oCpBcAiYD6OoljUhC7S1e32AMcSKZE hgWC4jnAl8hFoYXq0bV97tZ5404eEvbFZbNSnnZ6nYpthsRoj3pBIphZlLbnJ+zwxNq6 ObrA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a056a00000700b0063b77e2123csi6220819pfk.26.2023.04.16.21.23.40; Sun, 16 Apr 2023 21:23:54 -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 S230228AbjDQDwu (ORCPT + 99 others); Sun, 16 Apr 2023 23:52:50 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763395957782994568?= X-GMAIL-MSGID: =?utf-8?q?1763395957782994568?= 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 Acked-by: Michal Hocko --- 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);