mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-22 00:40:03 +00:00
![Christoph Lameter](/assets/img/avatar_default.png)
This patch modifies the way pagesets in struct zone are managed. Each zone has a per-cpu array of pagesets. So any particular CPU has some memory in each zone structure which belongs to itself. Even if that CPU is not local to that zone. So the patch relocates the pagesets for each cpu to the node that is nearest to the cpu instead of allocating the pagesets in the (possibly remote) target zone. This means that the operations to manage pages on remote zone can be done with information available locally. We play a macro trick so that non-NUMA pmachines avoid the additional pointer chase on the page allocator fastpath. AIM7 benchmark on a 32 CPU SGI Altix w/o patches: Tasks jobs/min jti jobs/min/task real cpu 1 484.68 100 484.6769 12.01 1.97 Fri Mar 25 11:01:42 2005 100 27140.46 89 271.4046 21.44 148.71 Fri Mar 25 11:02:04 2005 200 30792.02 82 153.9601 37.80 296.72 Fri Mar 25 11:02:42 2005 300 32209.27 81 107.3642 54.21 451.34 Fri Mar 25 11:03:37 2005 400 34962.83 78 87.4071 66.59 588.97 Fri Mar 25 11:04:44 2005 500 31676.92 75 63.3538 91.87 742.71 Fri Mar 25 11:06:16 2005 600 36032.69 73 60.0545 96.91 885.44 Fri Mar 25 11:07:54 2005 700 35540.43 77 50.7720 114.63 1024.28 Fri Mar 25 11:09:49 2005 800 33906.70 74 42.3834 137.32 1181.65 Fri Mar 25 11:12:06 2005 900 34120.67 73 37.9119 153.51 1325.26 Fri Mar 25 11:14:41 2005 1000 34802.37 74 34.8024 167.23 1465.26 Fri Mar 25 11:17:28 2005 with slab API changes and pageset patch: Tasks jobs/min jti jobs/min/task real cpu 1 485.00 100 485.0000 12.00 1.96 Fri Mar 25 11:46:18 2005 100 28000.96 89 280.0096 20.79 150.45 Fri Mar 25 11:46:39 2005 200 32285.80 79 161.4290 36.05 293.37 Fri Mar 25 11:47:16 2005 300 40424.15 84 134.7472 43.19 438.42 Fri Mar 25 11:47:59 2005 400 39155.01 79 97.8875 59.46 590.05 Fri Mar 25 11:48:59 2005 500 37881.25 82 75.7625 76.82 730.19 Fri Mar 25 11:50:16 2005 600 39083.14 78 65.1386 89.35 872.79 Fri Mar 25 11:51:46 2005 700 38627.83 77 55.1826 105.47 1022.46 Fri Mar 25 11:53:32 2005 800 39631.94 78 49.5399 117.48 1169.94 Fri Mar 25 11:55:30 2005 900 36903.70 79 41.0041 141.94 1310.78 Fri Mar 25 11:57:53 2005 1000 36201.23 77 36.2012 160.77 1458.31 Fri Mar 25 12:00:34 2005 Signed-off-by: Christoph Lameter <clameter@sgi.com> Signed-off-by: Shobhit Dayal <shobhit@calsoftinc.com> Signed-off-by: Shai Fultheim <Shai@Scalex86.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
443 lines
14 KiB
C
443 lines
14 KiB
C
#ifndef _LINUX_MMZONE_H
|
|
#define _LINUX_MMZONE_H
|
|
|
|
#ifdef __KERNEL__
|
|
#ifndef __ASSEMBLY__
|
|
|
|
#include <linux/config.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/list.h>
|
|
#include <linux/wait.h>
|
|
#include <linux/cache.h>
|
|
#include <linux/threads.h>
|
|
#include <linux/numa.h>
|
|
#include <linux/init.h>
|
|
#include <asm/atomic.h>
|
|
|
|
/* 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 nr_free;
|
|
};
|
|
|
|
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 {
|
|
char x[0];
|
|
} ____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;
|
|
|
|
#ifdef CONFIG_NUMA
|
|
#define zone_pcp(__z, __cpu) ((__z)->pageset[(__cpu)])
|
|
#else
|
|
#define zone_pcp(__z, __cpu) (&(__z)->pageset[(__cpu)])
|
|
#endif
|
|
|
|
#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)) */
|
|
|
|
|
|
/*
|
|
* When a memory allocation must conform to specific limitations (such
|
|
* as being suitable for DMA) the caller will pass in hints to the
|
|
* allocator in the gfp_mask, in the zone modifier bits. These bits
|
|
* are used to select a priority ordered list of memory zones which
|
|
* match the requested limits. GFP_ZONEMASK defines which bits within
|
|
* the gfp_mask should be considered as zone modifiers. Each valid
|
|
* combination of the zone modifier bits has a corresponding list
|
|
* of zones (in node_zonelists). Thus for two zone modifiers there
|
|
* will be a maximum of 4 (2 ** 2) zonelists, for 3 modifiers there will
|
|
* be 8 (2 ** 3) zonelists. GFP_ZONETYPES defines the number of possible
|
|
* combinations of zone modifiers in "zone modifier space".
|
|
*/
|
|
#define GFP_ZONEMASK 0x03
|
|
/*
|
|
* As an optimisation any zone modifier bits which are only valid when
|
|
* no other zone modifier bits are set (loners) should be placed in
|
|
* the highest order bits of this field. This allows us to reduce the
|
|
* extent of the zonelists thus saving space. For example in the case
|
|
* of three zone modifier bits, we could require up to eight zonelists.
|
|
* If the left most zone modifier is a "loner" then the highest valid
|
|
* zonelist would be four allowing us to allocate only five zonelists.
|
|
* Use the first form when the left most bit is not a "loner", otherwise
|
|
* use the second.
|
|
*/
|
|
/* #define GFP_ZONETYPES (GFP_ZONEMASK + 1) */ /* Non-loner */
|
|
#define GFP_ZONETYPES ((GFP_ZONEMASK + 1) / 2 + 1) /* Loner */
|
|
|
|
/*
|
|
* 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 {
|
|
/* Fields commonly accessed by the page allocator */
|
|
unsigned long free_pages;
|
|
unsigned long pages_min, pages_low, pages_high;
|
|
/*
|
|
* We don't know if the memory that we're going to allocate will be freeable
|
|
* or/and it will be released eventually, so to avoid totally wasting several
|
|
* GB of ram we must reserve some of the lower zone memory (otherwise we risk
|
|
* to run OOM on the lower zones despite there's tons of freeable ram
|
|
* on the higher zones). This array is recalculated at runtime if the
|
|
* sysctl_lowmem_reserve_ratio sysctl changes.
|
|
*/
|
|
unsigned long lowmem_reserve[MAX_NR_ZONES];
|
|
|
|
#ifdef CONFIG_NUMA
|
|
struct per_cpu_pageset *pageset[NR_CPUS];
|
|
#else
|
|
struct per_cpu_pageset pageset[NR_CPUS];
|
|
#endif
|
|
/*
|
|
* free areas of different sizes
|
|
*/
|
|
spinlock_t lock;
|
|
struct free_area free_area[MAX_ORDER];
|
|
|
|
|
|
ZONE_PADDING(_pad1_)
|
|
|
|
/* Fields commonly accessed by the page reclaim scanner */
|
|
spinlock_t lru_lock;
|
|
struct list_head active_list;
|
|
struct list_head inactive_list;
|
|
unsigned long nr_scan_active;
|
|
unsigned long nr_scan_inactive;
|
|
unsigned long nr_active;
|
|
unsigned long nr_inactive;
|
|
unsigned long pages_scanned; /* since last reclaim */
|
|
int all_unreclaimable; /* All pages pinned */
|
|
|
|
/*
|
|
* Does the allocator try to reclaim pages from the zone as soon
|
|
* as it fails a watermark_ok() in __alloc_pages?
|
|
*/
|
|
int reclaim_pages;
|
|
/* A count of how many reclaimers are scanning this zone */
|
|
atomic_t reclaim_in_progress;
|
|
|
|
/*
|
|
* prev_priority holds the scanning priority for this zone. It is
|
|
* defined as the scanning priority at which we achieved our reclaim
|
|
* target at the previous try_to_free_pages() or balance_pgdat()
|
|
* invokation.
|
|
*
|
|
* We use prev_priority as a measure of how much stress page reclaim is
|
|
* under - it drives the swappiness decision: whether to unmap mapped
|
|
* pages.
|
|
*
|
|
* temp_priority is used to remember the scanning priority at which
|
|
* this zone was successfully refilled to free_pages == pages_high.
|
|
*
|
|
* Access to both these fields is quite racy even on uniprocessor. But
|
|
* it is expected to average out OK.
|
|
*/
|
|
int temp_priority;
|
|
int prev_priority;
|
|
|
|
|
|
ZONE_PADDING(_pad2_)
|
|
/* Rarely used or read-mostly fields */
|
|
|
|
/*
|
|
* wait_table -- the array holding the hash table
|
|
* wait_table_size -- the size of the hash table array
|
|
* wait_table_bits -- wait_table_size == (1 << wait_table_bits)
|
|
*
|
|
* The purpose of all these is to keep track of the people
|
|
* waiting for a page to become available and make them
|
|
* runnable again when possible. The trouble is that this
|
|
* consumes a lot of space, especially when so few things
|
|
* wait on pages at a given time. So instead of using
|
|
* per-page waitqueues, we use a waitqueue hash table.
|
|
*
|
|
* The bucket discipline is to sleep on the same queue when
|
|
* colliding and wake all in that wait queue when removing.
|
|
* When something wakes, it must check to be sure its page is
|
|
* truly available, a la thundering herd. The cost of a
|
|
* collision is great, but given the expected load of the
|
|
* table, they should be so rare as to be outweighed by the
|
|
* benefits from the saved space.
|
|
*
|
|
* __wait_on_page_locked() and unlock_page() in mm/filemap.c, are the
|
|
* primary users of these fields, and in mm/page_alloc.c
|
|
* free_area_init_core() performs the initialization of them.
|
|
*/
|
|
wait_queue_head_t * wait_table;
|
|
unsigned long wait_table_size;
|
|
unsigned long wait_table_bits;
|
|
|
|
/*
|
|
* Discontig memory support fields.
|
|
*/
|
|
struct pglist_data *zone_pgdat;
|
|
struct page *zone_mem_map;
|
|
/* zone_start_pfn == zone_start_paddr >> PAGE_SHIFT */
|
|
unsigned long zone_start_pfn;
|
|
|
|
unsigned long spanned_pages; /* total size, including holes */
|
|
unsigned long present_pages; /* amount of memory (excluding holes) */
|
|
|
|
/*
|
|
* rarely used fields:
|
|
*/
|
|
char *name;
|
|
} ____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[GFP_ZONETYPES];
|
|
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;
|
|
int kswapd_max_order;
|
|
} 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 struct pglist_data *pgdat_list;
|
|
|
|
void __get_zone_counts(unsigned long *active, unsigned long *inactive,
|
|
unsigned long *free, struct pglist_data *pgdat);
|
|
void get_zone_counts(unsigned long *active, unsigned long *inactive,
|
|
unsigned long *free);
|
|
void build_all_zonelists(void);
|
|
void wakeup_kswapd(struct zone *zone, int order);
|
|
int zone_watermark_ok(struct zone *z, int order, unsigned long mark,
|
|
int alloc_type, int can_try_harder, int gfp_high);
|
|
|
|
#ifdef CONFIG_HAVE_MEMORY_PRESENT
|
|
void memory_present(int nid, unsigned long start, unsigned long end);
|
|
#else
|
|
static inline void memory_present(int nid, unsigned long start, unsigned long end) {}
|
|
#endif
|
|
|
|
#ifdef CONFIG_NEED_NODE_MEMMAP_SIZE
|
|
unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long);
|
|
#endif
|
|
|
|
/*
|
|
* 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))
|
|
|
|
static inline int is_highmem_idx(int idx)
|
|
{
|
|
return (idx == ZONE_HIGHMEM);
|
|
}
|
|
|
|
static inline int is_normal_idx(int idx)
|
|
{
|
|
return (idx == ZONE_NORMAL);
|
|
}
|
|
/**
|
|
* 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 *, loff_t *);
|
|
extern int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1];
|
|
int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *, int, struct file *,
|
|
void __user *, size_t *, loff_t *);
|
|
|
|
#include <linux/topology.h>
|
|
/* Returns the number of the current Node. */
|
|
#define numa_node_id() (cpu_to_node(raw_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 <asm/mmzone.h>
|
|
|
|
#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
|
|
|
|
#endif /* !__ASSEMBLY__ */
|
|
#endif /* __KERNEL__ */
|
|
#endif /* _LINUX_MMZONE_H */
|