-1

To allocate memory dynamically we use some system calls . so the operating system allocates memory on the heap of corresponding process. but how is memory allocated in operating system itself?
how allocates operating system memory when some data structure (e.g process tabel) must be created? dose OS kernel has its own stack and heap?

  • Does this answer your question? [What is the difference between vmalloc and kmalloc?](https://stackoverflow.com/questions/116343/what-is-the-difference-between-vmalloc-and-kmalloc) – wxz Aug 13 '21 at 15:19
  • i think my question is more banal ,,,, i just wanna know how variabels and data structurs are declared dynamically in kernel – Evariste Galois Aug 13 '21 at 15:28
  • Yes, the kernel does its own memory management. – Ian Abbott Aug 13 '21 at 15:40

1 Answers1

0

The Linux operating system does use have its own fixed size stack for each thread. you can see the stack in the source code defining thread_union.

When a syscall is preformed in x86/x64 the kernel swaps out the GS segment and CR3 registers to refer to its own memory and then uses the GS segment register to locate cpu_current_top_of_stack which points to the corresponding kernel stack pointer for the calling thread. You can see this in entry_SYSCALL_64.

When the kernel needs to allocate dynamic memory it uses kamlloc which uses the slob allocator.