Tim
Tim

Reputation: 99428

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!

Upvotes: 38

Views: 25147

Answers (3)

DennisB
DennisB

Reputation: 1

For posterity, here's a video lecture from UC Berkeley's OS course discussing this. https://www.youtube.com/watch?v=IBgkKX6DUTM&t=3345s

Tl;dr above answers (basically). But worth mentioning that the term does come from older style address translation where MMU's contained segment tables instead of page tables.

Upvotes: 0

c4757p
c4757p

Reputation: 1808

Segmentation faults occur when the memory is not allowed to be accessed (does not exist, or is forbidden). Most frequently they occur when you dereference a null variable or run off the end of an array. Page faults occur when memory that is mapped but not loaded is accessed. They are not errors, and signal to the operating system that it should load the appropriate page into memory.

Upvotes: 12

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

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.

Upvotes: 48

Related Questions