swap.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * linux/mm/swap.c
  3. *
  4. * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
  5. */
  6. /*
  7. * This file contains the default values for the operation of the
  8. * Linux VM subsystem. Fine-tuning documentation can be found in
  9. * Documentation/sysctl/vm.txt.
  10. * Started 18.12.91
  11. * Swap aging added 23.2.95, Stephen Tweedie.
  12. * Buffermem limits added 12.3.98, Rik van Riel.
  13. */
  14. #include <linux/mm.h>
  15. #include <linux/sched.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/swap.h>
  18. #include <linux/mman.h>
  19. #include <linux/pagemap.h>
  20. #include <linux/pagevec.h>
  21. #include <linux/init.h>
  22. #include <linux/module.h>
  23. #include <linux/mm_inline.h>
  24. #include <linux/buffer_head.h> /* for try_to_release_page() */
  25. #include <linux/percpu_counter.h>
  26. #include <linux/percpu.h>
  27. #include <linux/cpu.h>
  28. #include <linux/notifier.h>
  29. #include <linux/backing-dev.h>
  30. #include <linux/memcontrol.h>
  31. #include <linux/gfp.h>
  32. #include "internal.h"
  33. /* How many pages do we try to swap or page in/out together? */
  34. int page_cluster;
  35. static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
  36. static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
  37. static DEFINE_PER_CPU(struct pagevec, lru_deactivate_pvecs);
  38. /*
  39. * This path almost never happens for VM activity - pages are normally
  40. * freed via pagevecs. But it gets used by networking.
  41. */
  42. static void __page_cache_release(struct page *page)
  43. {
  44. if (PageLRU(page)) {
  45. unsigned long flags;
  46. struct zone *zone = page_zone(page);
  47. spin_lock_irqsave(&zone->lru_lock, flags);
  48. VM_BUG_ON(!PageLRU(page));
  49. __ClearPageLRU(page);
  50. del_page_from_lru(zone, page);
  51. spin_unlock_irqrestore(&zone->lru_lock, flags);
  52. }
  53. }
  54. static void __put_single_page(struct page *page)
  55. {
  56. __page_cache_release(page);
  57. free_hot_cold_page(page, 0);
  58. }
  59. static void __put_compound_page(struct page *page)
  60. {
  61. compound_page_dtor *dtor;
  62. __page_cache_release(page);
  63. dtor = get_compound_page_dtor(page);
  64. (*dtor)(page);
  65. }
  66. static void put_compound_page(struct page *page)
  67. {
  68. if (unlikely(PageTail(page))) {
  69. /* __split_huge_page_refcount can run under us */
  70. struct page *page_head = page->first_page;
  71. smp_rmb();
  72. /*
  73. * If PageTail is still set after smp_rmb() we can be sure
  74. * that the page->first_page we read wasn't a dangling pointer.
  75. * See __split_huge_page_refcount() smp_wmb().
  76. */
  77. if (likely(PageTail(page) && get_page_unless_zero(page_head))) {
  78. unsigned long flags;
  79. /*
  80. * Verify that our page_head wasn't converted
  81. * to a a regular page before we got a
  82. * reference on it.
  83. */
  84. if (unlikely(!PageHead(page_head))) {
  85. /* PageHead is cleared after PageTail */
  86. smp_rmb();
  87. VM_BUG_ON(PageTail(page));
  88. goto out_put_head;
  89. }
  90. /*
  91. * Only run compound_lock on a valid PageHead,
  92. * after having it pinned with
  93. * get_page_unless_zero() above.
  94. */
  95. smp_mb();
  96. /* page_head wasn't a dangling pointer */
  97. flags = compound_lock_irqsave(page_head);
  98. if (unlikely(!PageTail(page))) {
  99. /* __split_huge_page_refcount run before us */
  100. compound_unlock_irqrestore(page_head, flags);
  101. VM_BUG_ON(PageHead(page_head));
  102. out_put_head:
  103. if (put_page_testzero(page_head))
  104. __put_single_page(page_head);
  105. out_put_single:
  106. if (put_page_testzero(page))
  107. __put_single_page(page);
  108. return;
  109. }
  110. VM_BUG_ON(page_head != page->first_page);
  111. /*
  112. * We can release the refcount taken by
  113. * get_page_unless_zero now that
  114. * split_huge_page_refcount is blocked on the
  115. * compound_lock.
  116. */
  117. if (put_page_testzero(page_head))
  118. VM_BUG_ON(1);
  119. /* __split_huge_page_refcount will wait now */
  120. VM_BUG_ON(atomic_read(&page->_count) <= 0);
  121. atomic_dec(&page->_count);
  122. VM_BUG_ON(atomic_read(&page_head->_count) <= 0);
  123. compound_unlock_irqrestore(page_head, flags);
  124. if (put_page_testzero(page_head)) {
  125. if (PageHead(page_head))
  126. __put_compound_page(page_head);
  127. else
  128. __put_single_page(page_head);
  129. }
  130. } else {
  131. /* page_head is a dangling pointer */
  132. VM_BUG_ON(PageTail(page));
  133. goto out_put_single;
  134. }
  135. } else if (put_page_testzero(page)) {
  136. if (PageHead(page))
  137. __put_compound_page(page);
  138. else
  139. __put_single_page(page);
  140. }
  141. }
  142. void put_page(struct page *page)
  143. {
  144. if (unlikely(PageCompound(page)))
  145. put_compound_page(page);
  146. else if (put_page_testzero(page))
  147. __put_single_page(page);
  148. }
  149. EXPORT_SYMBOL(put_page);
  150. /**
  151. * put_pages_list() - release a list of pages
  152. * @pages: list of pages threaded on page->lru
  153. *
  154. * Release a list of pages which are strung together on page.lru. Currently
  155. * used by read_cache_pages() and related error recovery code.
  156. */
  157. void put_pages_list(struct list_head *pages)
  158. {
  159. while (!list_empty(pages)) {
  160. struct page *victim;
  161. victim = list_entry(pages->prev, struct page, lru);
  162. list_del(&victim->lru);
  163. page_cache_release(victim);
  164. }
  165. }
  166. EXPORT_SYMBOL(put_pages_list);
  167. /*
  168. * pagevec_move_tail() must be called with IRQ disabled.
  169. * Otherwise this may cause nasty races.
  170. */
  171. static void pagevec_move_tail(struct pagevec *pvec)
  172. {
  173. int i;
  174. int pgmoved = 0;
  175. struct zone *zone = NULL;
  176. for (i = 0; i < pagevec_count(pvec); i++) {
  177. struct page *page = pvec->pages[i];
  178. struct zone *pagezone = page_zone(page);
  179. if (pagezone != zone) {
  180. if (zone)
  181. spin_unlock(&zone->lru_lock);
  182. zone = pagezone;
  183. spin_lock(&zone->lru_lock);
  184. }
  185. if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
  186. int lru = page_lru_base_type(page);
  187. list_move_tail(&page->lru, &zone->lru[lru].list);
  188. pgmoved++;
  189. }
  190. }
  191. if (zone)
  192. spin_unlock(&zone->lru_lock);
  193. __count_vm_events(PGROTATED, pgmoved);
  194. release_pages(pvec->pages, pvec->nr, pvec->cold);
  195. pagevec_reinit(pvec);
  196. }
  197. /*
  198. * Writeback is about to end against a page which has been marked for immediate
  199. * reclaim. If it still appears to be reclaimable, move it to the tail of the
  200. * inactive list.
  201. */
  202. void rotate_reclaimable_page(struct page *page)
  203. {
  204. if (!PageLocked(page) && !PageDirty(page) && !PageActive(page) &&
  205. !PageUnevictable(page) && PageLRU(page)) {
  206. struct pagevec *pvec;
  207. unsigned long flags;
  208. page_cache_get(page);
  209. local_irq_save(flags);
  210. pvec = &__get_cpu_var(lru_rotate_pvecs);
  211. if (!pagevec_add(pvec, page))
  212. pagevec_move_tail(pvec);
  213. local_irq_restore(flags);
  214. }
  215. }
  216. static void update_page_reclaim_stat(struct zone *zone, struct page *page,
  217. int file, int rotated)
  218. {
  219. struct zone_reclaim_stat *reclaim_stat = &zone->reclaim_stat;
  220. struct zone_reclaim_stat *memcg_reclaim_stat;
  221. memcg_reclaim_stat = mem_cgroup_get_reclaim_stat_from_page(page);
  222. reclaim_stat->recent_scanned[file]++;
  223. if (rotated)
  224. reclaim_stat->recent_rotated[file]++;
  225. if (!memcg_reclaim_stat)
  226. return;
  227. memcg_reclaim_stat->recent_scanned[file]++;
  228. if (rotated)
  229. memcg_reclaim_stat->recent_rotated[file]++;
  230. }
  231. /*
  232. * FIXME: speed this up?
  233. */
  234. void activate_page(struct page *page)
  235. {
  236. struct zone *zone = page_zone(page);
  237. spin_lock_irq(&zone->lru_lock);
  238. if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
  239. int file = page_is_file_cache(page);
  240. int lru = page_lru_base_type(page);
  241. del_page_from_lru_list(zone, page, lru);
  242. SetPageActive(page);
  243. lru += LRU_ACTIVE;
  244. add_page_to_lru_list(zone, page, lru);
  245. __count_vm_event(PGACTIVATE);
  246. update_page_reclaim_stat(zone, page, file, 1);
  247. }
  248. spin_unlock_irq(&zone->lru_lock);
  249. }
  250. /*
  251. * Mark a page as having seen activity.
  252. *
  253. * inactive,unreferenced -> inactive,referenced
  254. * inactive,referenced -> active,unreferenced
  255. * active,unreferenced -> active,referenced
  256. */
  257. void mark_page_accessed(struct page *page)
  258. {
  259. if (!PageActive(page) && !PageUnevictable(page) &&
  260. PageReferenced(page) && PageLRU(page)) {
  261. activate_page(page);
  262. ClearPageReferenced(page);
  263. } else if (!PageReferenced(page)) {
  264. SetPageReferenced(page);
  265. }
  266. }
  267. EXPORT_SYMBOL(mark_page_accessed);
  268. void __lru_cache_add(struct page *page, enum lru_list lru)
  269. {
  270. struct pagevec *pvec = &get_cpu_var(lru_add_pvecs)[lru];
  271. page_cache_get(page);
  272. if (!pagevec_add(pvec, page))
  273. ____pagevec_lru_add(pvec, lru);
  274. put_cpu_var(lru_add_pvecs);
  275. }
  276. EXPORT_SYMBOL(__lru_cache_add);
  277. /**
  278. * lru_cache_add_lru - add a page to a page list
  279. * @page: the page to be added to the LRU.
  280. * @lru: the LRU list to which the page is added.
  281. */
  282. void lru_cache_add_lru(struct page *page, enum lru_list lru)
  283. {
  284. if (PageActive(page)) {
  285. VM_BUG_ON(PageUnevictable(page));
  286. ClearPageActive(page);
  287. } else if (PageUnevictable(page)) {
  288. VM_BUG_ON(PageActive(page));
  289. ClearPageUnevictable(page);
  290. }
  291. VM_BUG_ON(PageLRU(page) || PageActive(page) || PageUnevictable(page));
  292. __lru_cache_add(page, lru);
  293. }
  294. /**
  295. * add_page_to_unevictable_list - add a page to the unevictable list
  296. * @page: the page to be added to the unevictable list
  297. *
  298. * Add page directly to its zone's unevictable list. To avoid races with
  299. * tasks that might be making the page evictable, through eg. munlock,
  300. * munmap or exit, while it's not on the lru, we want to add the page
  301. * while it's locked or otherwise "invisible" to other tasks. This is
  302. * difficult to do when using the pagevec cache, so bypass that.
  303. */
  304. void add_page_to_unevictable_list(struct page *page)
  305. {
  306. struct zone *zone = page_zone(page);
  307. spin_lock_irq(&zone->lru_lock);
  308. SetPageUnevictable(page);
  309. SetPageLRU(page);
  310. add_page_to_lru_list(zone, page, LRU_UNEVICTABLE);
  311. spin_unlock_irq(&zone->lru_lock);
  312. }
  313. /*
  314. * If the page can not be invalidated, it is moved to the
  315. * inactive list to speed up its reclaim. It is moved to the
  316. * head of the list, rather than the tail, to give the flusher
  317. * threads some time to write it out, as this is much more
  318. * effective than the single-page writeout from reclaim.
  319. */
  320. static void lru_deactivate(struct page *page, struct zone *zone)
  321. {
  322. int lru, file;
  323. if (!PageLRU(page) || !PageActive(page))
  324. return;
  325. /* Some processes are using the page */
  326. if (page_mapped(page))
  327. return;
  328. file = page_is_file_cache(page);
  329. lru = page_lru_base_type(page);
  330. del_page_from_lru_list(zone, page, lru + LRU_ACTIVE);
  331. ClearPageActive(page);
  332. ClearPageReferenced(page);
  333. add_page_to_lru_list(zone, page, lru);
  334. __count_vm_event(PGDEACTIVATE);
  335. update_page_reclaim_stat(zone, page, file, 0);
  336. }
  337. static void ____pagevec_lru_deactivate(struct pagevec *pvec)
  338. {
  339. int i;
  340. struct zone *zone = NULL;
  341. for (i = 0; i < pagevec_count(pvec); i++) {
  342. struct page *page = pvec->pages[i];
  343. struct zone *pagezone = page_zone(page);
  344. if (pagezone != zone) {
  345. if (zone)
  346. spin_unlock_irq(&zone->lru_lock);
  347. zone = pagezone;
  348. spin_lock_irq(&zone->lru_lock);
  349. }
  350. lru_deactivate(page, zone);
  351. }
  352. if (zone)
  353. spin_unlock_irq(&zone->lru_lock);
  354. release_pages(pvec->pages, pvec->nr, pvec->cold);
  355. pagevec_reinit(pvec);
  356. }
  357. /*
  358. * Drain pages out of the cpu's pagevecs.
  359. * Either "cpu" is the current CPU, and preemption has already been
  360. * disabled; or "cpu" is being hot-unplugged, and is already dead.
  361. */
  362. static void drain_cpu_pagevecs(int cpu)
  363. {
  364. struct pagevec *pvecs = per_cpu(lru_add_pvecs, cpu);
  365. struct pagevec *pvec;
  366. int lru;
  367. for_each_lru(lru) {
  368. pvec = &pvecs[lru - LRU_BASE];
  369. if (pagevec_count(pvec))
  370. ____pagevec_lru_add(pvec, lru);
  371. }
  372. pvec = &per_cpu(lru_rotate_pvecs, cpu);
  373. if (pagevec_count(pvec)) {
  374. unsigned long flags;
  375. /* No harm done if a racing interrupt already did this */
  376. local_irq_save(flags);
  377. pagevec_move_tail(pvec);
  378. local_irq_restore(flags);
  379. }
  380. pvec = &per_cpu(lru_deactivate_pvecs, cpu);
  381. if (pagevec_count(pvec))
  382. ____pagevec_lru_deactivate(pvec);
  383. }
  384. /**
  385. * deactivate_page - forcefully deactivate a page
  386. * @page: page to deactivate
  387. *
  388. * This function hints the VM that @page is a good reclaim candidate,
  389. * for example if its invalidation fails due to the page being dirty
  390. * or under writeback.
  391. */
  392. void deactivate_page(struct page *page)
  393. {
  394. if (likely(get_page_unless_zero(page))) {
  395. struct pagevec *pvec = &get_cpu_var(lru_deactivate_pvecs);
  396. if (!pagevec_add(pvec, page))
  397. ____pagevec_lru_deactivate(pvec);
  398. put_cpu_var(lru_deactivate_pvecs);
  399. }
  400. }
  401. void lru_add_drain(void)
  402. {
  403. drain_cpu_pagevecs(get_cpu());
  404. put_cpu();
  405. }
  406. static void lru_add_drain_per_cpu(struct work_struct *dummy)
  407. {
  408. lru_add_drain();
  409. }
  410. /*
  411. * Returns 0 for success
  412. */
  413. int lru_add_drain_all(void)
  414. {
  415. return schedule_on_each_cpu(lru_add_drain_per_cpu);
  416. }
  417. /*
  418. * Batched page_cache_release(). Decrement the reference count on all the
  419. * passed pages. If it fell to zero then remove the page from the LRU and
  420. * free it.
  421. *
  422. * Avoid taking zone->lru_lock if possible, but if it is taken, retain it
  423. * for the remainder of the operation.
  424. *
  425. * The locking in this function is against shrink_inactive_list(): we recheck
  426. * the page count inside the lock to see whether shrink_inactive_list()
  427. * grabbed the page via the LRU. If it did, give up: shrink_inactive_list()
  428. * will free it.
  429. */
  430. void release_pages(struct page **pages, int nr, int cold)
  431. {
  432. int i;
  433. struct pagevec pages_to_free;
  434. struct zone *zone = NULL;
  435. unsigned long uninitialized_var(flags);
  436. pagevec_init(&pages_to_free, cold);
  437. for (i = 0; i < nr; i++) {
  438. struct page *page = pages[i];
  439. if (unlikely(PageCompound(page))) {
  440. if (zone) {
  441. spin_unlock_irqrestore(&zone->lru_lock, flags);
  442. zone = NULL;
  443. }
  444. put_compound_page(page);
  445. continue;
  446. }
  447. if (!put_page_testzero(page))
  448. continue;
  449. if (PageLRU(page)) {
  450. struct zone *pagezone = page_zone(page);
  451. if (pagezone != zone) {
  452. if (zone)
  453. spin_unlock_irqrestore(&zone->lru_lock,
  454. flags);
  455. zone = pagezone;
  456. spin_lock_irqsave(&zone->lru_lock, flags);
  457. }
  458. VM_BUG_ON(!PageLRU(page));
  459. __ClearPageLRU(page);
  460. del_page_from_lru(zone, page);
  461. }
  462. if (!pagevec_add(&pages_to_free, page)) {
  463. if (zone) {
  464. spin_unlock_irqrestore(&zone->lru_lock, flags);
  465. zone = NULL;
  466. }
  467. __pagevec_free(&pages_to_free);
  468. pagevec_reinit(&pages_to_free);
  469. }
  470. }
  471. if (zone)
  472. spin_unlock_irqrestore(&zone->lru_lock, flags);
  473. pagevec_free(&pages_to_free);
  474. }
  475. EXPORT_SYMBOL(release_pages);
  476. /*
  477. * The pages which we're about to release may be in the deferred lru-addition
  478. * queues. That would prevent them from really being freed right now. That's
  479. * OK from a correctness point of view but is inefficient - those pages may be
  480. * cache-warm and we want to give them back to the page allocator ASAP.
  481. *
  482. * So __pagevec_release() will drain those queues here. __pagevec_lru_add()
  483. * and __pagevec_lru_add_active() call release_pages() directly to avoid
  484. * mutual recursion.
  485. */
  486. void __pagevec_release(struct pagevec *pvec)
  487. {
  488. lru_add_drain();
  489. release_pages(pvec->pages, pagevec_count(pvec), pvec->cold);
  490. pagevec_reinit(pvec);
  491. }
  492. EXPORT_SYMBOL(__pagevec_release);
  493. /* used by __split_huge_page_refcount() */
  494. void lru_add_page_tail(struct zone* zone,
  495. struct page *page, struct page *page_tail)
  496. {
  497. int active;
  498. enum lru_list lru;
  499. const int file = 0;
  500. struct list_head *head;
  501. VM_BUG_ON(!PageHead(page));
  502. VM_BUG_ON(PageCompound(page_tail));
  503. VM_BUG_ON(PageLRU(page_tail));
  504. VM_BUG_ON(!spin_is_locked(&zone->lru_lock));
  505. SetPageLRU(page_tail);
  506. if (page_evictable(page_tail, NULL)) {
  507. if (PageActive(page)) {
  508. SetPageActive(page_tail);
  509. active = 1;
  510. lru = LRU_ACTIVE_ANON;
  511. } else {
  512. active = 0;
  513. lru = LRU_INACTIVE_ANON;
  514. }
  515. update_page_reclaim_stat(zone, page_tail, file, active);
  516. if (likely(PageLRU(page)))
  517. head = page->lru.prev;
  518. else
  519. head = &zone->lru[lru].list;
  520. __add_page_to_lru_list(zone, page_tail, lru, head);
  521. } else {
  522. SetPageUnevictable(page_tail);
  523. add_page_to_lru_list(zone, page_tail, LRU_UNEVICTABLE);
  524. }
  525. }
  526. /*
  527. * Add the passed pages to the LRU, then drop the caller's refcount
  528. * on them. Reinitialises the caller's pagevec.
  529. */
  530. void ____pagevec_lru_add(struct pagevec *pvec, enum lru_list lru)
  531. {
  532. int i;
  533. struct zone *zone = NULL;
  534. VM_BUG_ON(is_unevictable_lru(lru));
  535. for (i = 0; i < pagevec_count(pvec); i++) {
  536. struct page *page = pvec->pages[i];
  537. struct zone *pagezone = page_zone(page);
  538. int file;
  539. int active;
  540. if (pagezone != zone) {
  541. if (zone)
  542. spin_unlock_irq(&zone->lru_lock);
  543. zone = pagezone;
  544. spin_lock_irq(&zone->lru_lock);
  545. }
  546. VM_BUG_ON(PageActive(page));
  547. VM_BUG_ON(PageUnevictable(page));
  548. VM_BUG_ON(PageLRU(page));
  549. SetPageLRU(page);
  550. active = is_active_lru(lru);
  551. file = is_file_lru(lru);
  552. if (active)
  553. SetPageActive(page);
  554. update_page_reclaim_stat(zone, page, file, active);
  555. add_page_to_lru_list(zone, page, lru);
  556. }
  557. if (zone)
  558. spin_unlock_irq(&zone->lru_lock);
  559. release_pages(pvec->pages, pvec->nr, pvec->cold);
  560. pagevec_reinit(pvec);
  561. }
  562. EXPORT_SYMBOL(____pagevec_lru_add);
  563. /*
  564. * Try to drop buffers from the pages in a pagevec
  565. */
  566. void pagevec_strip(struct pagevec *pvec)
  567. {
  568. int i;
  569. for (i = 0; i < pagevec_count(pvec); i++) {
  570. struct page *page = pvec->pages[i];
  571. if (page_has_private(page) && trylock_page(page)) {
  572. if (page_has_private(page))
  573. try_to_release_page(page, 0);
  574. unlock_page(page);
  575. }
  576. }
  577. }
  578. /**
  579. * pagevec_lookup - gang pagecache lookup
  580. * @pvec: Where the resulting pages are placed
  581. * @mapping: The address_space to search
  582. * @start: The starting page index
  583. * @nr_pages: The maximum number of pages
  584. *
  585. * pagevec_lookup() will search for and return a group of up to @nr_pages pages
  586. * in the mapping. The pages are placed in @pvec. pagevec_lookup() takes a
  587. * reference against the pages in @pvec.
  588. *
  589. * The search returns a group of mapping-contiguous pages with ascending
  590. * indexes. There may be holes in the indices due to not-present pages.
  591. *
  592. * pagevec_lookup() returns the number of pages which were found.
  593. */
  594. unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
  595. pgoff_t start, unsigned nr_pages)
  596. {
  597. pvec->nr = find_get_pages(mapping, start, nr_pages, pvec->pages);
  598. return pagevec_count(pvec);
  599. }
  600. EXPORT_SYMBOL(pagevec_lookup);
  601. unsigned pagevec_lookup_tag(struct pagevec *pvec, struct address_space *mapping,
  602. pgoff_t *index, int tag, unsigned nr_pages)
  603. {
  604. pvec->nr = find_get_pages_tag(mapping, index, tag,
  605. nr_pages, pvec->pages);
  606. return pagevec_count(pvec);
  607. }
  608. EXPORT_SYMBOL(pagevec_lookup_tag);
  609. /*
  610. * Perform any setup for the swap system
  611. */
  612. void __init swap_setup(void)
  613. {
  614. unsigned long megs = totalram_pages >> (20 - PAGE_SHIFT);
  615. #ifdef CONFIG_SWAP
  616. bdi_init(swapper_space.backing_dev_info);
  617. #endif
  618. /* Use a smaller cluster for small-memory machines */
  619. if (megs < 16)
  620. page_cluster = 2;
  621. else
  622. page_cluster = 3;
  623. /*
  624. * Right now other parts of the system means that we
  625. * _really_ don't want to cluster much more
  626. */
  627. }