ALSA: intel8x0: Mute External Amplifier by default for ThinkPad X31
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / mm / vmscan.c
blob5c4620600333266bc7d092f93734db38475f2dfd
1 /*
2 * linux/mm/vmscan.c
4 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
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.
14 #include <linux/mm.h>
15 #include <linux/module.h>
16 #include <linux/gfp.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/swap.h>
19 #include <linux/pagemap.h>
20 #include <linux/init.h>
21 #include <linux/highmem.h>
22 #include <linux/vmstat.h>
23 #include <linux/file.h>
24 #include <linux/writeback.h>
25 #include <linux/blkdev.h>
26 #include <linux/buffer_head.h> /* for try_to_release_page(),
27 buffer_heads_over_limit */
28 #include <linux/mm_inline.h>
29 #include <linux/pagevec.h>
30 #include <linux/backing-dev.h>
31 #include <linux/rmap.h>
32 #include <linux/topology.h>
33 #include <linux/cpu.h>
34 #include <linux/cpuset.h>
35 #include <linux/notifier.h>
36 #include <linux/rwsem.h>
37 #include <linux/delay.h>
38 #include <linux/kthread.h>
39 #include <linux/freezer.h>
40 #include <linux/memcontrol.h>
41 #include <linux/delayacct.h>
42 #include <linux/sysctl.h>
44 #include <asm/tlbflush.h>
45 #include <asm/div64.h>
47 #include <linux/swapops.h>
49 #include "internal.h"
51 struct scan_control {
52 /* Incremented by the number of inactive pages that were scanned */
53 unsigned long nr_scanned;
55 /* Number of pages freed so far during a call to shrink_zones() */
56 unsigned long nr_reclaimed;
58 /* How many pages shrink_list() should reclaim */
59 unsigned long nr_to_reclaim;
61 unsigned long hibernation_mode;
63 /* This context's GFP mask */
64 gfp_t gfp_mask;
66 int may_writepage;
68 /* Can mapped pages be reclaimed? */
69 int may_unmap;
71 /* Can pages be swapped as part of reclaim? */
72 int may_swap;
74 int swappiness;
76 int all_unreclaimable;
78 int order;
80 /* Which cgroup do we reclaim from */
81 struct mem_cgroup *mem_cgroup;
84 * Nodemask of nodes allowed by the caller. If NULL, all nodes
85 * are scanned.
87 nodemask_t *nodemask;
89 /* Pluggable isolate pages callback */
90 unsigned long (*isolate_pages)(unsigned long nr, struct list_head *dst,
91 unsigned long *scanned, int order, int mode,
92 struct zone *z, struct mem_cgroup *mem_cont,
93 int active, int file);
96 #define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))
98 #ifdef ARCH_HAS_PREFETCH
99 #define prefetch_prev_lru_page(_page, _base, _field) \
100 do { \
101 if ((_page)->lru.prev != _base) { \
102 struct page *prev; \
104 prev = lru_to_page(&(_page->lru)); \
105 prefetch(&prev->_field); \
107 } while (0)
108 #else
109 #define prefetch_prev_lru_page(_page, _base, _field) do { } while (0)
110 #endif
112 #ifdef ARCH_HAS_PREFETCHW
113 #define prefetchw_prev_lru_page(_page, _base, _field) \
114 do { \
115 if ((_page)->lru.prev != _base) { \
116 struct page *prev; \
118 prev = lru_to_page(&(_page->lru)); \
119 prefetchw(&prev->_field); \
121 } while (0)
122 #else
123 #define prefetchw_prev_lru_page(_page, _base, _field) do { } while (0)
124 #endif
127 * From 0 .. 100. Higher means more swappy.
129 int vm_swappiness = 60;
130 long vm_total_pages; /* The total number of pages which the VM controls */
132 static LIST_HEAD(shrinker_list);
133 static DECLARE_RWSEM(shrinker_rwsem);
135 #ifdef CONFIG_CGROUP_MEM_RES_CTLR
136 #define scanning_global_lru(sc) (!(sc)->mem_cgroup)
137 #else
138 #define scanning_global_lru(sc) (1)
139 #endif
141 static struct zone_reclaim_stat *get_reclaim_stat(struct zone *zone,
142 struct scan_control *sc)
144 if (!scanning_global_lru(sc))
145 return mem_cgroup_get_reclaim_stat(sc->mem_cgroup, zone);
147 return &zone->reclaim_stat;
150 static unsigned long zone_nr_lru_pages(struct zone *zone,
151 struct scan_control *sc, enum lru_list lru)
153 if (!scanning_global_lru(sc))
154 return mem_cgroup_zone_nr_pages(sc->mem_cgroup, zone, lru);
156 return zone_page_state(zone, NR_LRU_BASE + lru);
161 * Add a shrinker callback to be called from the vm
163 void register_shrinker(struct shrinker *shrinker)
165 shrinker->nr = 0;
166 down_write(&shrinker_rwsem);
167 list_add_tail(&shrinker->list, &shrinker_list);
168 up_write(&shrinker_rwsem);
170 EXPORT_SYMBOL(register_shrinker);
173 * Remove one
175 void unregister_shrinker(struct shrinker *shrinker)
177 down_write(&shrinker_rwsem);
178 list_del(&shrinker->list);
179 up_write(&shrinker_rwsem);
181 EXPORT_SYMBOL(unregister_shrinker);
183 #define SHRINK_BATCH 128
185 * Call the shrink functions to age shrinkable caches
187 * Here we assume it costs one seek to replace a lru page and that it also
188 * takes a seek to recreate a cache object. With this in mind we age equal
189 * percentages of the lru and ageable caches. This should balance the seeks
190 * generated by these structures.
192 * If the vm encountered mapped pages on the LRU it increase the pressure on
193 * slab to avoid swapping.
195 * We do weird things to avoid (scanned*seeks*entries) overflowing 32 bits.
197 * `lru_pages' represents the number of on-LRU pages in all the zones which
198 * are eligible for the caller's allocation attempt. It is used for balancing
199 * slab reclaim versus page reclaim.
201 * Returns the number of slab objects which we shrunk.
203 unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask,
204 unsigned long lru_pages)
206 struct shrinker *shrinker;
207 unsigned long ret = 0;
209 if (scanned == 0)
210 scanned = SWAP_CLUSTER_MAX;
212 if (!down_read_trylock(&shrinker_rwsem))
213 return 1; /* Assume we'll be able to shrink next time */
215 list_for_each_entry(shrinker, &shrinker_list, list) {
216 unsigned long long delta;
217 unsigned long total_scan;
218 unsigned long max_pass = (*shrinker->shrink)(0, gfp_mask);
220 delta = (4 * scanned) / shrinker->seeks;
221 delta *= max_pass;
222 do_div(delta, lru_pages + 1);
223 shrinker->nr += delta;
224 if (shrinker->nr < 0) {
225 printk(KERN_ERR "shrink_slab: %pF negative objects to "
226 "delete nr=%ld\n",
227 shrinker->shrink, shrinker->nr);
228 shrinker->nr = max_pass;
232 * Avoid risking looping forever due to too large nr value:
233 * never try to free more than twice the estimate number of
234 * freeable entries.
236 if (shrinker->nr > max_pass * 2)
237 shrinker->nr = max_pass * 2;
239 total_scan = shrinker->nr;
240 shrinker->nr = 0;
242 while (total_scan >= SHRINK_BATCH) {
243 long this_scan = SHRINK_BATCH;
244 int shrink_ret;
245 int nr_before;
247 nr_before = (*shrinker->shrink)(0, gfp_mask);
248 shrink_ret = (*shrinker->shrink)(this_scan, gfp_mask);
249 if (shrink_ret == -1)
250 break;
251 if (shrink_ret < nr_before)
252 ret += nr_before - shrink_ret;
253 count_vm_events(SLABS_SCANNED, this_scan);
254 total_scan -= this_scan;
256 cond_resched();
259 shrinker->nr += total_scan;
261 up_read(&shrinker_rwsem);
262 return ret;
265 static inline int is_page_cache_freeable(struct page *page)
268 * A freeable page cache page is referenced only by the caller
269 * that isolated the page, the page cache radix tree and
270 * optional buffer heads at page->private.
272 return page_count(page) - page_has_private(page) == 2;
275 static int may_write_to_queue(struct backing_dev_info *bdi)
277 if (current->flags & PF_SWAPWRITE)
278 return 1;
279 if (!bdi_write_congested(bdi))
280 return 1;
281 if (bdi == current->backing_dev_info)
282 return 1;
283 return 0;
287 * We detected a synchronous write error writing a page out. Probably
288 * -ENOSPC. We need to propagate that into the address_space for a subsequent
289 * fsync(), msync() or close().
291 * The tricky part is that after writepage we cannot touch the mapping: nothing
292 * prevents it from being freed up. But we have a ref on the page and once
293 * that page is locked, the mapping is pinned.
295 * We're allowed to run sleeping lock_page() here because we know the caller has
296 * __GFP_FS.
298 static void handle_write_error(struct address_space *mapping,
299 struct page *page, int error)
301 lock_page(page);
302 if (page_mapping(page) == mapping)
303 mapping_set_error(mapping, error);
304 unlock_page(page);
307 /* Request for sync pageout. */
308 enum pageout_io {
309 PAGEOUT_IO_ASYNC,
310 PAGEOUT_IO_SYNC,
313 /* possible outcome of pageout() */
314 typedef enum {
315 /* failed to write page out, page is locked */
316 PAGE_KEEP,
317 /* move page to the active list, page is locked */
318 PAGE_ACTIVATE,
319 /* page has been sent to the disk successfully, page is unlocked */
320 PAGE_SUCCESS,
321 /* page is clean and locked */
322 PAGE_CLEAN,
323 } pageout_t;
326 * pageout is called by shrink_page_list() for each dirty page.
327 * Calls ->writepage().
329 static pageout_t pageout(struct page *page, struct address_space *mapping,
330 enum pageout_io sync_writeback)
333 * If the page is dirty, only perform writeback if that write
334 * will be non-blocking. To prevent this allocation from being
335 * stalled by pagecache activity. But note that there may be
336 * stalls if we need to run get_block(). We could test
337 * PagePrivate for that.
339 * If this process is currently in __generic_file_aio_write() against
340 * this page's queue, we can perform writeback even if that
341 * will block.
343 * If the page is swapcache, write it back even if that would
344 * block, for some throttling. This happens by accident, because
345 * swap_backing_dev_info is bust: it doesn't reflect the
346 * congestion state of the swapdevs. Easy to fix, if needed.
348 if (!is_page_cache_freeable(page))
349 return PAGE_KEEP;
350 if (!mapping) {
352 * Some data journaling orphaned pages can have
353 * page->mapping == NULL while being dirty with clean buffers.
355 if (page_has_private(page)) {
356 if (try_to_free_buffers(page)) {
357 ClearPageDirty(page);
358 printk("%s: orphaned page\n", __func__);
359 return PAGE_CLEAN;
362 return PAGE_KEEP;
364 if (mapping->a_ops->writepage == NULL)
365 return PAGE_ACTIVATE;
366 if (!may_write_to_queue(mapping->backing_dev_info))
367 return PAGE_KEEP;
369 if (clear_page_dirty_for_io(page)) {
370 int res;
371 struct writeback_control wbc = {
372 .sync_mode = WB_SYNC_NONE,
373 .nr_to_write = SWAP_CLUSTER_MAX,
374 .range_start = 0,
375 .range_end = LLONG_MAX,
376 .nonblocking = 1,
377 .for_reclaim = 1,
380 SetPageReclaim(page);
381 res = mapping->a_ops->writepage(page, &wbc);
382 if (res < 0)
383 handle_write_error(mapping, page, res);
384 if (res == AOP_WRITEPAGE_ACTIVATE) {
385 ClearPageReclaim(page);
386 return PAGE_ACTIVATE;
390 * Wait on writeback if requested to. This happens when
391 * direct reclaiming a large contiguous area and the
392 * first attempt to free a range of pages fails.
394 if (PageWriteback(page) && sync_writeback == PAGEOUT_IO_SYNC)
395 wait_on_page_writeback(page);
397 if (!PageWriteback(page)) {
398 /* synchronous write or broken a_ops? */
399 ClearPageReclaim(page);
401 inc_zone_page_state(page, NR_VMSCAN_WRITE);
402 return PAGE_SUCCESS;
405 return PAGE_CLEAN;
409 * Same as remove_mapping, but if the page is removed from the mapping, it
410 * gets returned with a refcount of 0.
412 static int __remove_mapping(struct address_space *mapping, struct page *page)
414 BUG_ON(!PageLocked(page));
415 BUG_ON(mapping != page_mapping(page));
417 spin_lock_irq(&mapping->tree_lock);
419 * The non racy check for a busy page.
421 * Must be careful with the order of the tests. When someone has
422 * a ref to the page, it may be possible that they dirty it then
423 * drop the reference. So if PageDirty is tested before page_count
424 * here, then the following race may occur:
426 * get_user_pages(&page);
427 * [user mapping goes away]
428 * write_to(page);
429 * !PageDirty(page) [good]
430 * SetPageDirty(page);
431 * put_page(page);
432 * !page_count(page) [good, discard it]
434 * [oops, our write_to data is lost]
436 * Reversing the order of the tests ensures such a situation cannot
437 * escape unnoticed. The smp_rmb is needed to ensure the page->flags
438 * load is not satisfied before that of page->_count.
440 * Note that if SetPageDirty is always performed via set_page_dirty,
441 * and thus under tree_lock, then this ordering is not required.
443 if (!page_freeze_refs(page, 2))
444 goto cannot_free;
445 /* note: atomic_cmpxchg in page_freeze_refs provides the smp_rmb */
446 if (unlikely(PageDirty(page))) {
447 page_unfreeze_refs(page, 2);
448 goto cannot_free;
451 if (PageSwapCache(page)) {
452 swp_entry_t swap = { .val = page_private(page) };
453 __delete_from_swap_cache(page);
454 spin_unlock_irq(&mapping->tree_lock);
455 swapcache_free(swap, page);
456 } else {
457 __remove_from_page_cache(page);
458 spin_unlock_irq(&mapping->tree_lock);
459 mem_cgroup_uncharge_cache_page(page);
462 return 1;
464 cannot_free:
465 spin_unlock_irq(&mapping->tree_lock);
466 return 0;
470 * Attempt to detach a locked page from its ->mapping. If it is dirty or if
471 * someone else has a ref on the page, abort and return 0. If it was
472 * successfully detached, return 1. Assumes the caller has a single ref on
473 * this page.
475 int remove_mapping(struct address_space *mapping, struct page *page)
477 if (__remove_mapping(mapping, page)) {
479 * Unfreezing the refcount with 1 rather than 2 effectively
480 * drops the pagecache ref for us without requiring another
481 * atomic operation.
483 page_unfreeze_refs(page, 1);
484 return 1;
486 return 0;
490 * putback_lru_page - put previously isolated page onto appropriate LRU list
491 * @page: page to be put back to appropriate lru list
493 * Add previously isolated @page to appropriate LRU list.
494 * Page may still be unevictable for other reasons.
496 * lru_lock must not be held, interrupts must be enabled.
498 void putback_lru_page(struct page *page)
500 int lru;
501 int active = !!TestClearPageActive(page);
502 int was_unevictable = PageUnevictable(page);
504 VM_BUG_ON(PageLRU(page));
506 redo:
507 ClearPageUnevictable(page);
509 if (page_evictable(page, NULL)) {
511 * For evictable pages, we can use the cache.
512 * In event of a race, worst case is we end up with an
513 * unevictable page on [in]active list.
514 * We know how to handle that.
516 lru = active + page_lru_base_type(page);
517 lru_cache_add_lru(page, lru);
518 } else {
520 * Put unevictable pages directly on zone's unevictable
521 * list.
523 lru = LRU_UNEVICTABLE;
524 add_page_to_unevictable_list(page);
526 * When racing with an mlock clearing (page is
527 * unlocked), make sure that if the other thread does
528 * not observe our setting of PG_lru and fails
529 * isolation, we see PG_mlocked cleared below and move
530 * the page back to the evictable list.
532 * The other side is TestClearPageMlocked().
534 smp_mb();
538 * page's status can change while we move it among lru. If an evictable
539 * page is on unevictable list, it never be freed. To avoid that,
540 * check after we added it to the list, again.
542 if (lru == LRU_UNEVICTABLE && page_evictable(page, NULL)) {
543 if (!isolate_lru_page(page)) {
544 put_page(page);
545 goto redo;
547 /* This means someone else dropped this page from LRU
548 * So, it will be freed or putback to LRU again. There is
549 * nothing to do here.
553 if (was_unevictable && lru != LRU_UNEVICTABLE)
554 count_vm_event(UNEVICTABLE_PGRESCUED);
555 else if (!was_unevictable && lru == LRU_UNEVICTABLE)
556 count_vm_event(UNEVICTABLE_PGCULLED);
558 put_page(page); /* drop ref from isolate */
561 enum page_references {
562 PAGEREF_RECLAIM,
563 PAGEREF_RECLAIM_CLEAN,
564 PAGEREF_KEEP,
565 PAGEREF_ACTIVATE,
568 static enum page_references page_check_references(struct page *page,
569 struct scan_control *sc)
571 int referenced_ptes, referenced_page;
572 unsigned long vm_flags;
574 referenced_ptes = page_referenced(page, 1, sc->mem_cgroup, &vm_flags);
575 referenced_page = TestClearPageReferenced(page);
577 /* Lumpy reclaim - ignore references */
578 if (sc->order > PAGE_ALLOC_COSTLY_ORDER)
579 return PAGEREF_RECLAIM;
582 * Mlock lost the isolation race with us. Let try_to_unmap()
583 * move the page to the unevictable list.
585 if (vm_flags & VM_LOCKED)
586 return PAGEREF_RECLAIM;
588 if (referenced_ptes) {
589 if (PageAnon(page))
590 return PAGEREF_ACTIVATE;
592 * All mapped pages start out with page table
593 * references from the instantiating fault, so we need
594 * to look twice if a mapped file page is used more
595 * than once.
597 * Mark it and spare it for another trip around the
598 * inactive list. Another page table reference will
599 * lead to its activation.
601 * Note: the mark is set for activated pages as well
602 * so that recently deactivated but used pages are
603 * quickly recovered.
605 SetPageReferenced(page);
607 if (referenced_page)
608 return PAGEREF_ACTIVATE;
610 return PAGEREF_KEEP;
613 /* Reclaim if clean, defer dirty pages to writeback */
614 if (referenced_page)
615 return PAGEREF_RECLAIM_CLEAN;
617 return PAGEREF_RECLAIM;
621 * shrink_page_list() returns the number of reclaimed pages
623 static unsigned long shrink_page_list(struct list_head *page_list,
624 struct scan_control *sc,
625 enum pageout_io sync_writeback)
627 LIST_HEAD(ret_pages);
628 struct pagevec freed_pvec;
629 int pgactivate = 0;
630 unsigned long nr_reclaimed = 0;
632 cond_resched();
634 pagevec_init(&freed_pvec, 1);
635 while (!list_empty(page_list)) {
636 enum page_references references;
637 struct address_space *mapping;
638 struct page *page;
639 int may_enter_fs;
641 cond_resched();
643 page = lru_to_page(page_list);
644 list_del(&page->lru);
646 if (!trylock_page(page))
647 goto keep;
649 VM_BUG_ON(PageActive(page));
651 sc->nr_scanned++;
653 if (unlikely(!page_evictable(page, NULL)))
654 goto cull_mlocked;
656 if (!sc->may_unmap && page_mapped(page))
657 goto keep_locked;
659 /* Double the slab pressure for mapped and swapcache pages */
660 if (page_mapped(page) || PageSwapCache(page))
661 sc->nr_scanned++;
663 may_enter_fs = (sc->gfp_mask & __GFP_FS) ||
664 (PageSwapCache(page) && (sc->gfp_mask & __GFP_IO));
666 if (PageWriteback(page)) {
668 * Synchronous reclaim is performed in two passes,
669 * first an asynchronous pass over the list to
670 * start parallel writeback, and a second synchronous
671 * pass to wait for the IO to complete. Wait here
672 * for any page for which writeback has already
673 * started.
675 if (sync_writeback == PAGEOUT_IO_SYNC && may_enter_fs)
676 wait_on_page_writeback(page);
677 else
678 goto keep_locked;
681 references = page_check_references(page, sc);
682 switch (references) {
683 case PAGEREF_ACTIVATE:
684 goto activate_locked;
685 case PAGEREF_KEEP:
686 goto keep_locked;
687 case PAGEREF_RECLAIM:
688 case PAGEREF_RECLAIM_CLEAN:
689 ; /* try to reclaim the page below */
693 * Anonymous process memory has backing store?
694 * Try to allocate it some swap space here.
696 if (PageAnon(page) && !PageSwapCache(page)) {
697 if (!(sc->gfp_mask & __GFP_IO))
698 goto keep_locked;
699 if (!add_to_swap(page))
700 goto activate_locked;
701 may_enter_fs = 1;
704 mapping = page_mapping(page);
707 * The page is mapped into the page tables of one or more
708 * processes. Try to unmap it here.
710 if (page_mapped(page) && mapping) {
711 switch (try_to_unmap(page, TTU_UNMAP)) {
712 case SWAP_FAIL:
713 goto activate_locked;
714 case SWAP_AGAIN:
715 goto keep_locked;
716 case SWAP_MLOCK:
717 goto cull_mlocked;
718 case SWAP_SUCCESS:
719 ; /* try to free the page below */
723 if (PageDirty(page)) {
724 if (references == PAGEREF_RECLAIM_CLEAN)
725 goto keep_locked;
726 if (!may_enter_fs)
727 goto keep_locked;
728 if (!sc->may_writepage)
729 goto keep_locked;
731 /* Page is dirty, try to write it out here */
732 switch (pageout(page, mapping, sync_writeback)) {
733 case PAGE_KEEP:
734 goto keep_locked;
735 case PAGE_ACTIVATE:
736 goto activate_locked;
737 case PAGE_SUCCESS:
738 if (PageWriteback(page) || PageDirty(page))
739 goto keep;
741 * A synchronous write - probably a ramdisk. Go
742 * ahead and try to reclaim the page.
744 if (!trylock_page(page))
745 goto keep;
746 if (PageDirty(page) || PageWriteback(page))
747 goto keep_locked;
748 mapping = page_mapping(page);
749 case PAGE_CLEAN:
750 ; /* try to free the page below */
755 * If the page has buffers, try to free the buffer mappings
756 * associated with this page. If we succeed we try to free
757 * the page as well.
759 * We do this even if the page is PageDirty().
760 * try_to_release_page() does not perform I/O, but it is
761 * possible for a page to have PageDirty set, but it is actually
762 * clean (all its buffers are clean). This happens if the
763 * buffers were written out directly, with submit_bh(). ext3
764 * will do this, as well as the blockdev mapping.
765 * try_to_release_page() will discover that cleanness and will
766 * drop the buffers and mark the page clean - it can be freed.
768 * Rarely, pages can have buffers and no ->mapping. These are
769 * the pages which were not successfully invalidated in
770 * truncate_complete_page(). We try to drop those buffers here
771 * and if that worked, and the page is no longer mapped into
772 * process address space (page_count == 1) it can be freed.
773 * Otherwise, leave the page on the LRU so it is swappable.
775 if (page_has_private(page)) {
776 if (!try_to_release_page(page, sc->gfp_mask))
777 goto activate_locked;
778 if (!mapping && page_count(page) == 1) {
779 unlock_page(page);
780 if (put_page_testzero(page))
781 goto free_it;
782 else {
784 * rare race with speculative reference.
785 * the speculative reference will free
786 * this page shortly, so we may
787 * increment nr_reclaimed here (and
788 * leave it off the LRU).
790 nr_reclaimed++;
791 continue;
796 if (!mapping || !__remove_mapping(mapping, page))
797 goto keep_locked;
800 * At this point, we have no other references and there is
801 * no way to pick any more up (removed from LRU, removed
802 * from pagecache). Can use non-atomic bitops now (and
803 * we obviously don't have to worry about waking up a process
804 * waiting on the page lock, because there are no references.
806 __clear_page_locked(page);
807 free_it:
808 nr_reclaimed++;
809 if (!pagevec_add(&freed_pvec, page)) {
810 __pagevec_free(&freed_pvec);
811 pagevec_reinit(&freed_pvec);
813 continue;
815 cull_mlocked:
816 if (PageSwapCache(page))
817 try_to_free_swap(page);
818 unlock_page(page);
819 putback_lru_page(page);
820 continue;
822 activate_locked:
823 /* Not a candidate for swapping, so reclaim swap space. */
824 if (PageSwapCache(page) && vm_swap_full())
825 try_to_free_swap(page);
826 VM_BUG_ON(PageActive(page));
827 SetPageActive(page);
828 pgactivate++;
829 keep_locked:
830 unlock_page(page);
831 keep:
832 list_add(&page->lru, &ret_pages);
833 VM_BUG_ON(PageLRU(page) || PageUnevictable(page));
835 list_splice(&ret_pages, page_list);
836 if (pagevec_count(&freed_pvec))
837 __pagevec_free(&freed_pvec);
838 count_vm_events(PGACTIVATE, pgactivate);
839 return nr_reclaimed;
842 /* LRU Isolation modes. */
843 #define ISOLATE_INACTIVE 0 /* Isolate inactive pages. */
844 #define ISOLATE_ACTIVE 1 /* Isolate active pages. */
845 #define ISOLATE_BOTH 2 /* Isolate both active and inactive pages. */
848 * Attempt to remove the specified page from its LRU. Only take this page
849 * if it is of the appropriate PageActive status. Pages which are being
850 * freed elsewhere are also ignored.
852 * page: page to consider
853 * mode: one of the LRU isolation modes defined above
855 * returns 0 on success, -ve errno on failure.
857 int __isolate_lru_page(struct page *page, int mode, int file)
859 int ret = -EINVAL;
861 /* Only take pages on the LRU. */
862 if (!PageLRU(page))
863 return ret;
866 * When checking the active state, we need to be sure we are
867 * dealing with comparible boolean values. Take the logical not
868 * of each.
870 if (mode != ISOLATE_BOTH && (!PageActive(page) != !mode))
871 return ret;
873 if (mode != ISOLATE_BOTH && page_is_file_cache(page) != file)
874 return ret;
877 * When this function is being called for lumpy reclaim, we
878 * initially look into all LRU pages, active, inactive and
879 * unevictable; only give shrink_page_list evictable pages.
881 if (PageUnevictable(page))
882 return ret;
884 ret = -EBUSY;
886 if (likely(get_page_unless_zero(page))) {
888 * Be careful not to clear PageLRU until after we're
889 * sure the page is not being freed elsewhere -- the
890 * page release code relies on it.
892 ClearPageLRU(page);
893 ret = 0;
896 return ret;
900 * zone->lru_lock is heavily contended. Some of the functions that
901 * shrink the lists perform better by taking out a batch of pages
902 * and working on them outside the LRU lock.
904 * For pagecache intensive workloads, this function is the hottest
905 * spot in the kernel (apart from copy_*_user functions).
907 * Appropriate locks must be held before calling this function.
909 * @nr_to_scan: The number of pages to look through on the list.
910 * @src: The LRU list to pull pages off.
911 * @dst: The temp list to put pages on to.
912 * @scanned: The number of pages that were scanned.
913 * @order: The caller's attempted allocation order
914 * @mode: One of the LRU isolation modes
915 * @file: True [1] if isolating file [!anon] pages
917 * returns how many pages were moved onto *@dst.
919 static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
920 struct list_head *src, struct list_head *dst,
921 unsigned long *scanned, int order, int mode, int file)
923 unsigned long nr_taken = 0;
924 unsigned long scan;
926 for (scan = 0; scan < nr_to_scan && !list_empty(src); scan++) {
927 struct page *page;
928 unsigned long pfn;
929 unsigned long end_pfn;
930 unsigned long page_pfn;
931 int zone_id;
933 page = lru_to_page(src);
934 prefetchw_prev_lru_page(page, src, flags);
936 VM_BUG_ON(!PageLRU(page));
938 switch (__isolate_lru_page(page, mode, file)) {
939 case 0:
940 list_move(&page->lru, dst);
941 mem_cgroup_del_lru(page);
942 nr_taken++;
943 break;
945 case -EBUSY:
946 /* else it is being freed elsewhere */
947 list_move(&page->lru, src);
948 mem_cgroup_rotate_lru_list(page, page_lru(page));
949 continue;
951 default:
952 BUG();
955 if (!order)
956 continue;
959 * Attempt to take all pages in the order aligned region
960 * surrounding the tag page. Only take those pages of
961 * the same active state as that tag page. We may safely
962 * round the target page pfn down to the requested order
963 * as the mem_map is guarenteed valid out to MAX_ORDER,
964 * where that page is in a different zone we will detect
965 * it from its zone id and abort this block scan.
967 zone_id = page_zone_id(page);
968 page_pfn = page_to_pfn(page);
969 pfn = page_pfn & ~((1 << order) - 1);
970 end_pfn = pfn + (1 << order);
971 for (; pfn < end_pfn; pfn++) {
972 struct page *cursor_page;
974 /* The target page is in the block, ignore it. */
975 if (unlikely(pfn == page_pfn))
976 continue;
978 /* Avoid holes within the zone. */
979 if (unlikely(!pfn_valid_within(pfn)))
980 break;
982 cursor_page = pfn_to_page(pfn);
984 /* Check that we have not crossed a zone boundary. */
985 if (unlikely(page_zone_id(cursor_page) != zone_id))
986 continue;
989 * If we don't have enough swap space, reclaiming of
990 * anon page which don't already have a swap slot is
991 * pointless.
993 if (nr_swap_pages <= 0 && PageAnon(cursor_page) &&
994 !PageSwapCache(cursor_page))
995 continue;
997 if (__isolate_lru_page(cursor_page, mode, file) == 0) {
998 list_move(&cursor_page->lru, dst);
999 mem_cgroup_del_lru(cursor_page);
1000 nr_taken++;
1001 scan++;
1006 *scanned = scan;
1007 return nr_taken;
1010 static unsigned long isolate_pages_global(unsigned long nr,
1011 struct list_head *dst,
1012 unsigned long *scanned, int order,
1013 int mode, struct zone *z,
1014 struct mem_cgroup *mem_cont,
1015 int active, int file)
1017 int lru = LRU_BASE;
1018 if (active)
1019 lru += LRU_ACTIVE;
1020 if (file)
1021 lru += LRU_FILE;
1022 return isolate_lru_pages(nr, &z->lru[lru].list, dst, scanned, order,
1023 mode, file);
1027 * clear_active_flags() is a helper for shrink_active_list(), clearing
1028 * any active bits from the pages in the list.
1030 static unsigned long clear_active_flags(struct list_head *page_list,
1031 unsigned int *count)
1033 int nr_active = 0;
1034 int lru;
1035 struct page *page;
1037 list_for_each_entry(page, page_list, lru) {
1038 lru = page_lru_base_type(page);
1039 if (PageActive(page)) {
1040 lru += LRU_ACTIVE;
1041 ClearPageActive(page);
1042 nr_active++;
1044 count[lru]++;
1047 return nr_active;
1051 * isolate_lru_page - tries to isolate a page from its LRU list
1052 * @page: page to isolate from its LRU list
1054 * Isolates a @page from an LRU list, clears PageLRU and adjusts the
1055 * vmstat statistic corresponding to whatever LRU list the page was on.
1057 * Returns 0 if the page was removed from an LRU list.
1058 * Returns -EBUSY if the page was not on an LRU list.
1060 * The returned page will have PageLRU() cleared. If it was found on
1061 * the active list, it will have PageActive set. If it was found on
1062 * the unevictable list, it will have the PageUnevictable bit set. That flag
1063 * may need to be cleared by the caller before letting the page go.
1065 * The vmstat statistic corresponding to the list on which the page was
1066 * found will be decremented.
1068 * Restrictions:
1069 * (1) Must be called with an elevated refcount on the page. This is a
1070 * fundamentnal difference from isolate_lru_pages (which is called
1071 * without a stable reference).
1072 * (2) the lru_lock must not be held.
1073 * (3) interrupts must be enabled.
1075 int isolate_lru_page(struct page *page)
1077 int ret = -EBUSY;
1079 if (PageLRU(page)) {
1080 struct zone *zone = page_zone(page);
1082 spin_lock_irq(&zone->lru_lock);
1083 if (PageLRU(page) && get_page_unless_zero(page)) {
1084 int lru = page_lru(page);
1085 ret = 0;
1086 ClearPageLRU(page);
1088 del_page_from_lru_list(zone, page, lru);
1090 spin_unlock_irq(&zone->lru_lock);
1092 return ret;
1096 * Are there way too many processes in the direct reclaim path already?
1098 static int too_many_isolated(struct zone *zone, int file,
1099 struct scan_control *sc)
1101 unsigned long inactive, isolated;
1103 if (current_is_kswapd())
1104 return 0;
1106 if (!scanning_global_lru(sc))
1107 return 0;
1109 if (file) {
1110 inactive = zone_page_state(zone, NR_INACTIVE_FILE);
1111 isolated = zone_page_state(zone, NR_ISOLATED_FILE);
1112 } else {
1113 inactive = zone_page_state(zone, NR_INACTIVE_ANON);
1114 isolated = zone_page_state(zone, NR_ISOLATED_ANON);
1117 return isolated > inactive;
1121 * Returns true if the caller should wait to clean dirty/writeback pages.
1123 * If we are direct reclaiming for contiguous pages and we do not reclaim
1124 * everything in the list, try again and wait for writeback IO to complete.
1125 * This will stall high-order allocations noticeably. Only do that when really
1126 * need to free the pages under high memory pressure.
1128 static inline bool should_reclaim_stall(unsigned long nr_taken,
1129 unsigned long nr_freed,
1130 int priority,
1131 int lumpy_reclaim,
1132 struct scan_control *sc)
1134 int lumpy_stall_priority;
1136 /* kswapd should not stall on sync IO */
1137 if (current_is_kswapd())
1138 return false;
1140 /* Only stall on lumpy reclaim */
1141 if (!lumpy_reclaim)
1142 return false;
1144 /* If we have relaimed everything on the isolated list, no stall */
1145 if (nr_freed == nr_taken)
1146 return false;
1149 * For high-order allocations, there are two stall thresholds.
1150 * High-cost allocations stall immediately where as lower
1151 * order allocations such as stacks require the scanning
1152 * priority to be much higher before stalling.
1154 if (sc->order > PAGE_ALLOC_COSTLY_ORDER)
1155 lumpy_stall_priority = DEF_PRIORITY;
1156 else
1157 lumpy_stall_priority = DEF_PRIORITY / 3;
1159 return priority <= lumpy_stall_priority;
1163 * shrink_inactive_list() is a helper for shrink_zone(). It returns the number
1164 * of reclaimed pages
1166 static unsigned long shrink_inactive_list(unsigned long max_scan,
1167 struct zone *zone, struct scan_control *sc,
1168 int priority, int file)
1170 LIST_HEAD(page_list);
1171 struct pagevec pvec;
1172 unsigned long nr_scanned = 0;
1173 unsigned long nr_reclaimed = 0;
1174 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
1175 int lumpy_reclaim = 0;
1177 while (unlikely(too_many_isolated(zone, file, sc))) {
1178 congestion_wait(BLK_RW_ASYNC, HZ/10);
1180 /* We are about to die and free our memory. Return now. */
1181 if (fatal_signal_pending(current))
1182 return SWAP_CLUSTER_MAX;
1186 * If we need a large contiguous chunk of memory, or have
1187 * trouble getting a small set of contiguous pages, we
1188 * will reclaim both active and inactive pages.
1190 * We use the same threshold as pageout congestion_wait below.
1192 if (sc->order > PAGE_ALLOC_COSTLY_ORDER)
1193 lumpy_reclaim = 1;
1194 else if (sc->order && priority < DEF_PRIORITY - 2)
1195 lumpy_reclaim = 1;
1197 pagevec_init(&pvec, 1);
1199 lru_add_drain();
1200 spin_lock_irq(&zone->lru_lock);
1201 do {
1202 struct page *page;
1203 unsigned long nr_taken;
1204 unsigned long nr_scan;
1205 unsigned long nr_freed;
1206 unsigned long nr_active;
1207 unsigned int count[NR_LRU_LISTS] = { 0, };
1208 int mode = lumpy_reclaim ? ISOLATE_BOTH : ISOLATE_INACTIVE;
1209 unsigned long nr_anon;
1210 unsigned long nr_file;
1212 nr_taken = sc->isolate_pages(SWAP_CLUSTER_MAX,
1213 &page_list, &nr_scan, sc->order, mode,
1214 zone, sc->mem_cgroup, 0, file);
1216 if (scanning_global_lru(sc)) {
1217 zone->pages_scanned += nr_scan;
1218 if (current_is_kswapd())
1219 __count_zone_vm_events(PGSCAN_KSWAPD, zone,
1220 nr_scan);
1221 else
1222 __count_zone_vm_events(PGSCAN_DIRECT, zone,
1223 nr_scan);
1226 if (nr_taken == 0)
1227 goto done;
1229 nr_active = clear_active_flags(&page_list, count);
1230 __count_vm_events(PGDEACTIVATE, nr_active);
1232 __mod_zone_page_state(zone, NR_ACTIVE_FILE,
1233 -count[LRU_ACTIVE_FILE]);
1234 __mod_zone_page_state(zone, NR_INACTIVE_FILE,
1235 -count[LRU_INACTIVE_FILE]);
1236 __mod_zone_page_state(zone, NR_ACTIVE_ANON,
1237 -count[LRU_ACTIVE_ANON]);
1238 __mod_zone_page_state(zone, NR_INACTIVE_ANON,
1239 -count[LRU_INACTIVE_ANON]);
1241 nr_anon = count[LRU_ACTIVE_ANON] + count[LRU_INACTIVE_ANON];
1242 nr_file = count[LRU_ACTIVE_FILE] + count[LRU_INACTIVE_FILE];
1243 __mod_zone_page_state(zone, NR_ISOLATED_ANON, nr_anon);
1244 __mod_zone_page_state(zone, NR_ISOLATED_FILE, nr_file);
1246 reclaim_stat->recent_scanned[0] += nr_anon;
1247 reclaim_stat->recent_scanned[1] += nr_file;
1249 spin_unlock_irq(&zone->lru_lock);
1251 nr_scanned += nr_scan;
1252 nr_freed = shrink_page_list(&page_list, sc, PAGEOUT_IO_ASYNC);
1254 /* Check if we should syncronously wait for writeback */
1255 if (should_reclaim_stall(nr_taken, nr_freed, priority,
1256 lumpy_reclaim, sc)) {
1257 congestion_wait(BLK_RW_ASYNC, HZ/10);
1260 * The attempt at page out may have made some
1261 * of the pages active, mark them inactive again.
1263 nr_active = clear_active_flags(&page_list, count);
1264 count_vm_events(PGDEACTIVATE, nr_active);
1266 nr_freed += shrink_page_list(&page_list, sc,
1267 PAGEOUT_IO_SYNC);
1270 nr_reclaimed += nr_freed;
1272 local_irq_disable();
1273 if (current_is_kswapd())
1274 __count_vm_events(KSWAPD_STEAL, nr_freed);
1275 __count_zone_vm_events(PGSTEAL, zone, nr_freed);
1277 spin_lock(&zone->lru_lock);
1279 * Put back any unfreeable pages.
1281 while (!list_empty(&page_list)) {
1282 int lru;
1283 page = lru_to_page(&page_list);
1284 VM_BUG_ON(PageLRU(page));
1285 list_del(&page->lru);
1286 if (unlikely(!page_evictable(page, NULL))) {
1287 spin_unlock_irq(&zone->lru_lock);
1288 putback_lru_page(page);
1289 spin_lock_irq(&zone->lru_lock);
1290 continue;
1292 SetPageLRU(page);
1293 lru = page_lru(page);
1294 add_page_to_lru_list(zone, page, lru);
1295 if (is_active_lru(lru)) {
1296 int file = is_file_lru(lru);
1297 reclaim_stat->recent_rotated[file]++;
1299 if (!pagevec_add(&pvec, page)) {
1300 spin_unlock_irq(&zone->lru_lock);
1301 __pagevec_release(&pvec);
1302 spin_lock_irq(&zone->lru_lock);
1305 __mod_zone_page_state(zone, NR_ISOLATED_ANON, -nr_anon);
1306 __mod_zone_page_state(zone, NR_ISOLATED_FILE, -nr_file);
1308 } while (nr_scanned < max_scan);
1310 done:
1311 spin_unlock_irq(&zone->lru_lock);
1312 pagevec_release(&pvec);
1313 return nr_reclaimed;
1317 * We are about to scan this zone at a certain priority level. If that priority
1318 * level is smaller (ie: more urgent) than the previous priority, then note
1319 * that priority level within the zone. This is done so that when the next
1320 * process comes in to scan this zone, it will immediately start out at this
1321 * priority level rather than having to build up its own scanning priority.
1322 * Here, this priority affects only the reclaim-mapped threshold.
1324 static inline void note_zone_scanning_priority(struct zone *zone, int priority)
1326 if (priority < zone->prev_priority)
1327 zone->prev_priority = priority;
1331 * This moves pages from the active list to the inactive list.
1333 * We move them the other way if the page is referenced by one or more
1334 * processes, from rmap.
1336 * If the pages are mostly unmapped, the processing is fast and it is
1337 * appropriate to hold zone->lru_lock across the whole operation. But if
1338 * the pages are mapped, the processing is slow (page_referenced()) so we
1339 * should drop zone->lru_lock around each page. It's impossible to balance
1340 * this, so instead we remove the pages from the LRU while processing them.
1341 * It is safe to rely on PG_active against the non-LRU pages in here because
1342 * nobody will play with that bit on a non-LRU page.
1344 * The downside is that we have to touch page->_count against each page.
1345 * But we had to alter page->flags anyway.
1348 static void move_active_pages_to_lru(struct zone *zone,
1349 struct list_head *list,
1350 enum lru_list lru)
1352 unsigned long pgmoved = 0;
1353 struct pagevec pvec;
1354 struct page *page;
1356 pagevec_init(&pvec, 1);
1358 while (!list_empty(list)) {
1359 page = lru_to_page(list);
1361 VM_BUG_ON(PageLRU(page));
1362 SetPageLRU(page);
1364 list_move(&page->lru, &zone->lru[lru].list);
1365 mem_cgroup_add_lru_list(page, lru);
1366 pgmoved++;
1368 if (!pagevec_add(&pvec, page) || list_empty(list)) {
1369 spin_unlock_irq(&zone->lru_lock);
1370 if (buffer_heads_over_limit)
1371 pagevec_strip(&pvec);
1372 __pagevec_release(&pvec);
1373 spin_lock_irq(&zone->lru_lock);
1376 __mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
1377 if (!is_active_lru(lru))
1378 __count_vm_events(PGDEACTIVATE, pgmoved);
1381 static void shrink_active_list(unsigned long nr_pages, struct zone *zone,
1382 struct scan_control *sc, int priority, int file)
1384 unsigned long nr_taken;
1385 unsigned long pgscanned;
1386 unsigned long vm_flags;
1387 LIST_HEAD(l_hold); /* The pages which were snipped off */
1388 LIST_HEAD(l_active);
1389 LIST_HEAD(l_inactive);
1390 struct page *page;
1391 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
1392 unsigned long nr_rotated = 0;
1394 lru_add_drain();
1395 spin_lock_irq(&zone->lru_lock);
1396 nr_taken = sc->isolate_pages(nr_pages, &l_hold, &pgscanned, sc->order,
1397 ISOLATE_ACTIVE, zone,
1398 sc->mem_cgroup, 1, file);
1400 * zone->pages_scanned is used for detect zone's oom
1401 * mem_cgroup remembers nr_scan by itself.
1403 if (scanning_global_lru(sc)) {
1404 zone->pages_scanned += pgscanned;
1406 reclaim_stat->recent_scanned[file] += nr_taken;
1408 __count_zone_vm_events(PGREFILL, zone, pgscanned);
1409 if (file)
1410 __mod_zone_page_state(zone, NR_ACTIVE_FILE, -nr_taken);
1411 else
1412 __mod_zone_page_state(zone, NR_ACTIVE_ANON, -nr_taken);
1413 __mod_zone_page_state(zone, NR_ISOLATED_ANON + file, nr_taken);
1414 spin_unlock_irq(&zone->lru_lock);
1416 while (!list_empty(&l_hold)) {
1417 cond_resched();
1418 page = lru_to_page(&l_hold);
1419 list_del(&page->lru);
1421 if (unlikely(!page_evictable(page, NULL))) {
1422 putback_lru_page(page);
1423 continue;
1426 if (page_referenced(page, 0, sc->mem_cgroup, &vm_flags)) {
1427 nr_rotated++;
1429 * Identify referenced, file-backed active pages and
1430 * give them one more trip around the active list. So
1431 * that executable code get better chances to stay in
1432 * memory under moderate memory pressure. Anon pages
1433 * are not likely to be evicted by use-once streaming
1434 * IO, plus JVM can create lots of anon VM_EXEC pages,
1435 * so we ignore them here.
1437 if ((vm_flags & VM_EXEC) && page_is_file_cache(page)) {
1438 list_add(&page->lru, &l_active);
1439 continue;
1443 ClearPageActive(page); /* we are de-activating */
1444 list_add(&page->lru, &l_inactive);
1448 * Move pages back to the lru list.
1450 spin_lock_irq(&zone->lru_lock);
1452 * Count referenced pages from currently used mappings as rotated,
1453 * even though only some of them are actually re-activated. This
1454 * helps balance scan pressure between file and anonymous pages in
1455 * get_scan_ratio.
1457 reclaim_stat->recent_rotated[file] += nr_rotated;
1459 move_active_pages_to_lru(zone, &l_active,
1460 LRU_ACTIVE + file * LRU_FILE);
1461 move_active_pages_to_lru(zone, &l_inactive,
1462 LRU_BASE + file * LRU_FILE);
1463 __mod_zone_page_state(zone, NR_ISOLATED_ANON + file, -nr_taken);
1464 spin_unlock_irq(&zone->lru_lock);
1467 static int inactive_anon_is_low_global(struct zone *zone)
1469 unsigned long active, inactive;
1471 active = zone_page_state(zone, NR_ACTIVE_ANON);
1472 inactive = zone_page_state(zone, NR_INACTIVE_ANON);
1474 if (inactive * zone->inactive_ratio < active)
1475 return 1;
1477 return 0;
1481 * inactive_anon_is_low - check if anonymous pages need to be deactivated
1482 * @zone: zone to check
1483 * @sc: scan control of this context
1485 * Returns true if the zone does not have enough inactive anon pages,
1486 * meaning some active anon pages need to be deactivated.
1488 static int inactive_anon_is_low(struct zone *zone, struct scan_control *sc)
1490 int low;
1492 if (scanning_global_lru(sc))
1493 low = inactive_anon_is_low_global(zone);
1494 else
1495 low = mem_cgroup_inactive_anon_is_low(sc->mem_cgroup);
1496 return low;
1499 static int inactive_file_is_low_global(struct zone *zone)
1501 unsigned long active, inactive;
1503 active = zone_page_state(zone, NR_ACTIVE_FILE);
1504 inactive = zone_page_state(zone, NR_INACTIVE_FILE);
1506 return (active > inactive);
1510 * inactive_file_is_low - check if file pages need to be deactivated
1511 * @zone: zone to check
1512 * @sc: scan control of this context
1514 * When the system is doing streaming IO, memory pressure here
1515 * ensures that active file pages get deactivated, until more
1516 * than half of the file pages are on the inactive list.
1518 * Once we get to that situation, protect the system's working
1519 * set from being evicted by disabling active file page aging.
1521 * This uses a different ratio than the anonymous pages, because
1522 * the page cache uses a use-once replacement algorithm.
1524 static int inactive_file_is_low(struct zone *zone, struct scan_control *sc)
1526 int low;
1528 if (scanning_global_lru(sc))
1529 low = inactive_file_is_low_global(zone);
1530 else
1531 low = mem_cgroup_inactive_file_is_low(sc->mem_cgroup);
1532 return low;
1535 static int inactive_list_is_low(struct zone *zone, struct scan_control *sc,
1536 int file)
1538 if (file)
1539 return inactive_file_is_low(zone, sc);
1540 else
1541 return inactive_anon_is_low(zone, sc);
1544 static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
1545 struct zone *zone, struct scan_control *sc, int priority)
1547 int file = is_file_lru(lru);
1549 if (is_active_lru(lru)) {
1550 if (inactive_list_is_low(zone, sc, file))
1551 shrink_active_list(nr_to_scan, zone, sc, priority, file);
1552 return 0;
1555 return shrink_inactive_list(nr_to_scan, zone, sc, priority, file);
1559 * Determine how aggressively the anon and file LRU lists should be
1560 * scanned. The relative value of each set of LRU lists is determined
1561 * by looking at the fraction of the pages scanned we did rotate back
1562 * onto the active list instead of evict.
1564 * percent[0] specifies how much pressure to put on ram/swap backed
1565 * memory, while percent[1] determines pressure on the file LRUs.
1567 static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
1568 unsigned long *percent)
1570 unsigned long anon, file, free;
1571 unsigned long anon_prio, file_prio;
1572 unsigned long ap, fp;
1573 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
1575 anon = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
1576 zone_nr_lru_pages(zone, sc, LRU_INACTIVE_ANON);
1577 file = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_FILE) +
1578 zone_nr_lru_pages(zone, sc, LRU_INACTIVE_FILE);
1580 if (scanning_global_lru(sc)) {
1581 free = zone_page_state(zone, NR_FREE_PAGES);
1582 /* If we have very few page cache pages,
1583 force-scan anon pages. */
1584 if (unlikely(file + free <= high_wmark_pages(zone))) {
1585 percent[0] = 100;
1586 percent[1] = 0;
1587 return;
1592 * OK, so we have swap space and a fair amount of page cache
1593 * pages. We use the recently rotated / recently scanned
1594 * ratios to determine how valuable each cache is.
1596 * Because workloads change over time (and to avoid overflow)
1597 * we keep these statistics as a floating average, which ends
1598 * up weighing recent references more than old ones.
1600 * anon in [0], file in [1]
1602 if (unlikely(reclaim_stat->recent_scanned[0] > anon / 4)) {
1603 spin_lock_irq(&zone->lru_lock);
1604 reclaim_stat->recent_scanned[0] /= 2;
1605 reclaim_stat->recent_rotated[0] /= 2;
1606 spin_unlock_irq(&zone->lru_lock);
1609 if (unlikely(reclaim_stat->recent_scanned[1] > file / 4)) {
1610 spin_lock_irq(&zone->lru_lock);
1611 reclaim_stat->recent_scanned[1] /= 2;
1612 reclaim_stat->recent_rotated[1] /= 2;
1613 spin_unlock_irq(&zone->lru_lock);
1617 * With swappiness at 100, anonymous and file have the same priority.
1618 * This scanning priority is essentially the inverse of IO cost.
1620 anon_prio = sc->swappiness;
1621 file_prio = 200 - sc->swappiness;
1624 * The amount of pressure on anon vs file pages is inversely
1625 * proportional to the fraction of recently scanned pages on
1626 * each list that were recently referenced and in active use.
1628 ap = (anon_prio + 1) * (reclaim_stat->recent_scanned[0] + 1);
1629 ap /= reclaim_stat->recent_rotated[0] + 1;
1631 fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
1632 fp /= reclaim_stat->recent_rotated[1] + 1;
1634 /* Normalize to percentages */
1635 percent[0] = 100 * ap / (ap + fp + 1);
1636 percent[1] = 100 - percent[0];
1640 * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
1641 * until we collected @swap_cluster_max pages to scan.
1643 static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
1644 unsigned long *nr_saved_scan)
1646 unsigned long nr;
1648 *nr_saved_scan += nr_to_scan;
1649 nr = *nr_saved_scan;
1651 if (nr >= SWAP_CLUSTER_MAX)
1652 *nr_saved_scan = 0;
1653 else
1654 nr = 0;
1656 return nr;
1660 * This is a basic per-zone page freer. Used by both kswapd and direct reclaim.
1662 static void shrink_zone(int priority, struct zone *zone,
1663 struct scan_control *sc)
1665 unsigned long nr[NR_LRU_LISTS];
1666 unsigned long nr_to_scan;
1667 unsigned long percent[2]; /* anon @ 0; file @ 1 */
1668 enum lru_list l;
1669 unsigned long nr_reclaimed = sc->nr_reclaimed;
1670 unsigned long nr_to_reclaim = sc->nr_to_reclaim;
1671 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
1672 int noswap = 0;
1674 /* If we have no swap space, do not bother scanning anon pages. */
1675 if (!sc->may_swap || (nr_swap_pages <= 0)) {
1676 noswap = 1;
1677 percent[0] = 0;
1678 percent[1] = 100;
1679 } else
1680 get_scan_ratio(zone, sc, percent);
1682 for_each_evictable_lru(l) {
1683 int file = is_file_lru(l);
1684 unsigned long scan;
1686 scan = zone_nr_lru_pages(zone, sc, l);
1687 if (priority || noswap) {
1688 scan >>= priority;
1689 scan = (scan * percent[file]) / 100;
1691 nr[l] = nr_scan_try_batch(scan,
1692 &reclaim_stat->nr_saved_scan[l]);
1695 while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
1696 nr[LRU_INACTIVE_FILE]) {
1697 for_each_evictable_lru(l) {
1698 if (nr[l]) {
1699 nr_to_scan = min_t(unsigned long,
1700 nr[l], SWAP_CLUSTER_MAX);
1701 nr[l] -= nr_to_scan;
1703 nr_reclaimed += shrink_list(l, nr_to_scan,
1704 zone, sc, priority);
1708 * On large memory systems, scan >> priority can become
1709 * really large. This is fine for the starting priority;
1710 * we want to put equal scanning pressure on each zone.
1711 * However, if the VM has a harder time of freeing pages,
1712 * with multiple processes reclaiming pages, the total
1713 * freeing target can get unreasonably large.
1715 if (nr_reclaimed >= nr_to_reclaim && priority < DEF_PRIORITY)
1716 break;
1719 sc->nr_reclaimed = nr_reclaimed;
1722 * Even if we did not try to evict anon pages at all, we want to
1723 * rebalance the anon lru active/inactive ratio.
1725 if (inactive_anon_is_low(zone, sc) && nr_swap_pages > 0)
1726 shrink_active_list(SWAP_CLUSTER_MAX, zone, sc, priority, 0);
1728 throttle_vm_writeout(sc->gfp_mask);
1732 * This is the direct reclaim path, for page-allocating processes. We only
1733 * try to reclaim pages from zones which will satisfy the caller's allocation
1734 * request.
1736 * We reclaim from a zone even if that zone is over high_wmark_pages(zone).
1737 * Because:
1738 * a) The caller may be trying to free *extra* pages to satisfy a higher-order
1739 * allocation or
1740 * b) The target zone may be at high_wmark_pages(zone) but the lower zones
1741 * must go *over* high_wmark_pages(zone) to satisfy the `incremental min'
1742 * zone defense algorithm.
1744 * If a zone is deemed to be full of pinned pages then just give it a light
1745 * scan then give up on it.
1747 static void shrink_zones(int priority, struct zonelist *zonelist,
1748 struct scan_control *sc)
1750 enum zone_type high_zoneidx = gfp_zone(sc->gfp_mask);
1751 struct zoneref *z;
1752 struct zone *zone;
1754 sc->all_unreclaimable = 1;
1755 for_each_zone_zonelist_nodemask(zone, z, zonelist, high_zoneidx,
1756 sc->nodemask) {
1757 if (!populated_zone(zone))
1758 continue;
1760 * Take care memory controller reclaiming has small influence
1761 * to global LRU.
1763 if (scanning_global_lru(sc)) {
1764 if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL))
1765 continue;
1766 note_zone_scanning_priority(zone, priority);
1768 if (zone->all_unreclaimable && priority != DEF_PRIORITY)
1769 continue; /* Let kswapd poll it */
1770 sc->all_unreclaimable = 0;
1771 } else {
1773 * Ignore cpuset limitation here. We just want to reduce
1774 * # of used pages by us regardless of memory shortage.
1776 sc->all_unreclaimable = 0;
1777 mem_cgroup_note_reclaim_priority(sc->mem_cgroup,
1778 priority);
1781 shrink_zone(priority, zone, sc);
1786 * This is the main entry point to direct page reclaim.
1788 * If a full scan of the inactive list fails to free enough memory then we
1789 * are "out of memory" and something needs to be killed.
1791 * If the caller is !__GFP_FS then the probability of a failure is reasonably
1792 * high - the zone may be full of dirty or under-writeback pages, which this
1793 * caller can't do much about. We kick the writeback threads and take explicit
1794 * naps in the hope that some of these pages can be written. But if the
1795 * allocating task holds filesystem locks which prevent writeout this might not
1796 * work, and the allocation attempt will fail.
1798 * returns: 0, if no pages reclaimed
1799 * else, the number of pages reclaimed
1801 static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
1802 struct scan_control *sc)
1804 int priority;
1805 unsigned long ret = 0;
1806 unsigned long total_scanned = 0;
1807 struct reclaim_state *reclaim_state = current->reclaim_state;
1808 unsigned long lru_pages = 0;
1809 struct zoneref *z;
1810 struct zone *zone;
1811 enum zone_type high_zoneidx = gfp_zone(sc->gfp_mask);
1812 unsigned long writeback_threshold;
1814 delayacct_freepages_start();
1816 if (scanning_global_lru(sc))
1817 count_vm_event(ALLOCSTALL);
1819 * mem_cgroup will not do shrink_slab.
1821 if (scanning_global_lru(sc)) {
1822 for_each_zone_zonelist(zone, z, zonelist, high_zoneidx) {
1824 if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL))
1825 continue;
1827 lru_pages += zone_reclaimable_pages(zone);
1831 for (priority = DEF_PRIORITY; priority >= 0; priority--) {
1832 sc->nr_scanned = 0;
1833 if (!priority)
1834 disable_swap_token();
1835 shrink_zones(priority, zonelist, sc);
1837 * Don't shrink slabs when reclaiming memory from
1838 * over limit cgroups
1840 if (scanning_global_lru(sc)) {
1841 shrink_slab(sc->nr_scanned, sc->gfp_mask, lru_pages);
1842 if (reclaim_state) {
1843 sc->nr_reclaimed += reclaim_state->reclaimed_slab;
1844 reclaim_state->reclaimed_slab = 0;
1847 total_scanned += sc->nr_scanned;
1848 if (sc->nr_reclaimed >= sc->nr_to_reclaim) {
1849 ret = sc->nr_reclaimed;
1850 goto out;
1854 * Try to write back as many pages as we just scanned. This
1855 * tends to cause slow streaming writers to write data to the
1856 * disk smoothly, at the dirtying rate, which is nice. But
1857 * that's undesirable in laptop mode, where we *want* lumpy
1858 * writeout. So in laptop mode, write out the whole world.
1860 writeback_threshold = sc->nr_to_reclaim + sc->nr_to_reclaim / 2;
1861 if (total_scanned > writeback_threshold) {
1862 wakeup_flusher_threads(laptop_mode ? 0 : total_scanned);
1863 sc->may_writepage = 1;
1866 /* Take a nap, wait for some writeback to complete */
1867 if (!sc->hibernation_mode && sc->nr_scanned &&
1868 priority < DEF_PRIORITY - 2)
1869 congestion_wait(BLK_RW_ASYNC, HZ/10);
1871 /* top priority shrink_zones still had more to do? don't OOM, then */
1872 if (!sc->all_unreclaimable && scanning_global_lru(sc))
1873 ret = sc->nr_reclaimed;
1874 out:
1876 * Now that we've scanned all the zones at this priority level, note
1877 * that level within the zone so that the next thread which performs
1878 * scanning of this zone will immediately start out at this priority
1879 * level. This affects only the decision whether or not to bring
1880 * mapped pages onto the inactive list.
1882 if (priority < 0)
1883 priority = 0;
1885 if (scanning_global_lru(sc)) {
1886 for_each_zone_zonelist(zone, z, zonelist, high_zoneidx) {
1888 if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL))
1889 continue;
1891 zone->prev_priority = priority;
1893 } else
1894 mem_cgroup_record_reclaim_priority(sc->mem_cgroup, priority);
1896 delayacct_freepages_end();
1898 return ret;
1901 unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
1902 gfp_t gfp_mask, nodemask_t *nodemask)
1904 struct scan_control sc = {
1905 .gfp_mask = gfp_mask,
1906 .may_writepage = !laptop_mode,
1907 .nr_to_reclaim = SWAP_CLUSTER_MAX,
1908 .may_unmap = 1,
1909 .may_swap = 1,
1910 .swappiness = vm_swappiness,
1911 .order = order,
1912 .mem_cgroup = NULL,
1913 .isolate_pages = isolate_pages_global,
1914 .nodemask = nodemask,
1917 return do_try_to_free_pages(zonelist, &sc);
1920 #ifdef CONFIG_CGROUP_MEM_RES_CTLR
1922 unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
1923 gfp_t gfp_mask, bool noswap,
1924 unsigned int swappiness,
1925 struct zone *zone, int nid)
1927 struct scan_control sc = {
1928 .may_writepage = !laptop_mode,
1929 .may_unmap = 1,
1930 .may_swap = !noswap,
1931 .swappiness = swappiness,
1932 .order = 0,
1933 .mem_cgroup = mem,
1934 .isolate_pages = mem_cgroup_isolate_pages,
1936 nodemask_t nm = nodemask_of_node(nid);
1938 sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) |
1939 (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK);
1940 sc.nodemask = &nm;
1941 sc.nr_reclaimed = 0;
1942 sc.nr_scanned = 0;
1944 * NOTE: Although we can get the priority field, using it
1945 * here is not a good idea, since it limits the pages we can scan.
1946 * if we don't reclaim here, the shrink_zone from balance_pgdat
1947 * will pick up pages from other mem cgroup's as well. We hack
1948 * the priority and make it zero.
1950 shrink_zone(0, zone, &sc);
1951 return sc.nr_reclaimed;
1954 unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
1955 gfp_t gfp_mask,
1956 bool noswap,
1957 unsigned int swappiness)
1959 struct zonelist *zonelist;
1960 struct scan_control sc = {
1961 .may_writepage = !laptop_mode,
1962 .may_unmap = 1,
1963 .may_swap = !noswap,
1964 .nr_to_reclaim = SWAP_CLUSTER_MAX,
1965 .swappiness = swappiness,
1966 .order = 0,
1967 .mem_cgroup = mem_cont,
1968 .isolate_pages = mem_cgroup_isolate_pages,
1969 .nodemask = NULL, /* we don't care the placement */
1972 sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) |
1973 (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK);
1974 zonelist = NODE_DATA(numa_node_id())->node_zonelists;
1975 return do_try_to_free_pages(zonelist, &sc);
1977 #endif
1979 /* is kswapd sleeping prematurely? */
1980 static int sleeping_prematurely(pg_data_t *pgdat, int order, long remaining)
1982 int i;
1984 /* If a direct reclaimer woke kswapd within HZ/10, it's premature */
1985 if (remaining)
1986 return 1;
1988 /* If after HZ/10, a zone is below the high mark, it's premature */
1989 for (i = 0; i < pgdat->nr_zones; i++) {
1990 struct zone *zone = pgdat->node_zones + i;
1992 if (!populated_zone(zone))
1993 continue;
1995 if (zone->all_unreclaimable)
1996 continue;
1998 if (!zone_watermark_ok(zone, order, high_wmark_pages(zone),
1999 0, 0))
2000 return 1;
2003 return 0;
2007 * For kswapd, balance_pgdat() will work across all this node's zones until
2008 * they are all at high_wmark_pages(zone).
2010 * Returns the number of pages which were actually freed.
2012 * There is special handling here for zones which are full of pinned pages.
2013 * This can happen if the pages are all mlocked, or if they are all used by
2014 * device drivers (say, ZONE_DMA). Or if they are all in use by hugetlb.
2015 * What we do is to detect the case where all pages in the zone have been
2016 * scanned twice and there has been zero successful reclaim. Mark the zone as
2017 * dead and from now on, only perform a short scan. Basically we're polling
2018 * the zone for when the problem goes away.
2020 * kswapd scans the zones in the highmem->normal->dma direction. It skips
2021 * zones which have free_pages > high_wmark_pages(zone), but once a zone is
2022 * found to have free_pages <= high_wmark_pages(zone), we scan that zone and the
2023 * lower zones regardless of the number of free pages in the lower zones. This
2024 * interoperates with the page allocator fallback scheme to ensure that aging
2025 * of pages is balanced across the zones.
2027 static unsigned long balance_pgdat(pg_data_t *pgdat, int order)
2029 int all_zones_ok;
2030 int priority;
2031 int i;
2032 unsigned long total_scanned;
2033 struct reclaim_state *reclaim_state = current->reclaim_state;
2034 struct scan_control sc = {
2035 .gfp_mask = GFP_KERNEL,
2036 .may_unmap = 1,
2037 .may_swap = 1,
2039 * kswapd doesn't want to be bailed out while reclaim. because
2040 * we want to put equal scanning pressure on each zone.
2042 .nr_to_reclaim = ULONG_MAX,
2043 .swappiness = vm_swappiness,
2044 .order = order,
2045 .mem_cgroup = NULL,
2046 .isolate_pages = isolate_pages_global,
2049 * temp_priority is used to remember the scanning priority at which
2050 * this zone was successfully refilled to
2051 * free_pages == high_wmark_pages(zone).
2053 int temp_priority[MAX_NR_ZONES];
2055 loop_again:
2056 total_scanned = 0;
2057 sc.nr_reclaimed = 0;
2058 sc.may_writepage = !laptop_mode;
2059 count_vm_event(PAGEOUTRUN);
2061 for (i = 0; i < pgdat->nr_zones; i++)
2062 temp_priority[i] = DEF_PRIORITY;
2064 for (priority = DEF_PRIORITY; priority >= 0; priority--) {
2065 int end_zone = 0; /* Inclusive. 0 = ZONE_DMA */
2066 unsigned long lru_pages = 0;
2067 int has_under_min_watermark_zone = 0;
2069 /* The swap token gets in the way of swapout... */
2070 if (!priority)
2071 disable_swap_token();
2073 all_zones_ok = 1;
2076 * Scan in the highmem->dma direction for the highest
2077 * zone which needs scanning
2079 for (i = pgdat->nr_zones - 1; i >= 0; i--) {
2080 struct zone *zone = pgdat->node_zones + i;
2082 if (!populated_zone(zone))
2083 continue;
2085 if (zone->all_unreclaimable && priority != DEF_PRIORITY)
2086 continue;
2089 * Do some background aging of the anon list, to give
2090 * pages a chance to be referenced before reclaiming.
2092 if (inactive_anon_is_low(zone, &sc))
2093 shrink_active_list(SWAP_CLUSTER_MAX, zone,
2094 &sc, priority, 0);
2096 if (!zone_watermark_ok(zone, order,
2097 high_wmark_pages(zone), 0, 0)) {
2098 end_zone = i;
2099 break;
2102 if (i < 0)
2103 goto out;
2105 for (i = 0; i <= end_zone; i++) {
2106 struct zone *zone = pgdat->node_zones + i;
2108 lru_pages += zone_reclaimable_pages(zone);
2112 * Now scan the zone in the dma->highmem direction, stopping
2113 * at the last zone which needs scanning.
2115 * We do this because the page allocator works in the opposite
2116 * direction. This prevents the page allocator from allocating
2117 * pages behind kswapd's direction of progress, which would
2118 * cause too much scanning of the lower zones.
2120 for (i = 0; i <= end_zone; i++) {
2121 struct zone *zone = pgdat->node_zones + i;
2122 int nr_slab;
2123 int nid, zid;
2125 if (!populated_zone(zone))
2126 continue;
2128 if (zone->all_unreclaimable && priority != DEF_PRIORITY)
2129 continue;
2131 temp_priority[i] = priority;
2132 sc.nr_scanned = 0;
2133 note_zone_scanning_priority(zone, priority);
2135 nid = pgdat->node_id;
2136 zid = zone_idx(zone);
2138 * Call soft limit reclaim before calling shrink_zone.
2139 * For now we ignore the return value
2141 mem_cgroup_soft_limit_reclaim(zone, order, sc.gfp_mask,
2142 nid, zid);
2144 * We put equal pressure on every zone, unless one
2145 * zone has way too many pages free already.
2147 if (!zone_watermark_ok(zone, order,
2148 8*high_wmark_pages(zone), end_zone, 0))
2149 shrink_zone(priority, zone, &sc);
2150 reclaim_state->reclaimed_slab = 0;
2151 nr_slab = shrink_slab(sc.nr_scanned, GFP_KERNEL,
2152 lru_pages);
2153 sc.nr_reclaimed += reclaim_state->reclaimed_slab;
2154 total_scanned += sc.nr_scanned;
2155 if (zone->all_unreclaimable)
2156 continue;
2157 if (nr_slab == 0 &&
2158 zone->pages_scanned >= (zone_reclaimable_pages(zone) * 6))
2159 zone->all_unreclaimable = 1;
2161 * If we've done a decent amount of scanning and
2162 * the reclaim ratio is low, start doing writepage
2163 * even in laptop mode
2165 if (total_scanned > SWAP_CLUSTER_MAX * 2 &&
2166 total_scanned > sc.nr_reclaimed + sc.nr_reclaimed / 2)
2167 sc.may_writepage = 1;
2169 if (!zone_watermark_ok(zone, order,
2170 high_wmark_pages(zone), end_zone, 0)) {
2171 all_zones_ok = 0;
2173 * We are still under min water mark. This
2174 * means that we have a GFP_ATOMIC allocation
2175 * failure risk. Hurry up!
2177 if (!zone_watermark_ok(zone, order,
2178 min_wmark_pages(zone), end_zone, 0))
2179 has_under_min_watermark_zone = 1;
2183 if (all_zones_ok)
2184 break; /* kswapd: all done */
2186 * OK, kswapd is getting into trouble. Take a nap, then take
2187 * another pass across the zones.
2189 if (total_scanned && (priority < DEF_PRIORITY - 2)) {
2190 if (has_under_min_watermark_zone)
2191 count_vm_event(KSWAPD_SKIP_CONGESTION_WAIT);
2192 else
2193 congestion_wait(BLK_RW_ASYNC, HZ/10);
2197 * We do this so kswapd doesn't build up large priorities for
2198 * example when it is freeing in parallel with allocators. It
2199 * matches the direct reclaim path behaviour in terms of impact
2200 * on zone->*_priority.
2202 if (sc.nr_reclaimed >= SWAP_CLUSTER_MAX)
2203 break;
2205 out:
2207 * Note within each zone the priority level at which this zone was
2208 * brought into a happy state. So that the next thread which scans this
2209 * zone will start out at that priority level.
2211 for (i = 0; i < pgdat->nr_zones; i++) {
2212 struct zone *zone = pgdat->node_zones + i;
2214 zone->prev_priority = temp_priority[i];
2216 if (!all_zones_ok) {
2217 cond_resched();
2219 try_to_freeze();
2222 * Fragmentation may mean that the system cannot be
2223 * rebalanced for high-order allocations in all zones.
2224 * At this point, if nr_reclaimed < SWAP_CLUSTER_MAX,
2225 * it means the zones have been fully scanned and are still
2226 * not balanced. For high-order allocations, there is
2227 * little point trying all over again as kswapd may
2228 * infinite loop.
2230 * Instead, recheck all watermarks at order-0 as they
2231 * are the most important. If watermarks are ok, kswapd will go
2232 * back to sleep. High-order users can still perform direct
2233 * reclaim if they wish.
2235 if (sc.nr_reclaimed < SWAP_CLUSTER_MAX)
2236 order = sc.order = 0;
2238 goto loop_again;
2241 return sc.nr_reclaimed;
2245 * The background pageout daemon, started as a kernel thread
2246 * from the init process.
2248 * This basically trickles out pages so that we have _some_
2249 * free memory available even if there is no other activity
2250 * that frees anything up. This is needed for things like routing
2251 * etc, where we otherwise might have all activity going on in
2252 * asynchronous contexts that cannot page things out.
2254 * If there are applications that are active memory-allocators
2255 * (most normal use), this basically shouldn't matter.
2257 static int kswapd(void *p)
2259 unsigned long order;
2260 pg_data_t *pgdat = (pg_data_t*)p;
2261 struct task_struct *tsk = current;
2262 DEFINE_WAIT(wait);
2263 struct reclaim_state reclaim_state = {
2264 .reclaimed_slab = 0,
2266 const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id);
2268 lockdep_set_current_reclaim_state(GFP_KERNEL);
2270 if (!cpumask_empty(cpumask))
2271 set_cpus_allowed_ptr(tsk, cpumask);
2272 current->reclaim_state = &reclaim_state;
2275 * Tell the memory management that we're a "memory allocator",
2276 * and that if we need more memory we should get access to it
2277 * regardless (see "__alloc_pages()"). "kswapd" should
2278 * never get caught in the normal page freeing logic.
2280 * (Kswapd normally doesn't need memory anyway, but sometimes
2281 * you need a small amount of memory in order to be able to
2282 * page out something else, and this flag essentially protects
2283 * us from recursively trying to free more memory as we're
2284 * trying to free the first piece of memory in the first place).
2286 tsk->flags |= PF_MEMALLOC | PF_SWAPWRITE | PF_KSWAPD;
2287 set_freezable();
2289 order = 0;
2290 for ( ; ; ) {
2291 unsigned long new_order;
2292 int ret;
2294 prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
2295 new_order = pgdat->kswapd_max_order;
2296 pgdat->kswapd_max_order = 0;
2297 if (order < new_order) {
2299 * Don't sleep if someone wants a larger 'order'
2300 * allocation
2302 order = new_order;
2303 } else {
2304 if (!freezing(current) && !kthread_should_stop()) {
2305 long remaining = 0;
2307 /* Try to sleep for a short interval */
2308 if (!sleeping_prematurely(pgdat, order, remaining)) {
2309 remaining = schedule_timeout(HZ/10);
2310 finish_wait(&pgdat->kswapd_wait, &wait);
2311 prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
2315 * After a short sleep, check if it was a
2316 * premature sleep. If not, then go fully
2317 * to sleep until explicitly woken up
2319 if (!sleeping_prematurely(pgdat, order, remaining))
2320 schedule();
2321 else {
2322 if (remaining)
2323 count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
2324 else
2325 count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
2329 order = pgdat->kswapd_max_order;
2331 finish_wait(&pgdat->kswapd_wait, &wait);
2333 ret = try_to_freeze();
2334 if (kthread_should_stop())
2335 break;
2338 * We can speed up thawing tasks if we don't call balance_pgdat
2339 * after returning from the refrigerator
2341 if (!ret)
2342 balance_pgdat(pgdat, order);
2344 return 0;
2348 * A zone is low on free memory, so wake its kswapd task to service it.
2350 void wakeup_kswapd(struct zone *zone, int order)
2352 pg_data_t *pgdat;
2354 if (!populated_zone(zone))
2355 return;
2357 pgdat = zone->zone_pgdat;
2358 if (zone_watermark_ok(zone, order, low_wmark_pages(zone), 0, 0))
2359 return;
2360 if (pgdat->kswapd_max_order < order)
2361 pgdat->kswapd_max_order = order;
2362 if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL))
2363 return;
2364 if (!waitqueue_active(&pgdat->kswapd_wait))
2365 return;
2366 wake_up_interruptible(&pgdat->kswapd_wait);
2370 * The reclaimable count would be mostly accurate.
2371 * The less reclaimable pages may be
2372 * - mlocked pages, which will be moved to unevictable list when encountered
2373 * - mapped pages, which may require several travels to be reclaimed
2374 * - dirty pages, which is not "instantly" reclaimable
2376 unsigned long global_reclaimable_pages(void)
2378 int nr;
2380 nr = global_page_state(NR_ACTIVE_FILE) +
2381 global_page_state(NR_INACTIVE_FILE);
2383 if (nr_swap_pages > 0)
2384 nr += global_page_state(NR_ACTIVE_ANON) +
2385 global_page_state(NR_INACTIVE_ANON);
2387 return nr;
2390 unsigned long zone_reclaimable_pages(struct zone *zone)
2392 int nr;
2394 nr = zone_page_state(zone, NR_ACTIVE_FILE) +
2395 zone_page_state(zone, NR_INACTIVE_FILE);
2397 if (nr_swap_pages > 0)
2398 nr += zone_page_state(zone, NR_ACTIVE_ANON) +
2399 zone_page_state(zone, NR_INACTIVE_ANON);
2401 return nr;
2404 #ifdef CONFIG_HIBERNATION
2406 * Try to free `nr_to_reclaim' of memory, system-wide, and return the number of
2407 * freed pages.
2409 * Rather than trying to age LRUs the aim is to preserve the overall
2410 * LRU order by reclaiming preferentially
2411 * inactive > active > active referenced > active mapped
2413 unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
2415 struct reclaim_state reclaim_state;
2416 struct scan_control sc = {
2417 .gfp_mask = GFP_HIGHUSER_MOVABLE,
2418 .may_swap = 1,
2419 .may_unmap = 1,
2420 .may_writepage = 1,
2421 .nr_to_reclaim = nr_to_reclaim,
2422 .hibernation_mode = 1,
2423 .swappiness = vm_swappiness,
2424 .order = 0,
2425 .isolate_pages = isolate_pages_global,
2427 struct zonelist * zonelist = node_zonelist(numa_node_id(), sc.gfp_mask);
2428 struct task_struct *p = current;
2429 unsigned long nr_reclaimed;
2431 p->flags |= PF_MEMALLOC;
2432 lockdep_set_current_reclaim_state(sc.gfp_mask);
2433 reclaim_state.reclaimed_slab = 0;
2434 p->reclaim_state = &reclaim_state;
2436 nr_reclaimed = do_try_to_free_pages(zonelist, &sc);
2438 p->reclaim_state = NULL;
2439 lockdep_clear_current_reclaim_state();
2440 p->flags &= ~PF_MEMALLOC;
2442 return nr_reclaimed;
2444 #endif /* CONFIG_HIBERNATION */
2446 /* It's optimal to keep kswapds on the same CPUs as their memory, but
2447 not required for correctness. So if the last cpu in a node goes
2448 away, we get changed to run anywhere: as the first one comes back,
2449 restore their cpu bindings. */
2450 static int __devinit cpu_callback(struct notifier_block *nfb,
2451 unsigned long action, void *hcpu)
2453 int nid;
2455 if (action == CPU_ONLINE || action == CPU_ONLINE_FROZEN) {
2456 for_each_node_state(nid, N_HIGH_MEMORY) {
2457 pg_data_t *pgdat = NODE_DATA(nid);
2458 const struct cpumask *mask;
2460 mask = cpumask_of_node(pgdat->node_id);
2462 if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids)
2463 /* One of our CPUs online: restore mask */
2464 set_cpus_allowed_ptr(pgdat->kswapd, mask);
2467 return NOTIFY_OK;
2471 * This kswapd start function will be called by init and node-hot-add.
2472 * On node-hot-add, kswapd will moved to proper cpus if cpus are hot-added.
2474 int kswapd_run(int nid)
2476 pg_data_t *pgdat = NODE_DATA(nid);
2477 int ret = 0;
2479 if (pgdat->kswapd)
2480 return 0;
2482 pgdat->kswapd = kthread_run(kswapd, pgdat, "kswapd%d", nid);
2483 if (IS_ERR(pgdat->kswapd)) {
2484 /* failure at boot is fatal */
2485 BUG_ON(system_state == SYSTEM_BOOTING);
2486 printk("Failed to start kswapd on node %d\n",nid);
2487 ret = -1;
2489 return ret;
2493 * Called by memory hotplug when all memory in a node is offlined.
2495 void kswapd_stop(int nid)
2497 struct task_struct *kswapd = NODE_DATA(nid)->kswapd;
2499 if (kswapd)
2500 kthread_stop(kswapd);
2503 static int __init kswapd_init(void)
2505 int nid;
2507 swap_setup();
2508 for_each_node_state(nid, N_HIGH_MEMORY)
2509 kswapd_run(nid);
2510 hotcpu_notifier(cpu_callback, 0);
2511 return 0;
2514 module_init(kswapd_init)
2516 #ifdef CONFIG_NUMA
2518 * Zone reclaim mode
2520 * If non-zero call zone_reclaim when the number of free pages falls below
2521 * the watermarks.
2523 int zone_reclaim_mode __read_mostly;
2525 #define RECLAIM_OFF 0
2526 #define RECLAIM_ZONE (1<<0) /* Run shrink_inactive_list on the zone */
2527 #define RECLAIM_WRITE (1<<1) /* Writeout pages during reclaim */
2528 #define RECLAIM_SWAP (1<<2) /* Swap pages out during reclaim */
2531 * Priority for ZONE_RECLAIM. This determines the fraction of pages
2532 * of a node considered for each zone_reclaim. 4 scans 1/16th of
2533 * a zone.
2535 #define ZONE_RECLAIM_PRIORITY 4
2538 * Percentage of pages in a zone that must be unmapped for zone_reclaim to
2539 * occur.
2541 int sysctl_min_unmapped_ratio = 1;
2544 * If the number of slab pages in a zone grows beyond this percentage then
2545 * slab reclaim needs to occur.
2547 int sysctl_min_slab_ratio = 5;
2549 static inline unsigned long zone_unmapped_file_pages(struct zone *zone)
2551 unsigned long file_mapped = zone_page_state(zone, NR_FILE_MAPPED);
2552 unsigned long file_lru = zone_page_state(zone, NR_INACTIVE_FILE) +
2553 zone_page_state(zone, NR_ACTIVE_FILE);
2556 * It's possible for there to be more file mapped pages than
2557 * accounted for by the pages on the file LRU lists because
2558 * tmpfs pages accounted for as ANON can also be FILE_MAPPED
2560 return (file_lru > file_mapped) ? (file_lru - file_mapped) : 0;
2563 /* Work out how many page cache pages we can reclaim in this reclaim_mode */
2564 static long zone_pagecache_reclaimable(struct zone *zone)
2566 long nr_pagecache_reclaimable;
2567 long delta = 0;
2570 * If RECLAIM_SWAP is set, then all file pages are considered
2571 * potentially reclaimable. Otherwise, we have to worry about
2572 * pages like swapcache and zone_unmapped_file_pages() provides
2573 * a better estimate
2575 if (zone_reclaim_mode & RECLAIM_SWAP)
2576 nr_pagecache_reclaimable = zone_page_state(zone, NR_FILE_PAGES);
2577 else
2578 nr_pagecache_reclaimable = zone_unmapped_file_pages(zone);
2580 /* If we can't clean pages, remove dirty pages from consideration */
2581 if (!(zone_reclaim_mode & RECLAIM_WRITE))
2582 delta += zone_page_state(zone, NR_FILE_DIRTY);
2584 /* Watch for any possible underflows due to delta */
2585 if (unlikely(delta > nr_pagecache_reclaimable))
2586 delta = nr_pagecache_reclaimable;
2588 return nr_pagecache_reclaimable - delta;
2592 * Try to free up some pages from this zone through reclaim.
2594 static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
2596 /* Minimum pages needed in order to stay on node */
2597 const unsigned long nr_pages = 1 << order;
2598 struct task_struct *p = current;
2599 struct reclaim_state reclaim_state;
2600 int priority;
2601 struct scan_control sc = {
2602 .may_writepage = !!(zone_reclaim_mode & RECLAIM_WRITE),
2603 .may_unmap = !!(zone_reclaim_mode & RECLAIM_SWAP),
2604 .may_swap = 1,
2605 .nr_to_reclaim = max_t(unsigned long, nr_pages,
2606 SWAP_CLUSTER_MAX),
2607 .gfp_mask = gfp_mask,
2608 .swappiness = vm_swappiness,
2609 .order = order,
2610 .isolate_pages = isolate_pages_global,
2612 unsigned long slab_reclaimable;
2614 disable_swap_token();
2615 cond_resched();
2617 * We need to be able to allocate from the reserves for RECLAIM_SWAP
2618 * and we also need to be able to write out pages for RECLAIM_WRITE
2619 * and RECLAIM_SWAP.
2621 p->flags |= PF_MEMALLOC | PF_SWAPWRITE;
2622 lockdep_set_current_reclaim_state(gfp_mask);
2623 reclaim_state.reclaimed_slab = 0;
2624 p->reclaim_state = &reclaim_state;
2626 if (zone_pagecache_reclaimable(zone) > zone->min_unmapped_pages) {
2628 * Free memory by calling shrink zone with increasing
2629 * priorities until we have enough memory freed.
2631 priority = ZONE_RECLAIM_PRIORITY;
2632 do {
2633 note_zone_scanning_priority(zone, priority);
2634 shrink_zone(priority, zone, &sc);
2635 priority--;
2636 } while (priority >= 0 && sc.nr_reclaimed < nr_pages);
2639 slab_reclaimable = zone_page_state(zone, NR_SLAB_RECLAIMABLE);
2640 if (slab_reclaimable > zone->min_slab_pages) {
2642 * shrink_slab() does not currently allow us to determine how
2643 * many pages were freed in this zone. So we take the current
2644 * number of slab pages and shake the slab until it is reduced
2645 * by the same nr_pages that we used for reclaiming unmapped
2646 * pages.
2648 * Note that shrink_slab will free memory on all zones and may
2649 * take a long time.
2651 while (shrink_slab(sc.nr_scanned, gfp_mask, order) &&
2652 zone_page_state(zone, NR_SLAB_RECLAIMABLE) >
2653 slab_reclaimable - nr_pages)
2657 * Update nr_reclaimed by the number of slab pages we
2658 * reclaimed from this zone.
2660 sc.nr_reclaimed += slab_reclaimable -
2661 zone_page_state(zone, NR_SLAB_RECLAIMABLE);
2664 p->reclaim_state = NULL;
2665 current->flags &= ~(PF_MEMALLOC | PF_SWAPWRITE);
2666 lockdep_clear_current_reclaim_state();
2667 return sc.nr_reclaimed >= nr_pages;
2670 int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
2672 int node_id;
2673 int ret;
2676 * Zone reclaim reclaims unmapped file backed pages and
2677 * slab pages if we are over the defined limits.
2679 * A small portion of unmapped file backed pages is needed for
2680 * file I/O otherwise pages read by file I/O will be immediately
2681 * thrown out if the zone is overallocated. So we do not reclaim
2682 * if less than a specified percentage of the zone is used by
2683 * unmapped file backed pages.
2685 if (zone_pagecache_reclaimable(zone) <= zone->min_unmapped_pages &&
2686 zone_page_state(zone, NR_SLAB_RECLAIMABLE) <= zone->min_slab_pages)
2687 return ZONE_RECLAIM_FULL;
2689 if (zone->all_unreclaimable)
2690 return ZONE_RECLAIM_FULL;
2693 * Do not scan if the allocation should not be delayed.
2695 if (!(gfp_mask & __GFP_WAIT) || (current->flags & PF_MEMALLOC))
2696 return ZONE_RECLAIM_NOSCAN;
2699 * Only run zone reclaim on the local zone or on zones that do not
2700 * have associated processors. This will favor the local processor
2701 * over remote processors and spread off node memory allocations
2702 * as wide as possible.
2704 node_id = zone_to_nid(zone);
2705 if (node_state(node_id, N_CPU) && node_id != numa_node_id())
2706 return ZONE_RECLAIM_NOSCAN;
2708 if (zone_test_and_set_flag(zone, ZONE_RECLAIM_LOCKED))
2709 return ZONE_RECLAIM_NOSCAN;
2711 ret = __zone_reclaim(zone, gfp_mask, order);
2712 zone_clear_flag(zone, ZONE_RECLAIM_LOCKED);
2714 if (!ret)
2715 count_vm_event(PGSCAN_ZONE_RECLAIM_FAILED);
2717 return ret;
2719 #endif
2722 * page_evictable - test whether a page is evictable
2723 * @page: the page to test
2724 * @vma: the VMA in which the page is or will be mapped, may be NULL
2726 * Test whether page is evictable--i.e., should be placed on active/inactive
2727 * lists vs unevictable list. The vma argument is !NULL when called from the
2728 * fault path to determine how to instantate a new page.
2730 * Reasons page might not be evictable:
2731 * (1) page's mapping marked unevictable
2732 * (2) page is part of an mlocked VMA
2735 int page_evictable(struct page *page, struct vm_area_struct *vma)
2738 if (mapping_unevictable(page_mapping(page)))
2739 return 0;
2741 if (PageMlocked(page) || (vma && is_mlocked_vma(vma, page)))
2742 return 0;
2744 return 1;
2748 * check_move_unevictable_page - check page for evictability and move to appropriate zone lru list
2749 * @page: page to check evictability and move to appropriate lru list
2750 * @zone: zone page is in
2752 * Checks a page for evictability and moves the page to the appropriate
2753 * zone lru list.
2755 * Restrictions: zone->lru_lock must be held, page must be on LRU and must
2756 * have PageUnevictable set.
2758 static void check_move_unevictable_page(struct page *page, struct zone *zone)
2760 VM_BUG_ON(PageActive(page));
2762 retry:
2763 ClearPageUnevictable(page);
2764 if (page_evictable(page, NULL)) {
2765 enum lru_list l = page_lru_base_type(page);
2767 __dec_zone_state(zone, NR_UNEVICTABLE);
2768 list_move(&page->lru, &zone->lru[l].list);
2769 mem_cgroup_move_lists(page, LRU_UNEVICTABLE, l);
2770 __inc_zone_state(zone, NR_INACTIVE_ANON + l);
2771 __count_vm_event(UNEVICTABLE_PGRESCUED);
2772 } else {
2774 * rotate unevictable list
2776 SetPageUnevictable(page);
2777 list_move(&page->lru, &zone->lru[LRU_UNEVICTABLE].list);
2778 mem_cgroup_rotate_lru_list(page, LRU_UNEVICTABLE);
2779 if (page_evictable(page, NULL))
2780 goto retry;
2785 * scan_mapping_unevictable_pages - scan an address space for evictable pages
2786 * @mapping: struct address_space to scan for evictable pages
2788 * Scan all pages in mapping. Check unevictable pages for
2789 * evictability and move them to the appropriate zone lru list.
2791 void scan_mapping_unevictable_pages(struct address_space *mapping)
2793 pgoff_t next = 0;
2794 pgoff_t end = (i_size_read(mapping->host) + PAGE_CACHE_SIZE - 1) >>
2795 PAGE_CACHE_SHIFT;
2796 struct zone *zone;
2797 struct pagevec pvec;
2799 if (mapping->nrpages == 0)
2800 return;
2802 pagevec_init(&pvec, 0);
2803 while (next < end &&
2804 pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) {
2805 int i;
2806 int pg_scanned = 0;
2808 zone = NULL;
2810 for (i = 0; i < pagevec_count(&pvec); i++) {
2811 struct page *page = pvec.pages[i];
2812 pgoff_t page_index = page->index;
2813 struct zone *pagezone = page_zone(page);
2815 pg_scanned++;
2816 if (page_index > next)
2817 next = page_index;
2818 next++;
2820 if (pagezone != zone) {
2821 if (zone)
2822 spin_unlock_irq(&zone->lru_lock);
2823 zone = pagezone;
2824 spin_lock_irq(&zone->lru_lock);
2827 if (PageLRU(page) && PageUnevictable(page))
2828 check_move_unevictable_page(page, zone);
2830 if (zone)
2831 spin_unlock_irq(&zone->lru_lock);
2832 pagevec_release(&pvec);
2834 count_vm_events(UNEVICTABLE_PGSCANNED, pg_scanned);
2840 * scan_zone_unevictable_pages - check unevictable list for evictable pages
2841 * @zone - zone of which to scan the unevictable list
2843 * Scan @zone's unevictable LRU lists to check for pages that have become
2844 * evictable. Move those that have to @zone's inactive list where they
2845 * become candidates for reclaim, unless shrink_inactive_zone() decides
2846 * to reactivate them. Pages that are still unevictable are rotated
2847 * back onto @zone's unevictable list.
2849 #define SCAN_UNEVICTABLE_BATCH_SIZE 16UL /* arbitrary lock hold batch size */
2850 static void scan_zone_unevictable_pages(struct zone *zone)
2852 struct list_head *l_unevictable = &zone->lru[LRU_UNEVICTABLE].list;
2853 unsigned long scan;
2854 unsigned long nr_to_scan = zone_page_state(zone, NR_UNEVICTABLE);
2856 while (nr_to_scan > 0) {
2857 unsigned long batch_size = min(nr_to_scan,
2858 SCAN_UNEVICTABLE_BATCH_SIZE);
2860 spin_lock_irq(&zone->lru_lock);
2861 for (scan = 0; scan < batch_size; scan++) {
2862 struct page *page = lru_to_page(l_unevictable);
2864 if (!trylock_page(page))
2865 continue;
2867 prefetchw_prev_lru_page(page, l_unevictable, flags);
2869 if (likely(PageLRU(page) && PageUnevictable(page)))
2870 check_move_unevictable_page(page, zone);
2872 unlock_page(page);
2874 spin_unlock_irq(&zone->lru_lock);
2876 nr_to_scan -= batch_size;
2882 * scan_all_zones_unevictable_pages - scan all unevictable lists for evictable pages
2884 * A really big hammer: scan all zones' unevictable LRU lists to check for
2885 * pages that have become evictable. Move those back to the zones'
2886 * inactive list where they become candidates for reclaim.
2887 * This occurs when, e.g., we have unswappable pages on the unevictable lists,
2888 * and we add swap to the system. As such, it runs in the context of a task
2889 * that has possibly/probably made some previously unevictable pages
2890 * evictable.
2892 static void scan_all_zones_unevictable_pages(void)
2894 struct zone *zone;
2896 for_each_zone(zone) {
2897 scan_zone_unevictable_pages(zone);
2902 * scan_unevictable_pages [vm] sysctl handler. On demand re-scan of
2903 * all nodes' unevictable lists for evictable pages
2905 unsigned long scan_unevictable_pages;
2907 int scan_unevictable_handler(struct ctl_table *table, int write,
2908 void __user *buffer,
2909 size_t *length, loff_t *ppos)
2911 proc_doulongvec_minmax(table, write, buffer, length, ppos);
2913 if (write && *(unsigned long *)table->data)
2914 scan_all_zones_unevictable_pages();
2916 scan_unevictable_pages = 0;
2917 return 0;
2921 * per node 'scan_unevictable_pages' attribute. On demand re-scan of
2922 * a specified node's per zone unevictable lists for evictable pages.
2925 static ssize_t read_scan_unevictable_node(struct sys_device *dev,
2926 struct sysdev_attribute *attr,
2927 char *buf)
2929 return sprintf(buf, "0\n"); /* always zero; should fit... */
2932 static ssize_t write_scan_unevictable_node(struct sys_device *dev,
2933 struct sysdev_attribute *attr,
2934 const char *buf, size_t count)
2936 struct zone *node_zones = NODE_DATA(dev->id)->node_zones;
2937 struct zone *zone;
2938 unsigned long res;
2939 unsigned long req = strict_strtoul(buf, 10, &res);
2941 if (!req)
2942 return 1; /* zero is no-op */
2944 for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
2945 if (!populated_zone(zone))
2946 continue;
2947 scan_zone_unevictable_pages(zone);
2949 return 1;
2953 static SYSDEV_ATTR(scan_unevictable_pages, S_IRUGO | S_IWUSR,
2954 read_scan_unevictable_node,
2955 write_scan_unevictable_node);
2957 int scan_unevictable_register_node(struct node *node)
2959 return sysdev_create_file(&node->sysdev, &attr_scan_unevictable_pages);
2962 void scan_unevictable_unregister_node(struct node *node)
2964 sysdev_remove_file(&node->sysdev, &attr_scan_unevictable_pages);