Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing minor page faults in real time process on linux

I need to make the process to run in real time as much as possible.

All the communication is done via shared memory - memory mapped files - no system calls at all - it uses busy waiting on shared memory.

The process runs under real time priority and all memory is locked with mlockall(MCL_CURRENT|MCL_FUTURE) which succeeds and process has enough ulimits to have all the memory locked.

When I run it on it perf stat -p PID I still get counts of minor page faults.

I tested this with both process affinity and without.

Question:

Is it possible to eliminate them at all - even minor page faults?

like image 780
Artyom Avatar asked Dec 02 '12 15:12

Artyom


People also ask

How do you prevent page faults?

You should try to keep code that can be modified and code that cannot be modified in separate sections of a large program. This will reduce page traffic by reducing the number of pages that are changed. Also, try to prevent I/O buffers from crossing page boundaries unnecessarily.

How page fault is handled in Linux?

The mapping between the virtual address space and physical memory is handled by the Linux kernel and by the CPU's MMU using pages of memory. When the CPU needs to access a page that isn't in memory it raises a page fault. A major page fault is one that can only be satisfied by accessing the disk.

What causes minor page faults?

A minor page fault is a type of exception that occurs when the operating system encounters an error in memory that can be caused by either hardware or software errors.

What are major and minor page faults?

A minor fault means the page is in memory but not allocated to the requesting process or not marked as present in the memory management unit. A major fault means the page in no longer in memory.


1 Answers

I solved this problem by switching from memory mapped files to POSIX shared memory shm_open + memory locking.

like image 74
Artyom Avatar answered Sep 23 '22 07:09

Artyom