2

I am working on a system with 4GB ram . I created a large file of 4GB and initialized it with zeros.

I started reading the large file integer by integer.

I find that the number of page faults (major) is zero, no matter how big is the file.

I read the file using both a FILE pointer as well as a file descriptor . I don't find any page faults(major) in both the cases.

Why is it so? Do page faults in a program occur only when internally swapping takes place ?

If yes can you suggest a C program which will incur a page fault.

I am working on Ubuntu 12.04, my computer specs: 4GB ram , 500 GB Hardisk

Thanks in advance

1 Answers1

2

Page faults happen when you try to access data in virtual memory and it isn't available in RAM. Reading from a file using I/O functions like read() or fscanf() doesn't do that; you're requesting the file's contents directly from disk, not through a virtual memory access

If you map the file into virtual memory using mmap() and then try to access that memory, you'll see page faults as the file's contents are loaded automatically.

Wyzard
  • 33,849
  • 3
  • 67
  • 87