提交 8e5105a0 编写于 作者: P Patrick McHardy 提交者: David S. Miller

[NETFILTER]: nf_conntrack: round up hashsize to next multiple of PAGE_SIZE

Don't let the rest of the page go to waste.
Signed-off-by: NPatrick McHardy <kaber@trash.net>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 61eb3107
...@@ -965,12 +965,14 @@ void nf_conntrack_cleanup(void) ...@@ -965,12 +965,14 @@ void nf_conntrack_cleanup(void)
nf_conntrack_helper_fini(); nf_conntrack_helper_fini();
} }
static struct list_head *alloc_hashtable(int size, int *vmalloced) static struct list_head *alloc_hashtable(int *sizep, int *vmalloced)
{ {
struct list_head *hash; struct list_head *hash;
unsigned int i; unsigned int size, i;
*vmalloced = 0; *vmalloced = 0;
size = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct list_head));
hash = (void*)__get_free_pages(GFP_KERNEL, hash = (void*)__get_free_pages(GFP_KERNEL,
get_order(sizeof(struct list_head) get_order(sizeof(struct list_head)
* size)); * size));
...@@ -1003,7 +1005,7 @@ int set_hashsize(const char *val, struct kernel_param *kp) ...@@ -1003,7 +1005,7 @@ int set_hashsize(const char *val, struct kernel_param *kp)
if (!hashsize) if (!hashsize)
return -EINVAL; return -EINVAL;
hash = alloc_hashtable(hashsize, &vmalloced); hash = alloc_hashtable(&hashsize, &vmalloced);
if (!hash) if (!hash)
return -ENOMEM; return -ENOMEM;
...@@ -1053,19 +1055,19 @@ int __init nf_conntrack_init(void) ...@@ -1053,19 +1055,19 @@ int __init nf_conntrack_init(void)
if (nf_conntrack_htable_size < 16) if (nf_conntrack_htable_size < 16)
nf_conntrack_htable_size = 16; nf_conntrack_htable_size = 16;
} }
nf_conntrack_max = 8 * nf_conntrack_htable_size; nf_conntrack_hash = alloc_hashtable(&nf_conntrack_htable_size,
printk("nf_conntrack version %s (%u buckets, %d max)\n",
NF_CONNTRACK_VERSION, nf_conntrack_htable_size,
nf_conntrack_max);
nf_conntrack_hash = alloc_hashtable(nf_conntrack_htable_size,
&nf_conntrack_vmalloc); &nf_conntrack_vmalloc);
if (!nf_conntrack_hash) { if (!nf_conntrack_hash) {
printk(KERN_ERR "Unable to create nf_conntrack_hash\n"); printk(KERN_ERR "Unable to create nf_conntrack_hash\n");
goto err_out; goto err_out;
} }
nf_conntrack_max = 8 * nf_conntrack_htable_size;
printk("nf_conntrack version %s (%u buckets, %d max)\n",
NF_CONNTRACK_VERSION, nf_conntrack_htable_size,
nf_conntrack_max);
nf_conntrack_cachep = kmem_cache_create("nf_conntrack", nf_conntrack_cachep = kmem_cache_create("nf_conntrack",
sizeof(struct nf_conn), sizeof(struct nf_conn),
0, 0, NULL, NULL); 0, 0, NULL, NULL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册