History

bpf: Enable task local storage for tracing programs

To access per-task data, BPF programs usually creates a hash table with pid as the key. This is not ideal because: 1. The user need to estimate the proper size of the hash table, which may be inaccurate; 2. Big hash tables are slow; 3. To clean up the data properly during task terminations, the user need to write extra logic. Task local storage overcomes these issues and offers a better option for these per-task data. Task local storage is only available to BPF_LSM. Now enable it for tracing programs. Unlike LSM programs, tracing programs can be called in IRQ contexts. Helpers that access task local storage are updated to use raw_spin_lock_irqsave() instead of raw_spin_lock_bh(). Tracing programs can attach to functions on the task free path, e.g. exit_creds(). To avoid allocating task local storage after bpf_task_storage_free(). bpf_task_storage_get() is updated to not allocate new storage when the task is not refcounted (task->usage == 0).

Song Liu committed 5 years ago

Commit a10787e1 parent 9c8f21e10 files · +51 −72Browse files

Showing the changes to kernel/trace (1 of 10 files). Show all

Unified · Split

kernel/trace/bpf_trace.c+4−0
@@ -1367,6 +1367,10 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) · 1366 unmodified lines
1367 return &bpf_per_cpu_ptr_proto;1367 return &bpf_per_cpu_ptr_proto;
1368 case BPF_FUNC_this_cpu_ptr:1368 case BPF_FUNC_this_cpu_ptr:
1369 return &bpf_this_cpu_ptr_proto;1369 return &bpf_this_cpu_ptr_proto;
1370 case BPF_FUNC_task_storage_get:
1371 return &bpf_task_storage_get_proto;
1372 case BPF_FUNC_task_storage_delete:
1373 return &bpf_task_storage_delete_proto;
1370 default:1374 default:
1371 return NULL;1375 return NULL;
1372 }1376 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t