Search

CN-122019198-A - Memory block management method and controller

CN122019198ACN 122019198 ACN122019198 ACN 122019198ACN-122019198-A

Abstract

The application provides a memory block management method and a controller, which comprises the steps of obtaining a configuration file in a Linux kernel, analyzing the configuration file to obtain a memory size interval, determining the use state of memory blocks in the memory size interval, setting bit marks of the use state in marking bits corresponding to each memory block, judging whether the memory size of a target memory block of a current allocation request is in the memory size interval, judging whether a first idle linked list in a SLUB distributor is empty or not if the memory size interval is in the memory size interval, wherein the first idle linked list is used for storing marking bits of the memory blocks with the bits marked as idle, and if the first idle linked list is not in the memory size interval, sequentially selecting marking bits of the target memory block of the linked list from the first idle linked list of the SLUB distributor, and determining the target memory block according to the marking bits of the target memory block for the current allocation request. The application can solve the problems of overhigh occupation of memory block metadata and low allocation efficiency in SLUB allocators.

Inventors

  • LI FENG
  • ZHANG JIANRONG
  • MO QINGLIANG

Assignees

  • 联通数字科技有限公司

Dates

Publication Date
20260512
Application Date
20260414

Claims (10)

  1. 1. The memory block management method based on the Linux kernel SLUB distributor is characterized by comprising the following steps: acquiring a configuration file in a Linux kernel, analyzing the configuration file to obtain a memory size interval, determining the use state of memory blocks in the memory size interval, and setting bit marks of the use state in marking bits corresponding to each memory block; Judging whether the memory size of a target memory block of a current allocation request is in the memory size interval, if so, judging whether a first idle linked list in a SLUB distributor is empty, wherein the first idle linked list is used for storing the marking bit of the memory block with the marking bit being empty; if not, sequentially selecting the marking bits of the target memory blocks of the linked list from the first idle linked list of the SLUB distributor, and determining the target memory blocks according to the marking bits of the target memory blocks for the current distribution request.
  2. 2. The memory block management method according to claim 1, wherein the setting the bit flag of the use state in the flag bit corresponding to each memory block comprises: And defining unsigned char-type state mark arrays, wherein addresses of the state mark arrays point to idle fields in a struct page data structure, each element of the state mark arrays is used as a bit mark, and each bit mark shows that the use state of a memory block is idle or occupied.
  3. 3. The memory block management method according to claim 1, further comprising, before acquiring the configuration file in the Linux kernel: writing the minimum memory capacity and the maximum memory capacity into a configuration file in the Linux kernel to configure the memory size interval.
  4. 4. The memory block management method according to claim 2, further comprising: When the memory block is released, judging whether the memory size of the currently released memory block is in the memory size interval or not; If the memory size interval is in the memory size interval, releasing the memory block and modifying the bit mark corresponding to the released memory block into idle; And inserting a marking bit corresponding to the memory block with the bit marking changed into the idle memory block into the tail part of the first idle linked list of the SLUB distributor.
  5. 5. The memory block management method according to claim 4, wherein the releasing the memory block and modifying the bit flag corresponding to the released memory block to be free comprises: Determining corresponding element sequence numbers in the state marker array according to the position sequence of the currently released memory blocks in all the memory blocks in the memory size interval; determining binary digits corresponding to the element sequence numbers in the idle field; and setting the bit mark in the binary bit as a binary number corresponding to the use state of which is idle.
  6. 6. The memory block management method according to claim 4, further comprising, before modifying the bit flag corresponding to the released memory block to be idle: Judging whether the use states of a preamble bit mark and a postamble bit mark adjacent to the bit mark of the currently released memory block are idle or not according to the bit mark of the currently released memory block in the SLUB distributor; And if the memory blocks are idle, releasing the memory blocks and modifying bit marks corresponding to the released memory blocks into idle, wherein the step of inserting mark bits corresponding to the memory blocks with the bit marks changed into idle into the tail part of a first idle linked list of the SLUB distributor comprises the following steps: And merging the current released memory block, the preamble bit marks and the memory blocks of the subsequent memory block into continuous memory blocks, updating the bit marks of the continuous memory blocks through one instruction, and inserting the mark bits of the continuous memory blocks to the tail part of the idle linked list at one time.
  7. 7. The memory block management method according to claim 6, further comprising, before modifying the bit flag corresponding to the released memory block to be idle: Determining whether the physical address of the currently released memory block has a memory block with an idle use state adjacent to the physical address of the currently released memory block; If so, merging the current memory block and the adjacent memory block into a new memory block, and determining and modifying the bit mark of the new memory block; And judging whether the new memory block exceeds the range of the memory size interval, if so, inserting the marking bit of the new memory block into a preset second idle linked list.
  8. 8. The memory block management method according to claim 1, further comprising: if the first free linked list in SLUB allocator is empty, then memory blocks are selected from the global free linked list for the current allocation request.
  9. 9. The memory block management method according to claim 7, further comprising: if the memory size of the target memory block of the current allocation request exceeds the memory size interval and is smaller than the theoretical maximum memory block capacity of the second idle linked list, judging whether the second idle linked list in the SLUB allocator is empty or not; if not, sequentially selecting the marking bits of the target memory block from the second idle linked list of the SLUB distributor, and determining the target memory block according to the marking bits of the target memory block for the current distribution request; If the second free linked list in SLUB allocator is empty, then memory blocks are selected from the global free linked list for the current allocation request.
  10. 10. A controller, the controller comprising: The information acquisition module is used for acquiring a configuration file in the Linux kernel, analyzing the configuration file to obtain a memory size interval, determining the use state of memory blocks in the memory size interval, and setting bit marks of the use state in marking bits corresponding to each memory block; The matching judging module is used for judging whether the memory size of the target memory block of the current allocation request is in the memory size interval, if so, judging whether a first idle linked list in the SLUB distributor is empty, wherein the first idle linked list is used for storing the marking bit of the memory block with the marking bit being empty; And the request processing module is used for sequentially selecting the marking bits of the target memory blocks of the linked list from the first idle linked list of the SLUB distributor if not, and determining the target memory blocks according to the marking bits of the target memory blocks for the current distribution request.

Description

Memory block management method and controller Technical Field The invention belongs to the technical field of Linux kernel memory management, and particularly relates to a memory block management method and a controller. Background While the design of the existing SLUB allocator simplifies the queue structure and metadata management of the traditional SLAB allocator, in the management scenario of small memory blocks (especially high-frequency small objects of 16 bytes-256 bytes), there are two outstanding problems that firstly, metadata occupation is high, SLUB allocator records the number of allocated objects in each SLAB through inuse field of struct page data structure, the field is short unsigned int type (occupies 2 bytes), for a large number of small memory blocks, only inuse field occupies more memory resources, and in embedded devices with limited memory resources, metadata redundancy can further squeeze available memory space. Secondly, the memory block allocation management efficiency is low because the applicable memory block needs to be globally searched for the memory block allocation request at present. At present, the optimization scheme aiming at Linux kernel memory management is mostly concentrated on large-scale modification such as large-page memory optimization and partner algorithm reconstruction, has huge functions and complex modification quantity, needs to modify a plurality of kernel modules of the kernel, is difficult to ensure compatibility and stability, and cannot adapt to scenes such as embedded type, internet of things and the like with limited memory resources and sensitivity to kernel modification quantity. Aiming at the local optimization scheme of SLUB distributor small memory block management, an effective technical means is not available, and the problems of metadata redundancy and low memory block management efficiency can be solved while the compatibility of the original framework of the kernel is not affected. Disclosure of Invention The embodiment of the invention provides a memory block management method and a controller, which aim to solve the problems of excessively high occupation and low distribution efficiency of memory block metadata of a preset memory size interval in a SLUB distributor under the condition of not affecting the original framework of a kernel. The invention discloses a memory block management method based on a Linux kernel SLUB distributor, which comprises the following steps: acquiring a configuration file in a Linux kernel, analyzing the configuration file to obtain a memory size interval, determining the use state of memory blocks in the memory size interval, and setting bit marks of the use state in marking bits corresponding to each memory block; Judging whether the memory size of a target memory block of a current allocation request is in the memory size interval, if so, judging whether a first idle linked list in a SLUB distributor is empty, wherein the first idle linked list is used for storing the marking bit of the memory block with the marking bit being empty; if not, sequentially selecting the marking bits of the target memory blocks of the linked list from the first idle linked list of the SLUB distributor, and determining the target memory blocks according to the marking bits of the target memory blocks for the current distribution request. Optionally, the setting the bit flag of the use state in the flag bit corresponding to each memory block includes: And defining unsigned char-type state mark arrays, wherein addresses of the state mark arrays point to idle fields in a struct page data structure, each element of the state mark arrays is used as a bit mark, and each bit mark shows that the use state of a memory block is idle or occupied. Optionally, before acquiring the configuration file in the Linux kernel: writing the minimum memory capacity and the maximum memory capacity into a configuration file in the Linux kernel to configure the memory size interval. Optionally, the method further comprises: When the memory block is released, judging whether the memory size of the currently released memory block is in the memory size interval or not; If the memory size interval is in the memory size interval, releasing the memory block and modifying the bit mark corresponding to the released memory block into idle; And inserting a marking bit corresponding to the memory block with the bit marking changed into the idle memory block into the tail part of the first idle linked list of the SLUB distributor. Optionally, the releasing the memory block and modifying the bit flag corresponding to the released memory block to be idle includes: Determining corresponding element sequence numbers in the state marker array according to the position sequence of the currently released memory blocks in all the memory blocks in the memory size interval; determining binary digits corresponding to the element sequence numbers in the idle field; and setting