Skip to content

Commit

Permalink
netns xfrm: per-netns xfrm_policy_byidx hashmask
Browse files Browse the repository at this point in the history
Per-netns hashes are independently resizeable.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alexey Dobriyan authored and David S. Miller committed Nov 26, 2008
1 parent 93b851c commit 8100bea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/net/netns/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct netns_xfrm {

struct list_head policy_all;
struct hlist_head *policy_byidx;
unsigned int policy_idx_hmask;
};

#endif
15 changes: 7 additions & 8 deletions net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,11 @@ struct xfrm_policy_hash {

static struct hlist_head xfrm_policy_inexact[XFRM_POLICY_MAX*2];
static struct xfrm_policy_hash xfrm_policy_bydst[XFRM_POLICY_MAX*2] __read_mostly;
static unsigned int xfrm_idx_hmask __read_mostly;
static unsigned int xfrm_policy_hashmax __read_mostly = 1 * 1024 * 1024;

static inline unsigned int idx_hash(u32 index)
{
return __idx_hash(index, xfrm_idx_hmask);
return __idx_hash(index, init_net.xfrm.policy_idx_hmask);
}

static struct hlist_head *policy_hash_bysel(struct xfrm_selector *sel, unsigned short family, int dir)
Expand Down Expand Up @@ -434,7 +433,7 @@ static void xfrm_bydst_resize(int dir)

static void xfrm_byidx_resize(int total)
{
unsigned int hmask = xfrm_idx_hmask;
unsigned int hmask = init_net.xfrm.policy_idx_hmask;
unsigned int nhashmask = xfrm_new_hash_mask(hmask);
unsigned int nsize = (nhashmask + 1) * sizeof(struct hlist_head);
struct hlist_head *oidx = init_net.xfrm.policy_byidx;
Expand All @@ -450,7 +449,7 @@ static void xfrm_byidx_resize(int total)
xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask);

init_net.xfrm.policy_byidx = nidx;
xfrm_idx_hmask = nhashmask;
init_net.xfrm.policy_idx_hmask = nhashmask;

write_unlock_bh(&xfrm_policy_lock);

Expand All @@ -474,7 +473,7 @@ static inline int xfrm_bydst_should_resize(int dir, int *total)

static inline int xfrm_byidx_should_resize(int total)
{
unsigned int hmask = xfrm_idx_hmask;
unsigned int hmask = init_net.xfrm.policy_idx_hmask;

if ((hmask + 1) < xfrm_policy_hashmax &&
total > hmask)
Expand All @@ -492,7 +491,7 @@ void xfrm_spd_getinfo(struct xfrmk_spdinfo *si)
si->inscnt = xfrm_policy_count[XFRM_POLICY_IN+XFRM_POLICY_MAX];
si->outscnt = xfrm_policy_count[XFRM_POLICY_OUT+XFRM_POLICY_MAX];
si->fwdscnt = xfrm_policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX];
si->spdhcnt = xfrm_idx_hmask;
si->spdhcnt = init_net.xfrm.policy_idx_hmask;
si->spdhmcnt = xfrm_policy_hashmax;
read_unlock_bh(&xfrm_policy_lock);
}
Expand Down Expand Up @@ -2410,7 +2409,7 @@ static int __net_init xfrm_policy_init(struct net *net)
net->xfrm.policy_byidx = xfrm_hash_alloc(sz);
if (!net->xfrm.policy_byidx)
goto out_byidx;
xfrm_idx_hmask = hmask;
net->xfrm.policy_idx_hmask = hmask;

for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) {
struct xfrm_policy_hash *htab;
Expand Down Expand Up @@ -2439,7 +2438,7 @@ static void xfrm_policy_fini(struct net *net)

WARN_ON(!list_empty(&net->xfrm.policy_all));

sz = (xfrm_idx_hmask + 1) * sizeof(struct hlist_head);
sz = (net->xfrm.policy_idx_hmask + 1) * sizeof(struct hlist_head);
WARN_ON(!hlist_empty(net->xfrm.policy_byidx));
xfrm_hash_free(net->xfrm.policy_byidx, sz);
}
Expand Down

0 comments on commit 8100bea

Please sign in to comment.