aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm/xfrm_policy.c
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@gmail.com>2008-11-25 20:22:58 -0500
committerDavid S. Miller <davem@davemloft.net>2008-11-25 20:22:58 -0500
commit8100bea7d619e8496ad8e545d1b41f536e076cd5 (patch)
treef0f6163bcfec148cb32941bea908737486896bc0 /net/xfrm/xfrm_policy.c
parent93b851c1c93c7d5cd8d94cd3f3a268b2d5460e9e (diff)
netns xfrm: per-netns xfrm_policy_byidx hashmask
Per-netns hashes are independently resizeable. Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm/xfrm_policy.c')
-rw-r--r--net/xfrm/xfrm_policy.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 700cdd7564e4..9e37a44f148e 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -329,12 +329,11 @@ struct xfrm_policy_hash {
329 329
330static struct hlist_head xfrm_policy_inexact[XFRM_POLICY_MAX*2]; 330static struct hlist_head xfrm_policy_inexact[XFRM_POLICY_MAX*2];
331static struct xfrm_policy_hash xfrm_policy_bydst[XFRM_POLICY_MAX*2] __read_mostly; 331static struct xfrm_policy_hash xfrm_policy_bydst[XFRM_POLICY_MAX*2] __read_mostly;
332static unsigned int xfrm_idx_hmask __read_mostly;
333static unsigned int xfrm_policy_hashmax __read_mostly = 1 * 1024 * 1024; 332static unsigned int xfrm_policy_hashmax __read_mostly = 1 * 1024 * 1024;
334 333
335static inline unsigned int idx_hash(u32 index) 334static inline unsigned int idx_hash(u32 index)
336{ 335{
337 return __idx_hash(index, xfrm_idx_hmask); 336 return __idx_hash(index, init_net.xfrm.policy_idx_hmask);
338} 337}
339 338
340static struct hlist_head *policy_hash_bysel(struct xfrm_selector *sel, unsigned short family, int dir) 339static struct hlist_head *policy_hash_bysel(struct xfrm_selector *sel, unsigned short family, int dir)
@@ -434,7 +433,7 @@ static void xfrm_bydst_resize(int dir)
434 433
435static void xfrm_byidx_resize(int total) 434static void xfrm_byidx_resize(int total)
436{ 435{
437 unsigned int hmask = xfrm_idx_hmask; 436 unsigned int hmask = init_net.xfrm.policy_idx_hmask;
438 unsigned int nhashmask = xfrm_new_hash_mask(hmask); 437 unsigned int nhashmask = xfrm_new_hash_mask(hmask);
439 unsigned int nsize = (nhashmask + 1) * sizeof(struct hlist_head); 438 unsigned int nsize = (nhashmask + 1) * sizeof(struct hlist_head);
440 struct hlist_head *oidx = init_net.xfrm.policy_byidx; 439 struct hlist_head *oidx = init_net.xfrm.policy_byidx;
@@ -450,7 +449,7 @@ static void xfrm_byidx_resize(int total)
450 xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask); 449 xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask);
451 450
452 init_net.xfrm.policy_byidx = nidx; 451 init_net.xfrm.policy_byidx = nidx;
453 xfrm_idx_hmask = nhashmask; 452 init_net.xfrm.policy_idx_hmask = nhashmask;
454 453
455 write_unlock_bh(&xfrm_policy_lock); 454 write_unlock_bh(&xfrm_policy_lock);
456 455
@@ -474,7 +473,7 @@ static inline int xfrm_bydst_should_resize(int dir, int *total)
474 473
475static inline int xfrm_byidx_should_resize(int total) 474static inline int xfrm_byidx_should_resize(int total)
476{ 475{
477 unsigned int hmask = xfrm_idx_hmask; 476 unsigned int hmask = init_net.xfrm.policy_idx_hmask;
478 477
479 if ((hmask + 1) < xfrm_policy_hashmax && 478 if ((hmask + 1) < xfrm_policy_hashmax &&
480 total > hmask) 479 total > hmask)
@@ -492,7 +491,7 @@ void xfrm_spd_getinfo(struct xfrmk_spdinfo *si)
492 si->inscnt = xfrm_policy_count[XFRM_POLICY_IN+XFRM_POLICY_MAX]; 491 si->inscnt = xfrm_policy_count[XFRM_POLICY_IN+XFRM_POLICY_MAX];
493 si->outscnt = xfrm_policy_count[XFRM_POLICY_OUT+XFRM_POLICY_MAX]; 492 si->outscnt = xfrm_policy_count[XFRM_POLICY_OUT+XFRM_POLICY_MAX];
494 si->fwdscnt = xfrm_policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX]; 493 si->fwdscnt = xfrm_policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX];
495 si->spdhcnt = xfrm_idx_hmask; 494 si->spdhcnt = init_net.xfrm.policy_idx_hmask;
496 si->spdhmcnt = xfrm_policy_hashmax; 495 si->spdhmcnt = xfrm_policy_hashmax;
497 read_unlock_bh(&xfrm_policy_lock); 496 read_unlock_bh(&xfrm_policy_lock);
498} 497}
@@ -2410,7 +2409,7 @@ static int __net_init xfrm_policy_init(struct net *net)
2410 net->xfrm.policy_byidx = xfrm_hash_alloc(sz); 2409 net->xfrm.policy_byidx = xfrm_hash_alloc(sz);
2411 if (!net->xfrm.policy_byidx) 2410 if (!net->xfrm.policy_byidx)
2412 goto out_byidx; 2411 goto out_byidx;
2413 xfrm_idx_hmask = hmask; 2412 net->xfrm.policy_idx_hmask = hmask;
2414 2413
2415 for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) { 2414 for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) {
2416 struct xfrm_policy_hash *htab; 2415 struct xfrm_policy_hash *htab;
@@ -2439,7 +2438,7 @@ static void xfrm_policy_fini(struct net *net)
2439 2438
2440 WARN_ON(!list_empty(&net->xfrm.policy_all)); 2439 WARN_ON(!list_empty(&net->xfrm.policy_all));
2441 2440
2442 sz = (xfrm_idx_hmask + 1) * sizeof(struct hlist_head); 2441 sz = (net->xfrm.policy_idx_hmask + 1) * sizeof(struct hlist_head);
2443 WARN_ON(!hlist_empty(net->xfrm.policy_byidx)); 2442 WARN_ON(!hlist_empty(net->xfrm.policy_byidx));
2444 xfrm_hash_free(net->xfrm.policy_byidx, sz); 2443 xfrm_hash_free(net->xfrm.policy_byidx, sz);
2445} 2444}