vmscan.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969
  1. /*
  2. * linux/mm/vmscan.c
  3. *
  4. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  5. *
  6. * Swap reorganised 29.12.95, Stephen Tweedie.
  7. * kswapd added: 7.1.96 sct
  8. * Removed kswapd_ctl limits, and swap out as many pages as needed
  9. * to bring the system back to freepages.high: 2.4.97, Rik van Riel.
  10. * Zone aware kswapd started 02/00, Kanoj Sarcar (kanoj@sgi.com).
  11. * Multiqueue VM started 5.8.00, Rik van Riel.
  12. */
  13. #include <linux/mm.h>
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/swap.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/init.h>
  20. #include <linux/highmem.h>
  21. #include <linux/file.h>
  22. #include <linux/writeback.h>
  23. #include <linux/blkdev.h>
  24. #include <linux/buffer_head.h> /* for try_to_release_page(),
  25. buffer_heads_over_limit */
  26. #include <linux/mm_inline.h>
  27. #include <linux/pagevec.h>
  28. #include <linux/backing-dev.h>
  29. #include <linux/rmap.h>
  30. #include <linux/topology.h>
  31. #include <linux/cpu.h>
  32. #include <linux/cpuset.h>
  33. #include <linux/notifier.h>
  34. #include <linux/rwsem.h>
  35. #include <asm/tlbflush.h>
  36. #include <asm/div64.h>
  37. #include <linux/swapops.h>
  38. /* possible outcome of pageout() */
  39. typedef enum {
  40. /* failed to write page out, page is locked */
  41. PAGE_KEEP,
  42. /* move page to the active list, page is locked */
  43. PAGE_ACTIVATE,
  44. /* page has been sent to the disk successfully, page is unlocked */
  45. PAGE_SUCCESS,
  46. /* page is clean and locked */
  47. PAGE_CLEAN,
  48. } pageout_t;
  49. struct scan_control {
  50. /* Incremented by the number of inactive pages that were scanned */
  51. unsigned long nr_scanned;
  52. /* Incremented by the number of pages reclaimed */
  53. unsigned long nr_reclaimed;
  54. unsigned long nr_mapped; /* From page_state */
  55. /* This context's GFP mask */
  56. gfp_t gfp_mask;
  57. int may_writepage;
  58. /* Can pages be swapped as part of reclaim? */
  59. int may_swap;
  60. /* This context's SWAP_CLUSTER_MAX. If freeing memory for
  61. * suspend, we effectively ignore SWAP_CLUSTER_MAX.
  62. * In this context, it doesn't matter that we scan the
  63. * whole list at once. */
  64. int swap_cluster_max;
  65. };
  66. /*
  67. * The list of shrinker callbacks used by to apply pressure to
  68. * ageable caches.
  69. */
  70. struct shrinker {
  71. shrinker_t shrinker;
  72. struct list_head list;
  73. int seeks; /* seeks to recreate an obj */
  74. long nr; /* objs pending delete */
  75. };
  76. #define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))
  77. #ifdef ARCH_HAS_PREFETCH
  78. #define prefetch_prev_lru_page(_page, _base, _field) \
  79. do { \
  80. if ((_page)->lru.prev != _base) { \
  81. struct page *prev; \
  82. \
  83. prev = lru_to_page(&(_page->lru)); \
  84. prefetch(&prev->_field); \
  85. } \
  86. } while (0)
  87. #else
  88. #define prefetch_prev_lru_page(_page, _base, _field) do { } while (0)
  89. #endif
  90. #ifdef ARCH_HAS_PREFETCHW
  91. #define prefetchw_prev_lru_page(_page, _base, _field) \
  92. do { \
  93. if ((_page)->lru.prev != _base) { \
  94. struct page *prev; \
  95. \
  96. prev = lru_to_page(&(_page->lru)); \
  97. prefetchw(&prev->_field); \
  98. } \
  99. } while (0)
  100. #else
  101. #define prefetchw_prev_lru_page(_page, _base, _field) do { } while (0)
  102. #endif
  103. /*
  104. * From 0 .. 100. Higher means more swappy.
  105. */
  106. int vm_swappiness = 60;
  107. static long total_memory;
  108. static LIST_HEAD(shrinker_list);
  109. static DECLARE_RWSEM(shrinker_rwsem);
  110. /*
  111. * Add a shrinker callback to be called from the vm
  112. */
  113. struct shrinker *set_shrinker(int seeks, shrinker_t theshrinker)
  114. {
  115. struct shrinker *shrinker;
  116. shrinker = kmalloc(sizeof(*shrinker), GFP_KERNEL);
  117. if (shrinker) {
  118. shrinker->shrinker = theshrinker;
  119. shrinker->seeks = seeks;
  120. shrinker->nr = 0;
  121. down_write(&shrinker_rwsem);
  122. list_add_tail(&shrinker->list, &shrinker_list);
  123. up_write(&shrinker_rwsem);
  124. }
  125. return shrinker;
  126. }
  127. EXPORT_SYMBOL(set_shrinker);
  128. /*
  129. * Remove one
  130. */
  131. void remove_shrinker(struct shrinker *shrinker)
  132. {
  133. down_write(&shrinker_rwsem);
  134. list_del(&shrinker->list);
  135. up_write(&shrinker_rwsem);
  136. kfree(shrinker);
  137. }
  138. EXPORT_SYMBOL(remove_shrinker);
  139. #define SHRINK_BATCH 128
  140. /*
  141. * Call the shrink functions to age shrinkable caches
  142. *
  143. * Here we assume it costs one seek to replace a lru page and that it also
  144. * takes a seek to recreate a cache object. With this in mind we age equal
  145. * percentages of the lru and ageable caches. This should balance the seeks
  146. * generated by these structures.
  147. *
  148. * If the vm encounted mapped pages on the LRU it increase the pressure on
  149. * slab to avoid swapping.
  150. *
  151. * We do weird things to avoid (scanned*seeks*entries) overflowing 32 bits.
  152. *
  153. * `lru_pages' represents the number of on-LRU pages in all the zones which
  154. * are eligible for the caller's allocation attempt. It is used for balancing
  155. * slab reclaim versus page reclaim.
  156. *
  157. * Returns the number of slab objects which we shrunk.
  158. */
  159. int shrink_slab(unsigned long scanned, gfp_t gfp_mask, unsigned long lru_pages)
  160. {
  161. struct shrinker *shrinker;
  162. int ret = 0;
  163. if (scanned == 0)
  164. scanned = SWAP_CLUSTER_MAX;
  165. if (!down_read_trylock(&shrinker_rwsem))
  166. return 1; /* Assume we'll be able to shrink next time */
  167. list_for_each_entry(shrinker, &shrinker_list, list) {
  168. unsigned long long delta;
  169. unsigned long total_scan;
  170. unsigned long max_pass = (*shrinker->shrinker)(0, gfp_mask);
  171. delta = (4 * scanned) / shrinker->seeks;
  172. delta *= max_pass;
  173. do_div(delta, lru_pages + 1);
  174. shrinker->nr += delta;
  175. if (shrinker->nr < 0) {
  176. printk(KERN_ERR "%s: nr=%ld\n",
  177. __FUNCTION__, shrinker->nr);
  178. shrinker->nr = max_pass;
  179. }
  180. /*
  181. * Avoid risking looping forever due to too large nr value:
  182. * never try to free more than twice the estimate number of
  183. * freeable entries.
  184. */
  185. if (shrinker->nr > max_pass * 2)
  186. shrinker->nr = max_pass * 2;
  187. total_scan = shrinker->nr;
  188. shrinker->nr = 0;
  189. while (total_scan >= SHRINK_BATCH) {
  190. long this_scan = SHRINK_BATCH;
  191. int shrink_ret;
  192. int nr_before;
  193. nr_before = (*shrinker->shrinker)(0, gfp_mask);
  194. shrink_ret = (*shrinker->shrinker)(this_scan, gfp_mask);
  195. if (shrink_ret == -1)
  196. break;
  197. if (shrink_ret < nr_before)
  198. ret += nr_before - shrink_ret;
  199. mod_page_state(slabs_scanned, this_scan);
  200. total_scan -= this_scan;
  201. cond_resched();
  202. }
  203. shrinker->nr += total_scan;
  204. }
  205. up_read(&shrinker_rwsem);
  206. return ret;
  207. }
  208. /* Called without lock on whether page is mapped, so answer is unstable */
  209. static inline int page_mapping_inuse(struct page *page)
  210. {
  211. struct address_space *mapping;
  212. /* Page is in somebody's page tables. */
  213. if (page_mapped(page))
  214. return 1;
  215. /* Be more reluctant to reclaim swapcache than pagecache */
  216. if (PageSwapCache(page))
  217. return 1;
  218. mapping = page_mapping(page);
  219. if (!mapping)
  220. return 0;
  221. /* File is mmap'd by somebody? */
  222. return mapping_mapped(mapping);
  223. }
  224. static inline int is_page_cache_freeable(struct page *page)
  225. {
  226. return page_count(page) - !!PagePrivate(page) == 2;
  227. }
  228. static int may_write_to_queue(struct backing_dev_info *bdi)
  229. {
  230. if (current->flags & PF_SWAPWRITE)
  231. return 1;
  232. if (!bdi_write_congested(bdi))
  233. return 1;
  234. if (bdi == current->backing_dev_info)
  235. return 1;
  236. return 0;
  237. }
  238. /*
  239. * We detected a synchronous write error writing a page out. Probably
  240. * -ENOSPC. We need to propagate that into the address_space for a subsequent
  241. * fsync(), msync() or close().
  242. *
  243. * The tricky part is that after writepage we cannot touch the mapping: nothing
  244. * prevents it from being freed up. But we have a ref on the page and once
  245. * that page is locked, the mapping is pinned.
  246. *
  247. * We're allowed to run sleeping lock_page() here because we know the caller has
  248. * __GFP_FS.
  249. */
  250. static void handle_write_error(struct address_space *mapping,
  251. struct page *page, int error)
  252. {
  253. lock_page(page);
  254. if (page_mapping(page) == mapping) {
  255. if (error == -ENOSPC)
  256. set_bit(AS_ENOSPC, &mapping->flags);
  257. else
  258. set_bit(AS_EIO, &mapping->flags);
  259. }
  260. unlock_page(page);
  261. }
  262. /*
  263. * pageout is called by shrink_list() for each dirty page. Calls ->writepage().
  264. */
  265. static pageout_t pageout(struct page *page, struct address_space *mapping)
  266. {
  267. /*
  268. * If the page is dirty, only perform writeback if that write
  269. * will be non-blocking. To prevent this allocation from being
  270. * stalled by pagecache activity. But note that there may be
  271. * stalls if we need to run get_block(). We could test
  272. * PagePrivate for that.
  273. *
  274. * If this process is currently in generic_file_write() against
  275. * this page's queue, we can perform writeback even if that
  276. * will block.
  277. *
  278. * If the page is swapcache, write it back even if that would
  279. * block, for some throttling. This happens by accident, because
  280. * swap_backing_dev_info is bust: it doesn't reflect the
  281. * congestion state of the swapdevs. Easy to fix, if needed.
  282. * See swapfile.c:page_queue_congested().
  283. */
  284. if (!is_page_cache_freeable(page))
  285. return PAGE_KEEP;
  286. if (!mapping) {
  287. /*
  288. * Some data journaling orphaned pages can have
  289. * page->mapping == NULL while being dirty with clean buffers.
  290. */
  291. if (PagePrivate(page)) {
  292. if (try_to_free_buffers(page)) {
  293. ClearPageDirty(page);
  294. printk("%s: orphaned page\n", __FUNCTION__);
  295. return PAGE_CLEAN;
  296. }
  297. }
  298. return PAGE_KEEP;
  299. }
  300. if (mapping->a_ops->writepage == NULL)
  301. return PAGE_ACTIVATE;
  302. if (!may_write_to_queue(mapping->backing_dev_info))
  303. return PAGE_KEEP;
  304. if (clear_page_dirty_for_io(page)) {
  305. int res;
  306. struct writeback_control wbc = {
  307. .sync_mode = WB_SYNC_NONE,
  308. .nr_to_write = SWAP_CLUSTER_MAX,
  309. .nonblocking = 1,
  310. .for_reclaim = 1,
  311. };
  312. SetPageReclaim(page);
  313. res = mapping->a_ops->writepage(page, &wbc);
  314. if (res < 0)
  315. handle_write_error(mapping, page, res);
  316. if (res == AOP_WRITEPAGE_ACTIVATE) {
  317. ClearPageReclaim(page);
  318. return PAGE_ACTIVATE;
  319. }
  320. if (!PageWriteback(page)) {
  321. /* synchronous write or broken a_ops? */
  322. ClearPageReclaim(page);
  323. }
  324. return PAGE_SUCCESS;
  325. }
  326. return PAGE_CLEAN;
  327. }
  328. static int remove_mapping(struct address_space *mapping, struct page *page)
  329. {
  330. if (!mapping)
  331. return 0; /* truncate got there first */
  332. write_lock_irq(&mapping->tree_lock);
  333. /*
  334. * The non-racy check for busy page. It is critical to check
  335. * PageDirty _after_ making sure that the page is freeable and
  336. * not in use by anybody. (pagecache + us == 2)
  337. */
  338. if (unlikely(page_count(page) != 2))
  339. goto cannot_free;
  340. smp_rmb();
  341. if (unlikely(PageDirty(page)))
  342. goto cannot_free;
  343. if (PageSwapCache(page)) {
  344. swp_entry_t swap = { .val = page_private(page) };
  345. __delete_from_swap_cache(page);
  346. write_unlock_irq(&mapping->tree_lock);
  347. swap_free(swap);
  348. __put_page(page); /* The pagecache ref */
  349. return 1;
  350. }
  351. __remove_from_page_cache(page);
  352. write_unlock_irq(&mapping->tree_lock);
  353. __put_page(page);
  354. return 1;
  355. cannot_free:
  356. write_unlock_irq(&mapping->tree_lock);
  357. return 0;
  358. }
  359. /*
  360. * shrink_list adds the number of reclaimed pages to sc->nr_reclaimed
  361. */
  362. static int shrink_list(struct list_head *page_list, struct scan_control *sc)
  363. {
  364. LIST_HEAD(ret_pages);
  365. struct pagevec freed_pvec;
  366. int pgactivate = 0;
  367. int reclaimed = 0;
  368. cond_resched();
  369. pagevec_init(&freed_pvec, 1);
  370. while (!list_empty(page_list)) {
  371. struct address_space *mapping;
  372. struct page *page;
  373. int may_enter_fs;
  374. int referenced;
  375. cond_resched();
  376. page = lru_to_page(page_list);
  377. list_del(&page->lru);
  378. if (TestSetPageLocked(page))
  379. goto keep;
  380. BUG_ON(PageActive(page));
  381. sc->nr_scanned++;
  382. if (!sc->may_swap && page_mapped(page))
  383. goto keep_locked;
  384. /* Double the slab pressure for mapped and swapcache pages */
  385. if (page_mapped(page) || PageSwapCache(page))
  386. sc->nr_scanned++;
  387. if (PageWriteback(page))
  388. goto keep_locked;
  389. referenced = page_referenced(page, 1);
  390. /* In active use or really unfreeable? Activate it. */
  391. if (referenced && page_mapping_inuse(page))
  392. goto activate_locked;
  393. #ifdef CONFIG_SWAP
  394. /*
  395. * Anonymous process memory has backing store?
  396. * Try to allocate it some swap space here.
  397. */
  398. if (PageAnon(page) && !PageSwapCache(page)) {
  399. if (!sc->may_swap)
  400. goto keep_locked;
  401. if (!add_to_swap(page, GFP_ATOMIC))
  402. goto activate_locked;
  403. }
  404. #endif /* CONFIG_SWAP */
  405. mapping = page_mapping(page);
  406. may_enter_fs = (sc->gfp_mask & __GFP_FS) ||
  407. (PageSwapCache(page) && (sc->gfp_mask & __GFP_IO));
  408. /*
  409. * The page is mapped into the page tables of one or more
  410. * processes. Try to unmap it here.
  411. */
  412. if (page_mapped(page) && mapping) {
  413. /*
  414. * No unmapping if we do not swap
  415. */
  416. if (!sc->may_swap)
  417. goto keep_locked;
  418. switch (try_to_unmap(page, 0)) {
  419. case SWAP_FAIL:
  420. goto activate_locked;
  421. case SWAP_AGAIN:
  422. goto keep_locked;
  423. case SWAP_SUCCESS:
  424. ; /* try to free the page below */
  425. }
  426. }
  427. if (PageDirty(page)) {
  428. if (referenced)
  429. goto keep_locked;
  430. if (!may_enter_fs)
  431. goto keep_locked;
  432. if (!sc->may_writepage)
  433. goto keep_locked;
  434. /* Page is dirty, try to write it out here */
  435. switch(pageout(page, mapping)) {
  436. case PAGE_KEEP:
  437. goto keep_locked;
  438. case PAGE_ACTIVATE:
  439. goto activate_locked;
  440. case PAGE_SUCCESS:
  441. if (PageWriteback(page) || PageDirty(page))
  442. goto keep;
  443. /*
  444. * A synchronous write - probably a ramdisk. Go
  445. * ahead and try to reclaim the page.
  446. */
  447. if (TestSetPageLocked(page))
  448. goto keep;
  449. if (PageDirty(page) || PageWriteback(page))
  450. goto keep_locked;
  451. mapping = page_mapping(page);
  452. case PAGE_CLEAN:
  453. ; /* try to free the page below */
  454. }
  455. }
  456. /*
  457. * If the page has buffers, try to free the buffer mappings
  458. * associated with this page. If we succeed we try to free
  459. * the page as well.
  460. *
  461. * We do this even if the page is PageDirty().
  462. * try_to_release_page() does not perform I/O, but it is
  463. * possible for a page to have PageDirty set, but it is actually
  464. * clean (all its buffers are clean). This happens if the
  465. * buffers were written out directly, with submit_bh(). ext3
  466. * will do this, as well as the blockdev mapping.
  467. * try_to_release_page() will discover that cleanness and will
  468. * drop the buffers and mark the page clean - it can be freed.
  469. *
  470. * Rarely, pages can have buffers and no ->mapping. These are
  471. * the pages which were not successfully invalidated in
  472. * truncate_complete_page(). We try to drop those buffers here
  473. * and if that worked, and the page is no longer mapped into
  474. * process address space (page_count == 1) it can be freed.
  475. * Otherwise, leave the page on the LRU so it is swappable.
  476. */
  477. if (PagePrivate(page)) {
  478. if (!try_to_release_page(page, sc->gfp_mask))
  479. goto activate_locked;
  480. if (!mapping && page_count(page) == 1)
  481. goto free_it;
  482. }
  483. if (!remove_mapping(mapping, page))
  484. goto keep_locked;
  485. free_it:
  486. unlock_page(page);
  487. reclaimed++;
  488. if (!pagevec_add(&freed_pvec, page))
  489. __pagevec_release_nonlru(&freed_pvec);
  490. continue;
  491. activate_locked:
  492. SetPageActive(page);
  493. pgactivate++;
  494. keep_locked:
  495. unlock_page(page);
  496. keep:
  497. list_add(&page->lru, &ret_pages);
  498. BUG_ON(PageLRU(page));
  499. }
  500. list_splice(&ret_pages, page_list);
  501. if (pagevec_count(&freed_pvec))
  502. __pagevec_release_nonlru(&freed_pvec);
  503. mod_page_state(pgactivate, pgactivate);
  504. sc->nr_reclaimed += reclaimed;
  505. return reclaimed;
  506. }
  507. #ifdef CONFIG_MIGRATION
  508. static inline void move_to_lru(struct page *page)
  509. {
  510. list_del(&page->lru);
  511. if (PageActive(page)) {
  512. /*
  513. * lru_cache_add_active checks that
  514. * the PG_active bit is off.
  515. */
  516. ClearPageActive(page);
  517. lru_cache_add_active(page);
  518. } else {
  519. lru_cache_add(page);
  520. }
  521. put_page(page);
  522. }
  523. /*
  524. * Add isolated pages on the list back to the LRU.
  525. *
  526. * returns the number of pages put back.
  527. */
  528. int putback_lru_pages(struct list_head *l)
  529. {
  530. struct page *page;
  531. struct page *page2;
  532. int count = 0;
  533. list_for_each_entry_safe(page, page2, l, lru) {
  534. move_to_lru(page);
  535. count++;
  536. }
  537. return count;
  538. }
  539. /*
  540. * Non migratable page
  541. */
  542. int fail_migrate_page(struct page *newpage, struct page *page)
  543. {
  544. return -EIO;
  545. }
  546. EXPORT_SYMBOL(fail_migrate_page);
  547. /*
  548. * swapout a single page
  549. * page is locked upon entry, unlocked on exit
  550. */
  551. static int swap_page(struct page *page)
  552. {
  553. struct address_space *mapping = page_mapping(page);
  554. if (page_mapped(page) && mapping)
  555. if (try_to_unmap(page, 1) != SWAP_SUCCESS)
  556. goto unlock_retry;
  557. if (PageDirty(page)) {
  558. /* Page is dirty, try to write it out here */
  559. switch(pageout(page, mapping)) {
  560. case PAGE_KEEP:
  561. case PAGE_ACTIVATE:
  562. goto unlock_retry;
  563. case PAGE_SUCCESS:
  564. goto retry;
  565. case PAGE_CLEAN:
  566. ; /* try to free the page below */
  567. }
  568. }
  569. if (PagePrivate(page)) {
  570. if (!try_to_release_page(page, GFP_KERNEL) ||
  571. (!mapping && page_count(page) == 1))
  572. goto unlock_retry;
  573. }
  574. if (remove_mapping(mapping, page)) {
  575. /* Success */
  576. unlock_page(page);
  577. return 0;
  578. }
  579. unlock_retry:
  580. unlock_page(page);
  581. retry:
  582. return -EAGAIN;
  583. }
  584. EXPORT_SYMBOL(swap_page);
  585. /*
  586. * Page migration was first developed in the context of the memory hotplug
  587. * project. The main authors of the migration code are:
  588. *
  589. * IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
  590. * Hirokazu Takahashi <taka@valinux.co.jp>
  591. * Dave Hansen <haveblue@us.ibm.com>
  592. * Christoph Lameter <clameter@sgi.com>
  593. */
  594. /*
  595. * Remove references for a page and establish the new page with the correct
  596. * basic settings to be able to stop accesses to the page.
  597. */
  598. int migrate_page_remove_references(struct page *newpage,
  599. struct page *page, int nr_refs)
  600. {
  601. struct address_space *mapping = page_mapping(page);
  602. struct page **radix_pointer;
  603. /*
  604. * Avoid doing any of the following work if the page count
  605. * indicates that the page is in use or truncate has removed
  606. * the page.
  607. */
  608. if (!mapping || page_mapcount(page) + nr_refs != page_count(page))
  609. return -EAGAIN;
  610. /*
  611. * Establish swap ptes for anonymous pages or destroy pte
  612. * maps for files.
  613. *
  614. * In order to reestablish file backed mappings the fault handlers
  615. * will take the radix tree_lock which may then be used to stop
  616. * processses from accessing this page until the new page is ready.
  617. *
  618. * A process accessing via a swap pte (an anonymous page) will take a
  619. * page_lock on the old page which will block the process until the
  620. * migration attempt is complete. At that time the PageSwapCache bit
  621. * will be examined. If the page was migrated then the PageSwapCache
  622. * bit will be clear and the operation to retrieve the page will be
  623. * retried which will find the new page in the radix tree. Then a new
  624. * direct mapping may be generated based on the radix tree contents.
  625. *
  626. * If the page was not migrated then the PageSwapCache bit
  627. * is still set and the operation may continue.
  628. */
  629. if (try_to_unmap(page, 1) == SWAP_FAIL)
  630. /* A vma has VM_LOCKED set -> Permanent failure */
  631. return -EPERM;
  632. /*
  633. * Give up if we were unable to remove all mappings.
  634. */
  635. if (page_mapcount(page))
  636. return -EAGAIN;
  637. write_lock_irq(&mapping->tree_lock);
  638. radix_pointer = (struct page **)radix_tree_lookup_slot(
  639. &mapping->page_tree,
  640. page_index(page));
  641. if (!page_mapping(page) || page_count(page) != nr_refs ||
  642. *radix_pointer != page) {
  643. write_unlock_irq(&mapping->tree_lock);
  644. return -EAGAIN;
  645. }
  646. /*
  647. * Now we know that no one else is looking at the page.
  648. *
  649. * Certain minimal information about a page must be available
  650. * in order for other subsystems to properly handle the page if they
  651. * find it through the radix tree update before we are finished
  652. * copying the page.
  653. */
  654. get_page(newpage);
  655. newpage->index = page->index;
  656. newpage->mapping = page->mapping;
  657. if (PageSwapCache(page)) {
  658. SetPageSwapCache(newpage);
  659. set_page_private(newpage, page_private(page));
  660. }
  661. *radix_pointer = newpage;
  662. __put_page(page);
  663. write_unlock_irq(&mapping->tree_lock);
  664. return 0;
  665. }
  666. EXPORT_SYMBOL(migrate_page_remove_references);
  667. /*
  668. * Copy the page to its new location
  669. */
  670. void migrate_page_copy(struct page *newpage, struct page *page)
  671. {
  672. copy_highpage(newpage, page);
  673. if (PageError(page))
  674. SetPageError(newpage);
  675. if (PageReferenced(page))
  676. SetPageReferenced(newpage);
  677. if (PageUptodate(page))
  678. SetPageUptodate(newpage);
  679. if (PageActive(page))
  680. SetPageActive(newpage);
  681. if (PageChecked(page))
  682. SetPageChecked(newpage);
  683. if (PageMappedToDisk(page))
  684. SetPageMappedToDisk(newpage);
  685. if (PageDirty(page)) {
  686. clear_page_dirty_for_io(page);
  687. set_page_dirty(newpage);
  688. }
  689. ClearPageSwapCache(page);
  690. ClearPageActive(page);
  691. ClearPagePrivate(page);
  692. set_page_private(page, 0);
  693. page->mapping = NULL;
  694. /*
  695. * If any waiters have accumulated on the new page then
  696. * wake them up.
  697. */
  698. if (PageWriteback(newpage))
  699. end_page_writeback(newpage);
  700. }
  701. EXPORT_SYMBOL(migrate_page_copy);
  702. /*
  703. * Common logic to directly migrate a single page suitable for
  704. * pages that do not use PagePrivate.
  705. *
  706. * Pages are locked upon entry and exit.
  707. */
  708. int migrate_page(struct page *newpage, struct page *page)
  709. {
  710. int rc;
  711. BUG_ON(PageWriteback(page)); /* Writeback must be complete */
  712. rc = migrate_page_remove_references(newpage, page, 2);
  713. if (rc)
  714. return rc;
  715. migrate_page_copy(newpage, page);
  716. /*
  717. * Remove auxiliary swap entries and replace
  718. * them with real ptes.
  719. *
  720. * Note that a real pte entry will allow processes that are not
  721. * waiting on the page lock to use the new page via the page tables
  722. * before the new page is unlocked.
  723. */
  724. remove_from_swap(newpage);
  725. return 0;
  726. }
  727. EXPORT_SYMBOL(migrate_page);
  728. /*
  729. * migrate_pages
  730. *
  731. * Two lists are passed to this function. The first list
  732. * contains the pages isolated from the LRU to be migrated.
  733. * The second list contains new pages that the pages isolated
  734. * can be moved to. If the second list is NULL then all
  735. * pages are swapped out.
  736. *
  737. * The function returns after 10 attempts or if no pages
  738. * are movable anymore because to has become empty
  739. * or no retryable pages exist anymore.
  740. *
  741. * Return: Number of pages not migrated when "to" ran empty.
  742. */
  743. int migrate_pages(struct list_head *from, struct list_head *to,
  744. struct list_head *moved, struct list_head *failed)
  745. {
  746. int retry;
  747. int nr_failed = 0;
  748. int pass = 0;
  749. struct page *page;
  750. struct page *page2;
  751. int swapwrite = current->flags & PF_SWAPWRITE;
  752. int rc;
  753. if (!swapwrite)
  754. current->flags |= PF_SWAPWRITE;
  755. redo:
  756. retry = 0;
  757. list_for_each_entry_safe(page, page2, from, lru) {
  758. struct page *newpage = NULL;
  759. struct address_space *mapping;
  760. cond_resched();
  761. rc = 0;
  762. if (page_count(page) == 1)
  763. /* page was freed from under us. So we are done. */
  764. goto next;
  765. if (to && list_empty(to))
  766. break;
  767. /*
  768. * Skip locked pages during the first two passes to give the
  769. * functions holding the lock time to release the page. Later we
  770. * use lock_page() to have a higher chance of acquiring the
  771. * lock.
  772. */
  773. rc = -EAGAIN;
  774. if (pass > 2)
  775. lock_page(page);
  776. else
  777. if (TestSetPageLocked(page))
  778. goto next;
  779. /*
  780. * Only wait on writeback if we have already done a pass where
  781. * we we may have triggered writeouts for lots of pages.
  782. */
  783. if (pass > 0) {
  784. wait_on_page_writeback(page);
  785. } else {
  786. if (PageWriteback(page))
  787. goto unlock_page;
  788. }
  789. /*
  790. * Anonymous pages must have swap cache references otherwise
  791. * the information contained in the page maps cannot be
  792. * preserved.
  793. */
  794. if (PageAnon(page) && !PageSwapCache(page)) {
  795. if (!add_to_swap(page, GFP_KERNEL)) {
  796. rc = -ENOMEM;
  797. goto unlock_page;
  798. }
  799. }
  800. if (!to) {
  801. rc = swap_page(page);
  802. goto next;
  803. }
  804. newpage = lru_to_page(to);
  805. lock_page(newpage);
  806. /*
  807. * Pages are properly locked and writeback is complete.
  808. * Try to migrate the page.
  809. */
  810. mapping = page_mapping(page);
  811. if (!mapping)
  812. goto unlock_both;
  813. if (mapping->a_ops->migratepage) {
  814. /*
  815. * Most pages have a mapping and most filesystems
  816. * should provide a migration function. Anonymous
  817. * pages are part of swap space which also has its
  818. * own migration function. This is the most common
  819. * path for page migration.
  820. */
  821. rc = mapping->a_ops->migratepage(newpage, page);
  822. goto unlock_both;
  823. }
  824. /*
  825. * Default handling if a filesystem does not provide
  826. * a migration function. We can only migrate clean
  827. * pages so try to write out any dirty pages first.
  828. */
  829. if (PageDirty(page)) {
  830. switch (pageout(page, mapping)) {
  831. case PAGE_KEEP:
  832. case PAGE_ACTIVATE:
  833. goto unlock_both;
  834. case PAGE_SUCCESS:
  835. unlock_page(newpage);
  836. goto next;
  837. case PAGE_CLEAN:
  838. ; /* try to migrate the page below */
  839. }
  840. }
  841. /*
  842. * Buffers are managed in a filesystem specific way.
  843. * We must have no buffers or drop them.
  844. */
  845. if (!page_has_buffers(page) ||
  846. try_to_release_page(page, GFP_KERNEL)) {
  847. rc = migrate_page(newpage, page);
  848. goto unlock_both;
  849. }
  850. /*
  851. * On early passes with mapped pages simply
  852. * retry. There may be a lock held for some
  853. * buffers that may go away. Later
  854. * swap them out.
  855. */
  856. if (pass > 4) {
  857. /*
  858. * Persistently unable to drop buffers..... As a
  859. * measure of last resort we fall back to
  860. * swap_page().
  861. */
  862. unlock_page(newpage);
  863. newpage = NULL;
  864. rc = swap_page(page);
  865. goto next;
  866. }
  867. unlock_both:
  868. unlock_page(newpage);
  869. unlock_page:
  870. unlock_page(page);
  871. next:
  872. if (rc == -EAGAIN) {
  873. retry++;
  874. } else if (rc) {
  875. /* Permanent failure */
  876. list_move(&page->lru, failed);
  877. nr_failed++;
  878. } else {
  879. if (newpage) {
  880. /* Successful migration. Return page to LRU */
  881. move_to_lru(newpage);
  882. }
  883. list_move(&page->lru, moved);
  884. }
  885. }
  886. if (retry && pass++ < 10)
  887. goto redo;
  888. if (!swapwrite)
  889. current->flags &= ~PF_SWAPWRITE;
  890. return nr_failed + retry;
  891. }
  892. /*
  893. * Isolate one page from the LRU lists and put it on the
  894. * indicated list with elevated refcount.
  895. *
  896. * Result:
  897. * 0 = page not on LRU list
  898. * 1 = page removed from LRU list and added to the specified list.
  899. */
  900. int isolate_lru_page(struct page *page)
  901. {
  902. int ret = 0;
  903. if (PageLRU(page)) {
  904. struct zone *zone = page_zone(page);
  905. spin_lock_irq(&zone->lru_lock);
  906. if (PageLRU(page)) {
  907. ret = 1;
  908. get_page(page);
  909. ClearPageLRU(page);
  910. if (PageActive(page))
  911. del_page_from_active_list(zone, page);
  912. else
  913. del_page_from_inactive_list(zone, page);
  914. }
  915. spin_unlock_irq(&zone->lru_lock);
  916. }
  917. return ret;
  918. }
  919. #endif
  920. /*
  921. * zone->lru_lock is heavily contended. Some of the functions that
  922. * shrink the lists perform better by taking out a batch of pages
  923. * and working on them outside the LRU lock.
  924. *
  925. * For pagecache intensive workloads, this function is the hottest
  926. * spot in the kernel (apart from copy_*_user functions).
  927. *
  928. * Appropriate locks must be held before calling this function.
  929. *
  930. * @nr_to_scan: The number of pages to look through on the list.
  931. * @src: The LRU list to pull pages off.
  932. * @dst: The temp list to put pages on to.
  933. * @scanned: The number of pages that were scanned.
  934. *
  935. * returns how many pages were moved onto *@dst.
  936. */
  937. static int isolate_lru_pages(int nr_to_scan, struct list_head *src,
  938. struct list_head *dst, int *scanned)
  939. {
  940. int nr_taken = 0;
  941. struct page *page;
  942. int scan = 0;
  943. while (scan++ < nr_to_scan && !list_empty(src)) {
  944. struct list_head *target;
  945. page = lru_to_page(src);
  946. prefetchw_prev_lru_page(page, src, flags);
  947. BUG_ON(!PageLRU(page));
  948. list_del(&page->lru);
  949. target = src;
  950. if (likely(get_page_unless_zero(page))) {
  951. /*
  952. * Be careful not to clear PageLRU until after we're
  953. * sure the page is not being freed elsewhere -- the
  954. * page release code relies on it.
  955. */
  956. ClearPageLRU(page);
  957. target = dst;
  958. nr_taken++;
  959. } /* else it is being freed elsewhere */
  960. list_add(&page->lru, target);
  961. }
  962. *scanned = scan;
  963. return nr_taken;
  964. }
  965. /*
  966. * shrink_cache() adds the number of pages reclaimed to sc->nr_reclaimed
  967. */
  968. static void shrink_cache(int max_scan, struct zone *zone, struct scan_control *sc)
  969. {
  970. LIST_HEAD(page_list);
  971. struct pagevec pvec;
  972. pagevec_init(&pvec, 1);
  973. lru_add_drain();
  974. spin_lock_irq(&zone->lru_lock);
  975. while (max_scan > 0) {
  976. struct page *page;
  977. int nr_taken;
  978. int nr_scan;
  979. int nr_freed;
  980. nr_taken = isolate_lru_pages(sc->swap_cluster_max,
  981. &zone->inactive_list,
  982. &page_list, &nr_scan);
  983. zone->nr_inactive -= nr_taken;
  984. zone->pages_scanned += nr_scan;
  985. spin_unlock_irq(&zone->lru_lock);
  986. if (nr_taken == 0)
  987. goto done;
  988. max_scan -= nr_scan;
  989. nr_freed = shrink_list(&page_list, sc);
  990. local_irq_disable();
  991. if (current_is_kswapd()) {
  992. __mod_page_state_zone(zone, pgscan_kswapd, nr_scan);
  993. __mod_page_state(kswapd_steal, nr_freed);
  994. } else
  995. __mod_page_state_zone(zone, pgscan_direct, nr_scan);
  996. __mod_page_state_zone(zone, pgsteal, nr_freed);
  997. spin_lock(&zone->lru_lock);
  998. /*
  999. * Put back any unfreeable pages.
  1000. */
  1001. while (!list_empty(&page_list)) {
  1002. page = lru_to_page(&page_list);
  1003. BUG_ON(PageLRU(page));
  1004. SetPageLRU(page);
  1005. list_del(&page->lru);
  1006. if (PageActive(page))
  1007. add_page_to_active_list(zone, page);
  1008. else
  1009. add_page_to_inactive_list(zone, page);
  1010. if (!pagevec_add(&pvec, page)) {
  1011. spin_unlock_irq(&zone->lru_lock);
  1012. __pagevec_release(&pvec);
  1013. spin_lock_irq(&zone->lru_lock);
  1014. }
  1015. }
  1016. }
  1017. spin_unlock_irq(&zone->lru_lock);
  1018. done:
  1019. pagevec_release(&pvec);
  1020. }
  1021. /*
  1022. * This moves pages from the active list to the inactive list.
  1023. *
  1024. * We move them the other way if the page is referenced by one or more
  1025. * processes, from rmap.
  1026. *
  1027. * If the pages are mostly unmapped, the processing is fast and it is
  1028. * appropriate to hold zone->lru_lock across the whole operation. But if
  1029. * the pages are mapped, the processing is slow (page_referenced()) so we
  1030. * should drop zone->lru_lock around each page. It's impossible to balance
  1031. * this, so instead we remove the pages from the LRU while processing them.
  1032. * It is safe to rely on PG_active against the non-LRU pages in here because
  1033. * nobody will play with that bit on a non-LRU page.
  1034. *
  1035. * The downside is that we have to touch page->_count against each page.
  1036. * But we had to alter page->flags anyway.
  1037. */
  1038. static void
  1039. refill_inactive_zone(int nr_pages, struct zone *zone, struct scan_control *sc)
  1040. {
  1041. int pgmoved;
  1042. int pgdeactivate = 0;
  1043. int pgscanned;
  1044. LIST_HEAD(l_hold); /* The pages which were snipped off */
  1045. LIST_HEAD(l_inactive); /* Pages to go onto the inactive_list */
  1046. LIST_HEAD(l_active); /* Pages to go onto the active_list */
  1047. struct page *page;
  1048. struct pagevec pvec;
  1049. int reclaim_mapped = 0;
  1050. if (unlikely(sc->may_swap)) {
  1051. long mapped_ratio;
  1052. long distress;
  1053. long swap_tendency;
  1054. /*
  1055. * `distress' is a measure of how much trouble we're having
  1056. * reclaiming pages. 0 -> no problems. 100 -> great trouble.
  1057. */
  1058. distress = 100 >> zone->prev_priority;
  1059. /*
  1060. * The point of this algorithm is to decide when to start
  1061. * reclaiming mapped memory instead of just pagecache. Work out
  1062. * how much memory
  1063. * is mapped.
  1064. */
  1065. mapped_ratio = (sc->nr_mapped * 100) / total_memory;
  1066. /*
  1067. * Now decide how much we really want to unmap some pages. The
  1068. * mapped ratio is downgraded - just because there's a lot of
  1069. * mapped memory doesn't necessarily mean that page reclaim
  1070. * isn't succeeding.
  1071. *
  1072. * The distress ratio is important - we don't want to start
  1073. * going oom.
  1074. *
  1075. * A 100% value of vm_swappiness overrides this algorithm
  1076. * altogether.
  1077. */
  1078. swap_tendency = mapped_ratio / 2 + distress + vm_swappiness;
  1079. /*
  1080. * Now use this metric to decide whether to start moving mapped
  1081. * memory onto the inactive list.
  1082. */
  1083. if (swap_tendency >= 100)
  1084. reclaim_mapped = 1;
  1085. }
  1086. lru_add_drain();
  1087. spin_lock_irq(&zone->lru_lock);
  1088. pgmoved = isolate_lru_pages(nr_pages, &zone->active_list,
  1089. &l_hold, &pgscanned);
  1090. zone->pages_scanned += pgscanned;
  1091. zone->nr_active -= pgmoved;
  1092. spin_unlock_irq(&zone->lru_lock);
  1093. while (!list_empty(&l_hold)) {
  1094. cond_resched();
  1095. page = lru_to_page(&l_hold);
  1096. list_del(&page->lru);
  1097. if (page_mapped(page)) {
  1098. if (!reclaim_mapped ||
  1099. (total_swap_pages == 0 && PageAnon(page)) ||
  1100. page_referenced(page, 0)) {
  1101. list_add(&page->lru, &l_active);
  1102. continue;
  1103. }
  1104. }
  1105. list_add(&page->lru, &l_inactive);
  1106. }
  1107. pagevec_init(&pvec, 1);
  1108. pgmoved = 0;
  1109. spin_lock_irq(&zone->lru_lock);
  1110. while (!list_empty(&l_inactive)) {
  1111. page = lru_to_page(&l_inactive);
  1112. prefetchw_prev_lru_page(page, &l_inactive, flags);
  1113. BUG_ON(PageLRU(page));
  1114. SetPageLRU(page);
  1115. BUG_ON(!PageActive(page));
  1116. ClearPageActive(page);
  1117. list_move(&page->lru, &zone->inactive_list);
  1118. pgmoved++;
  1119. if (!pagevec_add(&pvec, page)) {
  1120. zone->nr_inactive += pgmoved;
  1121. spin_unlock_irq(&zone->lru_lock);
  1122. pgdeactivate += pgmoved;
  1123. pgmoved = 0;
  1124. if (buffer_heads_over_limit)
  1125. pagevec_strip(&pvec);
  1126. __pagevec_release(&pvec);
  1127. spin_lock_irq(&zone->lru_lock);
  1128. }
  1129. }
  1130. zone->nr_inactive += pgmoved;
  1131. pgdeactivate += pgmoved;
  1132. if (buffer_heads_over_limit) {
  1133. spin_unlock_irq(&zone->lru_lock);
  1134. pagevec_strip(&pvec);
  1135. spin_lock_irq(&zone->lru_lock);
  1136. }
  1137. pgmoved = 0;
  1138. while (!list_empty(&l_active)) {
  1139. page = lru_to_page(&l_active);
  1140. prefetchw_prev_lru_page(page, &l_active, flags);
  1141. BUG_ON(PageLRU(page));
  1142. SetPageLRU(page);
  1143. BUG_ON(!PageActive(page));
  1144. list_move(&page->lru, &zone->active_list);
  1145. pgmoved++;
  1146. if (!pagevec_add(&pvec, page)) {
  1147. zone->nr_active += pgmoved;
  1148. pgmoved = 0;
  1149. spin_unlock_irq(&zone->lru_lock);
  1150. __pagevec_release(&pvec);
  1151. spin_lock_irq(&zone->lru_lock);
  1152. }
  1153. }
  1154. zone->nr_active += pgmoved;
  1155. spin_unlock(&zone->lru_lock);
  1156. __mod_page_state_zone(zone, pgrefill, pgscanned);
  1157. __mod_page_state(pgdeactivate, pgdeactivate);
  1158. local_irq_enable();
  1159. pagevec_release(&pvec);
  1160. }
  1161. /*
  1162. * This is a basic per-zone page freer. Used by both kswapd and direct reclaim.
  1163. */
  1164. static void
  1165. shrink_zone(int priority, struct zone *zone, struct scan_control *sc)
  1166. {
  1167. unsigned long nr_active;
  1168. unsigned long nr_inactive;
  1169. unsigned long nr_to_scan;
  1170. atomic_inc(&zone->reclaim_in_progress);
  1171. /*
  1172. * Add one to `nr_to_scan' just to make sure that the kernel will
  1173. * slowly sift through the active list.
  1174. */
  1175. zone->nr_scan_active += (zone->nr_active >> priority) + 1;
  1176. nr_active = zone->nr_scan_active;
  1177. if (nr_active >= sc->swap_cluster_max)
  1178. zone->nr_scan_active = 0;
  1179. else
  1180. nr_active = 0;
  1181. zone->nr_scan_inactive += (zone->nr_inactive >> priority) + 1;
  1182. nr_inactive = zone->nr_scan_inactive;
  1183. if (nr_inactive >= sc->swap_cluster_max)
  1184. zone->nr_scan_inactive = 0;
  1185. else
  1186. nr_inactive = 0;
  1187. while (nr_active || nr_inactive) {
  1188. if (nr_active) {
  1189. nr_to_scan = min(nr_active,
  1190. (unsigned long)sc->swap_cluster_max);
  1191. nr_active -= nr_to_scan;
  1192. refill_inactive_zone(nr_to_scan, zone, sc);
  1193. }
  1194. if (nr_inactive) {
  1195. nr_to_scan = min(nr_inactive,
  1196. (unsigned long)sc->swap_cluster_max);
  1197. nr_inactive -= nr_to_scan;
  1198. shrink_cache(nr_to_scan, zone, sc);
  1199. }
  1200. }
  1201. throttle_vm_writeout();
  1202. atomic_dec(&zone->reclaim_in_progress);
  1203. }
  1204. /*
  1205. * This is the direct reclaim path, for page-allocating processes. We only
  1206. * try to reclaim pages from zones which will satisfy the caller's allocation
  1207. * request.
  1208. *
  1209. * We reclaim from a zone even if that zone is over pages_high. Because:
  1210. * a) The caller may be trying to free *extra* pages to satisfy a higher-order
  1211. * allocation or
  1212. * b) The zones may be over pages_high but they must go *over* pages_high to
  1213. * satisfy the `incremental min' zone defense algorithm.
  1214. *
  1215. * Returns the number of reclaimed pages.
  1216. *
  1217. * If a zone is deemed to be full of pinned pages then just give it a light
  1218. * scan then give up on it.
  1219. */
  1220. static void
  1221. shrink_caches(int priority, struct zone **zones, struct scan_control *sc)
  1222. {
  1223. int i;
  1224. for (i = 0; zones[i] != NULL; i++) {
  1225. struct zone *zone = zones[i];
  1226. if (!populated_zone(zone))
  1227. continue;
  1228. if (!cpuset_zone_allowed(zone, __GFP_HARDWALL))
  1229. continue;
  1230. zone->temp_priority = priority;
  1231. if (zone->prev_priority > priority)
  1232. zone->prev_priority = priority;
  1233. if (zone->all_unreclaimable && priority != DEF_PRIORITY)
  1234. continue; /* Let kswapd poll it */
  1235. shrink_zone(priority, zone, sc);
  1236. }
  1237. }
  1238. /*
  1239. * This is the main entry point to direct page reclaim.
  1240. *
  1241. * If a full scan of the inactive list fails to free enough memory then we
  1242. * are "out of memory" and something needs to be killed.
  1243. *
  1244. * If the caller is !__GFP_FS then the probability of a failure is reasonably
  1245. * high - the zone may be full of dirty or under-writeback pages, which this
  1246. * caller can't do much about. We kick pdflush and take explicit naps in the
  1247. * hope that some of these pages can be written. But if the allocating task
  1248. * holds filesystem locks which prevent writeout this might not work, and the
  1249. * allocation attempt will fail.
  1250. */
  1251. int try_to_free_pages(struct zone **zones, gfp_t gfp_mask)
  1252. {
  1253. int priority;
  1254. int ret = 0;
  1255. int total_scanned = 0, total_reclaimed = 0;
  1256. struct reclaim_state *reclaim_state = current->reclaim_state;
  1257. unsigned long lru_pages = 0;
  1258. int i;
  1259. struct scan_control sc = {
  1260. .gfp_mask = gfp_mask,
  1261. .may_writepage = !laptop_mode,
  1262. .swap_cluster_max = SWAP_CLUSTER_MAX,
  1263. .may_swap = 1,
  1264. };
  1265. inc_page_state(allocstall);
  1266. for (i = 0; zones[i] != NULL; i++) {
  1267. struct zone *zone = zones[i];
  1268. if (!cpuset_zone_allowed(zone, __GFP_HARDWALL))
  1269. continue;
  1270. zone->temp_priority = DEF_PRIORITY;
  1271. lru_pages += zone->nr_active + zone->nr_inactive;
  1272. }
  1273. for (priority = DEF_PRIORITY; priority >= 0; priority--) {
  1274. sc.nr_mapped = read_page_state(nr_mapped);
  1275. sc.nr_scanned = 0;
  1276. sc.nr_reclaimed = 0;
  1277. if (!priority)
  1278. disable_swap_token();
  1279. shrink_caches(priority, zones, &sc);
  1280. shrink_slab(sc.nr_scanned, gfp_mask, lru_pages);
  1281. if (reclaim_state) {
  1282. sc.nr_reclaimed += reclaim_state->reclaimed_slab;
  1283. reclaim_state->reclaimed_slab = 0;
  1284. }
  1285. total_scanned += sc.nr_scanned;
  1286. total_reclaimed += sc.nr_reclaimed;
  1287. if (total_reclaimed >= sc.swap_cluster_max) {
  1288. ret = 1;
  1289. goto out;
  1290. }
  1291. /*
  1292. * Try to write back as many pages as we just scanned. This
  1293. * tends to cause slow streaming writers to write data to the
  1294. * disk smoothly, at the dirtying rate, which is nice. But
  1295. * that's undesirable in laptop mode, where we *want* lumpy
  1296. * writeout. So in laptop mode, write out the whole world.
  1297. */
  1298. if (total_scanned > sc.swap_cluster_max +
  1299. sc.swap_cluster_max / 2) {
  1300. wakeup_pdflush(laptop_mode ? 0 : total_scanned);
  1301. sc.may_writepage = 1;
  1302. }
  1303. /* Take a nap, wait for some writeback to complete */
  1304. if (sc.nr_scanned && priority < DEF_PRIORITY - 2)
  1305. blk_congestion_wait(WRITE, HZ/10);
  1306. }
  1307. out:
  1308. for (i = 0; zones[i] != 0; i++) {
  1309. struct zone *zone = zones[i];
  1310. if (!cpuset_zone_allowed(zone, __GFP_HARDWALL))
  1311. continue;
  1312. zone->prev_priority = zone->temp_priority;
  1313. }
  1314. return ret;
  1315. }
  1316. /*
  1317. * For kswapd, balance_pgdat() will work across all this node's zones until
  1318. * they are all at pages_high.
  1319. *
  1320. * If `nr_pages' is non-zero then it is the number of pages which are to be
  1321. * reclaimed, regardless of the zone occupancies. This is a software suspend
  1322. * special.
  1323. *
  1324. * Returns the number of pages which were actually freed.
  1325. *
  1326. * There is special handling here for zones which are full of pinned pages.
  1327. * This can happen if the pages are all mlocked, or if they are all used by
  1328. * device drivers (say, ZONE_DMA). Or if they are all in use by hugetlb.
  1329. * What we do is to detect the case where all pages in the zone have been
  1330. * scanned twice and there has been zero successful reclaim. Mark the zone as
  1331. * dead and from now on, only perform a short scan. Basically we're polling
  1332. * the zone for when the problem goes away.
  1333. *
  1334. * kswapd scans the zones in the highmem->normal->dma direction. It skips
  1335. * zones which have free_pages > pages_high, but once a zone is found to have
  1336. * free_pages <= pages_high, we scan that zone and the lower zones regardless
  1337. * of the number of free pages in the lower zones. This interoperates with
  1338. * the page allocator fallback scheme to ensure that aging of pages is balanced
  1339. * across the zones.
  1340. */
  1341. static int balance_pgdat(pg_data_t *pgdat, int nr_pages, int order)
  1342. {
  1343. int to_free = nr_pages;
  1344. int all_zones_ok;
  1345. int priority;
  1346. int i;
  1347. int total_scanned, total_reclaimed;
  1348. struct reclaim_state *reclaim_state = current->reclaim_state;
  1349. struct scan_control sc = {
  1350. .gfp_mask = GFP_KERNEL,
  1351. .may_swap = 1,
  1352. .swap_cluster_max = nr_pages ? nr_pages : SWAP_CLUSTER_MAX,
  1353. };
  1354. loop_again:
  1355. total_scanned = 0;
  1356. total_reclaimed = 0;
  1357. sc.may_writepage = !laptop_mode,
  1358. sc.nr_mapped = read_page_state(nr_mapped);
  1359. inc_page_state(pageoutrun);
  1360. for (i = 0; i < pgdat->nr_zones; i++) {
  1361. struct zone *zone = pgdat->node_zones + i;
  1362. zone->temp_priority = DEF_PRIORITY;
  1363. }
  1364. for (priority = DEF_PRIORITY; priority >= 0; priority--) {
  1365. int end_zone = 0; /* Inclusive. 0 = ZONE_DMA */
  1366. unsigned long lru_pages = 0;
  1367. /* The swap token gets in the way of swapout... */
  1368. if (!priority)
  1369. disable_swap_token();
  1370. all_zones_ok = 1;
  1371. if (nr_pages == 0) {
  1372. /*
  1373. * Scan in the highmem->dma direction for the highest
  1374. * zone which needs scanning
  1375. */
  1376. for (i = pgdat->nr_zones - 1; i >= 0; i--) {
  1377. struct zone *zone = pgdat->node_zones + i;
  1378. if (!populated_zone(zone))
  1379. continue;
  1380. if (zone->all_unreclaimable &&
  1381. priority != DEF_PRIORITY)
  1382. continue;
  1383. if (!zone_watermark_ok(zone, order,
  1384. zone->pages_high, 0, 0)) {
  1385. end_zone = i;
  1386. goto scan;
  1387. }
  1388. }
  1389. goto out;
  1390. } else {
  1391. end_zone = pgdat->nr_zones - 1;
  1392. }
  1393. scan:
  1394. for (i = 0; i <= end_zone; i++) {
  1395. struct zone *zone = pgdat->node_zones + i;
  1396. lru_pages += zone->nr_active + zone->nr_inactive;
  1397. }
  1398. /*
  1399. * Now scan the zone in the dma->highmem direction, stopping
  1400. * at the last zone which needs scanning.
  1401. *
  1402. * We do this because the page allocator works in the opposite
  1403. * direction. This prevents the page allocator from allocating
  1404. * pages behind kswapd's direction of progress, which would
  1405. * cause too much scanning of the lower zones.
  1406. */
  1407. for (i = 0; i <= end_zone; i++) {
  1408. struct zone *zone = pgdat->node_zones + i;
  1409. int nr_slab;
  1410. if (!populated_zone(zone))
  1411. continue;
  1412. if (zone->all_unreclaimable && priority != DEF_PRIORITY)
  1413. continue;
  1414. if (nr_pages == 0) { /* Not software suspend */
  1415. if (!zone_watermark_ok(zone, order,
  1416. zone->pages_high, end_zone, 0))
  1417. all_zones_ok = 0;
  1418. }
  1419. zone->temp_priority = priority;
  1420. if (zone->prev_priority > priority)
  1421. zone->prev_priority = priority;
  1422. sc.nr_scanned = 0;
  1423. sc.nr_reclaimed = 0;
  1424. shrink_zone(priority, zone, &sc);
  1425. reclaim_state->reclaimed_slab = 0;
  1426. nr_slab = shrink_slab(sc.nr_scanned, GFP_KERNEL,
  1427. lru_pages);
  1428. sc.nr_reclaimed += reclaim_state->reclaimed_slab;
  1429. total_reclaimed += sc.nr_reclaimed;
  1430. total_scanned += sc.nr_scanned;
  1431. if (zone->all_unreclaimable)
  1432. continue;
  1433. if (nr_slab == 0 && zone->pages_scanned >=
  1434. (zone->nr_active + zone->nr_inactive) * 4)
  1435. zone->all_unreclaimable = 1;
  1436. /*
  1437. * If we've done a decent amount of scanning and
  1438. * the reclaim ratio is low, start doing writepage
  1439. * even in laptop mode
  1440. */
  1441. if (total_scanned > SWAP_CLUSTER_MAX * 2 &&
  1442. total_scanned > total_reclaimed+total_reclaimed/2)
  1443. sc.may_writepage = 1;
  1444. }
  1445. if (nr_pages && to_free > total_reclaimed)
  1446. continue; /* swsusp: need to do more work */
  1447. if (all_zones_ok)
  1448. break; /* kswapd: all done */
  1449. /*
  1450. * OK, kswapd is getting into trouble. Take a nap, then take
  1451. * another pass across the zones.
  1452. */
  1453. if (total_scanned && priority < DEF_PRIORITY - 2)
  1454. blk_congestion_wait(WRITE, HZ/10);
  1455. /*
  1456. * We do this so kswapd doesn't build up large priorities for
  1457. * example when it is freeing in parallel with allocators. It
  1458. * matches the direct reclaim path behaviour in terms of impact
  1459. * on zone->*_priority.
  1460. */
  1461. if ((total_reclaimed >= SWAP_CLUSTER_MAX) && (!nr_pages))
  1462. break;
  1463. }
  1464. out:
  1465. for (i = 0; i < pgdat->nr_zones; i++) {
  1466. struct zone *zone = pgdat->node_zones + i;
  1467. zone->prev_priority = zone->temp_priority;
  1468. }
  1469. if (!all_zones_ok) {
  1470. cond_resched();
  1471. goto loop_again;
  1472. }
  1473. return total_reclaimed;
  1474. }
  1475. /*
  1476. * The background pageout daemon, started as a kernel thread
  1477. * from the init process.
  1478. *
  1479. * This basically trickles out pages so that we have _some_
  1480. * free memory available even if there is no other activity
  1481. * that frees anything up. This is needed for things like routing
  1482. * etc, where we otherwise might have all activity going on in
  1483. * asynchronous contexts that cannot page things out.
  1484. *
  1485. * If there are applications that are active memory-allocators
  1486. * (most normal use), this basically shouldn't matter.
  1487. */
  1488. static int kswapd(void *p)
  1489. {
  1490. unsigned long order;
  1491. pg_data_t *pgdat = (pg_data_t*)p;
  1492. struct task_struct *tsk = current;
  1493. DEFINE_WAIT(wait);
  1494. struct reclaim_state reclaim_state = {
  1495. .reclaimed_slab = 0,
  1496. };
  1497. cpumask_t cpumask;
  1498. daemonize("kswapd%d", pgdat->node_id);
  1499. cpumask = node_to_cpumask(pgdat->node_id);
  1500. if (!cpus_empty(cpumask))
  1501. set_cpus_allowed(tsk, cpumask);
  1502. current->reclaim_state = &reclaim_state;
  1503. /*
  1504. * Tell the memory management that we're a "memory allocator",
  1505. * and that if we need more memory we should get access to it
  1506. * regardless (see "__alloc_pages()"). "kswapd" should
  1507. * never get caught in the normal page freeing logic.
  1508. *
  1509. * (Kswapd normally doesn't need memory anyway, but sometimes
  1510. * you need a small amount of memory in order to be able to
  1511. * page out something else, and this flag essentially protects
  1512. * us from recursively trying to free more memory as we're
  1513. * trying to free the first piece of memory in the first place).
  1514. */
  1515. tsk->flags |= PF_MEMALLOC | PF_SWAPWRITE | PF_KSWAPD;
  1516. order = 0;
  1517. for ( ; ; ) {
  1518. unsigned long new_order;
  1519. try_to_freeze();
  1520. prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
  1521. new_order = pgdat->kswapd_max_order;
  1522. pgdat->kswapd_max_order = 0;
  1523. if (order < new_order) {
  1524. /*
  1525. * Don't sleep if someone wants a larger 'order'
  1526. * allocation
  1527. */
  1528. order = new_order;
  1529. } else {
  1530. schedule();
  1531. order = pgdat->kswapd_max_order;
  1532. }
  1533. finish_wait(&pgdat->kswapd_wait, &wait);
  1534. balance_pgdat(pgdat, 0, order);
  1535. }
  1536. return 0;
  1537. }
  1538. /*
  1539. * A zone is low on free memory, so wake its kswapd task to service it.
  1540. */
  1541. void wakeup_kswapd(struct zone *zone, int order)
  1542. {
  1543. pg_data_t *pgdat;
  1544. if (!populated_zone(zone))
  1545. return;
  1546. pgdat = zone->zone_pgdat;
  1547. if (zone_watermark_ok(zone, order, zone->pages_low, 0, 0))
  1548. return;
  1549. if (pgdat->kswapd_max_order < order)
  1550. pgdat->kswapd_max_order = order;
  1551. if (!cpuset_zone_allowed(zone, __GFP_HARDWALL))
  1552. return;
  1553. if (!waitqueue_active(&pgdat->kswapd_wait))
  1554. return;
  1555. wake_up_interruptible(&pgdat->kswapd_wait);
  1556. }
  1557. #ifdef CONFIG_PM
  1558. /*
  1559. * Try to free `nr_pages' of memory, system-wide. Returns the number of freed
  1560. * pages.
  1561. */
  1562. int shrink_all_memory(int nr_pages)
  1563. {
  1564. pg_data_t *pgdat;
  1565. int nr_to_free = nr_pages;
  1566. int ret = 0;
  1567. struct reclaim_state reclaim_state = {
  1568. .reclaimed_slab = 0,
  1569. };
  1570. current->reclaim_state = &reclaim_state;
  1571. for_each_pgdat(pgdat) {
  1572. int freed;
  1573. freed = balance_pgdat(pgdat, nr_to_free, 0);
  1574. ret += freed;
  1575. nr_to_free -= freed;
  1576. if (nr_to_free <= 0)
  1577. break;
  1578. }
  1579. current->reclaim_state = NULL;
  1580. return ret;
  1581. }
  1582. #endif
  1583. #ifdef CONFIG_HOTPLUG_CPU
  1584. /* It's optimal to keep kswapds on the same CPUs as their memory, but
  1585. not required for correctness. So if the last cpu in a node goes
  1586. away, we get changed to run anywhere: as the first one comes back,
  1587. restore their cpu bindings. */
  1588. static int __devinit cpu_callback(struct notifier_block *nfb,
  1589. unsigned long action,
  1590. void *hcpu)
  1591. {
  1592. pg_data_t *pgdat;
  1593. cpumask_t mask;
  1594. if (action == CPU_ONLINE) {
  1595. for_each_pgdat(pgdat) {
  1596. mask = node_to_cpumask(pgdat->node_id);
  1597. if (any_online_cpu(mask) != NR_CPUS)
  1598. /* One of our CPUs online: restore mask */
  1599. set_cpus_allowed(pgdat->kswapd, mask);
  1600. }
  1601. }
  1602. return NOTIFY_OK;
  1603. }
  1604. #endif /* CONFIG_HOTPLUG_CPU */
  1605. static int __init kswapd_init(void)
  1606. {
  1607. pg_data_t *pgdat;
  1608. swap_setup();
  1609. for_each_pgdat(pgdat)
  1610. pgdat->kswapd
  1611. = find_task_by_pid(kernel_thread(kswapd, pgdat, CLONE_KERNEL));
  1612. total_memory = nr_free_pagecache_pages();
  1613. hotcpu_notifier(cpu_callback, 0);
  1614. return 0;
  1615. }
  1616. module_init(kswapd_init)
  1617. #ifdef CONFIG_NUMA
  1618. /*
  1619. * Zone reclaim mode
  1620. *
  1621. * If non-zero call zone_reclaim when the number of free pages falls below
  1622. * the watermarks.
  1623. *
  1624. * In the future we may add flags to the mode. However, the page allocator
  1625. * should only have to check that zone_reclaim_mode != 0 before calling
  1626. * zone_reclaim().
  1627. */
  1628. int zone_reclaim_mode __read_mostly;
  1629. #define RECLAIM_OFF 0
  1630. #define RECLAIM_ZONE (1<<0) /* Run shrink_cache on the zone */
  1631. #define RECLAIM_WRITE (1<<1) /* Writeout pages during reclaim */
  1632. #define RECLAIM_SWAP (1<<2) /* Swap pages out during reclaim */
  1633. #define RECLAIM_SLAB (1<<3) /* Do a global slab shrink if the zone is out of memory */
  1634. /*
  1635. * Mininum time between zone reclaim scans
  1636. */
  1637. int zone_reclaim_interval __read_mostly = 30*HZ;
  1638. /*
  1639. * Priority for ZONE_RECLAIM. This determines the fraction of pages
  1640. * of a node considered for each zone_reclaim. 4 scans 1/16th of
  1641. * a zone.
  1642. */
  1643. #define ZONE_RECLAIM_PRIORITY 4
  1644. /*
  1645. * Try to free up some pages from this zone through reclaim.
  1646. */
  1647. static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
  1648. {
  1649. const int nr_pages = 1 << order;
  1650. struct task_struct *p = current;
  1651. struct reclaim_state reclaim_state;
  1652. int priority;
  1653. struct scan_control sc = {
  1654. .may_writepage = !!(zone_reclaim_mode & RECLAIM_WRITE),
  1655. .may_swap = !!(zone_reclaim_mode & RECLAIM_SWAP),
  1656. .nr_mapped = read_page_state(nr_mapped),
  1657. .swap_cluster_max = max(nr_pages, SWAP_CLUSTER_MAX),
  1658. .gfp_mask = gfp_mask,
  1659. };
  1660. disable_swap_token();
  1661. cond_resched();
  1662. /*
  1663. * We need to be able to allocate from the reserves for RECLAIM_SWAP
  1664. * and we also need to be able to write out pages for RECLAIM_WRITE
  1665. * and RECLAIM_SWAP.
  1666. */
  1667. p->flags |= PF_MEMALLOC | PF_SWAPWRITE;
  1668. reclaim_state.reclaimed_slab = 0;
  1669. p->reclaim_state = &reclaim_state;
  1670. /*
  1671. * Free memory by calling shrink zone with increasing priorities
  1672. * until we have enough memory freed.
  1673. */
  1674. priority = ZONE_RECLAIM_PRIORITY;
  1675. do {
  1676. shrink_zone(priority, zone, &sc);
  1677. priority--;
  1678. } while (priority >= 0 && sc.nr_reclaimed < nr_pages);
  1679. if (sc.nr_reclaimed < nr_pages && (zone_reclaim_mode & RECLAIM_SLAB)) {
  1680. /*
  1681. * shrink_slab does not currently allow us to determine
  1682. * how many pages were freed in the zone. So we just
  1683. * shake the slab and then go offnode for a single allocation.
  1684. *
  1685. * shrink_slab will free memory on all zones and may take
  1686. * a long time.
  1687. */
  1688. shrink_slab(sc.nr_scanned, gfp_mask, order);
  1689. }
  1690. p->reclaim_state = NULL;
  1691. current->flags &= ~(PF_MEMALLOC | PF_SWAPWRITE);
  1692. if (sc.nr_reclaimed == 0)
  1693. zone->last_unsuccessful_zone_reclaim = jiffies;
  1694. return sc.nr_reclaimed >= nr_pages;
  1695. }
  1696. int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
  1697. {
  1698. cpumask_t mask;
  1699. int node_id;
  1700. /*
  1701. * Do not reclaim if there was a recent unsuccessful attempt at zone
  1702. * reclaim. In that case we let allocations go off node for the
  1703. * zone_reclaim_interval. Otherwise we would scan for each off-node
  1704. * page allocation.
  1705. */
  1706. if (time_before(jiffies,
  1707. zone->last_unsuccessful_zone_reclaim + zone_reclaim_interval))
  1708. return 0;
  1709. /*
  1710. * Avoid concurrent zone reclaims, do not reclaim in a zone that does
  1711. * not have reclaimable pages and if we should not delay the allocation
  1712. * then do not scan.
  1713. */
  1714. if (!(gfp_mask & __GFP_WAIT) ||
  1715. zone->all_unreclaimable ||
  1716. atomic_read(&zone->reclaim_in_progress) > 0 ||
  1717. (current->flags & PF_MEMALLOC))
  1718. return 0;
  1719. /*
  1720. * Only run zone reclaim on the local zone or on zones that do not
  1721. * have associated processors. This will favor the local processor
  1722. * over remote processors and spread off node memory allocations
  1723. * as wide as possible.
  1724. */
  1725. node_id = zone->zone_pgdat->node_id;
  1726. mask = node_to_cpumask(node_id);
  1727. if (!cpus_empty(mask) && node_id != numa_node_id())
  1728. return 0;
  1729. return __zone_reclaim(zone, gfp_mask, order);
  1730. }
  1731. #endif