Linux Process Space

Source: Internet
Author: User

Virtual Memory ---

The Linux operating system uses the virtual memory management technology, so that each process has an independent process address space, which is 3 GB in size. Users can see and access virtual addresses, the actual physical address cannot be seen. Using this virtual address not only protects the operating system, but more importantly, the user program can use a larger address space than the actual physical memory.

 

Linux divides 4G virtual address space into two parts: user space and kernel space. The user space ranges from 0 to 0 xbfffff, and the kernel space ranges from 3g----4G. Generally, a user process can only access the virtual address of the user space and cannot access the kernel space. The exception is that the user process accesses the kernel space through system calls.

 

Process space ----

The user space corresponds to the process, so every time the process is switched, the user space will change.

The user space of each process is completely independent and irrelevant. Run the same program 10 times at the same time. The linear addresses used by the 10 processes are the same. CAT/proc/<pid> maps

Create a process fork (), load the program into execve (), and allocate the dynamic memory to processes such as malloc. At this time, the process does not apply for and obtain physical addresses, but virtual addresses.

The actual physical memory only when the process actually accesses the newly obtained virtual address will the page requesting mechanism generate a page missing exception, thus entering the program for allocating the actual page box. This exception is the basic guarantee for the existence of the virtual memory mechanism ------ it will tell the kernel to allocate physical pages to the process and create the corresponding page table, after that, the virtual address is mapped to the physical address.

In applications, common malloc functions are used for dynamic memory allocation. in linux kernels, kmalloc is usually used for dynamic memory allocation.

# Include <Linux/slab. h>

Void * kmalloc (size_t size, int flags)

Size -- memory size to be allocated

Flags -- the allocation flag, which controls the behavior of kmalloc.

Most
The common identifier is gfp_kernel. It means that the memory allocation is called by processes running in the kernel state. That is to say, the function that calls it belongs to a process. When idle memory is too small
The kmalloc function causes the current process to sleep and waits for idle pages to appear. If kmalloc is called outside the process context, such as interrupt processing, task queue processing, and kernel timing
Processing. These conditions are in the interrupt context and cannot enter sleep. In this case, the priority gfp_atomic should be used.

Gfp_atomic-allocate memory in code outside the process context and never sleep.

Gfp_kernel: the allocation in the process context, which may cause sleep. (16m---896m)

_ Gfp_dma ----- indicates that the memory zone that can be DMA is allocated (the physical address is within 16 MB of the page frame)

_ Gfp_highmem ---- indicates that the allocated memory is located in the high-end memory (more than MB)

Original article: http://blog.csdn.net/lidaqiang99/article/details/6624946

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.