STRUCT KFREE_RCU_CPU(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ struct kfree_rcu_cpu(9) ✨

okay so this is a page straight out of the Kernel API Manual, and bestie, we're about to get deep into the RCU weeds πŸ’…


🌸 NAME 🌸

struct kfree_rcu_cpu β€” batch up kfree_rcu() requests for an RCU grace period πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

struct kfree_rcu_cpu {
    struct kvfree_rcu_head *head;
    unsigned long head_gp_snap;
    atomic_t head_count;
    struct list_head bulk_head[FREE_N_CHANNELS];
    atomic_t bulk_count[FREE_N_CHANNELS];
    struct kfree_rcu_cpu_work krw_arr[KFREE_N_BATCHES];
    raw_spinlock_t lock;
    struct delayed_work monitor_work;
    bool initialized;
    struct delayed_work page_cache_work;
    atomic_t backoff_page_cache_fill;
    atomic_t work_in_progress;
    struct hrtimer hrtimer;
    struct llist_head bkvcache;
    int nr_bkv_objs;
 };

like, look at her. so many fields. main character struct fr fr πŸ‘‘


πŸ’– Members πŸ’–

  • head β€” the list of kfree_rcu objects that are not yet waiting for a grace period. they're just chilling here for now ✨
  • head_gp_snap β€” a snapshot of the RCU state, taken for the objects that got placed onto "head" πŸ“Έ
  • head_count β€” how many objects are sitting in the rcu_head singular list
  • bulk_head β€” the bulk-list of kvfree_rcu objects not yet waiting for a grace period
  • bulk_count β€” how many objects are in the bulk-list
  • krw_arr β€” an array of batches of kfree_rcu objects waiting for a grace period ⏳
  • lock β€” synchronizes access to this structure (respect the lock, bestie 🫢)
  • monitor_work β€” promotes head to head_free after KFREE_DRAIN_JIFFIES
  • initialized β€” the rcu_work fields have been initialized
  • page_cache_work β€” a work item that refills the cache when it's empty
  • backoff_page_cache_fill β€” delays the cache refills
  • work_in_progress β€” says whether page_cache_work is currently running
  • hrtimer β€” an hrtimer for scheduling a page_cache_work
  • bkvcache β€” a simple cache list holding objects for reuse purposes. and the way it saves per-cpu space is that the list is singular πŸŽ€ even though it's lockless, an access still has to be protected by the per-cpu lock ⚠️
  • nr_bkv_objs β€” the number of allocated objects at bkvcache

🌈 Description 🌈

so this is a per-CPU structure. the reason it's not tucked inside the rcu_data structure is so this code can be extracted from the RCU files β€” and that extraction could let the interactions with the slab allocators get further optimized. it's giving modular genius, honestly 🧚


⭐ SEE ALSO ⭐

Kernel file ./mm/slab_common.c

__kmem_cache_create_args(9), kmem_buckets_create(9), kmem_cache_shrink(9), kmem_dump_obj(9), kfree_sensitive(9), struct kvfree_rcu_bulk_data(9), struct kfree_rcu_cpu_work(9), kvfree_rcu_barrier(9), kvfree_rcu_barrier_on_cache(9)


ngl if you made it all the way down here you're lowkey an RCU icon now πŸ‘‘πŸ¦‹

and that's the whole page, bestie β€” brought to you by ./mm 🌸 from October 2026 πŸ’œ go drink some water and go touch a grace period ✨ periodt πŸ’…

πŸ“¦ where this page comes from