Skip to content

Commit 9859a79

Browse files
xemuldavem330
authored andcommitted
[NET]: Compact sk_stream_mem_schedule() code
This function references sk->sk_prot->xxx for many times. It turned out, that there's so many code in it, that gcc cannot always optimize access to sk->sk_prot's fields. After saving the sk->sk_prot on the stack and comparing disassembled code, it turned out that the function became ~10 bytes shorter and made less dereferences (on i386 and x86_64). Stack consumption didn't grow. Besides, this patch drives most of this function into the 80 columns limit. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3ef1355 commit 9859a79

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

‎net/core/stream.c‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,35 +210,36 @@ EXPORT_SYMBOL(__sk_stream_mem_reclaim);
210210
int sk_stream_mem_schedule(struct sock *sk, int size, int kind)
211211
{
212212
int amt = sk_stream_pages(size);
213+
struct proto *prot = sk->sk_prot;
213214

214215
sk->sk_forward_alloc += amt * SK_STREAM_MEM_QUANTUM;
215-
atomic_add(amt, sk->sk_prot->memory_allocated);
216+
atomic_add(amt, prot->memory_allocated);
216217

217218
/* Under limit. */
218-
if (atomic_read(sk->sk_prot->memory_allocated) < sk->sk_prot->sysctl_mem[0]) {
219-
if (*sk->sk_prot->memory_pressure)
220-
*sk->sk_prot->memory_pressure = 0;
219+
if (atomic_read(prot->memory_allocated) < prot->sysctl_mem[0]) {
220+
if (*prot->memory_pressure)
221+
*prot->memory_pressure = 0;
221222
return 1;
222223
}
223224

224225
/* Over hard limit. */
225-
if (atomic_read(sk->sk_prot->memory_allocated) > sk->sk_prot->sysctl_mem[2]) {
226-
sk->sk_prot->enter_memory_pressure();
226+
if (atomic_read(prot->memory_allocated) > prot->sysctl_mem[2]) {
227+
prot->enter_memory_pressure();
227228
goto suppress_allocation;
228229
}
229230

230231
/* Under pressure. */
231-
if (atomic_read(sk->sk_prot->memory_allocated) > sk->sk_prot->sysctl_mem[1])
232-
sk->sk_prot->enter_memory_pressure();
232+
if (atomic_read(prot->memory_allocated) > prot->sysctl_mem[1])
233+
prot->enter_memory_pressure();
233234

234235
if (kind) {
235-
if (atomic_read(&sk->sk_rmem_alloc) < sk->sk_prot->sysctl_rmem[0])
236+
if (atomic_read(&sk->sk_rmem_alloc) < prot->sysctl_rmem[0])
236237
return 1;
237-
} else if (sk->sk_wmem_queued < sk->sk_prot->sysctl_wmem[0])
238+
} else if (sk->sk_wmem_queued < prot->sysctl_wmem[0])
238239
return 1;
239240

240-
if (!*sk->sk_prot->memory_pressure ||
241-
sk->sk_prot->sysctl_mem[2] > atomic_read(sk->sk_prot->sockets_allocated) *
241+
if (!*prot->memory_pressure ||
242+
prot->sysctl_mem[2] > atomic_read(prot->sockets_allocated) *
242243
sk_stream_pages(sk->sk_wmem_queued +
243244
atomic_read(&sk->sk_rmem_alloc) +
244245
sk->sk_forward_alloc))
@@ -258,7 +259,7 @@ int sk_stream_mem_schedule(struct sock *sk, int size, int kind)
258259

259260
/* Alas. Undo changes. */
260261
sk->sk_forward_alloc -= amt * SK_STREAM_MEM_QUANTUM;
261-
atomic_sub(amt, sk->sk_prot->memory_allocated);
262+
atomic_sub(amt, prot->memory_allocated);
262263
return 0;
263264
}
264265

0 commit comments

Comments
 (0)