title: Why is MAP_GROWSDOWN mapping does not grow?
body: <p>I tried to create <code>MAP_GROWSDOWN</code> mapping with the expectation it would grow automatically. As specified in the manual page:</p>
  
  <blockquote>
    <p>MAP_GROWSDOWN</p>
    
    <p>This  flag  is used for stacks.  It indicates to the kernel virtual memory system that the mapping should extend downward in
    memory.  The return address is one page lower than the memory area
    that is actually created in the process's virtual address space. 
    <strong>Touching an address in the "guard" page below the mapping will cause</strong>
    <strong>the mapping to grow by a page</strong>. This growth can be repeated until the
    mapping grows to within a page of the high end of the next lower
    mapping, at which point touching the "guard" page will result in a
    <code>SIGSEGV</code> signal.</p>
  </blockquote>
  
  <p>So I wrote the following example to test the mapping growing:</p>
  
  <pre><code>#ifndef _GNU_SOURCE
      #define _GNU_SOURCE
  #endif
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;inttypes.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/mman.h&gt;
  #include &lt;stdio.h&gt;
  
  int main(void){
      char *mapped_ptr = mmap(NULL, 4096,
                              PROT_READ | PROT_WRITE,
                              MAP_ANONYMOUS | MAP_PRIVATE | MAP_STACK | MAP_GROWSDOWN,
                              -1, 0);
      if(mapped_ptr == MAP_FAILED){
          int error_code = errno;
          fprintf(stderr, "Cannot do MAP_FIXED mapping."
                          "Error code = %d, details = %s\n", error_code, strerror(error_code));
                          exit(EXIT_FAILURE);
      }
      volatile char *c_ptr_1 = mapped_ptr; //address returned by mmap
      *c_ptr_1 = 'a'; //fine
  
      volatile char *c_ptr_2 = mapped_ptr - 4095; //1 page below the guard
      *c_ptr_2 = 'b'; //crashes with SEGV
  }
  </code></pre>
  
  <p>So I got <code>SEGV</code> instead of growing the mapping. What does it mean by growing here?</p>