mmzone.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * linux/mm/mmzone.c
  3. *
  4. * management codes for pgdats and zones.
  5. */
  6. #include <linux/stddef.h>
  7. #include <linux/mm.h>
  8. #include <linux/mmzone.h>
  9. struct pglist_data *first_online_pgdat(void)
  10. {
  11. return NODE_DATA(first_online_node);
  12. }
  13. struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
  14. {
  15. int nid = next_online_node(pgdat->node_id);
  16. if (nid == MAX_NUMNODES)
  17. return NULL;
  18. return NODE_DATA(nid);
  19. }
  20. /*
  21. * next_zone - helper magic for for_each_zone()
  22. */
  23. struct zone *next_zone(struct zone *zone)
  24. {
  25. pg_data_t *pgdat = zone->zone_pgdat;
  26. if (zone < pgdat->node_zones + MAX_NR_ZONES - 1)
  27. zone++;
  28. else {
  29. pgdat = next_online_pgdat(pgdat);
  30. if (pgdat)
  31. zone = pgdat->node_zones;
  32. else
  33. zone = NULL;
  34. }
  35. return zone;
  36. }
  37. static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes)
  38. {
  39. #ifdef CONFIG_NUMA
  40. return node_isset(zonelist_node_idx(zref), *nodes);
  41. #else
  42. return 1;
  43. #endif /* CONFIG_NUMA */
  44. }
  45. /* Returns the next zone at or below highest_zoneidx in a zonelist */
  46. struct zoneref *next_zones_zonelist(struct zoneref *z,
  47. enum zone_type highest_zoneidx,
  48. nodemask_t *nodes,
  49. struct zone **zone)
  50. {
  51. /*
  52. * Find the next suitable zone to use for the allocation.
  53. * Only filter based on nodemask if it's set
  54. */
  55. if (likely(nodes == NULL))
  56. while (zonelist_zone_idx(z) > highest_zoneidx)
  57. z++;
  58. else
  59. while (zonelist_zone_idx(z) > highest_zoneidx ||
  60. (z->zone && !zref_in_nodemask(z, nodes)))
  61. z++;
  62. *zone = zonelist_zone(z);
  63. return z;
  64. }
  65. #ifdef CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
  66. int memmap_valid_within(unsigned long pfn,
  67. struct page *page, struct zone *zone)
  68. {
  69. if (page_to_pfn(page) != pfn)
  70. return 0;
  71. if (page_zone(page) != zone)
  72. return 0;
  73. return 1;
  74. }
  75. #endif /* CONFIG_ARCH_HAS_HOLES_MEMORYMODEL */