title: Location of OS Kernel Data
body: <p>I'm a beginner with operating systems, and I had a question about the OS Kernel.</p>
  
  <p>I'm used to the standard notion of each user process having a virtual address space of stack, heap, data, and code. My question is that when a context switch occurs to the OS Kernel, is the code run in the kernel treated as a process with a stack, heap, data, and code?</p>
  
  <p>I know there is a dedicated kernel stack, which the user program can't access. Is this located in the user program address space?</p>
  
  <p>I know the OS needs to maintain some data structures in order to do its job, like the process control block. Where are these data structures located? Are they in user-program address spaces? Are they in some dedicated segment of memory for kernel data structures? Are they scattered all around physical memory wherever there is space?</p>
  
  <p>Finally, I've seen some diagrams where OS code is located in the top portion of a user program's address space. Is the entire OS kernel located here? If not, where else does the OS kernel's code reside?</p>
  
  <p>Thanks for your help!</p>