import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / mm / mmzone.c
1 /*
2 * linux/mm/mmzone.c
3 *
4 * management codes for pgdats, zones and page flags
5 */
6
7
8 #include <linux/stddef.h>
9 #include <linux/mm.h>
10 #include <linux/mmzone.h>
11 #include <linux/export.h>
12
13 struct pglist_data *first_online_pgdat(void)
14 {
15 return NODE_DATA(first_online_node);
16 }
17 EXPORT_SYMBOL_GPL(first_online_pgdat);
18
19 struct 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 }
27 EXPORT_SYMBOL_GPL(next_online_pgdat);
28
29 /*
30 * next_zone - helper magic for for_each_zone()
31 */
32 struct 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 }
47 EXPORT_SYMBOL_GPL(next_zone);
48
49 static 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 */
59 struct 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
76 *zone = zonelist_zone(z);
77 return z;
78 }
79
80 #ifdef CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
81 int 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 */
93
94 void lruvec_init(struct lruvec *lruvec)
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]);
102 }
103
104 #if defined(CONFIG_NUMA_BALANCING) && !defined(LAST_NID_NOT_IN_PAGE_FLAGS)
105 int page_nid_xchg_last(struct page *page, int nid)
106 {
107 unsigned long old_flags, flags;
108 int last_nid;
109
110 do {
111 old_flags = flags = page->flags;
112 last_nid = page_nid_last(page);
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