U.S. state Updated 2025-07-16
x86 Paging Tutorial / Page faults Updated 2025-07-16
What if Process 1 tries to access 0x00003000, which is not present?
The hardware notifies the software via a Page Fault Exception.
When an exception happens, the CPU jumps to an address that the OS had previously registered as the fault handler. This is usually done at boot time by the OS.
This could happen for example due to a programming error:
int *is = malloc(1);
is[2] = 1;
but there are cases where it is not a bug, for example in Linux when:
  • the program wants to increase its stack.
    It just tries to accesses a certain byte in a given possible range, and if the OS is happy it adds that page to the process address space, otherwise, it sends a signal to the process.
  • the page was swapped to disk.
    The OS will need to do some work behind the processes back to get the page back into RAM.
    The OS can discover that this is the case based on the contents of the rest of the page table entry, since if the present flag is clear, the other entries of the page table entry are completely left for the OS to to what it wants.
    On Linux for example, when present = 0:
    • if all the fields of the page table entry are 0, invalid address.
    • else, the page has been swapped to disk, and the actual values of those fields encode the position of the page on the disk.
In any case, the OS needs to know which address generated the Page Fault to be able to deal with the problem. This is why the nice IA32 developers set the value of cr2 to that address whenever a Page Fault occurs. The exception handler can then just look into cr2 to get the address.
The exact format of table entries is fixed by the hardware.
Each page entry can be seen as a struct with many fields.
The page table is then an array of struct.
On this simplified example, the page table entries contain only two fields:
bits   function
-----  -----------------------------------------
20     physical address of the start of the page
1      present flag
so in this example the hardware designers could have chosen the size of the page table to b 21 instead of 32 as we've used so far.
All real page table entries have other fields, notably fields to set pages to read-only for Copy-on-write. This will be explained elsewhere.
It would be impractical to align things at 21 bits since memory is addressable by bytes and not bits. Therefore, even in only 21 bits are needed in this case, hardware designers would probably choose 32 to make access faster, and just reserve bits the remaining bits for later usage. The actual value on x86 is 32 bits.
Here is a screenshot from the Intel manual image "Formats of CR3 and Paging-Structure Entries with 32-Bit Paging" showing the structure of a page table in all its glory: Figure 1. "x86 page entry format".
Figure 1.
x86 page entry format
.
The fields are explained in the manual just after.
Aufbau principle Updated 2025-07-16
Boring rule that says that less energetic atomic orbitals are filled first.
Much more interesting is actually determining that order, which the Madelung energy ordering rule is a reasonable approximation to.
For each process, the virtual address space looks like this:
------------------ 2^32 - 1
Stack (grows down)
v v v v v v v v v
------------------

(unmapped)

------------------ Maximum stack size.


(unmapped)


-------------------
mmap
-------------------


(unmapped)


-------------------
^^^^^^^^^^^^^^^^^^^
brk (grows up)
-------------------
BSS
-------------------
Data
-------------------
Text
-------------------

------------------- 0
The kernel maintains a list of pages that belong to each process, and synchronizes that with the paging.
If the program accesses memory that does not belong to it, the kernel handles a page-fault, and decides what to do:
  • if it is above the maximum stack size, allocate those pages to the process
  • otherwise, send a SIGSEGV to the process, which usually kills it
When an ELF file is loaded by the kernel to start a program with the exec system call, the kernel automatically registers text, data, BSS and stack for the program.
The brk and mmap areas can be modified by request of the program through the brk and mmap system calls. But the kernel can also deny the program those areas if there is not enough memory.
brk and mmap can be used to implement malloc, or the so called "heap".
mmap is also used to load dynamically loaded libraries into the program's memory so that it can access and run it.
Calculating exact addresses Things are complicated by:
Comedian Updated 2025-07-16
If you can reduce a mathematical problem to the Halting problem of a specific turing machine, as in the case of a few machines of the Busy beaver scale, then using Turing machine deciders could serve as a method of automated theorem proving.
That feels like it could be an elegant proof method, as you reduce your problem to one of the most well studied representations that exists: a Turing machine.
However it also appears that certain problems cannot be reduced to a halting problem... OMG life sucks (or is awesome?): Section "Turing machine that halts if and only if Collatz conjecture is false".
How to teach Updated 2025-07-16
Off-the-shelf techniques to become a teaching superhero.
Customized website idea at: OurBigBook.com.
Industry Updated 2025-07-16
Universal basic income Updated 2025-07-16
Unconditional basic income is Ciro Santilli's ultimate non-transhumanist technological dream: to reach a state of technological advancement and distribution of resources so high that everyone gets money for doing nothing, enough for:
  • basic survival needs: food, housing, clothes, hygiene, etc.
  • two children to keep the world going. Or immortality tech, but is harder and borderline transhumanist :-)
  • high speed computer and Internet
Once a person has that, they can "learn, teach" and create whatever they want. Or play video games all day long if they wish.
Ciro Santilli will not live to see this, and is content with helping it happen faster by increasing the efficiency of the world as. And having at least two well educated kids to carry on the project after he dies :-)
Technologies which would help a lot towards unconditional basic income, and might be strictly required required are:
So in the worst case we can just grow brainless bodies and replace the cavity hole with a computer that controls the body, possibly with high level decisions coming from a remote building-sized genetically engineered biological AGI brain.
Of course, it is all about costs. A human costs about 130k 2010 USD/year. So how cheap can we make the AGI / robot human equivalent / year for a given task?
AGI + humanoid robots likely implies AI takeover though. It would then come down to human loving bots vs human hating bots fighting it out. It will be both terrifying and fun to watch.
AGI alone would be very dangerous, in case it can get control of our nuclear arsenals through software zero days or social engineering. Although some claim that is unlikely.
Humanity's best bet to achieve silicon AGI today is to work on: Ciro's 2D reinforcement learning games.
By Charles Bukowski mentioned e.g. at tatyanany.medium.com/slavery-was-never-abolished-it-was-only-extended-to-include-all-the-colors-6ca21d586e7e:
Slavery was never abolished, it was only extended to include all the colors.
Bibliography:
Video 1.
Easy street by Stan Kenton and June Christy (1945)
Source. TODO exact lyrics for copy paste? There seem to be several variants, and I don't have the patience to transcribe. Close enough: lyricsplayground.com/alpha/songs/e/easystreet.html. Except that with UBI there won't be a:
guy that you can hire to plant trees so you can have shade
because most people will have something better to do. That's where artificial general intelligence comes in!

Unlisted articles are being shown, click here to show only listed articles.