npages_in_range(9)
๐ npages_in_range(9) โ Kernel API Manual
okay bestie, so this is a page from the Kernel API Manual and honestly it's giving "small macro, big job" energy. Let's get into it โจ
๐ธ NAME ๐ธ
npages_in_range โ literally just: calculate the number of pages in a given range. that's it. that's the whole vibe ๐
โจ SYNOPSIS โจ
unsigned long npages_in_range (unsigned long start , unsigned long end
);
like, you hand it two unsigned longs and it hands you back an unsigned long. no cap, that's the whole signature ๐ซถ
๐ง ARGUMENTS ๐ง
startโ the start address of the range. where the vibe begins ๐endโ the end address of the range. where the vibe stops ๐ฆ
๐ฅ DESCRIPTION ๐ฅ
okay so here's the tea โ โ this macro calculates the number of pages in a given memory range, and that range is specified by the start and end addresses.
how does it do it? it takes the difference between the end and start addresses and divides that by the page size (PAGE_SIZE) to determine the number of pages in the range. math girlie behavior, honestly ๐งฎ๐
๐ RETURN ๐
the number of pages in the specified range. iconic. periodt. โญ
๐ SEE ALSO ๐
no like there's a whole friend group here, iykyk ๐
- Kernel file
./drivers/gpu/drm/drm_gpusvm.c Overview(9)Locking(9)Partial Unmapping of Ranges(9)Examples(9)drm_gpusvm_notifier_find(9)drm_gpusvm_range_find(9)drm_gpusvm_notifier_invalidate(9)drm_gpusvm_init(9)to_drm_gpusvm_notifier(9)drm_gpusvm_notifier_insert(9)drm_gpusvm_notifier_remove(9)drm_gpusvm_fini(9)drm_gpusvm_notifier_alloc(9)drm_gpusvm_notifier_free(9)to_drm_gpusvm_range(9)drm_gpusvm_range_insert(9)__drm_gpusvm_range_remove(9)drm_gpusvm_range_alloc(9)drm_gpusvm_hmm_pfn_to_order(9)drm_gpusvm_check_pages(9)drm_gpusvm_scan_mm(9)drm_gpusvm_range_chunk_size(9)drm_gpusvm_driver_lock_held(9)drm_gpusvm_find_vma_start(9)drm_gpusvm_range_find_or_insert(9)__drm_gpusvm_unmap_pages(9)__drm_gpusvm_free_pages(9)drm_gpusvm_free_pages(9)drm_gpusvm_range_remove(9)drm_gpusvm_range_get(9)drm_gpusvm_range_destroy(9)drm_gpusvm_range_put(9)drm_gpusvm_pages_valid(9)drm_gpusvm_pages_valid_unlocked(9)drm_gpusvm_get_pages(9)drm_gpusvm_unmap_pages(9)drm_gpusvm_range_evict(9)drm_gpusvm_has_mapping(9)drm_gpusvm_range_set_unmapped(9)
okay that's the whole page bestie, go divide something by PAGE_SIZE and slay ๐
source/version: ./drivers/gpu/drm ยท dated October 2026 ยท and yeah, it's npages_in_range(9) the whole way through ๐โจ
๐ฆ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms