drm_gem_get_pages(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– drm_gem_get_pages πŸ’–

okay so bestie, welcome to drm_gem_get_pages(9) from the Kernel API Manual β€” we're hanging out in the DRM/GEM corner of the kernel today and honestly? it's giving "I majored in page arrays" and I'm obsessed πŸŽ€


✨ NAME ✨

drm_gem_get_pages β€” the helper bestie that allocates backing pages for a GEM object straight out of shmem πŸ¦‹


✨ SYNOPSIS ✨

struct page ** drm_gem_get_pages (struct drm_gem_object *obj );

✨ ARGUMENTS ✨

  • obj β€” the obj in question, aka the GEM object you're doing all this for. that's the whole vibe check right there πŸ’…

✨ DESCRIPTION ✨

so what does this actually do? it reads the page-array of the shmem-backing storage for the gem object you passed in, and hands you back an array of pages. that's it, that's the tea ✨

and like β€” if a page isn't allocated yet, or it got swapped out? no worries, it will allocate it / swap it back in for you. but heads up, bestie: the whole object is covered by that page-array, and it gets pinned in memory. the entire thing. periodt πŸ’€

when you're done with your little page-array moment, use drm_gem_put_pages to release the array and unpin all the pages. don't just ghost them, okay? 🫢

this function uses the GFP-mask that's set on the shmem-mapping β€” you know, the one from mapping_set_gfp_mask. so if you need other GFP-masks, too bad, you're doing those allocations yourself. your mask, your problem, your character arc 😭

⚠️ important lore drop: you are not allowed to change gfp-zones during runtime. like, at all. meaning shmem_read_mapping_page_gfp must be called with the same gfp_zone(gfp) that was set during initialization. if you have special zone constraints, set them after drm_gem_object_init via mapping_set_gfp_mask β€” and don't stress, shmem-core takes care of keeping pages in the required zone during swap-in 🧚

and the big one: this function is only valid on objects initialized with drm_gem_object_init. it does not work for objects initialized with drm_gem_private_object_init only. not even a little bit. no cap πŸ™ˆ


✨ SEE ALSO ✨

Kernel file ./drivers/gpu/drm/drm_gem.c β€” plus the whole friend group, all together now πŸ’œ:


and that's the whole page, bestie!! 🌈 this little number lives in ./drivers/gpu/drm and it's dated October 2026 β€” go forth, allocate those backing pages, and remember to drm_gem_put_pages when you're done πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from