Skip to contentSkip to conversation

MMAP issues

DISCUSSION Peter Zaitsev 1 participant 1 message Nov 27, 2001 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hello Andrew,

Tuesday, November 27, 2001, 8:44:40 PM, you wrote:

OK. Of course. It's just a few lines length:
Just mention to create any "test.dat" file in the current directory;

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
int i=0;
void* p;
int t;
int fd;

  t=time(NULL);
  while(1)
    {     
     fd=open("test.dat",O_RDWR);
     if (fd<0)
      {
       puts("Unable to open file !");
       return;
      }
     p=mmap(NULL,4096, PROT_READ | PROT_WRITE , MAP_PRIVATE ,fd ,0);
     if ((int)p==-1) 
          {
           printf("Failed %d\n",errno);
           return;
          }       
     i++;     
     if (i%10000==0)
       {
        printf(" %d  Time: %d\n",i,time(NULL)-t);
        t=time(NULL);
       }
    } 

}

Quoted 7 lines · AM> Peter Zaitsev wrote:
Quoted 7 lines

Hello ,

I'm trying to write a program which uses mmap agressively to mmap files (really it's used as fail safe memory allocator to store data if application failed)

AM> It would really help if you could make your test application available to AM> the kernel developers.

AM> Thanks.

Additionally the interesting thing is - if I change MMAP params to:
p=mmap(NULL,4096, PROT_READ | PROT_WRITE , MAP_PRIVATE | MAP_ANON ,-1 ,0);

(The only change is mapping done ammoniums instead of mmaping a file
- this increases speed really much and it does not decrease)

Signature · 2 lines
Best regards,
 Peter                            mailto:[email protected]