]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - mm/swap.c
mm: remove free_hot_page()
[linux-2.6.git] / mm / swap.c
index 7417a2adbe50f40130badaf92016bcb42e4bc9e2..9036b89813aca85fabc8df912760747d14b40ad5 100644 (file)
--- a/mm/swap.c
+++ b/mm/swap.c
 #include <linux/backing-dev.h>
 #include <linux/memcontrol.h>
 
+#include "internal.h"
+
 /* How many pages do we try to swap or page in/out together? */
 int page_cluster;
 
-static DEFINE_PER_CPU(struct pagevec, lru_add_pvecs);
-static DEFINE_PER_CPU(struct pagevec, lru_add_active_pvecs);
+static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
 static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
 
 /*
@@ -54,7 +55,7 @@ static void __page_cache_release(struct page *page)
                del_page_from_lru(zone, page);
                spin_unlock_irqrestore(&zone->lru_lock, flags);
        }
-       free_hot_page(page);
+       free_hot_cold_page(page, 0);
 }
 
 static void put_compound_page(struct page *page)
@@ -116,8 +117,9 @@ static void pagevec_move_tail(struct pagevec *pvec)
                        zone = pagezone;
                        spin_lock(&zone->lru_lock);
                }
-               if (PageLRU(page) && !PageActive(page)) {
-                       list_move_tail(&page->lru, &zone->inactive_list);
+               if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
+                       int lru = page_lru_base_type(page);
+                       list_move_tail(&page->lru, &zone->lru[lru].list);
                        pgmoved++;
                }
        }
@@ -136,7 +138,7 @@ static void pagevec_move_tail(struct pagevec *pvec)
 void  rotate_reclaimable_page(struct page *page)
 {
        if (!PageLocked(page) && !PageDirty(page) && !PageActive(page) &&
-           PageLRU(page)) {
+           !PageUnevictable(page) && PageLRU(page)) {
                struct pagevec *pvec;
                unsigned long flags;
 
@@ -149,6 +151,26 @@ void  rotate_reclaimable_page(struct page *page)
        }
 }
 
+static void update_page_reclaim_stat(struct zone *zone, struct page *page,
+                                    int file, int rotated)
+{
+       struct zone_reclaim_stat *reclaim_stat = &zone->reclaim_stat;
+       struct zone_reclaim_stat *memcg_reclaim_stat;
+
+       memcg_reclaim_stat = mem_cgroup_get_reclaim_stat_from_page(page);
+
+       reclaim_stat->recent_scanned[file]++;
+       if (rotated)
+               reclaim_stat->recent_rotated[file]++;
+
+       if (!memcg_reclaim_stat)
+               return;
+
+       memcg_reclaim_stat->recent_scanned[file]++;
+       if (rotated)
+               memcg_reclaim_stat->recent_rotated[file]++;
+}
+
 /*
  * FIXME: speed this up?
  */
@@ -157,12 +179,17 @@ void activate_page(struct page *page)
        struct zone *zone = page_zone(page);
 
        spin_lock_irq(&zone->lru_lock);
-       if (PageLRU(page) && !PageActive(page)) {
-               del_page_from_inactive_list(zone, page);
+       if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
+               int file = page_is_file_cache(page);
+               int lru = page_lru_base_type(page);
+               del_page_from_lru_list(zone, page, lru);
+
                SetPageActive(page);
-               add_page_to_active_list(zone, page);
+               lru += LRU_ACTIVE;
+               add_page_to_lru_list(zone, page, lru);
                __count_vm_event(PGACTIVATE);
-               mem_cgroup_move_lists(page, true);
+
+               update_page_reclaim_stat(zone, page, file, 1);
        }
        spin_unlock_irq(&zone->lru_lock);
 }
@@ -176,7 +203,8 @@ void activate_page(struct page *page)
  */
 void mark_page_accessed(struct page *page)
 {
-       if (!PageActive(page) && PageReferenced(page) && PageLRU(page)) {
+       if (!PageActive(page) && !PageUnevictable(page) &&
+                       PageReferenced(page) && PageLRU(page)) {
                activate_page(page);
                ClearPageReferenced(page);
        } else if (!PageReferenced(page)) {
@@ -186,28 +214,54 @@ void mark_page_accessed(struct page *page)
 
 EXPORT_SYMBOL(mark_page_accessed);
 
-/**
- * lru_cache_add: add a page to the page lists
- * @page: the page to add
- */
-void lru_cache_add(struct page *page)
+void __lru_cache_add(struct page *page, enum lru_list lru)
 {
-       struct pagevec *pvec = &get_cpu_var(lru_add_pvecs);
+       struct pagevec *pvec = &get_cpu_var(lru_add_pvecs)[lru];
 
        page_cache_get(page);
        if (!pagevec_add(pvec, page))
-               __pagevec_lru_add(pvec);
+               ____pagevec_lru_add(pvec, lru);
        put_cpu_var(lru_add_pvecs);
 }
 
-void lru_cache_add_active(struct page *page)
+/**
+ * lru_cache_add_lru - add a page to a page list
+ * @page: the page to be added to the LRU.
+ * @lru: the LRU list to which the page is added.
+ */
+void lru_cache_add_lru(struct page *page, enum lru_list lru)
 {
-       struct pagevec *pvec = &get_cpu_var(lru_add_active_pvecs);
+       if (PageActive(page)) {
+               VM_BUG_ON(PageUnevictable(page));
+               ClearPageActive(page);
+       } else if (PageUnevictable(page)) {
+               VM_BUG_ON(PageActive(page));
+               ClearPageUnevictable(page);
+       }
 
-       page_cache_get(page);
-       if (!pagevec_add(pvec, page))
-               __pagevec_lru_add_active(pvec);
-       put_cpu_var(lru_add_active_pvecs);
+       VM_BUG_ON(PageLRU(page) || PageActive(page) || PageUnevictable(page));
+       __lru_cache_add(page, lru);
+}
+
+/**
+ * add_page_to_unevictable_list - add a page to the unevictable list
+ * @page:  the page to be added to the unevictable list
+ *
+ * Add page directly to its zone's unevictable list.  To avoid races with
+ * tasks that might be making the page evictable, through eg. munlock,
+ * munmap or exit, while it's not on the lru, we want to add the page
+ * while it's locked or otherwise "invisible" to other tasks.  This is
+ * difficult to do when using the pagevec cache, so bypass that.
+ */
+void add_page_to_unevictable_list(struct page *page)
+{
+       struct zone *zone = page_zone(page);
+
+       spin_lock_irq(&zone->lru_lock);
+       SetPageUnevictable(page);
+       SetPageLRU(page);
+       add_page_to_lru_list(zone, page, LRU_UNEVICTABLE);
+       spin_unlock_irq(&zone->lru_lock);
 }
 
 /*
@@ -217,15 +271,15 @@ void lru_cache_add_active(struct page *page)
  */
 static void drain_cpu_pagevecs(int cpu)
 {
+       struct pagevec *pvecs = per_cpu(lru_add_pvecs, cpu);
        struct pagevec *pvec;
+       int lru;
 
-       pvec = &per_cpu(lru_add_pvecs, cpu);
-       if (pagevec_count(pvec))
-               __pagevec_lru_add(pvec);
-
-       pvec = &per_cpu(lru_add_active_pvecs, cpu);
-       if (pagevec_count(pvec))
-               __pagevec_lru_add_active(pvec);
+       for_each_lru(lru) {
+               pvec = &pvecs[lru - LRU_BASE];
+               if (pagevec_count(pvec))
+                       ____pagevec_lru_add(pvec, lru);
+       }
 
        pvec = &per_cpu(lru_rotate_pvecs, cpu);
        if (pagevec_count(pvec)) {
@@ -244,7 +298,6 @@ void lru_add_drain(void)
        put_cpu();
 }
 
-#ifdef CONFIG_NUMA
 static void lru_add_drain_per_cpu(struct work_struct *dummy)
 {
        lru_add_drain();
@@ -258,18 +311,6 @@ int lru_add_drain_all(void)
        return schedule_on_each_cpu(lru_add_drain_per_cpu);
 }
 
-#else
-
-/*
- * Returns 0 for success
- */
-int lru_add_drain_all(void)
-{
-       lru_add_drain();
-       return 0;
-}
-#endif
-
 /*
  * Batched page_cache_release().  Decrement the reference count on all the
  * passed pages.  If it fell to zero then remove the page from the LRU and
@@ -308,6 +349,7 @@ void release_pages(struct page **pages, int nr, int cold)
 
                if (PageLRU(page)) {
                        struct zone *pagezone = page_zone(page);
+
                        if (pagezone != zone) {
                                if (zone)
                                        spin_unlock_irqrestore(&zone->lru_lock,
@@ -354,67 +396,22 @@ void __pagevec_release(struct pagevec *pvec)
 
 EXPORT_SYMBOL(__pagevec_release);
 
-/*
- * pagevec_release() for pages which are known to not be on the LRU
- *
- * This function reinitialises the caller's pagevec.
- */
-void __pagevec_release_nonlru(struct pagevec *pvec)
-{
-       int i;
-       struct pagevec pages_to_free;
-
-       pagevec_init(&pages_to_free, pvec->cold);
-       for (i = 0; i < pagevec_count(pvec); i++) {
-               struct page *page = pvec->pages[i];
-
-               VM_BUG_ON(PageLRU(page));
-               if (put_page_testzero(page))
-                       pagevec_add(&pages_to_free, page);
-       }
-       pagevec_free(&pages_to_free);
-       pagevec_reinit(pvec);
-}
-
 /*
  * Add the passed pages to the LRU, then drop the caller's refcount
  * on them.  Reinitialises the caller's pagevec.
  */
-void __pagevec_lru_add(struct pagevec *pvec)
+void ____pagevec_lru_add(struct pagevec *pvec, enum lru_list lru)
 {
        int i;
        struct zone *zone = NULL;
 
-       for (i = 0; i < pagevec_count(pvec); i++) {
-               struct page *page = pvec->pages[i];
-               struct zone *pagezone = page_zone(page);
-
-               if (pagezone != zone) {
-                       if (zone)
-                               spin_unlock_irq(&zone->lru_lock);
-                       zone = pagezone;
-                       spin_lock_irq(&zone->lru_lock);
-               }
-               VM_BUG_ON(PageLRU(page));
-               SetPageLRU(page);
-               add_page_to_inactive_list(zone, page);
-       }
-       if (zone)
-               spin_unlock_irq(&zone->lru_lock);
-       release_pages(pvec->pages, pvec->nr, pvec->cold);
-       pagevec_reinit(pvec);
-}
-
-EXPORT_SYMBOL(__pagevec_lru_add);
-
-void __pagevec_lru_add_active(struct pagevec *pvec)
-{
-       int i;
-       struct zone *zone = NULL;
+       VM_BUG_ON(is_unevictable_lru(lru));
 
        for (i = 0; i < pagevec_count(pvec); i++) {
                struct page *page = pvec->pages[i];
                struct zone *pagezone = page_zone(page);
+               int file;
+               int active;
 
                if (pagezone != zone) {
                        if (zone)
@@ -422,11 +419,16 @@ void __pagevec_lru_add_active(struct pagevec *pvec)
                        zone = pagezone;
                        spin_lock_irq(&zone->lru_lock);
                }
+               VM_BUG_ON(PageActive(page));
+               VM_BUG_ON(PageUnevictable(page));
                VM_BUG_ON(PageLRU(page));
                SetPageLRU(page);
-               VM_BUG_ON(PageActive(page));
-               SetPageActive(page);
-               add_page_to_active_list(zone, page);
+               active = is_active_lru(lru);
+               file = is_file_lru(lru);
+               if (active)
+                       SetPageActive(page);
+               update_page_reclaim_stat(zone, page, file, active);
+               add_page_to_lru_list(zone, page, lru);
        }
        if (zone)
                spin_unlock_irq(&zone->lru_lock);
@@ -434,6 +436,8 @@ void __pagevec_lru_add_active(struct pagevec *pvec)
        pagevec_reinit(pvec);
 }
 
+EXPORT_SYMBOL(____pagevec_lru_add);
+
 /*
  * Try to drop buffers from the pages in a pagevec
  */
@@ -444,8 +448,8 @@ void pagevec_strip(struct pagevec *pvec)
        for (i = 0; i < pagevec_count(pvec); i++) {
                struct page *page = pvec->pages[i];
 
-               if (PagePrivate(page) && !TestSetPageLocked(page)) {
-                       if (PagePrivate(page))
+               if (page_has_private(page) && trylock_page(page)) {
+                       if (page_has_private(page))
                                try_to_release_page(page, 0);
                        unlock_page(page);
                }
@@ -487,55 +491,12 @@ unsigned pagevec_lookup_tag(struct pagevec *pvec, struct address_space *mapping,
 
 EXPORT_SYMBOL(pagevec_lookup_tag);
 
-#ifdef CONFIG_SMP
-/*
- * We tolerate a little inaccuracy to avoid ping-ponging the counter between
- * CPUs
- */
-#define ACCT_THRESHOLD max(16, NR_CPUS * 2)
-
-static DEFINE_PER_CPU(long, committed_space);
-
-void vm_acct_memory(long pages)
-{
-       long *local;
-
-       preempt_disable();
-       local = &__get_cpu_var(committed_space);
-       *local += pages;
-       if (*local > ACCT_THRESHOLD || *local < -ACCT_THRESHOLD) {
-               atomic_long_add(*local, &vm_committed_space);
-               *local = 0;
-       }
-       preempt_enable();
-}
-
-#ifdef CONFIG_HOTPLUG_CPU
-
-/* Drop the CPU's cached committed space back into the central pool. */
-static int cpu_swap_callback(struct notifier_block *nfb,
-                            unsigned long action,
-                            void *hcpu)
-{
-       long *committed;
-
-       committed = &per_cpu(committed_space, (long)hcpu);
-       if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) {
-               atomic_long_add(*committed, &vm_committed_space);
-               *committed = 0;
-               drain_cpu_pagevecs((long)hcpu);
-       }
-       return NOTIFY_OK;
-}
-#endif /* CONFIG_HOTPLUG_CPU */
-#endif /* CONFIG_SMP */
-
 /*
  * Perform any setup for the swap system
  */
 void __init swap_setup(void)
 {
-       unsigned long megs = num_physpages >> (20 - PAGE_SHIFT);
+       unsigned long megs = totalram_pages >> (20 - PAGE_SHIFT);
 
 #ifdef CONFIG_SWAP
        bdi_init(swapper_space.backing_dev_info);
@@ -550,7 +511,4 @@ void __init swap_setup(void)
         * Right now other parts of the system means that we
         * _really_ don't want to cluster much more
         */
-#ifdef CONFIG_HOTPLUG_CPU
-       hotcpu_notifier(cpu_swap_callback, 0);
-#endif
 }