In Linux, pages of physical memory belong to the kernel data segment, with the possibility of replacement or not?

I ask, because I remember that all physical pages belong to the kernel, are locked in memory and therefore cannot be exchanged, for example, what is said here: http://www.cse.psu.edu/~axs53/spring01/linux /memory.ppt

However, I am reading a research article and feel confused as it says: "(physical) pages often move between the kernel data segment and user space."

It also mentions that, in contrast, physical pages do not move between the kernel code segment and user space.

I think that if a physical page sometimes belongs to a kernel data segment and sometimes belongs to user space, this should mean that physical pages belong to a kernel data segment that can be replaced, which contradicts my current understanding.

So, physical pages belong to the kernel data segment, which can be changed? unswappable?

PS Research work is available here: https://www.cs.cmu.edu/~arvinds/pubs/secvisor.pdf

Please search for "move between" and you will find it.

PS again, the virtual memory area from [3G + 896M] to 4G belongs to the kernel and is used to display physical pages in ZONE_HIGHMEM (32-bit x86 installation, 3G + 1G installation). In this case, the kernel can first map some virtual pages in this area to physical pages that host the current table of process pages, change some entries in the page table, and untie the virtual pages. Thus, physical pages can sometimes belong to the kernel and sometimes belong to user space because they do not belong to the kernel after they are expanded and thus become removable. This is the reason?

+6
source share
3 answers

tl; dr - memory pools and swapping are different concepts. You cannot draw any conclusions from one another.


kmalloc() and another kernel data distribution comes from slab / slub, etc. The same place that the kernel receives data for user space. Ergo pages often move between the kernel data segment and user space. It's right. He does not say anything about swapping. This is a separate issue, and you cannot deduce anything.

Kernel code is usually populated at boot time and is read-only and never changes after that. Ergo physical pages do not move between the kernel code segment and user space.

Why do you think that something comes from the same pool, is it the same? Network sockets also come from the same memory pool. This is a concern. Linux mm (memory management system) handles the swap. The page can be pinned (not exchangeable). Checking the kernel static memory (it can be .bss and .data) is a simple range check. Typically, memory is pinned and marked indispensable at the linux-mm level. User data (allocation of resources from the same pool) can be marked as replaceable linux-mm. For example, even without a swap, user space text is still available for replacement because it is supported by the index. Caching is much easier for read-only data. If data is exchanged, it is marked as such in the MMU tables, and the error handler must distinguish between swap and SIGBUS ; which is part of linux-mm.

There are also Linux versions with no-mm (or no MMU), and they never change. Theoretically, someone can exchange kernel data; but why is it in the core? The Linux path would be to use the module and load them as needed. Of course, linux-mm data is kernel data and hopefully you can see the problem of replacing this.

The problem with such conceptual questions,

  • It may differ from Linux versions.
  • It may differ from Linux configurations.
  • Tip may change as Linux evolves.

Surely, linux-mm code cannot be replaced, nor an interrupt handler. It is possible that at some point in time, the kernel code and / or data may be replaced. I do not think that this is ever in the current case outside of the module loading / unloading (and it is rather pedantic / esoteric as to whether you call this replacement or not).

+4
source

However, I am reading a research article and am embarrassed as it says: "(physical) pages often move between the kernel data segment and user space."

Could you give a link to this research papaer ?

As far as I know (only from UNIX lectures and laboratories at school), pages for kernel space have been allocated for the kernel, with a simple fixed mapping algorithm, and they are all fixed. After the kernel turns on search mode (operation of bits CR0 and CR3 for x86), there will be the first user-mode process, and the pages that were allocated to the kernel will not be in the available set of pages for user space.

0
source

I think that if a physical page sometimes belongs to a kernel data segment and sometimes belongs to user space, this should mean that physical pages belong to a kernel data segment that can be replaced, which contradicts my current understanding.

There is no connection between changing memory and moving a page between user space and kernel space. whether the page can be exchanged or not depends entirely on whether it is fixed or not. Attached pages do not change places, so their display is considered permanent.

So, physical pages belong to the kernel data segment, which can be changed? unswappable?

The pages used by the kernel are usually used, and therefore they cannot be replaceable.

0
source

Source: https://habr.com/ru/post/985480/


All Articles