From 77e4635ae191774526ed695482a151ac986f3806 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 28 Sep 2006 11:03:27 +1000 Subject: [XFS] Add a greedy allocation interface, allocating within a min/max size range. SGI-PV: 955302 SGI-Modid: xfs-linux-melb:xfs-kern:26803a Signed-off-by: Nathan Scott Signed-off-by: Tim Shimmin --- fs/xfs/linux-2.6/kmem.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'fs/xfs/linux-2.6/kmem.c') diff --git a/fs/xfs/linux-2.6/kmem.c b/fs/xfs/linux-2.6/kmem.c index f77fe5c8fcc..80b9340488e 100644 --- a/fs/xfs/linux-2.6/kmem.c +++ b/fs/xfs/linux-2.6/kmem.c @@ -68,6 +68,22 @@ 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; + + while (!(ptr = kmem_zalloc(maxsize, flags))) { + if ((maxsize >>= 1) <= minsize) { + maxsize = minsize; + flags = KM_SLEEP; + } + } + *size = maxsize; + return ptr; +} + void kmem_free(void *ptr, size_t size) { -- cgit v1.2.3-18-g5258