Linux memory-bound files reserve a lot of physical memory

I have a problem that has been described in several threads regarding memory mapping and rising memory consumption in Linux.

When I open a 1 GB file under Linux or MacOS X and convert it to memory using

me.data_begin = mmap(NULL, capacity(me), prot, MAP_SHARED, me.file.handle, 0);

and sequentially read the displayed memory, my program uses more and more physical memory, although I used posix_madvise (I even called it several times during the reading process):

posix_madvise(me.data_begin, capacity(me), MMAP_SEQUENTIAL);

without success .: - (

I tried:

  • various flags MMAP_RANDOM, MMAP_DONTNEED, MMAP_NORMAL without success
  • posix_fadvise (me.file.handle, 0, capacity (me), POSIX_FADV_DONTNEED) before and after calling mmap -> no success

It works under Mac OS X !!! when i combine

posix_madvise(.. MMAP_SEQUENTIAL)

and

msync(me.data_begin, capacity(me), MS_INVALIDATE).

16M ( msync 16mio ).

Linux . - Linux?

Cheers,

+5
1

Linux . , , , - . Linux , ( ) .

, " " Linux, , .

mmapped, , ( ), . , ( ) .

madvice() POSIX , . , , , . , .

madvice() Linux, , . . . 64- 2 , 50%. mmap 2- , . RSS 200 . madvice():

<juliano@home> ~% ./madvtest file.dat n
     0 :     3 MB
   200 :   202 MB
   400 :   402 MB
   600 :   602 MB
   800 :   802 MB
  1000 :  1002 MB
  1200 :  1066 MB
  1400 :  1068 MB
  1600 :  1078 MB
  1800 :  1113 MB
  2000 :  1113 MB

Linux , 1 . ( 50% ) .

madvice():

<juliano@home> ~% ./madvtest file.dat y
     0 :     3 MB
   200 :   202 MB
   400 :   402 MB
   600 :   494 MB
   800 :   501 MB
  1000 :   518 MB
  1200 :   530 MB
  1400 :   530 MB
  1600 :   530 MB
  1800 :   595 MB
  2000 :   788 MB

, Linux , 500 , , madvice(). , , , , , . VMM , , .

, Linux 500 , . , , - , . , , , , Linux .

, . - . . madvice() , , Linux .

+8

All Articles