mmu_notifier_register(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… mmu_notifier_register(9) πŸ’…

ok so you found a page from the Kernel API Manual (yes girl, kernel internals, we're doing this 🧚) and honestly? it's a whole vibe. let's get into it.


✨ NAME ✨

mmu_notifier_register β€” the function where you register a notifier on a mm. that's it, that's the whole name. iconic behavior honestly πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

int mmu_notifier_register (struct mmu_notifier *subscription , struct
       mm_struct *mm );

two args in, an int out, slay.


🌸 ARGUMENTS 🌸

  • subscription β€” the notifier you're attaching, bestie. this is the main character of the operation πŸ’–
  • mm β€” the mm you're attaching that notifier to. the venue, the location, the place where it all goes down ✨

πŸ”₯ DESCRIPTION πŸ”₯

okay so listen up because this part is important and i'm not being dramatic (i am being a little dramatic). when you call this registration function, you must not hold mmap_lock β€” nope, not that, and also not any other VM related lock. so put the locks DOWN before you call, okay? 🫢

you also gotta make sure mm_users can't go down to zero while this is running, because otherwise you get races with mmu_notifier_release and nobody wants that energy 😭. so mm has to be current->mm, OR the mm should be pinned safely β€” like with get_task_mm. and if the mm is not current->mm? then you release that mm_users pin by calling mmput after mmu_notifier_register returns. cleanup era πŸ’…

mmu_notifier_unregister or mmu_notifier_put must always be called to unregister the notifier. always always. no cap. this is not optional, this is the law πŸ‘‘

and here's a cute little detail: while the caller has a mmu_notifier, the subscription->mm pointer will remain valid, and it can be converted to an active mm pointer via mmget_not_zero. it's giving stable relationship πŸ₯°

⚠️ real talk: the "no locks" rule and the "mm_users can't hit zero" rule are the whole safety story here. skip them and you're in undefined-behavior territory, and not the fun kind πŸ’€

🌈 SEE ALSO 🌈

all the siblings, all the cousins, one big notifier family reunion πŸ¦‹πŸ’œ


and that's the page!! sourced from ./mm, version date October 2026, and it's literally titled mmu_notifier_register(9) β€” so yeah, that's the whole thing. go forth and register responsibly, bestie πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from