Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/mm/memory_hotplug.c |
| 3 | * |
| 4 | * Copyright (C) |
| 5 | */ |
| 6 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 7 | #include <linux/stddef.h> |
| 8 | #include <linux/mm.h> |
| 9 | #include <linux/swap.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/pagemap.h> |
| 12 | #include <linux/bootmem.h> |
| 13 | #include <linux/compiler.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/pagevec.h> |
Chandra Seetharaman | 2d1d43f | 2006-09-29 02:01:25 -0700 | [diff] [blame] | 16 | #include <linux/writeback.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 17 | #include <linux/slab.h> |
| 18 | #include <linux/sysctl.h> |
| 19 | #include <linux/cpu.h> |
| 20 | #include <linux/memory.h> |
| 21 | #include <linux/memory_hotplug.h> |
| 22 | #include <linux/highmem.h> |
| 23 | #include <linux/vmalloc.h> |
KAMEZAWA Hiroyuki | 0a54703 | 2006-06-27 02:53:35 -0700 | [diff] [blame] | 24 | #include <linux/ioport.h> |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> |
| 26 | #include <linux/migrate.h> |
| 27 | #include <linux/page-isolation.h> |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 28 | #include <linux/pfn.h> |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 29 | #include <linux/suspend.h> |
KOSAKI Motohiro | 6d9c285 | 2009-12-14 17:58:11 -0800 | [diff] [blame] | 30 | #include <linux/mm_inline.h> |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 31 | #include <linux/firmware-map.h> |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 32 | |
| 33 | #include <asm/tlbflush.h> |
| 34 | |
Adrian Bunk | 1e5ad9a | 2008-04-28 20:40:08 +0300 | [diff] [blame] | 35 | #include "internal.h" |
| 36 | |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 37 | DEFINE_MUTEX(mem_hotplug_mutex); |
| 38 | |
| 39 | void lock_memory_hotplug(void) |
| 40 | { |
| 41 | mutex_lock(&mem_hotplug_mutex); |
| 42 | |
| 43 | /* for exclusive hibernation if CONFIG_HIBERNATION=y */ |
| 44 | lock_system_sleep(); |
| 45 | } |
| 46 | |
| 47 | void unlock_memory_hotplug(void) |
| 48 | { |
| 49 | unlock_system_sleep(); |
| 50 | mutex_unlock(&mem_hotplug_mutex); |
| 51 | } |
| 52 | |
| 53 | |
Keith Mannthey | 45e0b78 | 2006-09-30 23:27:09 -0700 | [diff] [blame] | 54 | /* add this memory to iomem resource */ |
| 55 | static struct resource *register_memory_resource(u64 start, u64 size) |
| 56 | { |
| 57 | struct resource *res; |
| 58 | res = kzalloc(sizeof(struct resource), GFP_KERNEL); |
| 59 | BUG_ON(!res); |
| 60 | |
| 61 | res->name = "System RAM"; |
| 62 | res->start = start; |
| 63 | res->end = start + size - 1; |
Yasunori Goto | 887c3cb | 2007-11-14 16:59:20 -0800 | [diff] [blame] | 64 | res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
Keith Mannthey | 45e0b78 | 2006-09-30 23:27:09 -0700 | [diff] [blame] | 65 | if (request_resource(&iomem_resource, res) < 0) { |
| 66 | printk("System RAM resource %llx - %llx cannot be added\n", |
| 67 | (unsigned long long)res->start, (unsigned long long)res->end); |
| 68 | kfree(res); |
| 69 | res = NULL; |
| 70 | } |
| 71 | return res; |
| 72 | } |
| 73 | |
| 74 | static void release_memory_resource(struct resource *res) |
| 75 | { |
| 76 | if (!res) |
| 77 | return; |
| 78 | release_resource(res); |
| 79 | kfree(res); |
| 80 | return; |
| 81 | } |
| 82 | |
Keith Mannthey | 5394702 | 2006-09-30 23:27:08 -0700 | [diff] [blame] | 83 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 84 | #ifndef CONFIG_SPARSEMEM_VMEMMAP |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 85 | static void get_page_bootmem(unsigned long info, struct page *page, |
| 86 | unsigned long type) |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 87 | { |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 88 | page->lru.next = (struct list_head *) type; |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 89 | SetPagePrivate(page); |
| 90 | set_page_private(page, info); |
| 91 | atomic_inc(&page->_count); |
| 92 | } |
| 93 | |
Rakib Mullick | 23ce932 | 2009-12-14 17:59:44 -0800 | [diff] [blame] | 94 | /* reference to __meminit __free_pages_bootmem is valid |
| 95 | * so use __ref to tell modpost not to generate a warning */ |
| 96 | void __ref put_page_bootmem(struct page *page) |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 97 | { |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 98 | unsigned long type; |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 99 | |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 100 | type = (unsigned long) page->lru.next; |
| 101 | BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE || |
| 102 | type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE); |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 103 | |
| 104 | if (atomic_dec_return(&page->_count) == 1) { |
| 105 | ClearPagePrivate(page); |
| 106 | set_page_private(page, 0); |
Andrea Arcangeli | 5f24ce5 | 2011-01-13 15:47:00 -0800 | [diff] [blame] | 107 | INIT_LIST_HEAD(&page->lru); |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 108 | __free_pages_bootmem(page, 0); |
| 109 | } |
| 110 | |
| 111 | } |
| 112 | |
Adrian Bunk | d92bc31 | 2008-07-23 21:28:12 -0700 | [diff] [blame] | 113 | static void register_page_bootmem_info_section(unsigned long start_pfn) |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 114 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 115 | unsigned long *usemap, mapsize, page_mapsize, section_nr, i, j; |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 116 | struct mem_section *ms; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 117 | struct page *page, *memmap, *page_page; |
| 118 | int memmap_page_valid; |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 119 | |
| 120 | if (!pfn_valid(start_pfn)) |
| 121 | return; |
| 122 | |
| 123 | section_nr = pfn_to_section_nr(start_pfn); |
| 124 | ms = __nr_to_section(section_nr); |
| 125 | |
| 126 | /* Get section's memmap address */ |
| 127 | memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); |
| 128 | |
| 129 | /* |
| 130 | * Get page for the memmap's phys address |
| 131 | * XXX: need more consideration for sparse_vmemmap... |
| 132 | */ |
| 133 | page = virt_to_page(memmap); |
| 134 | mapsize = sizeof(struct page) * PAGES_PER_SECTION; |
| 135 | mapsize = PAGE_ALIGN(mapsize) >> PAGE_SHIFT; |
| 136 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 137 | page_mapsize = PAGE_SIZE/sizeof(struct page); |
| 138 | |
| 139 | /* remember memmap's page, except those that reference only holes */ |
| 140 | for (i = 0; i < mapsize; i++, page++) { |
| 141 | memmap_page_valid = 0; |
| 142 | page_page = __va(page_to_pfn(page) << PAGE_SHIFT); |
| 143 | for (j = 0; j < page_mapsize; j++, page_page++) { |
| 144 | if (early_pfn_valid(page_to_pfn(page_page))) { |
| 145 | memmap_page_valid = 1; |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | if (memmap_page_valid) |
| 150 | get_page_bootmem(section_nr, page, SECTION_INFO); |
| 151 | } |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 152 | |
| 153 | usemap = __nr_to_section(section_nr)->pageblock_flags; |
| 154 | page = virt_to_page(usemap); |
| 155 | |
| 156 | mapsize = PAGE_ALIGN(usemap_size()) >> PAGE_SHIFT; |
| 157 | |
| 158 | for (i = 0; i < mapsize; i++, page++) |
Yasunori Goto | af370fb | 2008-07-23 21:28:17 -0700 | [diff] [blame] | 159 | get_page_bootmem(section_nr, page, MIX_SECTION_INFO); |
Yasunori Goto | 0475327 | 2008-04-28 02:13:31 -0700 | [diff] [blame] | 160 | |
| 161 | } |
| 162 | |
| 163 | void register_page_bootmem_info_node(struct pglist_data *pgdat) |
| 164 | { |
| 165 | unsigned long i, pfn, end_pfn, nr_pages; |
| 166 | int node = pgdat->node_id; |
| 167 | struct page *page; |
| 168 | struct zone *zone; |
| 169 | |
| 170 | nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT; |
| 171 | page = virt_to_page(pgdat); |
| 172 | |
| 173 | for (i = 0; i < nr_pages; i++, page++) |
| 174 | get_page_bootmem(node, page, NODE_INFO); |
| 175 | |
| 176 | zone = &pgdat->node_zones[0]; |
| 177 | for (; zone < pgdat->node_zones + MAX_NR_ZONES - 1; zone++) { |
| 178 | if (zone->wait_table) { |
| 179 | nr_pages = zone->wait_table_hash_nr_entries |
| 180 | * sizeof(wait_queue_head_t); |
| 181 | nr_pages = PAGE_ALIGN(nr_pages) >> PAGE_SHIFT; |
| 182 | page = virt_to_page(zone->wait_table); |
| 183 | |
| 184 | for (i = 0; i < nr_pages; i++, page++) |
| 185 | get_page_bootmem(node, page, NODE_INFO); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | pfn = pgdat->node_start_pfn; |
| 190 | end_pfn = pfn + pgdat->node_spanned_pages; |
| 191 | |
| 192 | /* register_section info */ |
| 193 | for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) |
| 194 | register_page_bootmem_info_section(pfn); |
| 195 | |
| 196 | } |
| 197 | #endif /* !CONFIG_SPARSEMEM_VMEMMAP */ |
| 198 | |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 199 | static void grow_zone_span(struct zone *zone, unsigned long start_pfn, |
| 200 | unsigned long end_pfn) |
| 201 | { |
| 202 | unsigned long old_zone_end_pfn; |
| 203 | |
| 204 | zone_span_writelock(zone); |
| 205 | |
| 206 | old_zone_end_pfn = zone->zone_start_pfn + zone->spanned_pages; |
| 207 | if (start_pfn < zone->zone_start_pfn) |
| 208 | zone->zone_start_pfn = start_pfn; |
| 209 | |
| 210 | zone->spanned_pages = max(old_zone_end_pfn, end_pfn) - |
| 211 | zone->zone_start_pfn; |
| 212 | |
| 213 | zone_span_writeunlock(zone); |
| 214 | } |
| 215 | |
| 216 | static void grow_pgdat_span(struct pglist_data *pgdat, unsigned long start_pfn, |
| 217 | unsigned long end_pfn) |
| 218 | { |
| 219 | unsigned long old_pgdat_end_pfn = |
| 220 | pgdat->node_start_pfn + pgdat->node_spanned_pages; |
| 221 | |
| 222 | if (start_pfn < pgdat->node_start_pfn) |
| 223 | pgdat->node_start_pfn = start_pfn; |
| 224 | |
| 225 | pgdat->node_spanned_pages = max(old_pgdat_end_pfn, end_pfn) - |
| 226 | pgdat->node_start_pfn; |
| 227 | } |
| 228 | |
Al Viro | 3116848 | 2008-11-22 17:33:24 +0000 | [diff] [blame] | 229 | static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 230 | { |
| 231 | struct pglist_data *pgdat = zone->zone_pgdat; |
| 232 | int nr_pages = PAGES_PER_SECTION; |
| 233 | int nid = pgdat->node_id; |
| 234 | int zone_type; |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 235 | unsigned long flags; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 236 | |
| 237 | zone_type = zone - pgdat->node_zones; |
Heiko Carstens | 76cdd58 | 2008-05-14 16:05:52 -0700 | [diff] [blame] | 238 | if (!zone->wait_table) { |
| 239 | int ret; |
| 240 | |
| 241 | ret = init_currently_empty_zone(zone, phys_start_pfn, |
| 242 | nr_pages, MEMMAP_HOTPLUG); |
| 243 | if (ret) |
| 244 | return ret; |
| 245 | } |
| 246 | pgdat_resize_lock(zone->zone_pgdat, &flags); |
| 247 | grow_zone_span(zone, phys_start_pfn, phys_start_pfn + nr_pages); |
| 248 | grow_pgdat_span(zone->zone_pgdat, phys_start_pfn, |
| 249 | phys_start_pfn + nr_pages); |
| 250 | pgdat_resize_unlock(zone->zone_pgdat, &flags); |
Dave Hansen | a2f3aa0 | 2007-01-10 23:15:30 -0800 | [diff] [blame] | 251 | memmap_init_zone(nr_pages, nid, zone_type, |
| 252 | phys_start_pfn, MEMMAP_HOTPLUG); |
Yasunori Goto | 718127c | 2006-06-23 02:03:10 -0700 | [diff] [blame] | 253 | return 0; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 256 | static int __meminit __add_section(int nid, struct zone *zone, |
| 257 | unsigned long phys_start_pfn) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 258 | { |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 259 | int nr_pages = PAGES_PER_SECTION; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 260 | int ret; |
| 261 | |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 262 | if (pfn_valid(phys_start_pfn)) |
| 263 | return -EEXIST; |
| 264 | |
Dave Hansen | 0b0acbe | 2005-10-29 18:16:55 -0700 | [diff] [blame] | 265 | ret = sparse_add_one_section(zone, phys_start_pfn, nr_pages); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 266 | |
| 267 | if (ret < 0) |
| 268 | return ret; |
| 269 | |
Yasunori Goto | 718127c | 2006-06-23 02:03:10 -0700 | [diff] [blame] | 270 | ret = __add_zone(zone, phys_start_pfn); |
| 271 | |
| 272 | if (ret < 0) |
| 273 | return ret; |
| 274 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 275 | return register_new_memory(nid, __pfn_to_section(phys_start_pfn)); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Yasunori Goto | 0c0a4a5 | 2008-04-28 02:13:34 -0700 | [diff] [blame] | 278 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
| 279 | static int __remove_section(struct zone *zone, struct mem_section *ms) |
| 280 | { |
| 281 | /* |
| 282 | * XXX: Freeing memmap with vmemmap is not implement yet. |
| 283 | * This should be removed later. |
| 284 | */ |
| 285 | return -EBUSY; |
| 286 | } |
| 287 | #else |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 288 | static int __remove_section(struct zone *zone, struct mem_section *ms) |
| 289 | { |
| 290 | unsigned long flags; |
| 291 | struct pglist_data *pgdat = zone->zone_pgdat; |
| 292 | int ret = -EINVAL; |
| 293 | |
| 294 | if (!valid_section(ms)) |
| 295 | return ret; |
| 296 | |
| 297 | ret = unregister_memory_section(ms); |
| 298 | if (ret) |
| 299 | return ret; |
| 300 | |
| 301 | pgdat_resize_lock(pgdat, &flags); |
| 302 | sparse_remove_one_section(zone, ms); |
| 303 | pgdat_resize_unlock(pgdat, &flags); |
| 304 | return 0; |
| 305 | } |
Yasunori Goto | 0c0a4a5 | 2008-04-28 02:13:34 -0700 | [diff] [blame] | 306 | #endif |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 307 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 308 | /* |
| 309 | * Reasonably generic function for adding memory. It is |
| 310 | * expected that archs that support memory hotplug will |
| 311 | * call this function after deciding the zone to which to |
| 312 | * add the new pages. |
| 313 | */ |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 314 | int __ref __add_pages(int nid, struct zone *zone, unsigned long phys_start_pfn, |
| 315 | unsigned long nr_pages) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 316 | { |
| 317 | unsigned long i; |
| 318 | int err = 0; |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 319 | int start_sec, end_sec; |
| 320 | /* during initialize mem_map, align hot-added range to section */ |
| 321 | start_sec = pfn_to_section_nr(phys_start_pfn); |
| 322 | end_sec = pfn_to_section_nr(phys_start_pfn + nr_pages - 1); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 323 | |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 324 | for (i = start_sec; i <= end_sec; i++) { |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 325 | err = __add_section(nid, zone, i << PFN_SECTION_SHIFT); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 326 | |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 327 | /* |
Simon Arlott | 183ff22 | 2007-10-20 01:27:18 +0200 | [diff] [blame] | 328 | * EEXIST is finally dealt with by ioresource collision |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 329 | * check. see add_memory() => register_memory_resource() |
| 330 | * Warning will be printed if there is collision. |
Joel H Schopp | bed120c | 2006-05-01 12:16:11 -0700 | [diff] [blame] | 331 | */ |
| 332 | if (err && (err != -EEXIST)) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 333 | break; |
KAMEZAWA Hiroyuki | 6f71271 | 2006-08-05 12:14:58 -0700 | [diff] [blame] | 334 | err = 0; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | return err; |
| 338 | } |
Joel H Schopp | bed120c | 2006-05-01 12:16:11 -0700 | [diff] [blame] | 339 | EXPORT_SYMBOL_GPL(__add_pages); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 340 | |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 341 | /** |
| 342 | * __remove_pages() - remove sections of pages from a zone |
| 343 | * @zone: zone from which pages need to be removed |
| 344 | * @phys_start_pfn: starting pageframe (must be aligned to start of a section) |
| 345 | * @nr_pages: number of pages to remove (must be multiple of section size) |
| 346 | * |
| 347 | * Generic helper function to remove section mappings and sysfs entries |
| 348 | * for the section of the memory we are removing. Caller needs to make |
| 349 | * sure that pages are marked reserved and zones are adjust properly by |
| 350 | * calling offline_pages(). |
| 351 | */ |
| 352 | int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, |
| 353 | unsigned long nr_pages) |
| 354 | { |
| 355 | unsigned long i, ret = 0; |
| 356 | int sections_to_remove; |
| 357 | |
| 358 | /* |
| 359 | * We can only remove entire sections |
| 360 | */ |
| 361 | BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK); |
| 362 | BUG_ON(nr_pages % PAGES_PER_SECTION); |
| 363 | |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 364 | sections_to_remove = nr_pages / PAGES_PER_SECTION; |
| 365 | for (i = 0; i < sections_to_remove; i++) { |
| 366 | unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; |
Nathan Fontenot | de7f0cb | 2008-10-18 20:27:14 -0700 | [diff] [blame] | 367 | release_mem_region(pfn << PAGE_SHIFT, |
| 368 | PAGES_PER_SECTION << PAGE_SHIFT); |
Badari Pulavarty | ea01ea9 | 2008-04-28 02:12:01 -0700 | [diff] [blame] | 369 | ret = __remove_section(zone, __pfn_to_section(pfn)); |
| 370 | if (ret) |
| 371 | break; |
| 372 | } |
| 373 | return ret; |
| 374 | } |
| 375 | EXPORT_SYMBOL_GPL(__remove_pages); |
| 376 | |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 377 | void online_page(struct page *page) |
| 378 | { |
Jan Beulich | 4738e1b | 2009-09-21 17:03:03 -0700 | [diff] [blame] | 379 | unsigned long pfn = page_to_pfn(page); |
| 380 | |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 381 | totalram_pages++; |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 382 | #ifdef CONFIG_FIX_MOVABLE_ZONE |
| 383 | if (zone_idx(page_zone(page)) != ZONE_MOVABLE) |
| 384 | total_unmovable_pages++; |
| 385 | #endif |
Jan Beulich | 4738e1b | 2009-09-21 17:03:03 -0700 | [diff] [blame] | 386 | if (pfn >= num_physpages) |
| 387 | num_physpages = pfn + 1; |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 388 | |
| 389 | #ifdef CONFIG_HIGHMEM |
| 390 | if (PageHighMem(page)) |
| 391 | totalhigh_pages++; |
| 392 | #endif |
| 393 | |
Jeremy Fitzhardinge | 180c06e | 2008-04-28 02:12:03 -0700 | [diff] [blame] | 394 | ClearPageReserved(page); |
| 395 | init_page_count(page); |
| 396 | __free_page(page); |
| 397 | } |
| 398 | |
KAMEZAWA Hiroyuki | 75884fb | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 399 | static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages, |
| 400 | void *arg) |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 401 | { |
| 402 | unsigned long i; |
KAMEZAWA Hiroyuki | 75884fb | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 403 | unsigned long onlined_pages = *(unsigned long *)arg; |
| 404 | struct page *page; |
| 405 | if (PageReserved(pfn_to_page(start_pfn))) |
| 406 | for (i = 0; i < nr_pages; i++) { |
| 407 | page = pfn_to_page(start_pfn + i); |
| 408 | online_page(page); |
| 409 | onlined_pages++; |
| 410 | } |
| 411 | *(unsigned long *)arg = onlined_pages; |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | |
KOSAKI Motohiro | 839a4fc | 2011-05-24 17:11:31 -0700 | [diff] [blame] | 416 | int __ref online_pages(unsigned long pfn, unsigned long nr_pages) |
KAMEZAWA Hiroyuki | 75884fb | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 417 | { |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 418 | unsigned long onlined_pages = 0; |
| 419 | struct zone *zone; |
Yasunori Goto | 6811378 | 2006-06-23 02:03:11 -0700 | [diff] [blame] | 420 | int need_zonelists_rebuild = 0; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 421 | int nid; |
| 422 | int ret; |
| 423 | struct memory_notify arg; |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 424 | |
KAMEZAWA Hiroyuki | 925268a | 2011-01-11 16:44:01 +0900 | [diff] [blame] | 425 | lock_memory_hotplug(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 426 | arg.start_pfn = pfn; |
| 427 | arg.nr_pages = nr_pages; |
| 428 | arg.status_change_nid = -1; |
| 429 | |
| 430 | nid = page_to_nid(pfn_to_page(pfn)); |
| 431 | if (node_present_pages(nid) == 0) |
| 432 | arg.status_change_nid = nid; |
| 433 | |
| 434 | ret = memory_notify(MEM_GOING_ONLINE, &arg); |
| 435 | ret = notifier_to_errno(ret); |
| 436 | if (ret) { |
| 437 | memory_notify(MEM_CANCEL_ONLINE, &arg); |
KAMEZAWA Hiroyuki | 925268a | 2011-01-11 16:44:01 +0900 | [diff] [blame] | 438 | unlock_memory_hotplug(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 439 | return ret; |
| 440 | } |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 441 | /* |
| 442 | * This doesn't need a lock to do pfn_to_page(). |
| 443 | * The section can't be removed here because of the |
Daniel Walker | da19cbc | 2008-02-04 23:35:47 -0800 | [diff] [blame] | 444 | * memory_block->state_mutex. |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 445 | */ |
| 446 | zone = page_zone(pfn_to_page(pfn)); |
Yasunori Goto | 6811378 | 2006-06-23 02:03:11 -0700 | [diff] [blame] | 447 | /* |
| 448 | * If this zone is not populated, then it is not in zonelist. |
| 449 | * This means the page allocator ignores this zone. |
| 450 | * So, zonelist must be updated after online. |
| 451 | */ |
Haicheng Li | 4eaf3f6 | 2010-05-24 14:32:52 -0700 | [diff] [blame] | 452 | mutex_lock(&zonelists_mutex); |
Yasunori Goto | 6811378 | 2006-06-23 02:03:11 -0700 | [diff] [blame] | 453 | if (!populated_zone(zone)) |
| 454 | need_zonelists_rebuild = 1; |
| 455 | |
KAMEZAWA Hiroyuki | 908eedc | 2009-09-22 16:45:46 -0700 | [diff] [blame] | 456 | ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages, |
KAMEZAWA Hiroyuki | 75884fb | 2007-10-16 01:26:10 -0700 | [diff] [blame] | 457 | online_pages_range); |
Geoff Levand | fd8a422 | 2008-05-14 16:05:50 -0700 | [diff] [blame] | 458 | if (ret) { |
Haicheng Li | 4eaf3f6 | 2010-05-24 14:32:52 -0700 | [diff] [blame] | 459 | mutex_unlock(&zonelists_mutex); |
Geoff Levand | fd8a422 | 2008-05-14 16:05:50 -0700 | [diff] [blame] | 460 | printk(KERN_DEBUG "online_pages %lx at %lx failed\n", |
| 461 | nr_pages, pfn); |
| 462 | memory_notify(MEM_CANCEL_ONLINE, &arg); |
KAMEZAWA Hiroyuki | 925268a | 2011-01-11 16:44:01 +0900 | [diff] [blame] | 463 | unlock_memory_hotplug(); |
Geoff Levand | fd8a422 | 2008-05-14 16:05:50 -0700 | [diff] [blame] | 464 | return ret; |
| 465 | } |
| 466 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 467 | zone->present_pages += onlined_pages; |
Yasunori Goto | f2937be | 2006-03-09 17:33:51 -0800 | [diff] [blame] | 468 | zone->zone_pgdat->node_present_pages += onlined_pages; |
Haicheng Li | 1f52250 | 2010-05-24 14:32:51 -0700 | [diff] [blame] | 469 | if (need_zonelists_rebuild) |
| 470 | build_all_zonelists(zone); |
| 471 | else |
| 472 | zone_pcp_update(zone); |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 473 | |
Haicheng Li | 4eaf3f6 | 2010-05-24 14:32:52 -0700 | [diff] [blame] | 474 | mutex_unlock(&zonelists_mutex); |
KOSAKI Motohiro | 1b79acc | 2011-05-24 17:11:32 -0700 | [diff] [blame] | 475 | |
| 476 | init_per_zone_wmark_min(); |
| 477 | |
Christoph Lameter | 7ea1530 | 2007-10-16 01:25:29 -0700 | [diff] [blame] | 478 | if (onlined_pages) { |
| 479 | kswapd_run(zone_to_nid(zone)); |
| 480 | node_set_state(zone_to_nid(zone), N_HIGH_MEMORY); |
| 481 | } |
Dave Hansen | 61b1399 | 2005-10-29 18:16:56 -0700 | [diff] [blame] | 482 | |
Haicheng Li | 1f52250 | 2010-05-24 14:32:51 -0700 | [diff] [blame] | 483 | vm_total_pages = nr_free_pagecache_pages(); |
Kent Liu | 2f7f24e | 2008-07-23 21:28:18 -0700 | [diff] [blame] | 484 | |
Chandra Seetharaman | 2d1d43f | 2006-09-29 02:01:25 -0700 | [diff] [blame] | 485 | writeback_set_ratelimit(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 486 | |
| 487 | if (onlined_pages) |
| 488 | memory_notify(MEM_ONLINE, &arg); |
KAMEZAWA Hiroyuki | 925268a | 2011-01-11 16:44:01 +0900 | [diff] [blame] | 489 | unlock_memory_hotplug(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 490 | |
Dave Hansen | 3947be1 | 2005-10-29 18:16:54 -0700 | [diff] [blame] | 491 | return 0; |
| 492 | } |
Keith Mannthey | 5394702 | 2006-09-30 23:27:08 -0700 | [diff] [blame] | 493 | #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 494 | |
Hidetoshi Seto | e131933 | 2009-11-17 14:06:18 -0800 | [diff] [blame] | 495 | /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ |
| 496 | static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start) |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 497 | { |
| 498 | struct pglist_data *pgdat; |
| 499 | unsigned long zones_size[MAX_NR_ZONES] = {0}; |
| 500 | unsigned long zholes_size[MAX_NR_ZONES] = {0}; |
| 501 | unsigned long start_pfn = start >> PAGE_SHIFT; |
| 502 | |
| 503 | pgdat = arch_alloc_nodedata(nid); |
| 504 | if (!pgdat) |
| 505 | return NULL; |
| 506 | |
| 507 | arch_refresh_nodedata(nid, pgdat); |
| 508 | |
| 509 | /* we can use NODE_DATA(nid) from here */ |
| 510 | |
| 511 | /* init node's zones as empty zones, we don't have any present pages.*/ |
Johannes Weiner | 9109fb7 | 2008-07-23 21:27:20 -0700 | [diff] [blame] | 512 | free_area_init_node(nid, zones_size, start_pfn, zholes_size); |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 513 | |
KAMEZAWA Hiroyuki | 959ecc4 | 2011-06-15 15:08:38 -0700 | [diff] [blame] | 514 | /* |
| 515 | * The node we allocated has no zone fallback lists. For avoiding |
| 516 | * to access not-initialized zonelist, build here. |
| 517 | */ |
David Rientjes | f957db4 | 2011-06-22 18:13:04 -0700 | [diff] [blame] | 518 | mutex_lock(&zonelists_mutex); |
KAMEZAWA Hiroyuki | 959ecc4 | 2011-06-15 15:08:38 -0700 | [diff] [blame] | 519 | build_all_zonelists(NULL); |
David Rientjes | f957db4 | 2011-06-22 18:13:04 -0700 | [diff] [blame] | 520 | mutex_unlock(&zonelists_mutex); |
KAMEZAWA Hiroyuki | 959ecc4 | 2011-06-15 15:08:38 -0700 | [diff] [blame] | 521 | |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 522 | return pgdat; |
| 523 | } |
| 524 | |
| 525 | static void rollback_node_hotadd(int nid, pg_data_t *pgdat) |
| 526 | { |
| 527 | arch_refresh_nodedata(nid, NULL); |
| 528 | arch_free_nodedata(pgdat); |
| 529 | return; |
| 530 | } |
| 531 | |
KAMEZAWA Hiroyuki | 0a54703 | 2006-06-27 02:53:35 -0700 | [diff] [blame] | 532 | |
minskey guo | cf23422 | 2010-05-24 14:32:41 -0700 | [diff] [blame] | 533 | /* |
| 534 | * called by cpu_up() to online a node without onlined memory. |
| 535 | */ |
| 536 | int mem_online_node(int nid) |
| 537 | { |
| 538 | pg_data_t *pgdat; |
| 539 | int ret; |
| 540 | |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 541 | lock_memory_hotplug(); |
minskey guo | cf23422 | 2010-05-24 14:32:41 -0700 | [diff] [blame] | 542 | pgdat = hotadd_new_pgdat(nid, 0); |
David Rientjes | 7553e8f | 2011-06-22 18:13:01 -0700 | [diff] [blame] | 543 | if (!pgdat) { |
minskey guo | cf23422 | 2010-05-24 14:32:41 -0700 | [diff] [blame] | 544 | ret = -ENOMEM; |
| 545 | goto out; |
| 546 | } |
| 547 | node_set_online(nid); |
| 548 | ret = register_one_node(nid); |
| 549 | BUG_ON(ret); |
| 550 | |
| 551 | out: |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 552 | unlock_memory_hotplug(); |
minskey guo | cf23422 | 2010-05-24 14:32:41 -0700 | [diff] [blame] | 553 | return ret; |
| 554 | } |
| 555 | |
Al Viro | 3116848 | 2008-11-22 17:33:24 +0000 | [diff] [blame] | 556 | /* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ |
| 557 | int __ref add_memory(int nid, u64 start, u64 size) |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 558 | { |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 559 | pg_data_t *pgdat = NULL; |
| 560 | int new_pgdat = 0; |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 561 | struct resource *res; |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 562 | int ret; |
| 563 | |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 564 | lock_memory_hotplug(); |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 565 | |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 566 | res = register_memory_resource(start, size); |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 567 | ret = -EEXIST; |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 568 | if (!res) |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 569 | goto out; |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 570 | |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 571 | if (!node_online(nid)) { |
| 572 | pgdat = hotadd_new_pgdat(nid, start); |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 573 | ret = -ENOMEM; |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 574 | if (!pgdat) |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 575 | goto out; |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 576 | new_pgdat = 1; |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 579 | /* call arch's memory hotadd */ |
| 580 | ret = arch_add_memory(nid, start, size); |
| 581 | |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 582 | if (ret < 0) |
| 583 | goto error; |
| 584 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 585 | /* we online node here. we can't roll back from here. */ |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 586 | node_set_online(nid); |
| 587 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 588 | if (new_pgdat) { |
| 589 | ret = register_one_node(nid); |
| 590 | /* |
| 591 | * If sysfs file of new node can't create, cpu on the node |
| 592 | * can't be hot-added. There is no rollback way now. |
| 593 | * So, check by BUG_ON() to catch it reluctantly.. |
| 594 | */ |
| 595 | BUG_ON(ret); |
| 596 | } |
| 597 | |
akpm@linux-foundation.org | d96ae53 | 2010-03-05 13:41:58 -0800 | [diff] [blame] | 598 | /* create new memmap entry */ |
| 599 | firmware_map_add_hotplug(start, start + size, "System RAM"); |
| 600 | |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 601 | goto out; |
| 602 | |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 603 | error: |
| 604 | /* rollback pgdat allocation and others */ |
| 605 | if (new_pgdat) |
| 606 | rollback_node_hotadd(nid, pgdat); |
KAMEZAWA Hiroyuki | ebd1530 | 2006-08-05 12:15:06 -0700 | [diff] [blame] | 607 | if (res) |
| 608 | release_memory_resource(res); |
Yasunori Goto | 9af3c2d | 2006-06-27 02:53:34 -0700 | [diff] [blame] | 609 | |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 610 | out: |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 611 | unlock_memory_hotplug(); |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 612 | return ret; |
| 613 | } |
| 614 | EXPORT_SYMBOL_GPL(add_memory); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 615 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 616 | int __ref physical_remove_memory(u64 start, u64 size) |
| 617 | { |
| 618 | int ret; |
| 619 | struct resource *res, *res_old; |
| 620 | res = kzalloc(sizeof(struct resource), GFP_KERNEL); |
| 621 | BUG_ON(!res); |
| 622 | |
| 623 | ret = arch_physical_remove_memory(start, size); |
Larry Bassel | 2421717 | 2011-10-14 10:36:45 -0700 | [diff] [blame] | 624 | if (!ret) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 625 | kfree(res); |
Larry Bassel | 2421717 | 2011-10-14 10:36:45 -0700 | [diff] [blame] | 626 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | res->name = "System RAM"; |
| 630 | res->start = start; |
| 631 | res->end = start + size - 1; |
| 632 | res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
| 633 | |
| 634 | res_old = locate_resource(&iomem_resource, res); |
Larry Bassel | 2421717 | 2011-10-14 10:36:45 -0700 | [diff] [blame] | 635 | if (res_old) { |
| 636 | release_resource(res_old); |
| 637 | if (PageSlab(virt_to_head_page(res_old))) |
| 638 | kfree(res_old); |
| 639 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 640 | kfree(res); |
| 641 | |
| 642 | return ret; |
| 643 | } |
| 644 | EXPORT_SYMBOL_GPL(physical_remove_memory); |
| 645 | |
| 646 | int __ref physical_active_memory(u64 start, u64 size) |
| 647 | { |
| 648 | int ret; |
| 649 | |
| 650 | ret = arch_physical_active_memory(start, size); |
| 651 | return ret; |
| 652 | } |
| 653 | EXPORT_SYMBOL_GPL(physical_active_memory); |
| 654 | |
| 655 | int __ref physical_low_power_memory(u64 start, u64 size) |
| 656 | { |
| 657 | int ret; |
| 658 | |
| 659 | ret = arch_physical_low_power_memory(start, size); |
| 660 | return ret; |
| 661 | } |
| 662 | EXPORT_SYMBOL_GPL(physical_low_power_memory); |
| 663 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 664 | #ifdef CONFIG_MEMORY_HOTREMOVE |
| 665 | /* |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 666 | * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy |
| 667 | * set and the size of the free page is given by page_order(). Using this, |
| 668 | * the function determines if the pageblock contains only free pages. |
| 669 | * Due to buddy contraints, a free page at least the size of a pageblock will |
| 670 | * be located at the start of the pageblock |
| 671 | */ |
| 672 | static inline int pageblock_free(struct page *page) |
| 673 | { |
| 674 | return PageBuddy(page) && page_order(page) >= pageblock_order; |
| 675 | } |
| 676 | |
| 677 | /* Return the start of the next active pageblock after a given page */ |
| 678 | static struct page *next_active_pageblock(struct page *page) |
| 679 | { |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 680 | /* Ensure the starting page is pageblock-aligned */ |
| 681 | BUG_ON(page_to_pfn(page) & (pageblock_nr_pages - 1)); |
| 682 | |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 683 | /* If the entire pageblock is free, move to the end of free page */ |
KAMEZAWA Hiroyuki | 0dcc48c | 2010-09-09 16:38:01 -0700 | [diff] [blame] | 684 | if (pageblock_free(page)) { |
| 685 | int order; |
| 686 | /* be careful. we don't have locks, page_order can be changed.*/ |
| 687 | order = page_order(page); |
| 688 | if ((order < MAX_ORDER) && (order >= pageblock_order)) |
| 689 | return page + (1 << order); |
| 690 | } |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 691 | |
KAMEZAWA Hiroyuki | 0dcc48c | 2010-09-09 16:38:01 -0700 | [diff] [blame] | 692 | return page + pageblock_nr_pages; |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /* Checks if this range of memory is likely to be hot-removable. */ |
| 696 | int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages) |
| 697 | { |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 698 | struct page *page = pfn_to_page(start_pfn); |
| 699 | struct page *end_page = page + nr_pages; |
| 700 | |
| 701 | /* Check the starting page of each pageblock within the range */ |
| 702 | for (; page < end_page; page = next_active_pageblock(page)) { |
KAMEZAWA Hiroyuki | 49ac825 | 2010-10-26 14:21:30 -0700 | [diff] [blame] | 703 | if (!is_pageblock_removable_nolock(page)) |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 704 | return 0; |
KAMEZAWA Hiroyuki | 49ac825 | 2010-10-26 14:21:30 -0700 | [diff] [blame] | 705 | cond_resched(); |
Badari Pulavarty | 5c755e9 | 2008-07-23 21:28:19 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /* All pageblocks in the memory block are likely to be hot-removable */ |
| 709 | return 1; |
| 710 | } |
| 711 | |
| 712 | /* |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 713 | * Confirm all pages in a range [start, end) is belongs to the same zone. |
| 714 | */ |
| 715 | static int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn) |
| 716 | { |
| 717 | unsigned long pfn; |
| 718 | struct zone *zone = NULL; |
| 719 | struct page *page; |
| 720 | int i; |
| 721 | for (pfn = start_pfn; |
| 722 | pfn < end_pfn; |
| 723 | pfn += MAX_ORDER_NR_PAGES) { |
| 724 | i = 0; |
| 725 | /* This is just a CONFIG_HOLES_IN_ZONE check.*/ |
| 726 | while ((i < MAX_ORDER_NR_PAGES) && !pfn_valid_within(pfn + i)) |
| 727 | i++; |
| 728 | if (i == MAX_ORDER_NR_PAGES) |
| 729 | continue; |
| 730 | page = pfn_to_page(pfn + i); |
| 731 | if (zone && page_zone(page) != zone) |
| 732 | return 0; |
| 733 | zone = page_zone(page); |
| 734 | } |
| 735 | return 1; |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | * Scanning pfn is much easier than scanning lru list. |
| 740 | * Scan pfn from start to end and Find LRU page. |
| 741 | */ |
Andrew Morton | 7bbc090 | 2010-10-26 14:22:05 -0700 | [diff] [blame] | 742 | static unsigned long scan_lru_pages(unsigned long start, unsigned long end) |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 743 | { |
| 744 | unsigned long pfn; |
| 745 | struct page *page; |
| 746 | for (pfn = start; pfn < end; pfn++) { |
| 747 | if (pfn_valid(pfn)) { |
| 748 | page = pfn_to_page(pfn); |
| 749 | if (PageLRU(page)) |
| 750 | return pfn; |
| 751 | } |
| 752 | } |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | static struct page * |
Hugh Dickins | 3c1d437 | 2009-01-06 14:39:23 -0800 | [diff] [blame] | 757 | hotremove_migrate_alloc(struct page *page, unsigned long private, int **x) |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 758 | { |
Hugh Dickins | 3c1d437 | 2009-01-06 14:39:23 -0800 | [diff] [blame] | 759 | /* This should be improooooved!! */ |
Jack Cheung | 1e6ec3c | 2011-11-21 16:44:05 -0800 | [diff] [blame] | 760 | return alloc_page(GFP_HIGHUSER_MOVABLE | __GFP_NORETRY | __GFP_NOWARN | |
| 761 | __GFP_NOMEMALLOC); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 762 | } |
| 763 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 764 | #define NR_OFFLINE_AT_ONCE_PAGES (256) |
| 765 | static int |
| 766 | do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) |
| 767 | { |
| 768 | unsigned long pfn; |
| 769 | struct page *page; |
| 770 | int move_pages = NR_OFFLINE_AT_ONCE_PAGES; |
| 771 | int not_managed = 0; |
| 772 | int ret = 0; |
| 773 | LIST_HEAD(source); |
| 774 | |
| 775 | for (pfn = start_pfn; pfn < end_pfn && move_pages > 0; pfn++) { |
| 776 | if (!pfn_valid(pfn)) |
| 777 | continue; |
| 778 | page = pfn_to_page(pfn); |
Konstantin Khlebnikov | 700c2a4 | 2011-05-24 17:12:19 -0700 | [diff] [blame] | 779 | if (!get_page_unless_zero(page)) |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 780 | continue; |
| 781 | /* |
| 782 | * We can skip free pages. And we can only deal with pages on |
| 783 | * LRU. |
| 784 | */ |
Nick Piggin | 62695a8 | 2008-10-18 20:26:09 -0700 | [diff] [blame] | 785 | ret = isolate_lru_page(page); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 786 | if (!ret) { /* Success */ |
Konstantin Khlebnikov | 700c2a4 | 2011-05-24 17:12:19 -0700 | [diff] [blame] | 787 | put_page(page); |
Nick Piggin | 62695a8 | 2008-10-18 20:26:09 -0700 | [diff] [blame] | 788 | list_add_tail(&page->lru, &source); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 789 | move_pages--; |
KOSAKI Motohiro | 6d9c285 | 2009-12-14 17:58:11 -0800 | [diff] [blame] | 790 | inc_zone_page_state(page, NR_ISOLATED_ANON + |
| 791 | page_is_file_cache(page)); |
| 792 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 793 | } else { |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 794 | #ifdef CONFIG_DEBUG_VM |
Wu Fengguang | 718a382 | 2010-03-10 15:20:43 -0800 | [diff] [blame] | 795 | printk(KERN_ALERT "removing pfn %lx from LRU failed\n", |
| 796 | pfn); |
| 797 | dump_page(page); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 798 | #endif |
Konstantin Khlebnikov | 700c2a4 | 2011-05-24 17:12:19 -0700 | [diff] [blame] | 799 | put_page(page); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 800 | /* Because we don't have big zone->lock. we should |
Bob Liu | 809c444 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 801 | check this again here. */ |
| 802 | if (page_count(page)) { |
| 803 | not_managed++; |
Bob Liu | f3ab263 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 804 | ret = -EBUSY; |
Bob Liu | 809c444 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 805 | break; |
| 806 | } |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
Bob Liu | f3ab263 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 809 | if (!list_empty(&source)) { |
| 810 | if (not_managed) { |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 811 | putback_lru_pages(&source); |
Bob Liu | f3ab263 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 812 | goto out; |
| 813 | } |
| 814 | /* this function returns # of failed pages */ |
Mel Gorman | 77f1fe6 | 2011-01-13 15:45:57 -0800 | [diff] [blame] | 815 | ret = migrate_pages(&source, hotremove_migrate_alloc, 0, |
Mel Gorman | 7f0f249 | 2011-01-13 15:45:58 -0800 | [diff] [blame] | 816 | true, true); |
Bob Liu | f3ab263 | 2010-10-26 14:22:10 -0700 | [diff] [blame] | 817 | if (ret) |
| 818 | putback_lru_pages(&source); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 819 | } |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 820 | out: |
| 821 | return ret; |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * remove from free_area[] and mark all as Reserved. |
| 826 | */ |
| 827 | static int |
| 828 | offline_isolated_pages_cb(unsigned long start, unsigned long nr_pages, |
| 829 | void *data) |
| 830 | { |
| 831 | __offline_isolated_pages(start, start + nr_pages); |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | static void |
| 836 | offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) |
| 837 | { |
KAMEZAWA Hiroyuki | 908eedc | 2009-09-22 16:45:46 -0700 | [diff] [blame] | 838 | walk_system_ram_range(start_pfn, end_pfn - start_pfn, NULL, |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 839 | offline_isolated_pages_cb); |
| 840 | } |
| 841 | |
| 842 | /* |
| 843 | * Check all pages in range, recoreded as memory resource, are isolated. |
| 844 | */ |
| 845 | static int |
| 846 | check_pages_isolated_cb(unsigned long start_pfn, unsigned long nr_pages, |
| 847 | void *data) |
| 848 | { |
| 849 | int ret; |
| 850 | long offlined = *(long *)data; |
| 851 | ret = test_pages_isolated(start_pfn, start_pfn + nr_pages); |
| 852 | offlined = nr_pages; |
| 853 | if (!ret) |
| 854 | *(long *)data += offlined; |
| 855 | return ret; |
| 856 | } |
| 857 | |
| 858 | static long |
| 859 | check_pages_isolated(unsigned long start_pfn, unsigned long end_pfn) |
| 860 | { |
| 861 | long offlined = 0; |
| 862 | int ret; |
| 863 | |
KAMEZAWA Hiroyuki | 908eedc | 2009-09-22 16:45:46 -0700 | [diff] [blame] | 864 | ret = walk_system_ram_range(start_pfn, end_pfn - start_pfn, &offlined, |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 865 | check_pages_isolated_cb); |
| 866 | if (ret < 0) |
| 867 | offlined = (long)ret; |
| 868 | return offlined; |
| 869 | } |
| 870 | |
KOSAKI Motohiro | 839a4fc | 2011-05-24 17:11:31 -0700 | [diff] [blame] | 871 | static int __ref offline_pages(unsigned long start_pfn, |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 872 | unsigned long end_pfn, unsigned long timeout) |
| 873 | { |
| 874 | unsigned long pfn, nr_pages, expire; |
| 875 | long offlined_pages; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 876 | int ret, drain, retry_max, node; |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 877 | struct zone *zone; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 878 | struct memory_notify arg; |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 879 | |
| 880 | BUG_ON(start_pfn >= end_pfn); |
| 881 | /* at least, alignment against pageblock is necessary */ |
| 882 | if (!IS_ALIGNED(start_pfn, pageblock_nr_pages)) |
| 883 | return -EINVAL; |
| 884 | if (!IS_ALIGNED(end_pfn, pageblock_nr_pages)) |
| 885 | return -EINVAL; |
| 886 | /* This makes hotplug much easier...and readable. |
| 887 | we assume this for now. .*/ |
| 888 | if (!test_pages_in_a_zone(start_pfn, end_pfn)) |
| 889 | return -EINVAL; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 890 | |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 891 | lock_memory_hotplug(); |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 892 | |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 893 | zone = page_zone(pfn_to_page(start_pfn)); |
| 894 | node = zone_to_nid(zone); |
| 895 | nr_pages = end_pfn - start_pfn; |
| 896 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 897 | /* set above range as isolated */ |
| 898 | ret = start_isolate_page_range(start_pfn, end_pfn); |
| 899 | if (ret) |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 900 | goto out; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 901 | |
| 902 | arg.start_pfn = start_pfn; |
| 903 | arg.nr_pages = nr_pages; |
| 904 | arg.status_change_nid = -1; |
| 905 | if (nr_pages >= node_present_pages(node)) |
| 906 | arg.status_change_nid = node; |
| 907 | |
| 908 | ret = memory_notify(MEM_GOING_OFFLINE, &arg); |
| 909 | ret = notifier_to_errno(ret); |
| 910 | if (ret) |
| 911 | goto failed_removal; |
| 912 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 913 | pfn = start_pfn; |
| 914 | expire = jiffies + timeout; |
| 915 | drain = 0; |
| 916 | retry_max = 5; |
| 917 | repeat: |
| 918 | /* start memory hot removal */ |
| 919 | ret = -EAGAIN; |
| 920 | if (time_after(jiffies, expire)) |
| 921 | goto failed_removal; |
| 922 | ret = -EINTR; |
| 923 | if (signal_pending(current)) |
| 924 | goto failed_removal; |
| 925 | ret = 0; |
| 926 | if (drain) { |
| 927 | lru_add_drain_all(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 928 | cond_resched(); |
Christoph Lameter | 9f8f217 | 2008-02-04 22:29:11 -0800 | [diff] [blame] | 929 | drain_all_pages(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | pfn = scan_lru_pages(start_pfn, end_pfn); |
| 933 | if (pfn) { /* We have page on LRU */ |
| 934 | ret = do_migrate_range(pfn, end_pfn); |
| 935 | if (!ret) { |
| 936 | drain = 1; |
| 937 | goto repeat; |
| 938 | } else { |
| 939 | if (ret < 0) |
| 940 | if (--retry_max == 0) |
| 941 | goto failed_removal; |
| 942 | yield(); |
| 943 | drain = 1; |
| 944 | goto repeat; |
| 945 | } |
| 946 | } |
| 947 | /* drain all zone's lru pagevec, this is asyncronous... */ |
| 948 | lru_add_drain_all(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 949 | yield(); |
| 950 | /* drain pcp pages , this is synchrouns. */ |
Christoph Lameter | 9f8f217 | 2008-02-04 22:29:11 -0800 | [diff] [blame] | 951 | drain_all_pages(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 952 | /* check again */ |
| 953 | offlined_pages = check_pages_isolated(start_pfn, end_pfn); |
| 954 | if (offlined_pages < 0) { |
| 955 | ret = -EBUSY; |
| 956 | goto failed_removal; |
| 957 | } |
| 958 | printk(KERN_INFO "Offlined Pages %ld\n", offlined_pages); |
| 959 | /* Ok, all of our target is islaoted. |
| 960 | We cannot do rollback at this point. */ |
| 961 | offline_isolated_pages(start_pfn, end_pfn); |
KAMEZAWA Hiroyuki | dbc0e4c | 2007-11-14 16:59:12 -0800 | [diff] [blame] | 962 | /* reset pagetype flags and makes migrate type to be MOVABLE */ |
| 963 | undo_isolate_page_range(start_pfn, end_pfn); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 964 | /* removal success */ |
Jack Cheung | 80c201e | 2011-11-29 16:53:34 -0800 | [diff] [blame] | 965 | if (offlined_pages > zone->present_pages) |
| 966 | zone->present_pages = 0; |
| 967 | else |
| 968 | zone->present_pages -= offlined_pages; |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 969 | zone->zone_pgdat->node_present_pages -= offlined_pages; |
| 970 | totalram_pages -= offlined_pages; |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 971 | |
Jack Cheung | 59f9f1c | 2011-11-29 16:52:49 -0800 | [diff] [blame] | 972 | #ifdef CONFIG_FIX_MOVABLE_ZONE |
| 973 | if (zone_idx(zone) != ZONE_MOVABLE) |
| 974 | total_unmovable_pages -= offlined_pages; |
| 975 | #endif |
KOSAKI Motohiro | 1b79acc | 2011-05-24 17:11:32 -0700 | [diff] [blame] | 976 | init_per_zone_wmark_min(); |
| 977 | |
David Rientjes | 8fe23e0 | 2009-12-14 17:58:33 -0800 | [diff] [blame] | 978 | if (!node_present_pages(node)) { |
| 979 | node_clear_state(node, N_HIGH_MEMORY); |
| 980 | kswapd_stop(node); |
| 981 | } |
Minchan Kim | bce7394 | 2009-06-16 15:32:50 -0700 | [diff] [blame] | 982 | |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 983 | vm_total_pages = nr_free_pagecache_pages(); |
| 984 | writeback_set_ratelimit(); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 985 | |
| 986 | memory_notify(MEM_OFFLINE, &arg); |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 987 | unlock_memory_hotplug(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 988 | return 0; |
| 989 | |
| 990 | failed_removal: |
| 991 | printk(KERN_INFO "memory offlining %lx to %lx failed\n", |
| 992 | start_pfn, end_pfn); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 993 | memory_notify(MEM_CANCEL_OFFLINE, &arg); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 994 | /* pushback to free area */ |
| 995 | undo_isolate_page_range(start_pfn, end_pfn); |
Yasunori Goto | 7b78d33 | 2007-10-21 16:41:36 -0700 | [diff] [blame] | 996 | |
Andi Kleen | 6ad696d | 2009-11-17 14:06:22 -0800 | [diff] [blame] | 997 | out: |
KOSAKI Motohiro | 20d6c96 | 2010-12-02 14:31:19 -0800 | [diff] [blame] | 998 | unlock_memory_hotplug(); |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 999 | return ret; |
| 1000 | } |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 1001 | |
| 1002 | int remove_memory(u64 start, u64 size) |
| 1003 | { |
| 1004 | unsigned long start_pfn, end_pfn; |
| 1005 | |
| 1006 | start_pfn = PFN_DOWN(start); |
| 1007 | end_pfn = start_pfn + PFN_DOWN(size); |
| 1008 | return offline_pages(start_pfn, end_pfn, 120 * HZ); |
| 1009 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1010 | |
KAMEZAWA Hiroyuki | 48e9419 | 2007-10-16 01:26:14 -0700 | [diff] [blame] | 1011 | #else |
| 1012 | int remove_memory(u64 start, u64 size) |
| 1013 | { |
| 1014 | return -EINVAL; |
| 1015 | } |
KAMEZAWA Hiroyuki | 0c0e619 | 2007-10-16 01:26:12 -0700 | [diff] [blame] | 1016 | #endif /* CONFIG_MEMORY_HOTREMOVE */ |
Badari Pulavarty | 7108878 | 2008-10-18 20:25:58 -0700 | [diff] [blame] | 1017 | EXPORT_SYMBOL_GPL(remove_memory); |