4 * management codes for pgdats, zones and page flags
8 #include <linux/stddef.h>
10 #include <linux/mmzone.h>
11 #include <linux/export.h>
13 struct pglist_data
*first_online_pgdat(void)
15 return NODE_DATA(first_online_node
);
17 EXPORT_SYMBOL_GPL(first_online_pgdat
);
19 struct pglist_data
*next_online_pgdat(struct pglist_data
*pgdat
)
21 int nid
= next_online_node(pgdat
->node_id
);
23 if (nid
== MAX_NUMNODES
)
25 return NODE_DATA(nid
);
27 EXPORT_SYMBOL_GPL(next_online_pgdat
);
30 * next_zone - helper magic for for_each_zone()
32 struct zone
*next_zone(struct zone
*zone
)
34 pg_data_t
*pgdat
= zone
->zone_pgdat
;
36 if (zone
< pgdat
->node_zones
+ MAX_NR_ZONES
- 1)
39 pgdat
= next_online_pgdat(pgdat
);
41 zone
= pgdat
->node_zones
;
47 EXPORT_SYMBOL_GPL(next_zone
);
49 static inline int zref_in_nodemask(struct zoneref
*zref
, nodemask_t
*nodes
)
52 return node_isset(zonelist_node_idx(zref
), *nodes
);
55 #endif /* CONFIG_NUMA */
58 /* Returns the next zone at or below highest_zoneidx in a zonelist */
59 struct zoneref
*next_zones_zonelist(struct zoneref
*z
,
60 enum zone_type highest_zoneidx
,
65 * Find the next suitable zone to use for the allocation.
66 * Only filter based on nodemask if it's set
68 if (likely(nodes
== NULL
))
69 while (zonelist_zone_idx(z
) > highest_zoneidx
)
72 while (zonelist_zone_idx(z
) > highest_zoneidx
||
73 (z
->zone
&& !zref_in_nodemask(z
, nodes
)))
76 *zone
= zonelist_zone(z
);
80 #ifdef CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
81 int memmap_valid_within(unsigned long pfn
,
82 struct page
*page
, struct zone
*zone
)
84 if (page_to_pfn(page
) != pfn
)
87 if (page_zone(page
) != zone
)
92 #endif /* CONFIG_ARCH_HAS_HOLES_MEMORYMODEL */
94 void lruvec_init(struct lruvec
*lruvec
)
98 memset(lruvec
, 0, sizeof(struct lruvec
));
101 INIT_LIST_HEAD(&lruvec
->lists
[lru
]);
104 #if defined(CONFIG_NUMA_BALANCING) && !defined(LAST_NID_NOT_IN_PAGE_FLAGS)
105 int page_nid_xchg_last(struct page
*page
, int nid
)
107 unsigned long old_flags
, flags
;
111 old_flags
= flags
= page
->flags
;
112 last_nid
= page_nid_last(page
);
114 flags
&= ~(LAST_NID_MASK
<< LAST_NID_PGSHIFT
);
115 flags
|= (nid
& LAST_NID_MASK
) << LAST_NID_PGSHIFT
;
116 } while (unlikely(cmpxchg(&page
->flags
, old_flags
, flags
) != old_flags
));