2006-08-24 05:50:50 -06:00
|
|
|
/* xfrm_hash.c: Common hash table code.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 David S. Miller (davem@davemloft.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/xfrm.h>
|
|
|
|
|
|
|
|
#include "xfrm_hash.h"
|
|
|
|
|
|
|
|
struct hlist_head *xfrm_hash_alloc(unsigned int sz)
|
|
|
|
{
|
|
|
|
struct hlist_head *n;
|
|
|
|
|
|
|
|
if (sz <= PAGE_SIZE)
|
2007-11-26 08:23:21 -07:00
|
|
|
n = kzalloc(sz, GFP_KERNEL);
|
2006-08-24 05:50:50 -06:00
|
|
|
else if (hashdist)
|
2010-11-20 00:46:35 -07:00
|
|
|
n = vzalloc(sz);
|
2006-08-24 05:50:50 -06:00
|
|
|
else
|
|
|
|
n = (struct hlist_head *)
|
2007-11-26 08:23:21 -07:00
|
|
|
__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
|
2007-05-14 03:19:11 -06:00
|
|
|
get_order(sz));
|
2006-08-24 05:50:50 -06:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xfrm_hash_free(struct hlist_head *n, unsigned int sz)
|
|
|
|
{
|
|
|
|
if (sz <= PAGE_SIZE)
|
|
|
|
kfree(n);
|
|
|
|
else if (hashdist)
|
|
|
|
vfree(n);
|
|
|
|
else
|
|
|
|
free_pages((unsigned long)n, get_order(sz));
|
|
|
|
}
|