Merge branch 'virtex-for-2.6.25' of git://git.secretlab.ca/git/linux-2.6-virtex into...
[sfrench/cifs-2.6.git] / fs / xfs / linux-2.6 / kmem.c
index aba7fcf881a217d209d7c0c89fb9a573156e21ba..e040f1ce1b6a71885c6453c620bcf3642ddd45c1 100644 (file)
  * along with this program; if not, write the Free Software Foundation,
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
 #include <linux/highmem.h>
 #include <linux/swap.h>
 #include <linux/blkdev.h>
+#include <linux/backing-dev.h>
 #include "time.h"
 #include "kmem.h"
 
@@ -34,6 +34,14 @@ kmem_alloc(size_t size, unsigned int __nocast flags)
        gfp_t   lflags = kmem_flags_convert(flags);
        void    *ptr;
 
+#ifdef DEBUG
+       if (unlikely(!(flags & KM_LARGE) && (size > PAGE_SIZE))) {
+               printk(KERN_WARNING "Large %s attempt, size=%ld\n",
+                       __FUNCTION__, (long)size);
+               dump_stack();
+       }
+#endif
+
        do {
                if (size < MAX_SLAB_SIZE || retries > MAX_VMALLOCS)
                        ptr = kmalloc(size, lflags);
@@ -45,7 +53,7 @@ kmem_alloc(size_t size, unsigned int __nocast flags)
                        printk(KERN_ERR "XFS: possible memory allocation "
                                        "deadlock in %s (mode:0x%x)\n",
                                        __FUNCTION__, lflags);
-               blk_congestion_wait(WRITE, HZ/50);
+               congestion_wait(WRITE, HZ/50);
        } while (1);
 }
 
@@ -60,11 +68,31 @@ kmem_zalloc(size_t size, unsigned int __nocast flags)
        return ptr;
 }
 
+void *
+kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize,
+                  unsigned int __nocast flags)
+{
+       void            *ptr;
+       size_t          kmsize = maxsize;
+       unsigned int    kmflags = (flags & ~KM_SLEEP) | KM_NOSLEEP;
+
+       while (!(ptr = kmem_zalloc(kmsize, kmflags))) {
+               if ((kmsize <= minsize) && (flags & KM_NOSLEEP))
+                       break;
+               if ((kmsize >>= 1) <= minsize) {
+                       kmsize = minsize;
+                       kmflags = flags;
+               }
+       }
+       if (ptr)
+               *size = kmsize;
+       return ptr;
+}
+
 void
 kmem_free(void *ptr, size_t size)
 {
-       if (((unsigned long)ptr < VMALLOC_START) ||
-           ((unsigned long)ptr >= VMALLOC_END)) {
+       if (!is_vmalloc_addr(ptr)) {
                kfree(ptr);
        } else {
                vfree(ptr);
@@ -102,7 +130,7 @@ kmem_zone_alloc(kmem_zone_t *zone, unsigned int __nocast flags)
                        printk(KERN_ERR "XFS: possible memory allocation "
                                        "deadlock in %s (mode:0x%x)\n",
                                        __FUNCTION__, lflags);
-               blk_congestion_wait(WRITE, HZ/50);
+               congestion_wait(WRITE, HZ/50);
        } while (1);
 }