That function is the heart of the page allocator inside the Linux kernel [1]. The fundamental building block for every memory allocation on any system (running on Linux). Whether you call malloc() in a C program, kmalloc() inside a kernel driver, the new operator in C++, load a file in python, or almost any other operation, it will ultimately end up in __alloc_pages() (for small objects, multiple units will share a single __alloc_pages(), then there is a fine grain object manager on top of that such as Slab/Slub, jcmalloc, tcmalloc, mimalloc, etc. but you got the point).
very cool. i recall in one of my classes at unversity (i did a compsci degree) we used nachos (https://en.wikipedia.org/wiki/Not_Another_Completely_Heurist...) and i have vague memories of implementing some kind of virtual memory system with a page table. i also did a microkernel message-passing rtos for the i386 in another class but if i recall correctly, that particular os didn't have to support dynamic allocation (or maybe i have forgotten - it was a long time ago). i am not sure how useful such a limited system would be in practice.
thanks for the information. i am a high level programmer by trade these days, but given enough free time, i think that it would be fun to learn about the internals of the linux kernel in some depth. frankly, it intimidates me a bit (perhaps it should, im not sure).
This is literally __alloc_pages() in the Linux kernel.