title: madvise system call with MADV_SEQUENTIAL call takes too long to finish
body: <p>In my code I am using an external C library and the library calls madvise with MADV_SEQUENTIAL option which takes too long to finish. In my opinion only calling madvise with MADV_SEQUENTIAL is enough for our job. My first question is, why multiple madvise system calls are made, is there a logic in calling madvise with different options sequentially? My second question is, do you have any idea why madvise with MADV_SEQUENTIAL takes too long, sometimes about 1-2 minutes?</p>
  
  <pre><code>[root@mymachine ~]# strace -ttT my_compiled_code
  ...
  13:11:35.358982 open("/some/big/file", O_RDONLY) = 8 &lt;0.000010&gt;
  13:11:35.359060 fstat64(8, {st_mode=S_IFREG|0644, st_size=953360384, ...}) = 0 &lt;0.000006&gt;
  13:11:35.359155 mmap2(NULL, 1073741824, PROT_READ, MAP_SHARED, 8, 0) = 0x7755e000 &lt;0.000007&gt;
  13:11:35.359223 madvise(0x7755e000, 1073741824, MADV_NORMAL) = 0 &lt;0.000006&gt;
  13:11:35.359266 madvise(0x7755e000, 1073741824, MADV_RANDOM) = 0 &lt;0.000006&gt;
  13:11:35.359886 madvise(0x7755e000, 1073741824, MADV_SEQUENTIAL) = 0 &lt;0.000006&gt;
  13:11:53.730549 madvise(0x7755e000, 1073741824, MADV_RANDOM) = 0 &lt;0.000013&gt;
  ...
  </code></pre>
  
  <p>I am using 32-bit linux kernel: 3.4.52-9</p>
  
  <pre><code>[root@mymachine ~]# free -lk
               total       used       free     shared    buffers     cached
  Mem:       4034412    3419344     615068          0      55712     767824
  Low:        853572     495436     358136
  High:      3180840    2923908     256932
  -/+ buffers/cache:    2595808    1438604
  Swap:      4192960     218624    3974336
  
  
  [root@mymachine ~]# cat /proc/buddyinfo 
  Node 0, zone      DMA     89     23      9      4      5      4      4      1      0      2      0 
  Node 0, zone   Normal   9615   7099   3997   1723    931    397     78      0      0      1      1 
  Node 0, zone  HighMem   7313   8089   2187    420    206     92     41     15      8      3      6
  </code></pre>