An introduction to Linux Virtual Address Space Layout

(This is an introduction for the virtual address space layout I found in a web and there are also the other serious of operating system. And this is useful for those who are studying paging tech of operating system. For more information, you click at the following link:http://www.bottomupcs.com/virtual_memory_linux.html) Or another link:http://www.tldp.org/LDP/tlk/mm/memory.html But you have to keep in mind that the "VPFN" in the picture means "virtual page frame No."

1.Yet another comment from StackOverflow:

http://stackoverflow.com/questions/3552633/in-virtual-memory-can-two-different-processes-have-the-same-address

Theoretically every process executed by user in any present popular OSes(Win,linux,unix,Sol etc) are initially allowed to use the address range of 4gig ( 0x00000000 t0 0xffffffff on 32 bit platform),whether its a simple hello world program or its complex web container hosting stackoverflow site.It means every process has its range starting from the same start address and ending with the same address space VIRTUALLY. So obviously every process has that same virtual addresses in their respective virtual address space range. So answer for your first question is YES.

Difference comes when OS execute any process, modern OSes are multitasking OS and they run more then on process at any point of time.So accommodating 4gig of every process in the main memory is not feasible at all. So OSes using paging system,in which they divide the virtual address range (0x00000000 to 0xffffffff) into a page of 4k size(not always). So before starting the process it actually load the required pages which needed at the initial time to the main memory and then load the another virtual page ranges as required. So loading of virtual memory to physical memory (main memory) is called memory mapping. In this process you map the page's virtual address range to physical address range( like ox00000000 to ox00001000 virtaul address range to 0x00300000 to 0x00301000 physical address range)based on the slot free in the main memory.So at any point of time only one virtual address range will be mapped to that particular physical address range,so answer for your second question is NO.


2.Linux Specifics(http://www.bottomupcs.com/virtual_memory_linux.html)

Although the basic concepts of virtual memory remain constant, the specifics of implementations are highly dependent on the operating system and hardware.

Address Space Layout

Linux divides the available address space up into a shared kernel component and private user space addresses. This means that addresses in the kernel port of the address space map to the same physical memory for each process, whilst userspace addresses are private to the process. On Linux, the shared kernel space is at the very top of the available address space. On the most common processor, the 32 bit x86, this split happens at the 3GB point. As 32 bits can map a maximum of 4GB, this leaves the top 1GB for the shared kernel region[20].

Figure 6.5. Linux address space layout
The Linux address space layout. Note that pages in the userspace address space are private, whilst the kernel pages are shared.

Three Level Page Table

There are many different ways for an operating system to organise the page tables but Linux chooses to use a hierarchical system.

As the page tables use a heirarchy that is three levels deep, the Linux scheme is most commonly referred to as the three level page table. The three level page table has proven to be robust choice, although it is not without it's criticism. The details of the virtual memory implementation of each processor vary widley meaning that the generic page table Linux chooses must be portable and relatively generic.

The concept of the three level page table is not difficult. We already know that a virtual address consists of a page number and an offset in the physical memory page. In a three level page table, the virtual address is further split up into a number levels.

Each level is a page table of it's own right; i.e. it maps a page number of a physical page. In a single level page table the "level 1" entry would directly map to the physical frame. In the multilevel version each of the upper levels gives the address of the physical memory frame holding the next lower levels page table.

Figure 6.6. Linux Three Level Page Table
A three level page table

So a sample reference involves going to the top level page table, finding the physical frame that the next level address is on, reading that levels table and finding the physical frame that the next levels page table lives on, and so on.

At first, this model seems to be needlessly complex. The main reason this model is implemented is for size considerations. Imagine the theoretical situation of a process with only one single page mapped right near the end of it's virtual address space. We said before that the page table entry is found as an offset from the page table base register, so the page table needs to be a contiguous array in memory. So the single page near the end of the address space requires the entire array, which might take up considerable space (many, many physical pages of memory).

In a three level system, the first level is only one physical frame of memory. This maps to a second level, which is again only a single frame of memory, and again with the third. Consequently, the three level system reduces the number of pages required to only a fraction of those required for the single level system.

There are obvious disadvantages to the system. Looking up a single address takes more references, which can be expensive. Linux understands that this system may not be appropriate on many different types of processor, so each architecture can collapse the page table to have less levels easily (for example, the most common architecture, the x86, only uses a two level system in its implementation).


优化是指通过改进和改变策略、方法和资源的使用,使得某个系统或过程达到更好的性能、效率或质量。优化在各个领域都有应用,包括工程、经济、管理等。 优化的目标是找到最佳解决方案或最优解,以满足特定的约束条件和目标函数。在实际应用中,通过数学建模和算法求解的方法来解决优化问题。 优化问题通常包括以下几个要素:决策变量、目标函数和约束条件。决策变量是需要调整和优化的变量,目标函数是需要最大化或最小化的指标,而约束条件是限制决策变量的取值范围。 优化方法可以分为两大类:一是确定性优化方法,通过求解确定性数学模型来得到最优解;二是随机优化方法,通过随机抽样和模拟来进行优化。 确定性优化方法包括线性规划、非线性规划、整数规划等。线性规划适用于目标函数和约束条件都是线性关系的问题,非线性规划适用于一些目标函数和/或约束条件是非线性关系的问题,整数规划适用于决策变量为整数的问题。 随机优化方法包括模拟退火、遗传算法、粒子群算法等。这些方法并不要求求解确定性数学模型,而是通过模拟自然界的进化和优化过程来搜索最优解。 优化的应用非常广泛,例如生产调度、资源配置、物流路径规划等。通过优化,可以提高资源利用效率,降低成本,提升产品质量和服务水平。 总之,优化是一种通过改进方法和资源的使用,以达到更好性能和效率的过程。它在各个领域都有应用,可以通过确定性或随机的方法来解决优化问题。通过优化,可以达到更优的目标,提升系统的整体效益。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值