Linux slob Memory Management Analysis

Source: Internet
Author: User

The slob allocation object size is selected from the three links.

Static list_head (free_slob_small );

Static list_head (free_slob_medium );

Static list_head (free_slob_large );

 

For objects smaller than 256 bytes, slob will be searched from the free_slob_small linked list for allocation;

For objects smaller than 1024 bytes, slob will be searched from the free_slob_medium linked list for allocation;

For objects larger than 1024 bytes, slob will be searched from the free_slob_large linked list for allocation;

Objects larger than page_size will be allocated directly through the partner system without slob allocation;

There are only three linked lists in total. How can I manage idle objects in the cache of the slob distributor? In fact, the so-called cache of different categories is only a pseudo cache, because they do not have their own memory. When you create a cache in the slob distributor, it only declares the size and size of the cached object, align, and so on. When you want to allocate an object from the cache, the corresponding linked list will be located based on the size to seek allocation. Therefore, the dedicated cache allocation object (kmem_cache_alloc () and the common cache allocation object (kmalloc () are not much different. Their objects come from these three linked lists, but these interfaces are retained by the kernel. As you can imagine, struct
The structure of kmem_cache is concise in the slob distributor.

 

1.
Struct kmem_cache {

2.
UnsignedIntSize, align; // object size, align Value

3.
UnsignedLongFlags; // attribute ID

4.
ConstChar* Name; // cache name

5.
Void (* ctor) (void *); // constructor used to allocate objects

6.
};

In a slob distributor, a slob always occupies the size of a page box. Therefore, objects larger than page_size are allocated directly through the partner system.

The slob distributor packs the variables describing the slob into a structure and returns the string with the page descriptor struct.
Page together to form a consortium, so that you can directly use the space occupied by the page descriptor to fill irrelevant fields in the page descriptor into valid description fields of slob, this saves a lot of memory!

1.
Struct slob_page {

2.
Union {

3.
Struct {

4.
UnsignedLongFlags;/* fill, in order not to overwrite page-> flags */

5.
Atomic_t _ count;/* fill, in order not to overwrite page-> _ count */

6.
Slobidx_t units;/* Number of idle slob units */

7.
UnsignedLongPad [2];

8.
Slob_t * free;/* points to the first idle block */

9.
Struct list_head list;/* used to link the slob global linked list */

10.
};

11.
Struct page;

12.
};

13.
};

 

1.
# If page_size <= (32767*2)

2.
Typedef S16 slobidx_t;

3.
# Else

4.
Typedef s32 slobidx_t;

5.
# Endif

 

 

For different types of blocks, the management data is also slightly different:

For idle common blocks (the number of occupied units is greater than 1), the first unit is used to fill the block size, and the second unit is used to fill in the offset of the next idle block.

For small idle blocks (only one unit is occupied), the Unit is filled with the opposite number of offsets of the next idle object, that is, a negative number.

For allocated blocks, the first unit is used to fill the block size.

 

 

 

 

 

 

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.