Thread (3 messages) flat view 3 messages, 2 authors, 2017-03-20

Re: [PATCH 2/4] flowcache: make flow_cache_hash_size() return "unsigned int"

From: Alexey Dobriyan <hidden>
Date: 2017-03-20 06:17:09

On Sun, Mar 19, 2017 at 04:13:41PM -0700, Eric Dumazet wrote:
On Mon, 2017-03-20 at 01:24 +0300, Alexey Dobriyan wrote:
quoted
Hash size can't negative so "unsigned int" is logically correct.
quoted
 	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) {
 		fcp->hash_table = kzalloc_node(sz, GFP_KERNEL, cpu_to_node(cpu));
 		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);

I do not see any improvement here.

What is wrong with size_t exactly ?
REX prefixes and sign extensions, lots of them.

Before:
	ffffffff8505b1b5:       41 bd 01 00 00 00       mov    r13d,0x1
	ffffffff8505b1bb:       41 d3 e5                shl    r13d,cl
	ffffffff8505b1be:       4d 63 ed                movsxd r13,r13d
	ffffffff8505b1c1:       49 c1 e5 03             shl    r13,0x3
	ffffffff8505b1c5:       e8 86 28 0a fc          call   __cpu_to_node
			...
	ffffffff8505b20b:       4c 89 ee                mov    rsi,r13

After:
	ffffffff8505b1b5:       41 bd 08 00 00 00       mov    r13d,0x8
	ffffffff8505b1bb:       41 d3 e5                shl    r13d,cl
	ffffffff8505b1be:       e8 8d 28 0a fc          call   __cpu_to_node
			...
	ffffffff8505b1c3:       44 89 ef                mov    edi,r13d

Basically, one can do s/size_t/unsigned int/g across whole networking
stack and nothing will change but the code becomes smaller (including
things like sendmsg() because VFS truncates lengths at INT_MAX).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help