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
, int flags
)
51 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
, int 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
, int flags
)
96 new = kmem_alloc(newsize
, flags
);
100 ((oldsize
< newsize
) ? oldsize
: newsize
));
101 kmem_free(ptr
, oldsize
);
107 kmem_zone_alloc(kmem_zone_t
*zone
, int flags
)
110 int lflags
= kmem_flags_convert(flags
);
114 ptr
= kmem_cache_alloc(zone
, lflags
);
115 if (ptr
|| (flags
& (KM_MAYFAIL
|KM_NOSLEEP
)))
117 if (!(++retries
% 100))
118 printk(KERN_ERR
"XFS: possible memory allocation "
119 "deadlock in %s (mode:0x%x)\n",
120 __FUNCTION__
, lflags
);
121 blk_congestion_wait(WRITE
, HZ
/50);
126 kmem_zone_zalloc(kmem_zone_t
*zone
, int flags
)
130 ptr
= kmem_zone_alloc(zone
, flags
);
132 memset((char *)ptr
, 0, kmem_cache_size(zone
));