Mmap and fread processing for large files between processes

I have two processes: Process A maps a large file (~ 170 GB - the content is constantly changing) to the memory for writing with the MAP_NONBLOCK and MAP_SHARED flags :

MyDataType *myDataType; = (MyDataType*)mmap(NULL, sizeof(MyDataType), PROT_WRITE, MAP_NONBLOCK | MAP_SHARED , fileDescriptor, 0);

and every second I call msync:

msync((void *)myDataType, sizeof(MyDataType), MS_ASYNC); 

This section works great.

The problem occurs when process B tries to read from the same file to which process A is running, process A does not respond for ~ 20 seconds. Process B tries to read from the file about 1000 times using fread()and fseek(), small blocks (~ 4 bytes each time). Most of the content that the process reads is close to each other.

What is the cause of this problem? Is this related to page distribution? How can I solve it?

, , mmap() B fread().

+4
3

msync(), , . , ​​ . , Linux ( Solaris BTW), msync(). msync() / read()/write(), , HOWTO. mmap() "" . , , . , . .

mmap, msync linux - realworldtech, , .

PS: fseek()/fread() , , pread(). 1 2. , fseek()/fread() 4K , , fseek(), , , A.

+4

, IO-Starvation, (mmap fread), . (pre-) / IO- (cfq , , )

, /sys:

echo deadline > /sys/block/<device>/queue/scheduler
0

, strace, , . 20 , io msync().

, A , ?

0

Source: https://habr.com/ru/post/1620555/


All Articles