提交 2c96c25d 编写于 作者: P Patrick McHardy 提交者: Pablo Neira Ayuso

netfilter: nft_hash: use set global element counter instead of private one

Now that nf_tables performs global accounting of set elements, it is not
needed in the hash type anymore.
Signed-off-by: NPatrick McHardy <kaber@trash.net>
Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
上级 c50b960c
...@@ -28,7 +28,6 @@ struct nft_hash { ...@@ -28,7 +28,6 @@ struct nft_hash {
struct nft_hash_table { struct nft_hash_table {
unsigned int size; unsigned int size;
unsigned int elements;
struct nft_hash_elem __rcu *buckets[]; struct nft_hash_elem __rcu *buckets[];
}; };
...@@ -167,7 +166,6 @@ static int nft_hash_tbl_expand(const struct nft_set *set, struct nft_hash *priv) ...@@ -167,7 +166,6 @@ static int nft_hash_tbl_expand(const struct nft_set *set, struct nft_hash *priv)
break; break;
} }
} }
ntbl->elements = tbl->elements;
/* Publish new table */ /* Publish new table */
rcu_assign_pointer(priv->tbl, ntbl); rcu_assign_pointer(priv->tbl, ntbl);
...@@ -207,7 +205,6 @@ static int nft_hash_tbl_shrink(const struct nft_set *set, struct nft_hash *priv) ...@@ -207,7 +205,6 @@ static int nft_hash_tbl_shrink(const struct nft_set *set, struct nft_hash *priv)
; ;
RCU_INIT_POINTER(*pprev, tbl->buckets[i + ntbl->size]); RCU_INIT_POINTER(*pprev, tbl->buckets[i + ntbl->size]);
} }
ntbl->elements = tbl->elements;
/* Publish new table */ /* Publish new table */
rcu_assign_pointer(priv->tbl, ntbl); rcu_assign_pointer(priv->tbl, ntbl);
...@@ -243,10 +240,9 @@ static int nft_hash_insert(const struct nft_set *set, ...@@ -243,10 +240,9 @@ static int nft_hash_insert(const struct nft_set *set,
h = nft_hash_data(&he->key, tbl->size, set->klen); h = nft_hash_data(&he->key, tbl->size, set->klen);
RCU_INIT_POINTER(he->next, tbl->buckets[h]); RCU_INIT_POINTER(he->next, tbl->buckets[h]);
rcu_assign_pointer(tbl->buckets[h], he); rcu_assign_pointer(tbl->buckets[h], he);
tbl->elements++;
/* Expand table when exceeding 75% load */ /* Expand table when exceeding 75% load */
if (tbl->elements > tbl->size / 4 * 3) if (set->nelems + 1 > tbl->size / 4 * 3)
nft_hash_tbl_expand(set, priv); nft_hash_tbl_expand(set, priv);
return 0; return 0;
...@@ -274,10 +270,9 @@ static void nft_hash_remove(const struct nft_set *set, ...@@ -274,10 +270,9 @@ static void nft_hash_remove(const struct nft_set *set,
RCU_INIT_POINTER(*pprev, he->next); RCU_INIT_POINTER(*pprev, he->next);
synchronize_rcu(); synchronize_rcu();
kfree(he); kfree(he);
tbl->elements--;
/* Shrink table beneath 30% load */ /* Shrink table beneath 30% load */
if (tbl->elements < tbl->size * 3 / 10 && if (set->nelems - 1 < tbl->size * 3 / 10 &&
tbl->size > NFT_HASH_MIN_SIZE) tbl->size > NFT_HASH_MIN_SIZE)
nft_hash_tbl_shrink(set, priv); nft_hash_tbl_shrink(set, priv);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册