Re[2]: MMAP issues

Peter Zaitsev (pz@spylog.ru)
Tue, 27 Nov 2001 20:54:24 +0300


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);
}

}
}

AM> Peter Zaitsev wrote:
>>
>> 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)

-- 
Best regards,
 Peter                            mailto:pz@spylog.ru

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/