Re: [PATCH v2] Documentation/page_tables: Add info about MMU/TLB and Page Faults

From: Linus Walleij
Date: Tue Aug 15 2023 - 04:52:31 EST


Hi Fabio,

overall this v2 looks good!

The below are my grammar and spelling nitpicks.

On Sun, Aug 13, 2023 at 8:25 PM Fabio M. De Francesco
<fmdefrancesco@xxxxxxxxx> wrote:

> Extend page_tables.rst by adding a section about the role of MMU and TLB
> in translating between virtual addresses and physical page frames.
> Furthermore explain the concept behind Page Faults and how the Linux
> kernel handles TLB misses. Finally briefly explain how and why to disable
> the page faults handler.
>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Ira Weiny <ira.weiny@xxxxxxxxx>
> Cc: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> Cc: Jonathan Corbet <corbet@xxxxxxx>
> Cc: Linus Walleij <linus.walleij@xxxxxxxxxx>
> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
> Cc: Mike Rapoport <rppt@xxxxxxxxxx>
> Cc: Randy Dunlap <rdunlap@xxxxxxxxxxxxx>
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@xxxxxxxxx>
(...)
> +If the above-mentioned conditions happen in user-space, the kernel sends a
> +`Segmentation Fault` (SIGSEGV) signal to the current thread. That signal usually
> +causes the termination of the thread and of the process it belongs to.
> +
> +Instead, there are also common and expected other causes of page faults. These

The word you are looking for is "Additionally" right?

"Additionally, there are..."

> +These techniques improve memory efficiency, reduce latency, and minimize space
> +occupation. This document won't go deeper into the details of "Lazy Allocation"
> +and "Copy-on-Write" because these subjects are out of scope for they belong to

"for they belong" -> "as they belong"
(I think)

> +Swapping differentiate itself from the other mentioned techniques because it's

differentiates

> +not so desirable since it's performed as a means to reduce memory under heavy
> +pressure.

"not so desirable" -> "undesirable"

> +Swapping can't work for memory mapped by kernel logical addresses. These are a

"kernel logical addresses" -> "kernel-internal logical addresses"

> +If everything fails to make room for the data that must reside be present in

"If everything fails" -> "If the kernel fails"

> +This document is going to simplify and show an high altitude view of how the
> +Linux kernel handles these page faults, creates tables and tables' entries,
> +check if memory is present and, if not, requests to load data from persistent
> +storage or from other devices, and updates the MMU and its caches...

Skip "..." for just period "."

> +The first steps are architectures dependent. Most architectures jump to

architectures -> architecture

> +Whatever the routes, all architectures end up to the invocation of
> +`handle_mm_fault()` which, in turn, (likely) ends up calling
> +`__handle_mm_fault()` to carry out the actual work of allocation of the page
> +tables.

"of allocation of the" -> "of allocating the"

> +`__handle_mm_fault()` carries out its work by calling several functions to
> +find the entry's offsets of the upper layers of the page tables and allocate
> +the tables that it may need to.

Skip the last "to".

> +Linux supports larger page sizes than the usual 4KB (i.e., the so called
> +`huge pages`). When using these kinds of larger pages, higher level pages can
> +directly map them, with no need to use lower level page entries (PTE). Huge
> +pages contain large contiguos physical regions that usually span from 2MB to

contiguous

> +The huge pages bring with them several benefits like reduced TLB pressure,
> +reduced page table overhead, memory allocation efficiency, and performance
> +improvement for certain workloads. However, these benefits come with
> +trade-offs, like wasted memory and allocation challenges. Huge pages are out
> +of scope of the present document, therefore, it won't go into further details.

Since you explain what they are, it feels they are in scope?
I would just skip the last sentence.

> +To conclude this brief overview from very high altitude of how Linux handles

To conclude this high altitude view of...

> +Several code path make use of the latter two functions because they need to

code paths

With or without the above suggestions:
Reviewed-by: Linus Walleij <linus.walleij@xxxxxxxxxx>

Yours,
Linus Walleij