bpf: reduce verifier memory consumption
authorAlexei Starovoitov <ast@plumgrid.com>
Tue, 28 Oct 2014 22:11:41 +0000 (15:11 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 30 Oct 2014 19:44:37 +0000 (15:44 -0400)
commit9c3997601d51069ec08d7d06cf31a17884056cc2
tree640f601a6df8b0cd19d33af5c47691e3294db143
parentd3627795d074d3877e0818ab533c86139ea31413
bpf: reduce verifier memory consumption

verifier keeps track of register state spilled to stack.
registers are 8-byte wide and always aligned, so instead of tracking them
in every byte-sized stack slot, use MAX_BPF_STACK / 8 array to track
spilled register state.
Though verifier runs in user context and its state freed immediately
after verification, it makes sense to reduce its memory usage.
This optimization reduces sizeof(struct verifier_state)
from 12464 to 1712 on 64-bit and from 6232 to 1112 on 32-bit.

Note, this patch doesn't change existing limits, which are there to bound
time and memory during verification: 4k total number of insns in a program,
1k number of jumps (states to visit) and 32k number of processed insn
(since an insn may be visited multiple times). Theoretical worst case memory
during verification is 1712 * 1k = 17Mbyte. Out-of-memory situation triggers
cleanup and rejects the program.

Suggested-by: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/verifier.c
This page took 0.024872 seconds and 5 git commands to generate.