Merge tag 'v3.10.68' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / mm / mmzone.c
CommitLineData
95144c78
KH
1/*
2 * linux/mm/mmzone.c
3 *
4468b8f1 4 * management codes for pgdats, zones and page flags
95144c78
KH
5 */
6
7
95144c78 8#include <linux/stddef.h>
eb33575c 9#include <linux/mm.h>
95144c78 10#include <linux/mmzone.h>
6fa3eb70 11#include <linux/export.h>
95144c78
KH
12
13struct pglist_data *first_online_pgdat(void)
14{
15 return NODE_DATA(first_online_node);
16}
6fa3eb70 17EXPORT_SYMBOL_GPL(first_online_pgdat);
95144c78 18
95144c78
KH
19struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
20{
21 int nid = next_online_node(pgdat->node_id);
22
23 if (nid == MAX_NUMNODES)
24 return NULL;
25 return NODE_DATA(nid);
26}
6fa3eb70 27EXPORT_SYMBOL_GPL(next_online_pgdat);
95144c78
KH
28
29/*
30 * next_zone - helper magic for for_each_zone()
31 */
32struct zone *next_zone(struct zone *zone)
33{
34 pg_data_t *pgdat = zone->zone_pgdat;
35
36 if (zone < pgdat->node_zones + MAX_NR_ZONES - 1)
37 zone++;
38 else {
39 pgdat = next_online_pgdat(pgdat);
40 if (pgdat)
41 zone = pgdat->node_zones;
42 else
43 zone = NULL;
44 }
45 return zone;
46}
6fa3eb70 47EXPORT_SYMBOL_GPL(next_zone);
95144c78 48
19770b32
MG
49static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes)
50{
51#ifdef CONFIG_NUMA
52 return node_isset(zonelist_node_idx(zref), *nodes);
53#else
54 return 1;
55#endif /* CONFIG_NUMA */
56}
57
58/* Returns the next zone at or below highest_zoneidx in a zonelist */
59struct zoneref *next_zones_zonelist(struct zoneref *z,
60 enum zone_type highest_zoneidx,
61 nodemask_t *nodes,
62 struct zone **zone)
63{
64 /*
65 * Find the next suitable zone to use for the allocation.
66 * Only filter based on nodemask if it's set
67 */
68 if (likely(nodes == NULL))
69 while (zonelist_zone_idx(z) > highest_zoneidx)
70 z++;
71 else
72 while (zonelist_zone_idx(z) > highest_zoneidx ||
73 (z->zone && !zref_in_nodemask(z, nodes)))
74 z++;
75
5bead2a0 76 *zone = zonelist_zone(z);
19770b32
MG
77 return z;
78}
eb33575c
MG
79
80#ifdef CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
81int memmap_valid_within(unsigned long pfn,
82 struct page *page, struct zone *zone)
83{
84 if (page_to_pfn(page) != pfn)
85 return 0;
86
87 if (page_zone(page) != zone)
88 return 0;
89
90 return 1;
91}
92#endif /* CONFIG_ARCH_HAS_HOLES_MEMORYMODEL */
7f5e86c2 93
bea8c150 94void lruvec_init(struct lruvec *lruvec)
7f5e86c2
KK
95{
96 enum lru_list lru;
97
98 memset(lruvec, 0, sizeof(struct lruvec));
99
100 for_each_lru(lru)
101 INIT_LIST_HEAD(&lruvec->lists[lru]);
7f5e86c2 102}
4468b8f1
MG
103
104#if defined(CONFIG_NUMA_BALANCING) && !defined(LAST_NID_NOT_IN_PAGE_FLAGS)
22b751c3 105int page_nid_xchg_last(struct page *page, int nid)
4468b8f1
MG
106{
107 unsigned long old_flags, flags;
108 int last_nid;
109
110 do {
111 old_flags = flags = page->flags;
22b751c3 112 last_nid = page_nid_last(page);
4468b8f1
MG
113
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));
117
118 return last_nid;
119}
120#endif