mm: access zone->node via zone_to_nid() and zone_set_nid()
authorPavel Tatashin <pasha.tatashin@oracle.com>
Wed, 22 Aug 2018 04:53:32 +0000 (21:53 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 22 Aug 2018 17:52:45 +0000 (10:52 -0700)
zone->node is configured only when CONFIG_NUMA=y, so it is a good idea to
have inline functions to access this field in order to avoid ifdef's in c
files.

Link: http://lkml.kernel.org/r/20180730101757.28058-3-osalvador@techadventures.net
Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Aaron Lu <aaron.lu@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Pasha Tatashin <Pavel.Tatashin@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/mm.h
include/linux/mmzone.h
mm/mempolicy.c
mm/mm_init.c
mm/page_alloc.c

index 3a4b87d1a59abc2fa911b8d8e108f7d653d192ca..a55f5389c491b8184a0fba53bdc9ffdb1f01eed9 100644 (file)
@@ -960,15 +960,6 @@ static inline int page_zone_id(struct page *page)
        return (page->flags >> ZONEID_PGSHIFT) & ZONEID_MASK;
 }
 
-static inline int zone_to_nid(struct zone *zone)
-{
-#ifdef CONFIG_NUMA
-       return zone->node;
-#else
-       return 0;
-#endif
-}
-
 #ifdef NODE_NOT_IN_PAGE_FLAGS
 extern int page_to_nid(const struct page *page);
 #else
index 3d4577a3ae7e5fa23d3db1a3a8f6ebd91395fc82..1e22d96734e0099476b18d14ca7c11a991d3a470 100644 (file)
@@ -834,6 +834,25 @@ static inline bool populated_zone(struct zone *zone)
        return zone->present_pages;
 }
 
+#ifdef CONFIG_NUMA
+static inline int zone_to_nid(struct zone *zone)
+{
+       return zone->node;
+}
+
+static inline void zone_set_nid(struct zone *zone, int nid)
+{
+       zone->node = nid;
+}
+#else
+static inline int zone_to_nid(struct zone *zone)
+{
+       return 0;
+}
+
+static inline void zone_set_nid(struct zone *zone, int nid) {}
+#endif
+
 extern int movable_zone;
 
 #ifdef CONFIG_HIGHMEM
@@ -949,12 +968,7 @@ static inline int zonelist_zone_idx(struct zoneref *zoneref)
 
 static inline int zonelist_node_idx(struct zoneref *zoneref)
 {
-#ifdef CONFIG_NUMA
-       /* zone_to_nid not available in this context */
-       return zoneref->zone->node;
-#else
-       return 0;
-#endif /* CONFIG_NUMA */
+       return zone_to_nid(zoneref->zone);
 }
 
 struct zoneref *__next_zones_zonelist(struct zoneref *z,
index 4861ba738d6fc672903b633375765e54dda8916c..da858f794eb694a934afb58da49f749343ed8c08 100644 (file)
@@ -1784,7 +1784,7 @@ unsigned int mempolicy_slab_node(void)
                zonelist = &NODE_DATA(node)->node_zonelists[ZONELIST_FALLBACK];
                z = first_zones_zonelist(zonelist, highest_zoneidx,
                                                        &policy->v.nodes);
-               return z->zone ? z->zone->node : node;
+               return z->zone ? zone_to_nid(z->zone) : node;
        }
 
        default:
@@ -2326,7 +2326,7 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
                                node_zonelist(numa_node_id(), GFP_HIGHUSER),
                                gfp_zone(GFP_HIGHUSER),
                                &pol->v.nodes);
-               polnid = z->zone->node;
+               polnid = zone_to_nid(z->zone);
                break;
 
        default:
index 5b72266b4b03362ebb792ccbbfbf9b84e30c1702..6838a530789b414bcda3a2fca71747d067760118 100644 (file)
@@ -53,13 +53,8 @@ void __init mminit_verify_zonelist(void)
                                zone->name);
 
                        /* Iterate the zonelist */
-                       for_each_zone_zonelist(zone, z, zonelist, zoneid) {
-#ifdef CONFIG_NUMA
-                               pr_cont("%d:%s ", zone->node, zone->name);
-#else
-                               pr_cont("0:%s ", zone->name);
-#endif /* CONFIG_NUMA */
-                       }
+                       for_each_zone_zonelist(zone, z, zonelist, zoneid)
+                               pr_cont("%d:%s ", zone_to_nid(zone), zone->name);
                        pr_cont("\n");
                }
        }
index 455cc3bfae9991347ecfbd1f36d1f9ff4dc30e95..6b2324bc61dbaa7e58e972f255e139687d789010 100644 (file)
@@ -2909,10 +2909,10 @@ static inline void zone_statistics(struct zone *preferred_zone, struct zone *z)
        if (!static_branch_likely(&vm_numa_stat_key))
                return;
 
-       if (z->node != numa_node_id())
+       if (zone_to_nid(z) != numa_node_id())
                local_stat = NUMA_OTHER;
 
-       if (z->node == preferred_zone->node)
+       if (zone_to_nid(z) == zone_to_nid(preferred_zone))
                __inc_numa_state(z, NUMA_HIT);
        else {
                __inc_numa_state(z, NUMA_MISS);
@@ -5278,7 +5278,7 @@ int local_memory_node(int node)
        z = first_zones_zonelist(node_zonelist(node, GFP_KERNEL),
                                   gfp_zone(GFP_KERNEL),
                                   NULL);
-       return z->zone->node;
+       return zone_to_nid(z->zone);
 }
 #endif
 
@@ -6299,9 +6299,7 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)
                 * And all highmem pages will be managed by the buddy system.
                 */
                zone->managed_pages = freesize;
-#ifdef CONFIG_NUMA
-               zone->node = nid;
-#endif
+               zone_set_nid(zone, nid);
                zone->name = zone_names[j];
                zone->zone_pgdat = pgdat;
                spin_lock_init(&zone->lock);