linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / mm / swap.c
index 687686a..b524ea9 100644 (file)
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -54,26 +54,6 @@ void put_page(struct page *page)
 }
 EXPORT_SYMBOL(put_page);
 
-/**
- * put_pages_list(): release a list of pages
- *
- * Release a list of pages which are strung together on page.lru.  Currently
- * used by read_cache_pages() and related error recovery code.
- *
- * @pages: list of pages threaded on page->lru
- */
-void put_pages_list(struct list_head *pages)
-{
-       while (!list_empty(pages)) {
-               struct page *victim;
-
-               victim = list_entry(pages->prev, struct page, lru);
-               list_del(&victim->lru);
-               page_cache_release(victim);
-       }
-}
-EXPORT_SYMBOL(put_pages_list);
-
 /*
  * Writeback is about to end against a page which has been marked for immediate
  * reclaim.  If it still appears to be reclaimable, move it to the tail of the
@@ -106,8 +86,9 @@ int rotate_reclaimable_page(struct page *page)
        zone = page_zone(page);
        spin_lock_irqsave(&zone->lru_lock, flags);
        if (PageLRU(page) && !PageActive(page)) {
-               list_move_tail(&page->lru, &zone->inactive_list);
-               __count_vm_event(PGROTATED);
+               list_del(&page->lru);
+               list_add_tail(&page->lru, &zone->inactive_list);
+               inc_page_state(pgrotated);
        }
        if (!test_clear_page_writeback(page))
                BUG();
@@ -127,7 +108,7 @@ void fastcall activate_page(struct page *page)
                del_page_from_inactive_list(zone, page);
                SetPageActive(page);
                add_page_to_active_list(zone, page);
-               __count_vm_event(PGACTIVATE);
+               inc_page_state(pgactivate);
        }
        spin_unlock_irq(&zone->lru_lock);
 }
@@ -228,18 +209,19 @@ int lru_add_drain_all(void)
  */
 void fastcall __page_cache_release(struct page *page)
 {
-       if (PageLRU(page)) {
-               unsigned long flags;
-               struct zone *zone = page_zone(page);
+       unsigned long flags;
+       struct zone *zone = page_zone(page);
 
-               spin_lock_irqsave(&zone->lru_lock, flags);
-               BUG_ON(!PageLRU(page));
-               __ClearPageLRU(page);
+       spin_lock_irqsave(&zone->lru_lock, flags);
+       if (TestClearPageLRU(page))
                del_page_from_lru(zone, page);
-               spin_unlock_irqrestore(&zone->lru_lock, flags);
-       }
-       free_hot_page(page);
+       if (page_count(page) != 0)
+               page = NULL;
+       spin_unlock_irqrestore(&zone->lru_lock, flags);
+       if (page)
+               free_hot_page(page);
 }
+
 EXPORT_SYMBOL(__page_cache_release);
 
 /*
@@ -263,6 +245,7 @@ void release_pages(struct page **pages, int nr, int cold)
        pagevec_init(&pages_to_free, cold);
        for (i = 0; i < nr; i++) {
                struct page *page = pages[i];
+               struct zone *pagezone;
 
                if (unlikely(PageCompound(page))) {
                        if (zone) {
@@ -276,27 +259,23 @@ void release_pages(struct page **pages, int nr, int cold)
                if (!put_page_testzero(page))
                        continue;
 
-               if (PageLRU(page)) {
-                       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);
-                       }
-                       BUG_ON(!PageLRU(page));
-                       __ClearPageLRU(page);
-                       del_page_from_lru(zone, page);
+               pagezone = page_zone(page);
+               if (pagezone != zone) {
+                       if (zone)
+                               spin_unlock_irq(&zone->lru_lock);
+                       zone = pagezone;
+                       spin_lock_irq(&zone->lru_lock);
                }
-
-               if (!pagevec_add(&pages_to_free, page)) {
-                       if (zone) {
+               if (TestClearPageLRU(page))
+                       del_page_from_lru(zone, page);
+               if (page_count(page) == 0) {
+                       if (!pagevec_add(&pages_to_free, page)) {
                                spin_unlock_irq(&zone->lru_lock);
-                               zone = NULL;
+                               __pagevec_free(&pages_to_free);
+                               pagevec_reinit(&pages_to_free);
+                               zone = NULL;    /* No lock is held */
                        }
-                       __pagevec_free(&pages_to_free);
-                       pagevec_reinit(&pages_to_free);
-               }
+               }
        }
        if (zone)
                spin_unlock_irq(&zone->lru_lock);
@@ -364,8 +343,8 @@ void __pagevec_lru_add(struct pagevec *pvec)
                        zone = pagezone;
                        spin_lock_irq(&zone->lru_lock);
                }
-               BUG_ON(PageLRU(page));
-               SetPageLRU(page);
+               if (TestSetPageLRU(page))
+                       BUG();
                add_page_to_inactive_list(zone, page);
        }
        if (zone)
@@ -391,10 +370,10 @@ void __pagevec_lru_add_active(struct pagevec *pvec)
                        zone = pagezone;
                        spin_lock_irq(&zone->lru_lock);
                }
-               BUG_ON(PageLRU(page));
-               SetPageLRU(page);
-               BUG_ON(PageActive(page));
-               SetPageActive(page);
+               if (TestSetPageLRU(page))
+                       BUG();
+               if (TestSetPageActive(page))
+                       BUG();
                add_page_to_active_list(zone, page);
        }
        if (zone)
@@ -499,6 +478,48 @@ static int cpu_swap_callback(struct notifier_block *nfb,
 #endif /* CONFIG_HOTPLUG_CPU */
 #endif /* CONFIG_SMP */
 
+#ifdef CONFIG_SMP
+void percpu_counter_mod(struct percpu_counter *fbc, long amount)
+{
+       long count;
+       long *pcount;
+       int cpu = get_cpu();
+
+       pcount = per_cpu_ptr(fbc->counters, cpu);
+       count = *pcount + amount;
+       if (count >= FBC_BATCH || count <= -FBC_BATCH) {
+               spin_lock(&fbc->lock);
+               fbc->count += count;
+               *pcount = 0;
+               spin_unlock(&fbc->lock);
+       } else {
+               *pcount = count;
+       }
+       put_cpu();
+}
+EXPORT_SYMBOL(percpu_counter_mod);
+
+/*
+ * Add up all the per-cpu counts, return the result.  This is a more accurate
+ * but much slower version of percpu_counter_read_positive()
+ */
+long percpu_counter_sum(struct percpu_counter *fbc)
+{
+       long ret;
+       int cpu;
+
+       spin_lock(&fbc->lock);
+       ret = fbc->count;
+       for_each_cpu(cpu) {
+               long *pcount = per_cpu_ptr(fbc->counters, cpu);
+               ret += *pcount;
+       }
+       spin_unlock(&fbc->lock);
+       return ret < 0 ? 0 : ret;
+}
+EXPORT_SYMBOL(percpu_counter_sum);
+#endif
+
 /*
  * Perform any setup for the swap system
  */