2 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #include <linux/sched.h>
35 #include <linux/vmalloc.h>
36 #include <linux/highmem.h>
37 #include <linux/swap.h>
38 #include <linux/blkdev.h>
43 #define MAX_VMALLOCS 6
44 #define MAX_SLAB_SIZE 0x20000
48 kmem_alloc(size_t size, gfp_t flags)
51 unsigned int lflags = kmem_flags_convert(flags);
55 if (size < MAX_SLAB_SIZE || retries > MAX_VMALLOCS)
56 ptr = kmalloc(size, lflags);
58 ptr = __vmalloc(size, lflags, PAGE_KERNEL);
59 if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
61 if (!(++retries % 100))
62 printk(KERN_ERR "XFS: possible memory allocation "
63 "deadlock in %s (mode:0x%x)\n",
64 __FUNCTION__, lflags);
65 blk_congestion_wait(WRITE, HZ/50);
70 kmem_zalloc(size_t size, gfp_t flags)
74 ptr = kmem_alloc(size, flags);
76 memset((char *)ptr, 0, (int)size);
81 kmem_free(void *ptr, size_t size)
83 if (((unsigned long)ptr < VMALLOC_START) ||
84 ((unsigned long)ptr >= VMALLOC_END)) {
92 kmem_realloc(void *ptr, size_t newsize, size_t oldsize,
97 new = kmem_alloc(newsize, flags);
101 ((oldsize < newsize) ? oldsize : newsize));
102 kmem_free(ptr, oldsize);
108 kmem_zone_alloc(kmem_zone_t *zone, gfp_t flags)
111 unsigned int lflags = kmem_flags_convert(flags);
115 ptr = kmem_cache_alloc(zone, lflags);
116 if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
118 if (!(++retries % 100))
119 printk(KERN_ERR "XFS: possible memory allocation "
120 "deadlock in %s (mode:0x%x)\n",
121 __FUNCTION__, lflags);
122 blk_congestion_wait(WRITE, HZ/50);
127 kmem_zone_zalloc(kmem_zone_t *zone, gfp_t flags)
131 ptr = kmem_zone_alloc(zone, flags);
133 memset((char *)ptr, 0, kmem_cache_size(zone));