list_lru_add(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– list_lru_add(9) β€” the Kernel API Manual glow-up πŸ’–

okay so bestie, you know list_lru_add(9) from the Kernel API Manual? no? literally sit down, we're doing this 🫢


✨ NAME ✨

list_lru_add β€” add an element to the lru list's tail πŸŽ€ (yes, the tail. iconic behavior, we love a queue.)


🌸 SYNOPSIS 🌸

bool list_lru_add (struct list_lru *lru , struct list_head *item , int
nid , struct mem_cgroup *memcg );

that's the whole vibe check right there β€” takes stuff, returns a bool. simple. elegant. slay.


πŸ¦‹ ARGUMENTS πŸ¦‹

okay let's meet the cast, main character energy all around:

  • lru β€” the lru pointer πŸ’… this is the list herself.
  • item β€” the item to be added. the one we're inserting. she's the moment.
  • nid β€” the node id of the sublist to add the item to. (yes bestie, there are sublists, we'll get there, breathe 🧚)
  • memcg β€” the cgroup of the sublist to add the item to. remember her name, she comes back.

πŸŽ€ DESCRIPTION πŸŽ€

so here's the tea β˜• β€” if the element is already part of a list, this function just returns and does nothing. no drama, no re-inserting, it simply peaces out. and that's actually a flex, because it means you do not need to keep state about whether or not the element already belongs in the list. no bookkeeping, no journal, nothing. we love low-maintenance πŸ’–

but careful, bestie β€” that logic only works if the item is in this list. if the item might be in some other list, then you cannot rely on this check 😭 and you must remove it from the other list before trying to insert it. no cap, that's the rule.

now, the part I need you to actually internalize: the lru list consists of many sublists internally πŸŒ€ and the nid and memcg parameters are used to determine which sublist to insert the item into. it's giving "there are many doors, pick the right one."

it's important to use the right value of nid and memcg when deleting the item, since it might otherwise get deleted from the wrong sublist πŸ’€ yeah. wrong door. embarrassing.

and this also applies when attempting to insert the item multiple times β€” if the item is currently in one sublist and you call list_lru_add again, you must pass the right nid and memcg parameters so that the same sublist is used. consistency is the whole aesthetic, periodt πŸ‘‘

last thing, and this one is non-negotiable: you must ensure that the memcg is not freed during this call (e.g., with rcu or by taking a css refcnt). for real for real. don't let her get freed mid-call, that's not the vibe πŸ™ˆ


πŸ”₯ RETURN πŸ”₯

  • true β€” the list was updated ✨ ate, no crumbs
  • false β€” otherwise πŸ’€

🌈 SEE ALSO 🌈

go read these next, iykyk β€” kernel file ./include/linux/list_lru.h, folio_memcg_list_lru_alloc(9), list_lru_lock(9), list_lru_unlock(9), list_lru_add_obj(9), list_lru_del(9), list_lru_del_obj(9), list_lru_count_one(9), list_lru_walk_one(9), list_lru_walk_one_irq(9) 🌟


okay that's the whole page bestie, go forth and insert responsibly πŸ’œ

this lil masterpiece lives in ./include/linux, dated October 2026 β€” so yeah, it's giving future icon πŸ‘‘ πŸ’… ⭐

πŸ“¦ where this page comes from