4 ms·
Not to mention how and why the kernel receives the trap. There is no mention of the words "page table", and it's very light on use of the word "interrupt".
by asveikau 11y ago
Not to mention how and why the kernel receives the trap.
There is no mention of the words "page table", and it's very light on use of the word "interrupt".
- pjc50 11y agoPage faults are a "trap" rather than an "interrupt", aren't they? In that they're internal to the CPU-MMU system and delivered synchronously. The answer is a good stackexchange answer in that it's about a page long and covers all the key points. It gives a link to "page" for those who want to understand that subsystem. It's not necessary to include a whole computer architecture course.
- DSMan195276 11y agoIt's debatable - 'trap' isn't extremely well defined, it depends on the architecture. For x86 you'd really call it an exception rather then trap (Trap is used for a bit of a different meaning as far as interrupts go). At the end of the day though, with x86 exceptions/traps/interrupts are all handled like an interrupt (With a few differing details in how they are setup), so saying it's "basically an interrupt" is probably fine, at the very least it's close enough for a high-level explanation.
- steveklabnik 11y agoMy understanding is that "interrupt" is the most general term, and "fault," "trap," and "exception" are all various kinds of interrupts with a very unclear set of rules distinguishing them. And of course this is all architecture dependent.
- hacknat 11y agoFault simply means that the TLB has a cache miss and then traps to the OS to handle the miss. "Fault" is a concept of what is happening a "trap" is what happens. Edit: x86 does have a register for defining the location of page tables that it will walk, the it would trap on a miss if the PTE is missing. Idk, if Linux uses this register or not or uses a software defined TLB, or some kind of hybrid approach.
- moyix 11y ago> x86 does have a register for defining the location of page tables that it will walk, the it would trap on a miss if the PTE is missing. Idk, if Linux uses this register or not or uses a software defined TLB, or some kind of hybrid approach. TLB management is done in hardware on x86. TLB misses don't generate exceptions, they just trigger page table walks in hardware, and then if the page table walk fails (e.g. because of a non-present page table entry) it triggers a CPU exception (page fault) that the OS can then handle. Things like MIPS use a software-managed TLB that works roughly as you describe, though.
- deleted 11y ago[deleted]
- hacknat 11y agoIf you read what I wrote you'll see that I said this.
- geofft 11y agoThe kernel receives the trap because the address is either invalid or has the wrong permissions. The exact details of how this could happen are architecture-dependent, and indeed, the UNIX use of the phrase "Segmentation fault" instead of "Page fault" is a holdover from platforms which used segmentation instead of paging. (Windows 9x's "This program has performed an illegal operation" dialog box gave it the much more accurate name of an "invalid page fault"; I think current Windows goes with "access violation".) The CPU doesn't really know about processes. (Some CPUs have features to manage "tasks", but they are not commonly used 1-to-1 with actual processes, largely for efficiency/performance reasons as I understand it.) The OS tells the CPU that any time it hits a page fault, it should start running code at this address with kernel privilege; this configuration itself also requires kernel privilege. Then it drops privileges and jumps to user code. When the user code makes an invalid memory access, the CPU follows the previous configuration about what to do in the case of an error. That runs a kernel function that delivers the signal (which is an entirely UNIX-specific concept).
- deleted 11y ago[deleted]
- asveikau 11y agoI'm amused when HN replies take this sort of lecturing tone and I am already well familiar with the subject matter.
- geofft 11y agoHaha. I wasn't quite sure if you were asking because you were familiar or unfamiliar, but I figured I'd post it anyway for the benefit of other people clicking through the thread (e.g. GP, who sees replies to descendant comments). Don't read it as a reply to you personally :P
- deleted 11y ago[deleted]