Mm_count vs mm_users of Linux Process address space

Source: Internet
Author: User

First, reference the ulk's explanation above:

The mm_users field stores the number of lightweight processes that share the mm_struct data structure (see the section "the clone (), fork (), and vfork () system CILS "in Chapter 3 ). the mm_count field is the main usage counter of the memory descriptor;
All "users" in mm_users count as one unit in mm_count. every time the mm_count field is decreased, the kernel checks whether it becomes zero; if so, the memory descriptor is deallocated because it is no longer in use.

We'll try to explain the difference between the use of mm_users and mm_count with an example. consider a memory descriptor shared by two lightweight processes. normally, its mm_users field stores the value 2, while its mm_count field stores the value 1 (both
Owner processes count as one ).

If the memory descriptor is temporarily lent to a kernel thread (see the next section), the kernel increases the mm_count field. in this way, even if both lightweight processes die and the mm_users field becomes zero, the memory descriptor is not released
The kernel thread finishes using it because the mm_count field remains greater than zero.

If the kernel wants to be sure that the memory descriptor is not released in the middle of a lengthy operation, it might increase the mm_users field instead of mm_count (this is what the try_to_unuse () function does; see the section "activating and deactivating
A swap area "in chapter 17). The final result is the same because the increment of mm_users ensures that mm_count does not become zero even if all lightweight processes that own the memory descriptor die.

The mm_alloc () function is invoked to get a new memory descriptor. because these descriptors are stored in a Slab allocator cache, mm_alloc () CILS kmem_cache_alloc (), initializes the new memory descriptor, and sets the mm_count and mm_users field to 1.

Conversely, the matrix () function decreases the mm_users field of a memory descriptor. if that field becomes 0, the function releases the Local Descriptor Table, the memory region Descriptors (see later in this chapter), and the page tables referenced by
Memory descriptor, and then invokes mmdrop (). The latter function decreases mm_count and, if it becomes zero, releases the mm_struct data structure.

 

In short

Mm_count indicates the reference to mm, while mm_users indicates the reference to mm-related resources, which has two levels. Mm_count is similar to process. Mm_users is similar to threads.

The kernel thread will borrow the mm_struct of other processes during runtime. Such a thread is called "Anonymous Users ",
Because they do not care about the user space that mm_struct points to, and will not access this user space. They just borrow it temporarily.
Mm_count records such threads.

Mm_users is the count of all processes that share the user space pointed to by mm_struct.
That is to say, multiple processes will share the same user space.

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.