UBUNTU: SAUCE: (no-up) swap: Add notify_swap_entry_free callback for compcache
[linux-flexiantxendom0-natty.git] / mm / swapfile.c
index 6d6d28c..7c23299 100644 (file)
@@ -594,6 +594,12 @@ static unsigned char swap_entry_free(struct swap_info_struct *p,
                        disk->fops->swap_slot_free_notify(p->bdev, offset);
        }
 
+       if (!swap_count(count)) {
+               mem_cgroup_uncharge_swap(entry);
+                       if (p->notify_swap_entry_free_fn)
+                               p->notify_swap_entry_free_fn(offset);
+       }
+
        return usage;
 }
 
@@ -2299,6 +2305,23 @@ int swapcache_prepare(swp_entry_t entry)
 }
 
 /*
+ * Sets callback for event when swap_map[offset] == 0
+ * i.e. page at this swap offset is not longer used.
+ *
+ * type: identifies swap file
+ * fn: callback function
+ */
+void set_notify_swap_entry_free(unsigned type, void (*fn) (unsigned long))
+{
+       struct swap_info_struct *sis;
+       sis = swap_info[type];
+       BUG_ON(!sis);
+       sis->notify_swap_entry_free_fn = fn;
+       return;
+}
+EXPORT_SYMBOL(set_notify_swap_entry_free);
+
+/*
  * swap_lock prevents swap_map being freed. Don't grab an extra
  * reference on the swaphandle, it doesn't matter if it becomes unused.
  */