Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

segmentation fault vs page fault

  1. I was wondering what differences and relations are between segmentation fault and page fault?

  2. Does segmentation fault only belong to segmented memory model?

    Does page fault only belong to paged memory model?

    If both are yes, since most computer systems such as x86 and Linux use paged memory model instead of segmented memory model, why does GCC C compiler sometimes report segmentation fault error?

Thanks and regards!

like image 404
Tim Avatar asked Aug 05 '11 01:08

Tim


People also ask

What is meant by segmentation fault?

A segmentation fault (aka segfault) is a common condition that causes programs to crash; they are often associated with a file named core . Segfaults are caused by a program trying to read or write an illegal memory location.

What type of error is segmentation fault?

Segmentation faults are a common class of error in programs written in languages like C that provide low-level memory access and few to no safety checks. They arise primarily due to errors in use of pointers for virtual memory addressing, particularly illegal access.

What does page fault mean?

In computing, a page fault (sometimes called PF or hard fault) is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added to the process's virtual address space.

Is a segmentation fault a runtime error?

The segmentation error is one of the runtime error, that is caused because of the memory access violation, like accessing invalid array index, pointing some restricted address etc.


1 Answers

These two things are very dissimilar, actually. A segmentation fault means a program tried to access an invalid or illegal memory address: for example, 0, or a value larger than any valid pointer. A page fault is when a pointer tries to access a page of address space that's currently not mapped onto physical memory, so that the MMU needs to grab it off of disk before it can be used. The former is an illegal condition and the program will generally be aborted; the latter is perfectly normal and the program won't even know about it.

"Segmentation" isn't at all related to the old "segmented memory model" used by early x86 processors; it's an earlier use which just refers to a portion or segment of memory.

like image 159
Ernest Friedman-Hill Avatar answered Sep 23 '22 14:09

Ernest Friedman-Hill