title: Why mm_struct->start_stack and vm_area_struct->start don't point to the same address?
body: <p>As far as I understand memory management in Linux kernel, there is a mm_struct structure responsible for address space in each process. One important memory region is stack. This should be identified by vm_area_struct memory region and mm_struct itself has a pointer mm_struct->stack_start which is stack's address. </p>
  
  <p>I came accross the code below and what I cannot understand is why any of the memory region start/end addresses are not equal to mm_struct->stack_start value. Any help in understanding this would be very much appreciated. Thanks</p>
  
  <p>Some of the results of loading the compiled kernel module:</p>
  
  <blockquote>
    <p>Vma number 14:   Starts at 0x7fff4bb68000, Ends at 0x7fff4bb8a000 
    Vma number 15: Starts at 0x7fff4bbfc000, Ends at 0x7fff4bbfe000 
    Vma number 16: Starts at 0x7fff4bbfe000, Ends at 0x7fff4bc00000 
    Code  Segment start = 0x400000, end = 0x400854
    Data  Segment start = 0x600858, end = 0x600a94
    Stack Segment start = 0x7fff4bb88420</p>
  </blockquote>
  
  <p>One can find that stack segment start (0x7fff4bb88420) belongs to the vma number 14 but I don't know the addresses are different.</p>
  
  <p>Kernel module source code:</p>
  
  <pre><code>#include &lt;linux/init.h&gt;
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;linux/sched.h&gt;
  #include &lt;linux/mm.h&gt;
  
  static int pid_mem = 1;
  
  static void print_mem(struct task_struct *task)
  {
          struct mm_struct *mm;
          struct vm_area_struct *vma;
          int count = 0;
          mm = task-&gt;mm;
          printk("\nThis mm_struct has %d vmas.\n", mm-&gt;map_count);
          for (vma = mm-&gt;mmap ; vma ; vma = vma-&gt;vm_next) {
                  printk ("\nVma number %d: \n", ++count);
                  printk("  Starts at 0x%lx, Ends at 0x%lx\n",
                            vma-&gt;vm_start, vma-&gt;vm_end);
          }
          printk("\nCode  Segment start = 0x%lx, end = 0x%lx \n"
                   "Data  Segment start = 0x%lx, end = 0x%lx\n"
                   "Stack Segment start = 0x%lx\n",
                   mm-&gt;start_code, mm-&gt;end_code,
                   mm-&gt;start_data, mm-&gt;end_data,
                   mm-&gt;start_stack);
  }
  
  static int mm_exp_load(void){
          struct task_struct *task;
          printk("\nGot the process id to look up as %d.\n", pid_mem);
          for_each_process(task) {
                  if ( task-&gt;pid == pid_mem) {
                          printk("%s[%d]\n", task-&gt;comm, task-&gt;pid);
                          print_mem(task);
                  }
          }
          return 0;
  }
  
  static void mm_exp_unload(void)
  {
          printk("\nPrint segment information module exiting.\n");
  }
  
  module_init(mm_exp_load);
  module_exit(mm_exp_unload);
  module_param(pid_mem, int, 0);
  
  MODULE_AUTHOR ("Krishnakumar. R, rkrishnakumar@gmail.com");
  MODULE_DESCRIPTION ("Print segment information");
  MODULE_LICENSE("GPL");
  </code></pre>