Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | /* * linux/mm/swap.c * * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds */ /* * This file contains the default values for the opereation of the * Linux VM subsystem. Fine-tuning documentation can be found in * linux/Documentation/sysctl/vm.txt. * Started 18.12.91 * Swap aging added 23.2.95, Stephen Tweedie. * Buffermem limits added 12.3.98, Rik van Riel. */ #include <linux/mm.h> #include <linux/kernel_stat.h> #include <linux/swap.h> #include <linux/swapctl.h> #include <linux/pagemap.h> #include <linux/init.h> #include <asm/dma.h> #include <asm/uaccess.h> /* for copy_to/from_user */ #include <asm/pgtable.h> /* How many pages do we try to swap or page in/out together? */ int page_cluster; pager_daemon_t pager_daemon = { 512, /* base number for calculating the number of tries */ SWAP_CLUSTER_MAX, /* minimum number of tries */ 8, /* do swap I/O in clusters of this size */ }; /* * Move an inactive page to the active list. */ static inline void activate_page_nolock(struct page * page) { if (PageLRU(page) && !PageActive(page)) { del_page_from_inactive_list(page); add_page_to_active_list(page); } } void activate_page(struct page * page) { spin_lock(&pagemap_lru_lock); activate_page_nolock(page); spin_unlock(&pagemap_lru_lock); } /** * lru_cache_add: add a page to the page lists * @page: the page to add */ void lru_cache_add(struct page * page) { if (!PageLRU(page)) { spin_lock(&pagemap_lru_lock); if (!TestSetPageLRU(page)) add_page_to_inactive_list(page); spin_unlock(&pagemap_lru_lock); } } /** * __lru_cache_del: remove a page from the page lists * @page: the page to add * * This function is for when the caller already holds * the pagemap_lru_lock. */ void __lru_cache_del(struct page * page) { if (TestClearPageLRU(page)) { if (PageActive(page)) { del_page_from_active_list(page); } else { del_page_from_inactive_list(page); } } } /** * lru_cache_del: remove a page from the page lists * @page: the page to remove */ void lru_cache_del(struct page * page) { spin_lock(&pagemap_lru_lock); __lru_cache_del(page); spin_unlock(&pagemap_lru_lock); } /** * delta_nr_active_pages: alter the number of active pages. * * @page: the page which is being activated/deactivated * @delta: +1 for activation, -1 for deactivation * * Called under pagecache_lock */ void delta_nr_active_pages(struct page *page, long delta) { pg_data_t *pgdat; zone_t *classzone, *overflow; classzone = page_zone(page); pgdat = classzone->zone_pgdat; overflow = pgdat->node_zones + pgdat->nr_zones; while (classzone < overflow) { classzone->nr_active_pages += delta; classzone++; } nr_active_pages += delta; } /** * delta_nr_inactive_pages: alter the number of inactive pages. * * @page: the page which is being deactivated/activated * @delta: +1 for deactivation, -1 for activation * * Called under pagecache_lock */ void delta_nr_inactive_pages(struct page *page, long delta) { pg_data_t *pgdat; zone_t *classzone, *overflow; classzone = page_zone(page); pgdat = classzone->zone_pgdat; overflow = pgdat->node_zones + pgdat->nr_zones; while (classzone < overflow) { classzone->nr_inactive_pages += delta; classzone++; } nr_inactive_pages += delta; } /** * delta_nr_cache_pages: alter the number of pages in the pagecache * * @page: the page which is being added/removed * @delta: +1 for addition, -1 for removal * * Called under pagecache_lock */ void delta_nr_cache_pages(struct page *page, long delta) { pg_data_t *pgdat; zone_t *classzone, *overflow; classzone = page_zone(page); pgdat = classzone->zone_pgdat; overflow = pgdat->node_zones + pgdat->nr_zones; while (classzone < overflow) { classzone->nr_cache_pages += delta; classzone++; } page_cache_size += delta; } /* * Perform any setup for the swap system */ void __init swap_setup(void) { unsigned long megs = num_physpages >> (20 - PAGE_SHIFT); /* Use a smaller cluster for small-memory machines */ if (megs < 16) page_cluster = 2; else page_cluster = 3; /* * Right now other parts of the system means that we * _really_ don't want to cluster much more */ } |