Breakout page_order() to internal.h to avoid special knowledge of the buddy allocator
[sfrench/cifs-2.6.git] / mm / internal.h
index 17256bb2f4ef23bfef9ec32856057124149f414d..953f941ea8676a6f1768257428e8f917e75d7a2c 100644 (file)
@@ -8,23 +8,43 @@
  * as published by the Free Software Foundation; either version
  * 2 of the License, or (at your option) any later version.
  */
+#ifndef __MM_INTERNAL_H
+#define __MM_INTERNAL_H
 
-static inline void set_page_refs(struct page *page, int order)
+#include <linux/mm.h>
+
+static inline void set_page_count(struct page *page, int v)
+{
+       atomic_set(&page->_count, v);
+}
+
+/*
+ * Turn a non-refcounted page (->_count == 0) into refcounted with
+ * a count of one.
+ */
+static inline void set_page_refcounted(struct page *page)
 {
-#ifdef CONFIG_MMU
+       VM_BUG_ON(PageCompound(page) && PageTail(page));
+       VM_BUG_ON(atomic_read(&page->_count));
        set_page_count(page, 1);
-#else
-       int i;
+}
 
-       /*
-        * We need to reference all the pages for this order, otherwise if
-        * anyone accesses one of the pages with (get/put) it will be freed.
-        * - eg: access_process_vm()
-        */
-       for (i = 0; i < (1 << order); i++)
-               set_page_count(page + i, 1);
-#endif /* CONFIG_MMU */
+static inline void __put_page(struct page *page)
+{
+       atomic_dec(&page->_count);
 }
 
 extern void fastcall __init __free_pages_bootmem(struct page *page,
                                                unsigned int order);
+
+/*
+ * function for dealing with page's order in buddy system.
+ * zone->lock is already acquired when we use these.
+ * So, we don't need atomic page->flags operations here.
+ */
+static inline unsigned long page_order(struct page *page)
+{
+       VM_BUG_ON(!PageBuddy(page));
+       return page_private(page);
+}
+#endif