mmzone.c 1.8 KB

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