nfsd: Add fh_{want,drop}_write()
[linux/fpc-iii.git] / mm / swap.c
bloba4b90161be66313444dfe0e57b67a8a9d2235585
1 /*
2 * linux/mm/swap.c
4 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
5 */
7 /*
8 * This file contains the default values for the operation of the
9 * Linux VM subsystem. Fine-tuning documentation can be found in
10 * Documentation/sysctl/vm.txt.
11 * Started 18.12.91
12 * Swap aging added 23.2.95, Stephen Tweedie.
13 * Buffermem limits added 12.3.98, Rik van Riel.
16 #include <linux/mm.h>
17 #include <linux/sched.h>
18 #include <linux/kernel_stat.h>
19 #include <linux/swap.h>
20 #include <linux/mman.h>
21 #include <linux/pagemap.h>
22 #include <linux/pagevec.h>
23 #include <linux/init.h>
24 #include <linux/export.h>
25 #include <linux/mm_inline.h>
26 #include <linux/buffer_head.h> /* for try_to_release_page() */
27 #include <linux/percpu_counter.h>
28 #include <linux/percpu.h>
29 #include <linux/cpu.h>
30 #include <linux/notifier.h>
31 #include <linux/backing-dev.h>
32 #include <linux/memcontrol.h>
33 #include <linux/gfp.h>
34 #include <linux/hugetlb.h>
36 #include "internal.h"
38 /* How many pages do we try to swap or page in/out together? */
39 int page_cluster;
41 static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
42 static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
43 static DEFINE_PER_CPU(struct pagevec, lru_deactivate_pvecs);
46 * This path almost never happens for VM activity - pages are normally
47 * freed via pagevecs. But it gets used by networking.
49 static void __page_cache_release(struct page *page)
51 if (PageLRU(page)) {
52 unsigned long flags;
53 struct zone *zone = page_zone(page);
55 spin_lock_irqsave(&zone->lru_lock, flags);
56 VM_BUG_ON(!PageLRU(page));
57 __ClearPageLRU(page);
58 del_page_from_lru(zone, page);
59 spin_unlock_irqrestore(&zone->lru_lock, flags);
63 static void __put_single_page(struct page *page)
65 __page_cache_release(page);
66 free_hot_cold_page(page, 0);
69 static void __put_compound_page(struct page *page)
71 compound_page_dtor *dtor;
73 if (!PageHuge(page))
74 __page_cache_release(page);
75 dtor = get_compound_page_dtor(page);
76 (*dtor)(page);
79 static void put_compound_page(struct page *page)
81 if (unlikely(PageTail(page))) {
82 /* __split_huge_page_refcount can run under us */
83 struct page *page_head = compound_trans_head(page);
85 if (likely(page != page_head &&
86 get_page_unless_zero(page_head))) {
87 unsigned long flags;
89 if (PageHeadHuge(page_head)) {
90 if (likely(PageTail(page))) {
92 * __split_huge_page_refcount
93 * cannot race here.
95 VM_BUG_ON(!PageHead(page_head));
96 atomic_dec(&page->_mapcount);
97 if (put_page_testzero(page_head))
98 VM_BUG_ON(1);
99 if (put_page_testzero(page_head))
100 __put_compound_page(page_head);
101 return;
102 } else {
104 * __split_huge_page_refcount
105 * run before us, "page" was a
106 * THP tail. The split
107 * page_head has been freed
108 * and reallocated as slab or
109 * hugetlbfs page of smaller
110 * order (only possible if
111 * reallocated as slab on
112 * x86).
114 goto skip_lock;
118 * page_head wasn't a dangling pointer but it
119 * may not be a head page anymore by the time
120 * we obtain the lock. That is ok as long as it
121 * can't be freed from under us.
123 flags = compound_lock_irqsave(page_head);
124 if (unlikely(!PageTail(page))) {
125 /* __split_huge_page_refcount run before us */
126 compound_unlock_irqrestore(page_head, flags);
127 VM_BUG_ON(PageHead(page_head));
128 skip_lock:
129 if (put_page_testzero(page_head)) {
131 * The head page may have been
132 * freed and reallocated as a
133 * compound page of smaller
134 * order and then freed again.
135 * All we know is that it
136 * cannot have become: a THP
137 * page, a compound page of
138 * higher order, a tail page.
139 * That is because we still
140 * hold the refcount of the
141 * split THP tail and
142 * page_head was the THP head
143 * before the split.
145 if (PageHead(page_head))
146 __put_compound_page(page_head);
147 else
148 __put_single_page(page_head);
150 out_put_single:
151 if (put_page_testzero(page))
152 __put_single_page(page);
153 return;
155 VM_BUG_ON(page_head != page->first_page);
157 * We can release the refcount taken by
158 * get_page_unless_zero() now that
159 * __split_huge_page_refcount() is blocked on
160 * the compound_lock.
162 if (put_page_testzero(page_head))
163 VM_BUG_ON(1);
164 /* __split_huge_page_refcount will wait now */
165 VM_BUG_ON(page_mapcount(page) <= 0);
166 atomic_dec(&page->_mapcount);
167 VM_BUG_ON(atomic_read(&page_head->_count) <= 0);
168 VM_BUG_ON(atomic_read(&page->_count) != 0);
169 compound_unlock_irqrestore(page_head, flags);
170 if (put_page_testzero(page_head)) {
171 if (PageHead(page_head))
172 __put_compound_page(page_head);
173 else
174 __put_single_page(page_head);
176 } else {
177 /* page_head is a dangling pointer */
178 VM_BUG_ON(PageTail(page));
179 goto out_put_single;
181 } else if (put_page_testzero(page)) {
182 if (PageHead(page))
183 __put_compound_page(page);
184 else
185 __put_single_page(page);
189 void put_page(struct page *page)
191 if (unlikely(PageCompound(page)))
192 put_compound_page(page);
193 else if (put_page_testzero(page))
194 __put_single_page(page);
196 EXPORT_SYMBOL(put_page);
199 * This function is exported but must not be called by anything other
200 * than get_page(). It implements the slow path of get_page().
202 bool __get_page_tail(struct page *page)
205 * This takes care of get_page() if run on a tail page
206 * returned by one of the get_user_pages/follow_page variants.
207 * get_user_pages/follow_page itself doesn't need the compound
208 * lock because it runs __get_page_tail_foll() under the
209 * proper PT lock that already serializes against
210 * split_huge_page().
212 unsigned long flags;
213 bool got = false;
214 struct page *page_head = compound_trans_head(page);
216 if (likely(page != page_head && get_page_unless_zero(page_head))) {
217 /* Ref to put_compound_page() comment. */
218 if (PageHeadHuge(page_head)) {
219 if (likely(PageTail(page))) {
221 * This is a hugetlbfs
222 * page. __split_huge_page_refcount
223 * cannot race here.
225 VM_BUG_ON(!PageHead(page_head));
226 __get_page_tail_foll(page, false);
227 return true;
228 } else {
230 * __split_huge_page_refcount run
231 * before us, "page" was a THP
232 * tail. The split page_head has been
233 * freed and reallocated as slab or
234 * hugetlbfs page of smaller order
235 * (only possible if reallocated as
236 * slab on x86).
238 put_page(page_head);
239 return false;
243 * page_head wasn't a dangling pointer but it
244 * may not be a head page anymore by the time
245 * we obtain the lock. That is ok as long as it
246 * can't be freed from under us.
248 flags = compound_lock_irqsave(page_head);
249 /* here __split_huge_page_refcount won't run anymore */
250 if (likely(PageTail(page))) {
251 __get_page_tail_foll(page, false);
252 got = true;
254 compound_unlock_irqrestore(page_head, flags);
255 if (unlikely(!got))
256 put_page(page_head);
258 return got;
260 EXPORT_SYMBOL(__get_page_tail);
263 * put_pages_list() - release a list of pages
264 * @pages: list of pages threaded on page->lru
266 * Release a list of pages which are strung together on page.lru. Currently
267 * used by read_cache_pages() and related error recovery code.
269 void put_pages_list(struct list_head *pages)
271 while (!list_empty(pages)) {
272 struct page *victim;
274 victim = list_entry(pages->prev, struct page, lru);
275 list_del(&victim->lru);
276 page_cache_release(victim);
279 EXPORT_SYMBOL(put_pages_list);
281 static void pagevec_lru_move_fn(struct pagevec *pvec,
282 void (*move_fn)(struct page *page, void *arg),
283 void *arg)
285 int i;
286 struct zone *zone = NULL;
287 unsigned long flags = 0;
289 for (i = 0; i < pagevec_count(pvec); i++) {
290 struct page *page = pvec->pages[i];
291 struct zone *pagezone = page_zone(page);
293 if (pagezone != zone) {
294 if (zone)
295 spin_unlock_irqrestore(&zone->lru_lock, flags);
296 zone = pagezone;
297 spin_lock_irqsave(&zone->lru_lock, flags);
300 (*move_fn)(page, arg);
302 if (zone)
303 spin_unlock_irqrestore(&zone->lru_lock, flags);
304 release_pages(pvec->pages, pvec->nr, pvec->cold);
305 pagevec_reinit(pvec);
308 static void pagevec_move_tail_fn(struct page *page, void *arg)
310 int *pgmoved = arg;
311 struct zone *zone = page_zone(page);
313 if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
314 enum lru_list lru = page_lru_base_type(page);
315 list_move_tail(&page->lru, &zone->lru[lru].list);
316 mem_cgroup_rotate_reclaimable_page(page);
317 (*pgmoved)++;
322 * pagevec_move_tail() must be called with IRQ disabled.
323 * Otherwise this may cause nasty races.
325 static void pagevec_move_tail(struct pagevec *pvec)
327 int pgmoved = 0;
329 pagevec_lru_move_fn(pvec, pagevec_move_tail_fn, &pgmoved);
330 __count_vm_events(PGROTATED, pgmoved);
334 * Writeback is about to end against a page which has been marked for immediate
335 * reclaim. If it still appears to be reclaimable, move it to the tail of the
336 * inactive list.
338 void rotate_reclaimable_page(struct page *page)
340 if (!PageLocked(page) && !PageDirty(page) && !PageActive(page) &&
341 !PageUnevictable(page) && PageLRU(page)) {
342 struct pagevec *pvec;
343 unsigned long flags;
345 page_cache_get(page);
346 local_irq_save(flags);
347 pvec = &__get_cpu_var(lru_rotate_pvecs);
348 if (!pagevec_add(pvec, page))
349 pagevec_move_tail(pvec);
350 local_irq_restore(flags);
354 static void update_page_reclaim_stat(struct zone *zone, struct page *page,
355 int file, int rotated)
357 struct zone_reclaim_stat *reclaim_stat = &zone->reclaim_stat;
358 struct zone_reclaim_stat *memcg_reclaim_stat;
360 memcg_reclaim_stat = mem_cgroup_get_reclaim_stat_from_page(page);
362 reclaim_stat->recent_scanned[file]++;
363 if (rotated)
364 reclaim_stat->recent_rotated[file]++;
366 if (!memcg_reclaim_stat)
367 return;
369 memcg_reclaim_stat->recent_scanned[file]++;
370 if (rotated)
371 memcg_reclaim_stat->recent_rotated[file]++;
374 static void __activate_page(struct page *page, void *arg)
376 struct zone *zone = page_zone(page);
378 if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
379 int file = page_is_file_cache(page);
380 int lru = page_lru_base_type(page);
381 del_page_from_lru_list(zone, page, lru);
383 SetPageActive(page);
384 lru += LRU_ACTIVE;
385 add_page_to_lru_list(zone, page, lru);
386 __count_vm_event(PGACTIVATE);
388 update_page_reclaim_stat(zone, page, file, 1);
392 #ifdef CONFIG_SMP
393 static DEFINE_PER_CPU(struct pagevec, activate_page_pvecs);
395 static void activate_page_drain(int cpu)
397 struct pagevec *pvec = &per_cpu(activate_page_pvecs, cpu);
399 if (pagevec_count(pvec))
400 pagevec_lru_move_fn(pvec, __activate_page, NULL);
403 void activate_page(struct page *page)
405 if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
406 struct pagevec *pvec = &get_cpu_var(activate_page_pvecs);
408 page_cache_get(page);
409 if (!pagevec_add(pvec, page))
410 pagevec_lru_move_fn(pvec, __activate_page, NULL);
411 put_cpu_var(activate_page_pvecs);
415 #else
416 static inline void activate_page_drain(int cpu)
420 void activate_page(struct page *page)
422 struct zone *zone = page_zone(page);
424 spin_lock_irq(&zone->lru_lock);
425 __activate_page(page, NULL);
426 spin_unlock_irq(&zone->lru_lock);
428 #endif
431 * Mark a page as having seen activity.
433 * inactive,unreferenced -> inactive,referenced
434 * inactive,referenced -> active,unreferenced
435 * active,unreferenced -> active,referenced
437 void mark_page_accessed(struct page *page)
439 if (!PageActive(page) && !PageUnevictable(page) &&
440 PageReferenced(page) && PageLRU(page)) {
441 activate_page(page);
442 ClearPageReferenced(page);
443 } else if (!PageReferenced(page)) {
444 SetPageReferenced(page);
448 EXPORT_SYMBOL(mark_page_accessed);
450 void __lru_cache_add(struct page *page, enum lru_list lru)
452 struct pagevec *pvec = &get_cpu_var(lru_add_pvecs)[lru];
454 page_cache_get(page);
455 if (!pagevec_add(pvec, page))
456 ____pagevec_lru_add(pvec, lru);
457 put_cpu_var(lru_add_pvecs);
459 EXPORT_SYMBOL(__lru_cache_add);
462 * lru_cache_add_lru - add a page to a page list
463 * @page: the page to be added to the LRU.
464 * @lru: the LRU list to which the page is added.
466 void lru_cache_add_lru(struct page *page, enum lru_list lru)
468 if (PageActive(page)) {
469 VM_BUG_ON(PageUnevictable(page));
470 ClearPageActive(page);
471 } else if (PageUnevictable(page)) {
472 VM_BUG_ON(PageActive(page));
473 ClearPageUnevictable(page);
476 VM_BUG_ON(PageLRU(page) || PageActive(page) || PageUnevictable(page));
477 __lru_cache_add(page, lru);
481 * add_page_to_unevictable_list - add a page to the unevictable list
482 * @page: the page to be added to the unevictable list
484 * Add page directly to its zone's unevictable list. To avoid races with
485 * tasks that might be making the page evictable, through eg. munlock,
486 * munmap or exit, while it's not on the lru, we want to add the page
487 * while it's locked or otherwise "invisible" to other tasks. This is
488 * difficult to do when using the pagevec cache, so bypass that.
490 void add_page_to_unevictable_list(struct page *page)
492 struct zone *zone = page_zone(page);
494 spin_lock_irq(&zone->lru_lock);
495 SetPageUnevictable(page);
496 SetPageLRU(page);
497 add_page_to_lru_list(zone, page, LRU_UNEVICTABLE);
498 spin_unlock_irq(&zone->lru_lock);
502 * If the page can not be invalidated, it is moved to the
503 * inactive list to speed up its reclaim. It is moved to the
504 * head of the list, rather than the tail, to give the flusher
505 * threads some time to write it out, as this is much more
506 * effective than the single-page writeout from reclaim.
508 * If the page isn't page_mapped and dirty/writeback, the page
509 * could reclaim asap using PG_reclaim.
511 * 1. active, mapped page -> none
512 * 2. active, dirty/writeback page -> inactive, head, PG_reclaim
513 * 3. inactive, mapped page -> none
514 * 4. inactive, dirty/writeback page -> inactive, head, PG_reclaim
515 * 5. inactive, clean -> inactive, tail
516 * 6. Others -> none
518 * In 4, why it moves inactive's head, the VM expects the page would
519 * be write it out by flusher threads as this is much more effective
520 * than the single-page writeout from reclaim.
522 static void lru_deactivate_fn(struct page *page, void *arg)
524 int lru, file;
525 bool active;
526 struct zone *zone = page_zone(page);
528 if (!PageLRU(page))
529 return;
531 if (PageUnevictable(page))
532 return;
534 /* Some processes are using the page */
535 if (page_mapped(page))
536 return;
538 active = PageActive(page);
540 file = page_is_file_cache(page);
541 lru = page_lru_base_type(page);
542 del_page_from_lru_list(zone, page, lru + active);
543 ClearPageActive(page);
544 ClearPageReferenced(page);
545 add_page_to_lru_list(zone, page, lru);
547 if (PageWriteback(page) || PageDirty(page)) {
549 * PG_reclaim could be raced with end_page_writeback
550 * It can make readahead confusing. But race window
551 * is _really_ small and it's non-critical problem.
553 SetPageReclaim(page);
554 } else {
556 * The page's writeback ends up during pagevec
557 * We moves tha page into tail of inactive.
559 list_move_tail(&page->lru, &zone->lru[lru].list);
560 mem_cgroup_rotate_reclaimable_page(page);
561 __count_vm_event(PGROTATED);
564 if (active)
565 __count_vm_event(PGDEACTIVATE);
566 update_page_reclaim_stat(zone, page, file, 0);
570 * Drain pages out of the cpu's pagevecs.
571 * Either "cpu" is the current CPU, and preemption has already been
572 * disabled; or "cpu" is being hot-unplugged, and is already dead.
574 static void drain_cpu_pagevecs(int cpu)
576 struct pagevec *pvecs = per_cpu(lru_add_pvecs, cpu);
577 struct pagevec *pvec;
578 int lru;
580 for_each_lru(lru) {
581 pvec = &pvecs[lru - LRU_BASE];
582 if (pagevec_count(pvec))
583 ____pagevec_lru_add(pvec, lru);
586 pvec = &per_cpu(lru_rotate_pvecs, cpu);
587 if (pagevec_count(pvec)) {
588 unsigned long flags;
590 /* No harm done if a racing interrupt already did this */
591 local_irq_save(flags);
592 pagevec_move_tail(pvec);
593 local_irq_restore(flags);
596 pvec = &per_cpu(lru_deactivate_pvecs, cpu);
597 if (pagevec_count(pvec))
598 pagevec_lru_move_fn(pvec, lru_deactivate_fn, NULL);
600 activate_page_drain(cpu);
604 * deactivate_page - forcefully deactivate a page
605 * @page: page to deactivate
607 * This function hints the VM that @page is a good reclaim candidate,
608 * for example if its invalidation fails due to the page being dirty
609 * or under writeback.
611 void deactivate_page(struct page *page)
614 * In a workload with many unevictable page such as mprotect, unevictable
615 * page deactivation for accelerating reclaim is pointless.
617 if (PageUnevictable(page))
618 return;
620 if (likely(get_page_unless_zero(page))) {
621 struct pagevec *pvec = &get_cpu_var(lru_deactivate_pvecs);
623 if (!pagevec_add(pvec, page))
624 pagevec_lru_move_fn(pvec, lru_deactivate_fn, NULL);
625 put_cpu_var(lru_deactivate_pvecs);
629 void lru_add_drain(void)
631 drain_cpu_pagevecs(get_cpu());
632 put_cpu();
635 static void lru_add_drain_per_cpu(struct work_struct *dummy)
637 lru_add_drain();
641 * Returns 0 for success
643 int lru_add_drain_all(void)
645 return schedule_on_each_cpu(lru_add_drain_per_cpu);
649 * Batched page_cache_release(). Decrement the reference count on all the
650 * passed pages. If it fell to zero then remove the page from the LRU and
651 * free it.
653 * Avoid taking zone->lru_lock if possible, but if it is taken, retain it
654 * for the remainder of the operation.
656 * The locking in this function is against shrink_inactive_list(): we recheck
657 * the page count inside the lock to see whether shrink_inactive_list()
658 * grabbed the page via the LRU. If it did, give up: shrink_inactive_list()
659 * will free it.
661 void release_pages(struct page **pages, int nr, int cold)
663 int i;
664 struct pagevec pages_to_free;
665 struct zone *zone = NULL;
666 unsigned long uninitialized_var(flags);
668 pagevec_init(&pages_to_free, cold);
669 for (i = 0; i < nr; i++) {
670 struct page *page = pages[i];
672 if (unlikely(PageCompound(page))) {
673 if (zone) {
674 spin_unlock_irqrestore(&zone->lru_lock, flags);
675 zone = NULL;
677 put_compound_page(page);
678 continue;
681 if (!put_page_testzero(page))
682 continue;
684 if (PageLRU(page)) {
685 struct zone *pagezone = page_zone(page);
687 if (pagezone != zone) {
688 if (zone)
689 spin_unlock_irqrestore(&zone->lru_lock,
690 flags);
691 zone = pagezone;
692 spin_lock_irqsave(&zone->lru_lock, flags);
694 VM_BUG_ON(!PageLRU(page));
695 __ClearPageLRU(page);
696 del_page_from_lru(zone, page);
699 if (!pagevec_add(&pages_to_free, page)) {
700 if (zone) {
701 spin_unlock_irqrestore(&zone->lru_lock, flags);
702 zone = NULL;
704 __pagevec_free(&pages_to_free);
705 pagevec_reinit(&pages_to_free);
708 if (zone)
709 spin_unlock_irqrestore(&zone->lru_lock, flags);
711 pagevec_free(&pages_to_free);
713 EXPORT_SYMBOL(release_pages);
716 * The pages which we're about to release may be in the deferred lru-addition
717 * queues. That would prevent them from really being freed right now. That's
718 * OK from a correctness point of view but is inefficient - those pages may be
719 * cache-warm and we want to give them back to the page allocator ASAP.
721 * So __pagevec_release() will drain those queues here. __pagevec_lru_add()
722 * and __pagevec_lru_add_active() call release_pages() directly to avoid
723 * mutual recursion.
725 void __pagevec_release(struct pagevec *pvec)
727 lru_add_drain();
728 release_pages(pvec->pages, pagevec_count(pvec), pvec->cold);
729 pagevec_reinit(pvec);
732 EXPORT_SYMBOL(__pagevec_release);
734 /* used by __split_huge_page_refcount() */
735 void lru_add_page_tail(struct zone* zone,
736 struct page *page, struct page *page_tail)
738 int active;
739 enum lru_list lru;
740 const int file = 0;
741 struct list_head *head;
743 VM_BUG_ON(!PageHead(page));
744 VM_BUG_ON(PageCompound(page_tail));
745 VM_BUG_ON(PageLRU(page_tail));
746 VM_BUG_ON(NR_CPUS != 1 && !spin_is_locked(&zone->lru_lock));
748 SetPageLRU(page_tail);
750 if (page_evictable(page_tail, NULL)) {
751 if (PageActive(page)) {
752 SetPageActive(page_tail);
753 active = 1;
754 lru = LRU_ACTIVE_ANON;
755 } else {
756 active = 0;
757 lru = LRU_INACTIVE_ANON;
759 update_page_reclaim_stat(zone, page_tail, file, active);
760 if (likely(PageLRU(page)))
761 head = page->lru.prev;
762 else
763 head = &zone->lru[lru].list;
764 __add_page_to_lru_list(zone, page_tail, lru, head);
765 } else {
766 SetPageUnevictable(page_tail);
767 add_page_to_lru_list(zone, page_tail, LRU_UNEVICTABLE);
771 static void ____pagevec_lru_add_fn(struct page *page, void *arg)
773 enum lru_list lru = (enum lru_list)arg;
774 struct zone *zone = page_zone(page);
775 int file = is_file_lru(lru);
776 int active = is_active_lru(lru);
778 VM_BUG_ON(PageActive(page));
779 VM_BUG_ON(PageUnevictable(page));
780 VM_BUG_ON(PageLRU(page));
782 SetPageLRU(page);
783 if (active)
784 SetPageActive(page);
785 update_page_reclaim_stat(zone, page, file, active);
786 add_page_to_lru_list(zone, page, lru);
790 * Add the passed pages to the LRU, then drop the caller's refcount
791 * on them. Reinitialises the caller's pagevec.
793 void ____pagevec_lru_add(struct pagevec *pvec, enum lru_list lru)
795 VM_BUG_ON(is_unevictable_lru(lru));
797 pagevec_lru_move_fn(pvec, ____pagevec_lru_add_fn, (void *)lru);
800 EXPORT_SYMBOL(____pagevec_lru_add);
803 * Try to drop buffers from the pages in a pagevec
805 void pagevec_strip(struct pagevec *pvec)
807 int i;
809 for (i = 0; i < pagevec_count(pvec); i++) {
810 struct page *page = pvec->pages[i];
812 if (page_has_private(page) && trylock_page(page)) {
813 if (page_has_private(page))
814 try_to_release_page(page, 0);
815 unlock_page(page);
821 * pagevec_lookup - gang pagecache lookup
822 * @pvec: Where the resulting pages are placed
823 * @mapping: The address_space to search
824 * @start: The starting page index
825 * @nr_pages: The maximum number of pages
827 * pagevec_lookup() will search for and return a group of up to @nr_pages pages
828 * in the mapping. The pages are placed in @pvec. pagevec_lookup() takes a
829 * reference against the pages in @pvec.
831 * The search returns a group of mapping-contiguous pages with ascending
832 * indexes. There may be holes in the indices due to not-present pages.
834 * pagevec_lookup() returns the number of pages which were found.
836 unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
837 pgoff_t start, unsigned nr_pages)
839 pvec->nr = find_get_pages(mapping, start, nr_pages, pvec->pages);
840 return pagevec_count(pvec);
843 EXPORT_SYMBOL(pagevec_lookup);
845 unsigned pagevec_lookup_tag(struct pagevec *pvec, struct address_space *mapping,
846 pgoff_t *index, int tag, unsigned nr_pages)
848 pvec->nr = find_get_pages_tag(mapping, index, tag,
849 nr_pages, pvec->pages);
850 return pagevec_count(pvec);
853 EXPORT_SYMBOL(pagevec_lookup_tag);
856 * Perform any setup for the swap system
858 void __init swap_setup(void)
860 unsigned long megs = totalram_pages >> (20 - PAGE_SHIFT);
862 #ifdef CONFIG_SWAP
863 bdi_init(swapper_space.backing_dev_info);
864 #endif
866 /* Use a smaller cluster for small-memory machines */
867 if (megs < 16)
868 page_cluster = 2;
869 else
870 page_cluster = 3;
872 * Right now other parts of the system means that we
873 * _really_ don't want to cluster much more