swap.c 18 KB

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