Commit f31cc7e8 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by David S. Miller

flowcache: make flow_cache_hash_size() return "unsigned int"

Hash size can't negative so "unsigned int" is logically correct.

Propagate "unsigned int" to loop counters.

Space savings:

	add/remove: 0/0 grow/shrink: 2/2 up/down: 6/-18 (-12)
	function                                     old     new   delta
	flow_cache_flush_tasklet                     362     365      +3
	__flow_cache_shrink                          333     336      +3
	flow_cache_cpu_up_prep                       178     171      -7
	flow_cache_lookup                           1159    1148     -11
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5a17d9ed
...@@ -47,7 +47,7 @@ struct flow_flush_info { ...@@ -47,7 +47,7 @@ struct flow_flush_info {
static struct kmem_cache *flow_cachep __read_mostly; static struct kmem_cache *flow_cachep __read_mostly;
#define flow_cache_hash_size(cache) (1 << (cache)->hash_shift) #define flow_cache_hash_size(cache) (1U << (cache)->hash_shift)
#define FLOW_HASH_RND_PERIOD (10 * 60 * HZ) #define FLOW_HASH_RND_PERIOD (10 * 60 * HZ)
static void flow_cache_new_hashrnd(unsigned long arg) static void flow_cache_new_hashrnd(unsigned long arg)
...@@ -119,9 +119,10 @@ static void __flow_cache_shrink(struct flow_cache *fc, ...@@ -119,9 +119,10 @@ static void __flow_cache_shrink(struct flow_cache *fc,
struct flow_cache_entry *fle; struct flow_cache_entry *fle;
struct hlist_node *tmp; struct hlist_node *tmp;
LIST_HEAD(gc_list); LIST_HEAD(gc_list);
int i, deleted = 0; int deleted = 0;
struct netns_xfrm *xfrm = container_of(fc, struct netns_xfrm, struct netns_xfrm *xfrm = container_of(fc, struct netns_xfrm,
flow_cache_global); flow_cache_global);
unsigned int i;
for (i = 0; i < flow_cache_hash_size(fc); i++) { for (i = 0; i < flow_cache_hash_size(fc); i++) {
int saved = 0; int saved = 0;
...@@ -295,9 +296,10 @@ static void flow_cache_flush_tasklet(unsigned long data) ...@@ -295,9 +296,10 @@ static void flow_cache_flush_tasklet(unsigned long data)
struct flow_cache_entry *fle; struct flow_cache_entry *fle;
struct hlist_node *tmp; struct hlist_node *tmp;
LIST_HEAD(gc_list); LIST_HEAD(gc_list);
int i, deleted = 0; int deleted = 0;
struct netns_xfrm *xfrm = container_of(fc, struct netns_xfrm, struct netns_xfrm *xfrm = container_of(fc, struct netns_xfrm,
flow_cache_global); flow_cache_global);
unsigned int i;
fcp = this_cpu_ptr(fc->percpu); fcp = this_cpu_ptr(fc->percpu);
for (i = 0; i < flow_cache_hash_size(fc); i++) { for (i = 0; i < flow_cache_hash_size(fc); i++) {
...@@ -327,7 +329,7 @@ static void flow_cache_flush_tasklet(unsigned long data) ...@@ -327,7 +329,7 @@ static void flow_cache_flush_tasklet(unsigned long data)
static int flow_cache_percpu_empty(struct flow_cache *fc, int cpu) static int flow_cache_percpu_empty(struct flow_cache *fc, int cpu)
{ {
struct flow_cache_percpu *fcp; struct flow_cache_percpu *fcp;
int i; unsigned int i;
fcp = per_cpu_ptr(fc->percpu, cpu); fcp = per_cpu_ptr(fc->percpu, cpu);
for (i = 0; i < flow_cache_hash_size(fc); i++) for (i = 0; i < flow_cache_hash_size(fc); i++)
...@@ -402,12 +404,12 @@ void flow_cache_flush_deferred(struct net *net) ...@@ -402,12 +404,12 @@ void flow_cache_flush_deferred(struct net *net)
static int flow_cache_cpu_prepare(struct flow_cache *fc, int cpu) static int flow_cache_cpu_prepare(struct flow_cache *fc, int cpu)
{ {
struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, cpu); struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, cpu);
size_t sz = sizeof(struct hlist_head) * flow_cache_hash_size(fc); unsigned int sz = sizeof(struct hlist_head) * flow_cache_hash_size(fc);
if (!fcp->hash_table) { if (!fcp->hash_table) {
fcp->hash_table = kzalloc_node(sz, GFP_KERNEL, cpu_to_node(cpu)); fcp->hash_table = kzalloc_node(sz, GFP_KERNEL, cpu_to_node(cpu));
if (!fcp->hash_table) { if (!fcp->hash_table) {
pr_err("NET: failed to allocate flow cache sz %zu\n", sz); pr_err("NET: failed to allocate flow cache sz %u\n", sz);
return -ENOMEM; return -ENOMEM;
} }
fcp->hash_rnd_recalc = 1; fcp->hash_rnd_recalc = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment