netdev_alloc_skb(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– netdev_alloc_skb β€” kernel API manual, but make it make sense ✨

okay bestie, welcome to the netdev_alloc_skb(9) page, straight out of the kernel API manual. this one's a little function with a big job and honestly she's iconic for it πŸŽ€


🌸 NAME 🌸

netdev_alloc_skb β€” allocate an skbuff for rx on a specific device

like, you're grabbing a fresh sk_buff specifically to receive stuff on one particular network device. that's the whole vibe. no cap πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

struct sk_buff * netdev_alloc_skb (struct net_device *dev , unsigned int
length );

copy it exactly, don't be cute with the signature, she is who she is 🫢


✨ ARGUMENTS ✨

  • dev β€” the network device you're receiving on. your main character interface, basically πŸ‘‘
  • length β€” the length to allocate. how much room you're asking for, fr fr

πŸ’œ DESCRIPTION πŸ’œ

so here's the tea πŸ“ β€” this function allocates a brand new sk_buff and assigns it a usage count of one. that's your starting refcount, periodt.

here's the part that trips people up though: the buffer has unspecified headroom built in. like, unspecified. you don't get to know. πŸ™ˆ so if you're a user of this function, you should go ahead and allocate the headroom you think you need β€” without accounting for that built-in space. the built-in space exists purely for optimisations, so don't go counting it like it's yours, bestie.

and ngl, NULL is returned if there's no free memory. that's your out-of-memory signal, so check for it, okay? 😭

also this is lowkey the coolest part: even though this function allocates memory, it can be called from an interrupt. yeah. she works in interrupt context. slay πŸ”₯


⭐ SEE ALSO ⭐

the whole friend group 🫢 β€” kernel file ./include/linux/skbuff.h, plus:

that's a lot of links and yes i typed every single one of them, you're welcome πŸ’… went through them all, no skips, no shortcuts 🧚


πŸ’€ real talk though: that unspecified headroom thing is not a suggestion. don't assume built-in space is your space. allocate what you need yourself and let the built-in stuff do its optimisation thing in peace.

πŸŽ€ the cute sign-off πŸŽ€

this page lives over in ./include/linux, and she's dated October 2026. anyway ily, go check your NULL returns, and remember: allocate your own headroom, bestie πŸŒˆβœ¨πŸ¦‹

πŸ“¦ where this page comes from