1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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/percpu_counter.h>
27#include <linux/memremap.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/memremap.h>
33#include <linux/memcontrol.h>
34#include <linux/gfp.h>
35#include <linux/uio.h>
36#include <linux/hugetlb.h>
37#include <linux/page_idle.h>
38
39#include "internal.h"
40
41#define CREATE_TRACE_POINTS
42#include <trace/events/pagemap.h>
43
44
45int page_cluster;
46
47static DEFINE_PER_CPU(struct pagevec, lru_add_pvec);
48static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
49static DEFINE_PER_CPU(struct pagevec, lru_deactivate_file_pvecs);
50static DEFINE_PER_CPU(struct pagevec, lru_lazyfree_pvecs);
51#ifdef CONFIG_SMP
52static DEFINE_PER_CPU(struct pagevec, activate_page_pvecs);
53#endif
54
55
56
57
58
59static void __page_cache_release(struct page *page)
60{
61 if (PageLRU(page)) {
62 struct zone *zone = page_zone(page);
63 struct lruvec *lruvec;
64 unsigned long flags;
65
66 spin_lock_irqsave(zone_lru_lock(zone), flags);
67 lruvec = mem_cgroup_page_lruvec(page, zone->zone_pgdat);
68 VM_BUG_ON_PAGE(!PageLRU(page), page);
69 __ClearPageLRU(page);
70 del_page_from_lru_list(page, lruvec, page_off_lru(page));
71 spin_unlock_irqrestore(zone_lru_lock(zone), flags);
72 }
73 __ClearPageWaiters(page);
74 mem_cgroup_uncharge(page);
75}
76
77static void __put_single_page(struct page *page)
78{
79 __page_cache_release(page);
80 free_unref_page(page);
81}
82
83static void __put_compound_page(struct page *page)
84{
85 compound_page_dtor *dtor;
86
87
88
89
90
91
92
93 if (!PageHuge(page))
94 __page_cache_release(page);
95 dtor = get_compound_page_dtor(page);
96 (*dtor)(page);
97}
98
99void __put_page(struct page *page)
100{
101 if (is_zone_device_page(page)) {
102 put_dev_pagemap(page->pgmap);
103
104
105
106
107
108 return;
109 }
110
111 if (unlikely(PageCompound(page)))
112 __put_compound_page(page);
113 else
114 __put_single_page(page);
115}
116EXPORT_SYMBOL(__put_page);
117
118
119
120
121
122
123
124
125void put_pages_list(struct list_head *pages)
126{
127 while (!list_empty(pages)) {
128 struct page *victim;
129
130 victim = list_entry(pages->prev, struct page, lru);
131 list_del(&victim->lru);
132 put_page(victim);
133 }
134}
135EXPORT_SYMBOL(put_pages_list);
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150int get_kernel_pages(const struct kvec *kiov, int nr_segs, int write,
151 struct page **pages)
152{
153 int seg;
154
155 for (seg = 0; seg < nr_segs; seg++) {
156 if (WARN_ON(kiov[seg].iov_len != PAGE_SIZE))
157 return seg;
158
159 pages[seg] = kmap_to_page(kiov[seg].iov_base);
160 get_page(pages[seg]);
161 }
162
163 return seg;
164}
165EXPORT_SYMBOL_GPL(get_kernel_pages);
166
167
168
169
170
171
172
173
174
175
176
177
178int get_kernel_page(unsigned long start, int write, struct page **pages)
179{
180 const struct kvec kiov = {
181 .iov_base = (void *)start,
182 .iov_len = PAGE_SIZE
183 };
184
185 return get_kernel_pages(&kiov, 1, write, pages);
186}
187EXPORT_SYMBOL_GPL(get_kernel_page);
188
189static void pagevec_lru_move_fn(struct pagevec *pvec,
190 void (*move_fn)(struct page *page, struct lruvec *lruvec, void *arg),
191 void *arg)
192{
193 int i;
194 struct pglist_data *pgdat = NULL;
195 struct lruvec *lruvec;
196 unsigned long flags = 0;
197
198 for (i = 0; i < pagevec_count(pvec); i++) {
199 struct page *page = pvec->pages[i];
200 struct pglist_data *pagepgdat = page_pgdat(page);
201
202 if (pagepgdat != pgdat) {
203 if (pgdat)
204 spin_unlock_irqrestore(&pgdat->lru_lock, flags);
205 pgdat = pagepgdat;
206 spin_lock_irqsave(&pgdat->lru_lock, flags);
207 }
208
209 lruvec = mem_cgroup_page_lruvec(page, pgdat);
210 (*move_fn)(page, lruvec, arg);
211 }
212 if (pgdat)
213 spin_unlock_irqrestore(&pgdat->lru_lock, flags);
214 release_pages(pvec->pages, pvec->nr);
215 pagevec_reinit(pvec);
216}
217
218static void pagevec_move_tail_fn(struct page *page, struct lruvec *lruvec,
219 void *arg)
220{
221 int *pgmoved = arg;
222
223 if (PageLRU(page) && !PageUnevictable(page)) {
224 del_page_from_lru_list(page, lruvec, page_lru(page));
225 ClearPageActive(page);
226 add_page_to_lru_list_tail(page, lruvec, page_lru(page));
227 (*pgmoved)++;
228 }
229}
230
231
232
233
234
235static void pagevec_move_tail(struct pagevec *pvec)
236{
237 int pgmoved = 0;
238
239 pagevec_lru_move_fn(pvec, pagevec_move_tail_fn, &pgmoved);
240 __count_vm_events(PGROTATED, pgmoved);
241}
242
243
244
245
246
247
248void rotate_reclaimable_page(struct page *page)
249{
250 if (!PageLocked(page) && !PageDirty(page) &&
251 !PageUnevictable(page) && PageLRU(page)) {
252 struct pagevec *pvec;
253 unsigned long flags;
254
255 get_page(page);
256 local_irq_save(flags);
257 pvec = this_cpu_ptr(&lru_rotate_pvecs);
258 if (!pagevec_add(pvec, page) || PageCompound(page))
259 pagevec_move_tail(pvec);
260 local_irq_restore(flags);
261 }
262}
263
264static void update_page_reclaim_stat(struct lruvec *lruvec,
265 int file, int rotated)
266{
267 struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat;
268
269 reclaim_stat->recent_scanned[file]++;
270 if (rotated)
271 reclaim_stat->recent_rotated[file]++;
272}
273
274static void __activate_page(struct page *page, struct lruvec *lruvec,
275 void *arg)
276{
277 if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
278 int file = page_is_file_cache(page);
279 int lru = page_lru_base_type(page);
280
281 del_page_from_lru_list(page, lruvec, lru);
282 SetPageActive(page);
283 lru += LRU_ACTIVE;
284 add_page_to_lru_list(page, lruvec, lru);
285 trace_mm_lru_activate(page);
286
287 __count_vm_event(PGACTIVATE);
288 update_page_reclaim_stat(lruvec, file, 1);
289 }
290}
291
292#ifdef CONFIG_SMP
293static void activate_page_drain(int cpu)
294{
295 struct pagevec *pvec = &per_cpu(activate_page_pvecs, cpu);
296
297 if (pagevec_count(pvec))
298 pagevec_lru_move_fn(pvec, __activate_page, NULL);
299}
300
301static bool need_activate_page_drain(int cpu)
302{
303 return pagevec_count(&per_cpu(activate_page_pvecs, cpu)) != 0;
304}
305
306void activate_page(struct page *page)
307{
308 page = compound_head(page);
309 if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
310 struct pagevec *pvec = &get_cpu_var(activate_page_pvecs);
311
312 get_page(page);
313 if (!pagevec_add(pvec, page) || PageCompound(page))
314 pagevec_lru_move_fn(pvec, __activate_page, NULL);
315 put_cpu_var(activate_page_pvecs);
316 }
317}
318
319#else
320static inline void activate_page_drain(int cpu)
321{
322}
323
324static bool need_activate_page_drain(int cpu)
325{
326 return false;
327}
328
329void activate_page(struct page *page)
330{
331 struct zone *zone = page_zone(page);
332
333 page = compound_head(page);
334 spin_lock_irq(zone_lru_lock(zone));
335 __activate_page(page, mem_cgroup_page_lruvec(page, zone->zone_pgdat), NULL);
336 spin_unlock_irq(zone_lru_lock(zone));
337}
338#endif
339
340static void __lru_cache_activate_page(struct page *page)
341{
342 struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
343 int i;
344
345
346
347
348
349
350
351
352
353
354
355 for (i = pagevec_count(pvec) - 1; i >= 0; i--) {
356 struct page *pagevec_page = pvec->pages[i];
357
358 if (pagevec_page == page) {
359 SetPageActive(page);
360 break;
361 }
362 }
363
364 put_cpu_var(lru_add_pvec);
365}
366
367
368
369
370
371
372
373
374
375
376
377void mark_page_accessed(struct page *page)
378{
379 page = compound_head(page);
380 if (!PageActive(page) && !PageUnevictable(page) &&
381 PageReferenced(page)) {
382
383
384
385
386
387
388
389 if (PageLRU(page))
390 activate_page(page);
391 else
392 __lru_cache_activate_page(page);
393 ClearPageReferenced(page);
394 if (page_is_file_cache(page))
395 workingset_activation(page);
396 } else if (!PageReferenced(page)) {
397 SetPageReferenced(page);
398 }
399 if (page_is_idle(page))
400 clear_page_idle(page);
401}
402EXPORT_SYMBOL(mark_page_accessed);
403
404static void __lru_cache_add(struct page *page)
405{
406 struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
407
408 get_page(page);
409 if (!pagevec_add(pvec, page) || PageCompound(page))
410 __pagevec_lru_add(pvec);
411 put_cpu_var(lru_add_pvec);
412}
413
414
415
416
417
418void lru_cache_add_anon(struct page *page)
419{
420 if (PageActive(page))
421 ClearPageActive(page);
422 __lru_cache_add(page);
423}
424
425void lru_cache_add_file(struct page *page)
426{
427 if (PageActive(page))
428 ClearPageActive(page);
429 __lru_cache_add(page);
430}
431EXPORT_SYMBOL(lru_cache_add_file);
432
433
434
435
436
437
438
439
440
441
442void lru_cache_add(struct page *page)
443{
444 VM_BUG_ON_PAGE(PageActive(page) && PageUnevictable(page), page);
445 VM_BUG_ON_PAGE(PageLRU(page), page);
446 __lru_cache_add(page);
447}
448
449
450
451
452
453
454
455
456
457
458
459void lru_cache_add_active_or_unevictable(struct page *page,
460 struct vm_area_struct *vma)
461{
462 VM_BUG_ON_PAGE(PageLRU(page), page);
463
464 if (likely((vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) != VM_LOCKED))
465 SetPageActive(page);
466 else if (!TestSetPageMlocked(page)) {
467
468
469
470
471
472 __mod_zone_page_state(page_zone(page), NR_MLOCK,
473 hpage_nr_pages(page));
474 count_vm_event(UNEVICTABLE_PGMLOCKED);
475 }
476 lru_cache_add(page);
477}
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500static void lru_deactivate_file_fn(struct page *page, struct lruvec *lruvec,
501 void *arg)
502{
503 int lru, file;
504 bool active;
505
506 if (!PageLRU(page))
507 return;
508
509 if (PageUnevictable(page))
510 return;
511
512
513 if (page_mapped(page))
514 return;
515
516 active = PageActive(page);
517 file = page_is_file_cache(page);
518 lru = page_lru_base_type(page);
519
520 del_page_from_lru_list(page, lruvec, lru + active);
521 ClearPageActive(page);
522 ClearPageReferenced(page);
523 add_page_to_lru_list(page, lruvec, lru);
524
525 if (PageWriteback(page) || PageDirty(page)) {
526
527
528
529
530
531 SetPageReclaim(page);
532 } else {
533
534
535
536
537 list_move_tail(&page->lru, &lruvec->lists[lru]);
538 __count_vm_event(PGROTATED);
539 }
540
541 if (active)
542 __count_vm_event(PGDEACTIVATE);
543 update_page_reclaim_stat(lruvec, file, 0);
544}
545
546
547static void lru_lazyfree_fn(struct page *page, struct lruvec *lruvec,
548 void *arg)
549{
550 if (PageLRU(page) && PageAnon(page) && PageSwapBacked(page) &&
551 !PageSwapCache(page) && !PageUnevictable(page)) {
552 bool active = PageActive(page);
553
554 del_page_from_lru_list(page, lruvec,
555 LRU_INACTIVE_ANON + active);
556 ClearPageActive(page);
557 ClearPageReferenced(page);
558
559
560
561
562
563 ClearPageSwapBacked(page);
564 add_page_to_lru_list(page, lruvec, LRU_INACTIVE_FILE);
565
566 __count_vm_events(PGLAZYFREE, hpage_nr_pages(page));
567 count_memcg_page_event(page, PGLAZYFREE);
568 update_page_reclaim_stat(lruvec, 1, 0);
569 }
570}
571
572
573
574
575
576
577void lru_add_drain_cpu(int cpu)
578{
579 struct pagevec *pvec = &per_cpu(lru_add_pvec, cpu);
580
581 if (pagevec_count(pvec))
582 __pagevec_lru_add(pvec);
583
584 pvec = &per_cpu(lru_rotate_pvecs, cpu);
585 if (pagevec_count(pvec)) {
586 unsigned long flags;
587
588
589 local_irq_save(flags);
590 pagevec_move_tail(pvec);
591 local_irq_restore(flags);
592 }
593
594 pvec = &per_cpu(lru_deactivate_file_pvecs, cpu);
595 if (pagevec_count(pvec))
596 pagevec_lru_move_fn(pvec, lru_deactivate_file_fn, NULL);
597
598 pvec = &per_cpu(lru_lazyfree_pvecs, cpu);
599 if (pagevec_count(pvec))
600 pagevec_lru_move_fn(pvec, lru_lazyfree_fn, NULL);
601
602 activate_page_drain(cpu);
603}
604
605
606
607
608
609
610
611
612
613void deactivate_file_page(struct page *page)
614{
615
616
617
618
619 if (PageUnevictable(page))
620 return;
621
622 if (likely(get_page_unless_zero(page))) {
623 struct pagevec *pvec = &get_cpu_var(lru_deactivate_file_pvecs);
624
625 if (!pagevec_add(pvec, page) || PageCompound(page))
626 pagevec_lru_move_fn(pvec, lru_deactivate_file_fn, NULL);
627 put_cpu_var(lru_deactivate_file_pvecs);
628 }
629}
630
631
632
633
634
635
636
637
638void mark_page_lazyfree(struct page *page)
639{
640 if (PageLRU(page) && PageAnon(page) && PageSwapBacked(page) &&
641 !PageSwapCache(page) && !PageUnevictable(page)) {
642 struct pagevec *pvec = &get_cpu_var(lru_lazyfree_pvecs);
643
644 get_page(page);
645 if (!pagevec_add(pvec, page) || PageCompound(page))
646 pagevec_lru_move_fn(pvec, lru_lazyfree_fn, NULL);
647 put_cpu_var(lru_lazyfree_pvecs);
648 }
649}
650
651void lru_add_drain(void)
652{
653 lru_add_drain_cpu(get_cpu());
654 put_cpu();
655}
656
657static void lru_add_drain_per_cpu(struct work_struct *dummy)
658{
659 lru_add_drain();
660}
661
662static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work);
663
664
665
666
667
668
669
670
671void lru_add_drain_all(void)
672{
673 static DEFINE_MUTEX(lock);
674 static struct cpumask has_work;
675 int cpu;
676
677
678
679
680
681 if (WARN_ON(!mm_percpu_wq))
682 return;
683
684 mutex_lock(&lock);
685 cpumask_clear(&has_work);
686
687 for_each_online_cpu(cpu) {
688 struct work_struct *work = &per_cpu(lru_add_drain_work, cpu);
689
690 if (pagevec_count(&per_cpu(lru_add_pvec, cpu)) ||
691 pagevec_count(&per_cpu(lru_rotate_pvecs, cpu)) ||
692 pagevec_count(&per_cpu(lru_deactivate_file_pvecs, cpu)) ||
693 pagevec_count(&per_cpu(lru_lazyfree_pvecs, cpu)) ||
694 need_activate_page_drain(cpu)) {
695 INIT_WORK(work, lru_add_drain_per_cpu);
696 queue_work_on(cpu, mm_percpu_wq, work);
697 cpumask_set_cpu(cpu, &has_work);
698 }
699 }
700
701 for_each_cpu(cpu, &has_work)
702 flush_work(&per_cpu(lru_add_drain_work, cpu));
703
704 mutex_unlock(&lock);
705}
706
707
708
709
710
711
712
713
714
715void release_pages(struct page **pages, int nr)
716{
717 int i;
718 LIST_HEAD(pages_to_free);
719 struct pglist_data *locked_pgdat = NULL;
720 struct lruvec *lruvec;
721 unsigned long uninitialized_var(flags);
722 unsigned int uninitialized_var(lock_batch);
723
724 for (i = 0; i < nr; i++) {
725 struct page *page = pages[i];
726
727
728
729
730
731
732 if (locked_pgdat && ++lock_batch == SWAP_CLUSTER_MAX) {
733 spin_unlock_irqrestore(&locked_pgdat->lru_lock, flags);
734 locked_pgdat = NULL;
735 }
736
737 if (is_huge_zero_page(page))
738 continue;
739
740
741 if (is_device_public_page(page)) {
742 if (locked_pgdat) {
743 spin_unlock_irqrestore(&locked_pgdat->lru_lock,
744 flags);
745 locked_pgdat = NULL;
746 }
747 put_devmap_managed_page(page);
748 continue;
749 }
750
751 page = compound_head(page);
752 if (!put_page_testzero(page))
753 continue;
754
755 if (PageCompound(page)) {
756 if (locked_pgdat) {
757 spin_unlock_irqrestore(&locked_pgdat->lru_lock, flags);
758 locked_pgdat = NULL;
759 }
760 __put_compound_page(page);
761 continue;
762 }
763
764 if (PageLRU(page)) {
765 struct pglist_data *pgdat = page_pgdat(page);
766
767 if (pgdat != locked_pgdat) {
768 if (locked_pgdat)
769 spin_unlock_irqrestore(&locked_pgdat->lru_lock,
770 flags);
771 lock_batch = 0;
772 locked_pgdat = pgdat;
773 spin_lock_irqsave(&locked_pgdat->lru_lock, flags);
774 }
775
776 lruvec = mem_cgroup_page_lruvec(page, locked_pgdat);
777 VM_BUG_ON_PAGE(!PageLRU(page), page);
778 __ClearPageLRU(page);
779 del_page_from_lru_list(page, lruvec, page_off_lru(page));
780 }
781
782
783 __ClearPageActive(page);
784 __ClearPageWaiters(page);
785
786 list_add(&page->lru, &pages_to_free);
787 }
788 if (locked_pgdat)
789 spin_unlock_irqrestore(&locked_pgdat->lru_lock, flags);
790
791 mem_cgroup_uncharge_list(&pages_to_free);
792 free_unref_page_list(&pages_to_free);
793}
794EXPORT_SYMBOL(release_pages);
795
796
797
798
799
800
801
802
803
804
805
806void __pagevec_release(struct pagevec *pvec)
807{
808 if (!pvec->percpu_pvec_drained) {
809 lru_add_drain();
810 pvec->percpu_pvec_drained = true;
811 }
812 release_pages(pvec->pages, pagevec_count(pvec));
813 pagevec_reinit(pvec);
814}
815EXPORT_SYMBOL(__pagevec_release);
816
817#ifdef CONFIG_TRANSPARENT_HUGEPAGE
818
819void lru_add_page_tail(struct page *page, struct page *page_tail,
820 struct lruvec *lruvec, struct list_head *list)
821{
822 const int file = 0;
823
824 VM_BUG_ON_PAGE(!PageHead(page), page);
825 VM_BUG_ON_PAGE(PageCompound(page_tail), page);
826 VM_BUG_ON_PAGE(PageLRU(page_tail), page);
827 VM_BUG_ON(NR_CPUS != 1 &&
828 !spin_is_locked(&lruvec_pgdat(lruvec)->lru_lock));
829
830 if (!list)
831 SetPageLRU(page_tail);
832
833 if (likely(PageLRU(page)))
834 list_add_tail(&page_tail->lru, &page->lru);
835 else if (list) {
836
837 get_page(page_tail);
838 list_add_tail(&page_tail->lru, list);
839 } else {
840 struct list_head *list_head;
841
842
843
844
845
846
847
848 add_page_to_lru_list(page_tail, lruvec, page_lru(page_tail));
849 list_head = page_tail->lru.prev;
850 list_move_tail(&page_tail->lru, list_head);
851 }
852
853 if (!PageUnevictable(page))
854 update_page_reclaim_stat(lruvec, file, PageActive(page_tail));
855}
856#endif
857
858static void __pagevec_lru_add_fn(struct page *page, struct lruvec *lruvec,
859 void *arg)
860{
861 enum lru_list lru;
862 int was_unevictable = TestClearPageUnevictable(page);
863
864 VM_BUG_ON_PAGE(PageLRU(page), page);
865
866 SetPageLRU(page);
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893 smp_mb();
894
895 if (page_evictable(page)) {
896 lru = page_lru(page);
897 update_page_reclaim_stat(lruvec, page_is_file_cache(page),
898 PageActive(page));
899 if (was_unevictable)
900 count_vm_event(UNEVICTABLE_PGRESCUED);
901 } else {
902 lru = LRU_UNEVICTABLE;
903 ClearPageActive(page);
904 SetPageUnevictable(page);
905 if (!was_unevictable)
906 count_vm_event(UNEVICTABLE_PGCULLED);
907 }
908
909 add_page_to_lru_list(page, lruvec, lru);
910 trace_mm_lru_insertion(page, lru);
911}
912
913
914
915
916
917void __pagevec_lru_add(struct pagevec *pvec)
918{
919 pagevec_lru_move_fn(pvec, __pagevec_lru_add_fn, NULL);
920}
921EXPORT_SYMBOL(__pagevec_lru_add);
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943unsigned pagevec_lookup_entries(struct pagevec *pvec,
944 struct address_space *mapping,
945 pgoff_t start, unsigned nr_entries,
946 pgoff_t *indices)
947{
948 pvec->nr = find_get_entries(mapping, start, nr_entries,
949 pvec->pages, indices);
950 return pagevec_count(pvec);
951}
952
953
954
955
956
957
958
959
960
961
962void pagevec_remove_exceptionals(struct pagevec *pvec)
963{
964 int i, j;
965
966 for (i = 0, j = 0; i < pagevec_count(pvec); i++) {
967 struct page *page = pvec->pages[i];
968 if (!radix_tree_exceptional_entry(page))
969 pvec->pages[j++] = page;
970 }
971 pvec->nr = j;
972}
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994unsigned pagevec_lookup_range(struct pagevec *pvec,
995 struct address_space *mapping, pgoff_t *start, pgoff_t end)
996{
997 pvec->nr = find_get_pages_range(mapping, start, end, PAGEVEC_SIZE,
998 pvec->pages);
999 return pagevec_count(pvec);
1000}
1001EXPORT_SYMBOL(pagevec_lookup_range);
1002
1003unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
1004 struct address_space *mapping, pgoff_t *index, pgoff_t end,
1005 int tag)
1006{
1007 pvec->nr = find_get_pages_range_tag(mapping, index, end, tag,
1008 PAGEVEC_SIZE, pvec->pages);
1009 return pagevec_count(pvec);
1010}
1011EXPORT_SYMBOL(pagevec_lookup_range_tag);
1012
1013unsigned pagevec_lookup_range_nr_tag(struct pagevec *pvec,
1014 struct address_space *mapping, pgoff_t *index, pgoff_t end,
1015 int tag, unsigned max_pages)
1016{
1017 pvec->nr = find_get_pages_range_tag(mapping, index, end, tag,
1018 min_t(unsigned int, max_pages, PAGEVEC_SIZE), pvec->pages);
1019 return pagevec_count(pvec);
1020}
1021EXPORT_SYMBOL(pagevec_lookup_range_nr_tag);
1022
1023
1024
1025void __init swap_setup(void)
1026{
1027 unsigned long megs = totalram_pages >> (20 - PAGE_SHIFT);
1028
1029
1030 if (megs < 16)
1031 page_cluster = 2;
1032 else
1033 page_cluster = 3;
1034
1035
1036
1037
1038}
1039