#ifndef _LINUX_MMZONE_H #define _LINUX_MMZONE_H #ifdef __KERNEL__ #ifndef __ASSEMBLY__ #include #include #include #include #include #include #include #include /* Free memory management - zoned buddy allocator. */ #ifndef CONFIG_FORCE_MAX_ZONEORDER #define MAX_ORDER 11 #else #define MAX_ORDER CONFIG_FORCE_MAX_ZONEORDER #endif struct free_area { struct list_head free_list; unsigned long *map; }; struct pglist_data; /* * zone->lock and zone->lru_lock are two of the hottest locks in the kernel. * So add a wild amount of padding here to ensure that they fall into separate * cachelines. There are very few zone structures in the machine, so space * consumption is not a concern here. */ #if defined(CONFIG_SMP) struct zone_padding { int x; } ____cacheline_maxaligned_in_smp; #define ZONE_PADDING(name) struct zone_padding name; #else #define ZONE_PADDING(name) #endif struct per_cpu_pages { int count; /* number of pages in the list */ int low; /* low watermark, refill needed */ int high; /* high watermark, emptying needed */ int batch; /* chunk size for buddy add/remove */ struct list_head list; /* the list of pages */ }; struct per_cpu_pageset { struct per_cpu_pages pcp[2]; /* 0: hot. 1: cold */ #ifdef CONFIG_NUMA unsigned long numa_hit; /* allocated in intended node */ unsigned long numa_miss; /* allocated in non intended node */ unsigned long numa_foreign; /* was intended here, hit elsewhere */ unsigned long interleave_hit; /* interleaver prefered this zone */ unsigned long local_node; /* allocation from local node */ unsigned long other_node; /* allocation from other node */ #endif } ____cacheline_aligned_in_smp; #define ZONE_DMA 0 #define ZONE_NORMAL 1 #define ZONE_HIGHMEM 2 #define MAX_NR_ZONES 3 /* Sync this with ZONES_SHIFT */ #define ZONES_SHIFT 2 /* ceil(log2(MAX_NR_ZONES)) */ #define GFP_ZONEMASK 0x03 /* * On machines where it is needed (eg PCs) we divide physical memory * into multiple physical zones. On a PC we have 3 zones: * * ZONE_DMA < 16 MB ISA DMA capable memory * ZONE_NORMAL 16-896 MB direct mapped by the kernel * ZONE_HIGHMEM > 896 MB only page cache and user processes */ struct zone { /* * Commonly accessed fields: */ spinlock_t lock; unsigned long free_pages; unsigned long pages_min, pages_low, pages_high; /* * protection[] is a pre-calculated number of extra pages that must be * available in a zone in order for __alloc_pages() to allocate memory * from the zone. i.e., for a GFP_KERNEL alloc of "order" there must * be "(1<> PAGE_SHIFT */ unsigned long zone_start_pfn; /* * rarely used fields: */ char *name; unsigned long spanned_pages; /* total size, including holes */ unsigned long present_pages; /* amount of memory (excluding holes) */ } ____cacheline_maxaligned_in_smp; /* * The "priority" of VM scanning is how much of the queues we will scan in one * go. A value of 12 for DEF_PRIORITY implies that we will scan 1/4096th of the * queues ("queue_length >> 12") during an aging round. */ #define DEF_PRIORITY 12 /* * One allocation request operates on a zonelist. A zonelist * is a list of zones, the first one is the 'goal' of the * allocation, the other zones are fallback zones, in decreasing * priority. * * Right now a zonelist takes up less than a cacheline. We never * modify it apart from boot-up, and only a few indices are used, * so despite the zonelist table being relatively big, the cache * footprint of this construct is very small. */ struct zonelist { struct zone *zones[MAX_NUMNODES * MAX_NR_ZONES + 1]; // NULL delimited }; /* * The pg_data_t structure is used in machines with CONFIG_DISCONTIGMEM * (mostly NUMA machines?) to denote a higher-level memory zone than the * zone denotes. * * On NUMA machines, each NUMA node would have a pg_data_t to describe * it's memory layout. * * Memory statistics and page replacement data structures are maintained on a * per-zone basis. */ struct bootmem_data; typedef struct pglist_data { struct zone node_zones[MAX_NR_ZONES]; struct zonelist node_zonelists[MAX_NR_ZONES]; int nr_zones; struct page *node_mem_map; struct bootmem_data *bdata; unsigned long node_start_pfn; unsigned long node_present_pages; /* total number of physical pages */ unsigned long node_spanned_pages; /* total size of physical page range, including holes */ int node_id; struct pglist_data *pgdat_next; wait_queue_head_t kswapd_wait; struct task_struct *kswapd; } pg_data_t; #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) #define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages) extern int numnodes; extern struct pglist_data *pgdat_list; void get_zone_counts(unsigned long *active, unsigned long *inactive, unsigned long *free); void build_all_zonelists(void); void wakeup_kswapd(struct zone *zone); /* * zone_idx() returns 0 for the ZONE_DMA zone, 1 for the ZONE_NORMAL zone, etc. */ #define zone_idx(zone) ((zone) - (zone)->zone_pgdat->node_zones) /** * for_each_pgdat - helper macro to iterate over all nodes * @pgdat - pointer to a pg_data_t variable * * Meant to help with common loops of the form * pgdat = pgdat_list; * while(pgdat) { * ... * pgdat = pgdat->pgdat_next; * } */ #define for_each_pgdat(pgdat) \ for (pgdat = pgdat_list; pgdat; pgdat = pgdat->pgdat_next) /* * next_zone - helper magic for for_each_zone() * Thanks to William Lee Irwin III for this piece of ingenuity. */ static inline struct zone *next_zone(struct zone *zone) { pg_data_t *pgdat = zone->zone_pgdat; if (zone - pgdat->node_zones < MAX_NR_ZONES - 1) zone++; else if (pgdat->pgdat_next) { pgdat = pgdat->pgdat_next; zone = pgdat->node_zones; } else zone = NULL; return zone; } /** * for_each_zone - helper macro to iterate over all memory zones * @zone - pointer to struct zone variable * * The user only needs to declare the zone variable, for_each_zone * fills it in. This basically means for_each_zone() is an * easier to read version of this piece of code: * * for (pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next) * for (i = 0; i < MAX_NR_ZONES; ++i) { * struct zone * z = pgdat->node_zones + i; * ... * } * } */ #define for_each_zone(zone) \ for (zone = pgdat_list->node_zones; zone; zone = next_zone(zone)) /** * is_highmem - helper function to quickly check if a struct zone is a * highmem zone or not. This is an attempt to keep references * to ZONE_{DMA/NORMAL/HIGHMEM/etc} in general code to a minimum. * @zone - pointer to struct zone variable */ static inline int is_highmem(struct zone *zone) { return (zone - zone->zone_pgdat->node_zones == ZONE_HIGHMEM); } static inline int is_normal(struct zone *zone) { return (zone - zone->zone_pgdat->node_zones == ZONE_NORMAL); } /* These two functions are used to setup the per zone pages min values */ struct ctl_table; struct file; int min_free_kbytes_sysctl_handler(struct ctl_table *, int, struct file *, void __user *, size_t *); int lower_zone_protection_sysctl_handler(struct ctl_table *, int, struct file *, void __user *, size_t *); #include /* Returns the number of the current Node. */ #define numa_node_id() (cpu_to_node(smp_processor_id())) #ifndef CONFIG_DISCONTIGMEM extern struct pglist_data contig_page_data; #define NODE_DATA(nid) (&contig_page_data) #define NODE_MEM_MAP(nid) mem_map #define MAX_NODES_SHIFT 1 #define pfn_to_nid(pfn) (0) #else /* CONFIG_DISCONTIGMEM */ #include #if BITS_PER_LONG == 32 || defined(ARCH_HAS_ATOMIC_UNSIGNED) /* * with 32 bit page->flags field, we reserve 8 bits for node/zone info. * there are 3 zones (2 bits) and this leaves 8-2=6 bits for nodes. */ #define MAX_NODES_SHIFT 6 #elif BITS_PER_LONG == 64 /* * with 64 bit flags field, there's plenty of room. */ #define MAX_NODES_SHIFT 10 #endif #endif /* !CONFIG_DISCONTIGMEM */ #if NODES_SHIFT > MAX_NODES_SHIFT #error NODES_SHIFT > MAX_NODES_SHIFT #endif /* There are currently 3 zones: DMA, Normal & Highmem, thus we need 2 bits */ #define MAX_ZONES_SHIFT 2 #if ZONES_SHIFT > MAX_ZONES_SHIFT #error ZONES_SHIFT > MAX_ZONES_SHIFT #endif extern DECLARE_BITMAP(node_online_map, MAX_NUMNODES); #if defined(CONFIG_DISCONTIGMEM) || defined(CONFIG_NUMA) #define node_online(node) test_bit(node, node_online_map) #define node_set_online(node) set_bit(node, node_online_map) #define node_set_offline(node) clear_bit(node, node_online_map) static inline unsigned int num_online_nodes(void) { int i, num = 0; for(i = 0; i < MAX_NUMNODES; i++){ if (node_online(i)) num++; } return num; } #else /* !CONFIG_DISCONTIGMEM && !CONFIG_NUMA */ #define node_online(node) \ ({ BUG_ON((node) != 0); test_bit(node, node_online_map); }) #define node_set_online(node) \ ({ BUG_ON((node) != 0); set_bit(node, node_online_map); }) #define node_set_offline(node) \ ({ BUG_ON((node) != 0); clear_bit(node, node_online_map); }) #define num_online_nodes() 1 #endif /* CONFIG_DISCONTIGMEM || CONFIG_NUMA */ #endif /* !__ASSEMBLY__ */ #endif /* __KERNEL__ */ #endif /* _LINUX_MMZONE_H */