__alloc_skb(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– __alloc_skb β€” the kernel manual, but make it make sense πŸ’–

okay so this is a page from the Kernel API Manual (section 9, kernel devs, bestie, that's the driver/internal zone) and we're talking about __alloc_skb. yes the double underscore is part of the name, it's not me being dramatic for once. πŸŽ€


✨ NAME ✨

__alloc_skb β€” allocate a network buffer</p> πŸ¦‹ like, the whole entire point of this function is "give me a fresh sk_buff please and thank you"


🌸 SYNOPSIS 🌸

struct sk_buff * __alloc_skb (unsigned int size , gfp_t gfp_mask , int
flags , int node );

that's the shape of it β€” returns a struct sk_buff *, takes four args, slay. ⭐


πŸ’… ARGUMENTS πŸ’…

  • size β€” the size to allocate. literally just how many bytes you want. πŸ’–
  • gfp_mask β€” the allocation mask. this is the whole "how am I allowed to get this memory" vibe check. (GFP_ATOMIC girlies, see the warning in DESCRIPTION πŸ‘€)
  • flags β€” the spicy ones, so pay attention:
    • if SKB_ALLOC_FCLONE is set β†’ allocate from the fclone cache instead of the head cache, and allocate a cloned (child) skb. it's giving main character with a backup dancer. πŸ‘‘
    • if SKB_ALLOC_RX is set β†’ __GFP_MEMALLOC will be used for allocations in case the data is required for writeback. πŸ”₯
  • node β€” the numa node to allocate memory on. yes, NUMA. yes, it matters. ngl locality is lowkey everything. 🌸

🧚 DESCRIPTION 🧚

So __alloc_skb allocates a new sk_buff. The returned buffer has no headroom and a tail room of at least size bytes`. The object has a reference count of one. πŸŽ€

The return is the buffer. On a failure the return is NULL. (so like, always check, bestie, please. πŸ™ˆ)

Buffers may only be allocated from interrupts using a gfp_mask of GFP_ATOMIC. 🫢 this is not a suggestion, this is the law of the land, do not come crying to me when you sleep in an interrupt context.

πŸ’€ SEE ALSO πŸ’€

okay this is the long one, buckle up, the whole skb cinematic universe is here, listed like the end credits of a marvel movie:

Kernel file ./net/core/skbuff.c drop_reasons_register_subsys(9), drop_reasons_unregister_subsys(9), skb_panic(9), napi_skb_cache_get_bulk(9), __build_skb(9), build_skb_around(9), __napi_build_skb(9), napi_build_skb(9), __netdev_alloc_skb(9), napi_alloc_skb(9), skb_pp_cow_data(9), skb_pp_frag_ref(9), __kfree_skb(9), sk_skb_reason_drop(9), skb_tx_error(9), consume_skb(9), __consume_stateless_skb(9), napi_consume_skb(9), alloc_skb_for_msg(9), skb_morph(9), skb_copy_ubufs(9), skb_clone(9), skb_copy(9), __pskb_copy_fclone(9), pskb_expand_head(9), skb_expand_head(9), skb_copy_expand(9), __skb_pad(9), pskb_put(9), skb_put(9), skb_push(9), skb_pull(9), skb_pull_data(9), skb_trim(9), __pskb_pull_tail(9), skb_copy_bits(9), skb_store_bits(9), skb_zerocopy(9), skb_dequeue(9), skb_dequeue_tail(9), skb_queue_purge_reason(9), skb_rbtree_purge(9), skb_queue_head(9), skb_queue_tail(9), skb_unlink(9), skb_append(9), skb_split(9), skb_shift(9), skb_prepare_seq_read(9), skb_seq_read(9), skb_abort_seq_read(9), skb_copy_seq_read(9), skb_find_text(9), skb_pull_rcsum(9), skb_segment(9), skb_to_sgvec(9), skb_cow_data(9), skb_clone_sk(9), skb_partial_csum_set(9), skb_checksum_setup(9), skb_checksum_maybe_trim(9), skb_checksum_trimmed(9), skb_try_coalesce(9), skb_scrub_packet(9), skb_eth_pop(9), skb_eth_push(9), skb_mpls_push(9), skb_mpls_pop(9), skb_mpls_update_lse(9), skb_mpls_dec_ttl(9), alloc_skb_with_frags(9), skb_condense(9), __skb_ext_alloc(9), __skb_ext_set(9), skb_ext_add(9), skb_attempt_defer_free(9), skb_splice_from_iter(9)

like I said. the whole extended universe. iykyk. πŸ’œ


✨ and that's the page ✨ β€” it lives in ./net/core, the source/version tag says October 2026, and it's __alloc_skb(9) all the way down. go forth and allocate responsibly, bestie, and remember: reference count of one means you own it. πŸ«ΆπŸ’–πŸŽ€

πŸ“¦ where this page comes from