[PATCH -next] mm: page_alloc: simplify has_managed_dma()

From: Kefeng Wang
Date: Mon May 29 2023 - 10:24:27 EST


The ZONE_DMA should only exists on Node 0, only check NODE_DATA(0)
is enough, so simplify has_managed_dma() and make it inline.

Cc: Baoquan He <bhe@xxxxxxxxxx>
Signed-off-by: Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>
---
include/linux/mmzone.h | 21 +++++++++++----------
mm/page_alloc.c | 15 ---------------
2 files changed, 11 insertions(+), 25 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 5a7ada0413da..48e9fd8eccb4 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1503,16 +1503,6 @@ static inline int is_highmem(struct zone *zone)
return is_highmem_idx(zone_idx(zone));
}

-#ifdef CONFIG_ZONE_DMA
-bool has_managed_dma(void);
-#else
-static inline bool has_managed_dma(void)
-{
- return false;
-}
-#endif
-
-
#ifndef CONFIG_NUMA

extern struct pglist_data contig_page_data;
@@ -1527,6 +1517,17 @@ static inline struct pglist_data *NODE_DATA(int nid)

#endif /* !CONFIG_NUMA */

+static inline bool has_managed_dma(void)
+{
+#ifdef CONFIG_ZONE_DMA
+ struct zone *zone = NODE_DATA(0)->node_zones + ZONE_DMA;
+
+ if (managed_zone(zone))
+ return true;
+#endif
+ return false;
+}
+
extern struct pglist_data *first_online_pgdat(void);
extern struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
extern struct zone *next_zone(struct zone *zone);
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e671c747892f..e847b39939b8 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6613,18 +6613,3 @@ bool put_page_back_buddy(struct page *page)
return ret;
}
#endif
-
-#ifdef CONFIG_ZONE_DMA
-bool has_managed_dma(void)
-{
- struct pglist_data *pgdat;
-
- for_each_online_pgdat(pgdat) {
- struct zone *zone = &pgdat->node_zones[ZONE_DMA];
-
- if (managed_zone(zone))
- return true;
- }
- return false;
-}
-#endif /* CONFIG_ZONE_DMA */
--
2.35.3