0

I am learning about operating systems and there are two things I would like to know.

Assuming that the address space division is 1/3 gb (1gb for the kernel and 3gb for the process).

  • What happens if the kernel needs to use more than 1gb?
  • At boot time, if there is no process, how is the kernel mapped?

I would be very grateful if the answer is detailed, but explained so that someone (me) who is in his first year of computer science can understand it. Thanks!

2 Answers 2

0

The kernel does not need to use a lot of memory, but it needs to have a mapping from virtual addresses to physical memory. When paging is enabled on the processor, the only way to access memory is through the paging mechanism, i.e. the addresses the CPU instructions use are virtual addresses, not physical addresses. The kernel mapping is needed for the the kernel to be able to access any part of physical memory, for example to zero pages before mapping them into the process's address space.

When Linux was designed in the early 1990s, it was targeted to run on the 80386, which offered a 32-bit virtual address space. However, the typical PC at that time didn't have more than 8 megabytes of physical memory. The kernel was designed to create a 1:1 mapping where the virtual address 0xC0000000 points to physical address 0, the virtual address 0xC0001000 points to physical address 0x1000, and so on, until the end of physical memory. The kernel's code and data use part of this address space, but most of the memory are "free" pages that can be allocated to processes.

The process address space in this model is mapped to the address space below 3 GB. Several mappings to the same physical memory pages can coexist. A memory page allocated to a running process has at least two mappings, the "kernel view" described above, and the "process view", which uses addresses below the 3 GB mark.

When PCs were shipped with increasing amounts of RAM, the (originally luxurious) 1 GB kernel space got cramped, so all kinds of stopgap solutions were introduced. For example, we got the 2 GB + 2 GB split, which allowed for 2 GB of RAM, but at the same time limited the process address space to 2 GB. The "final" solution was of course moving to 64-bit processors, which has solved the problem for the time being.

-1

Assuming that the address space division is 1/3 gb (1gb for the kernel and 3gb for the process).

But that's not the case. There's no static address space division like that on a machine that can run Linux – quite the contrary, the virtual address spaces that processes and that the kernel uses can be (relatively) arbitrary.

Notice that I said "virtual address spaces", plural: different processes and the kernel all have a different "view" on physical address space, which itself isn't linear. So, I'm not sure where that boundary would come from.

What happens if the kernel needs to use more than 1gb?

Allocate more than 1 GB.

At boot time, if there is no process, how is the kernel mapped?

At boot time, it's the kernel that enables (depending on the CPU architecture you're using) memory protection, and starts mapping its own memory space. It actively randomizes that mapping – KASLR.

I'm not sure why you think anything is special about 1 GB. It isn't! The kernel maps its memory as needed.

Are you perhaps referring to a limitation of the nearly-died out 32 bit i386 architecture? In earlier versions of Linux, there was, in the kernel address space, a constant mapping below PAGE_OFFSET (which IIRC was indeed at 1 GB?), above which userspace memory spaces might have been "mapped in".

So, whatever material you're learning this from: Needs to be updated, and is definitely predating https://en.wikipedia.org/wiki/Kernel_page-table_isolation .

11
  • KASLR and KPTI don’t have anything to do with the kernel/userspace address space split; they only affect where kernel data is mapped inside its part of the address space. Commented Dec 26, 2024 at 22:04
  • @StephenKitt agreed, nothing to do with the main topic of the question, but the sub-question here was "how is the kernel mapped", and I understood that as "how does the kernel-space mapping look like?", and that's randomized in KASLR / thinned out to the interfaces under KPTI. Commented Dec 26, 2024 at 22:18
  • For one, I think it's rather obvious that they're referring to the 3G/1G split on 32-bit systems, be it from times of yore or not. That split very much did exist and had consequences. (Though we might argue that how it worked belongs to retrocomputing.SE) In any case, as far as I understand, it's not true that a split would still not exist, as even on x86_64 user space address all have the most significant bit set to zero, while kernel addresses have the MSB set to one (or whatever the exact details are). Commented Dec 26, 2024 at 22:47
  • Also, AFAIK, the kernel is mapped into the upper part of the memory of each process, so it's also not exactly the case that different processes and the kernel all have a different view of the memory. One could say that the kernel has a separate view for each process, or, for a system without page-table isolation, the kernel doesn't even have a separate view, just the processes do. The isolated page tables also still contain the same mappings for the user-space part, so it's not like the kernel could just allocate any memory for itself just like that. Commented Dec 26, 2024 at 22:48
  • 1
    @StephenKitt I'd like to delete this answer, but then nobody would have answered frannco. Would it be possible for you, ilkkachu or Jörg to write a short answer? Commented Dec 27, 2024 at 10:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.