xt_percpu_counter_alloc(9)
π xt_percpu_counter_alloc(9) β the kernel API manual, bestie edition π
okay so picture this: it's a 9 manual page, kernel API manual energy, and the star of the show is xt_percpu_counter_alloc β¨ she allocates x_tables rule counters and she does it well. let's get into it π«Ά
β¨ NAME β¨
xt_percpu_counter_alloc β allocate x_tables rule counter π
πΈ SYNOPSIS πΈ
bool xt_percpu_counter_alloc (struct xt_percpu_counter_alloc_state
*state , struct xt_counters *counter );
literally just those two args, no cap π
π¦ ARGUMENTS π¦
stateβ pointer toxt_percpuallocation state. she's the vibe keeper of where everything's at πcounterβ pointer to the counter struct inside theip(6)/arpt_entrystruct. iykyk, it lives nested in there πͺ
π DESCRIPTION π
On SMP, the packet counter [ ip(6)t_entry->counters.pcnt ] will then contain the address of the real (percpu) counter. yes bestie, it's holding an address now, not the number itself β the plot twist of it all π
Rule evaluation needs to use the xt_get_this_cpu_counter helper to fetch the real percpu counter. don't forget the helper, she's essential π
To speed up allocation and improve data locality, a 4kb block is allocated β efficiency queen π
β οΈ and this is the big one: freeing any counter may free an entire block, so all counters allocated using the same state must be freed at the same time. like, all of them, together, at once, no stragglers π this is a group project where everyone actually has to leave at the same time fr fr
xt_percpu_counter_alloc_state contains the base address of the allocated page and the current sub-offset. that's it, that's the whole struct's personality π
returns false on error π so check your return value, bestie, always.
π SEE ALSO π
Kernel file ./net/netfilter/x_tables.c, plus the whole friend group: xt_check_proc_name(9), xt_check_entry_offsets(9), xt_alloc_entry_offsets(9), xt_find_jump_offset(9), xt_copy_counters(9), xt_unregister_table_pre_exit(9), xt_unregister_table_exit(9), xt_hook_ops_alloc(9) π go say hi to all of them.
and that's the page!! π§ source/version lives at ./net/netfilter, dated October 2026, and the header/footer both already told you it's xt_percpu_counter_alloc(9) β slay, you're caught up ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms