CN110209489B - Memory management method and device suitable for memory page structure - Google Patents

Memory management method and device suitable for memory page structure Download PDF

Info

Publication number
CN110209489B
CN110209489B CN201810169210.1A CN201810169210A CN110209489B CN 110209489 B CN110209489 B CN 110209489B CN 201810169210 A CN201810169210 A CN 201810169210A CN 110209489 B CN110209489 B CN 110209489B
Authority
CN
China
Prior art keywords
memory
page
composite
pages
slab
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810169210.1A
Other languages
Chinese (zh)
Other versions
CN110209489A (en
Inventor
陈闯
李树龙
张炎泼
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guizhou Baishancloud Technology Co Ltd
Original Assignee
Guizhou Baishancloud Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guizhou Baishancloud Technology Co Ltd filed Critical Guizhou Baishancloud Technology Co Ltd
Priority to CN201810169210.1A priority Critical patent/CN110209489B/en
Publication of CN110209489A publication Critical patent/CN110209489A/en
Application granted granted Critical
Publication of CN110209489B publication Critical patent/CN110209489B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The invention discloses a memory management method suitable for a memory page structure, which comprises the following steps: constructing various composite pages respectively comprising one memory page and a plurality of continuous memory pages with different quantities; memory pages are managed based on a variety of compound pages. The disclosed method can reduce fragmented pages caused by memory page allocation, simplify memory page management operation, and improve memory page management efficiency.

Description

Memory management method and device suitable for memory page structure
Technical Field
The present invention relates to computer systems, and more particularly, to a memory management method and apparatus for a memory page structure.
Background
The memory capacity of a computer system is usually limited, and many computer applications can run on the same computer system, and in order to ensure that different computer applications use the system memory efficiently, the system memory needs to be managed effectively, which is a key technology in the field of computers.
Most computer systems currently employ a dual-layer memory management structure to manage the system memory. As shown in fig. 1, the page allocator 101 is a first-level memory management structure that generally manages system memory in basic units of memory pages (memory blocks with a storage capacity of 4 kbytes), thereby allocating a dedicated cache for applications such as file systems/drivers (this relationship is shown in fig. 1 in the form of an arrow 105). The slab allocator 103 is a second layer memory management structure, and typically further manages (this relationship is shown in the form of an arrow 111 in fig. 1) the system memory that contains one or more continuous memory pages and is allocated by the page allocator 101, with chunk blocks (e.g., memory blocks with storage capacity of 8 bytes, 16 bytes, etc.) that are smaller than the size of the memory pages and are contained in the slab structure as a basic unit, so as to allocate a dedicated cache (this relationship is shown in the form of an arrow 109 in fig. 1) for an application such as a network layer/application layer program; furthermore, when objects in the file system/driver need to be allocated and freed based on chunk blocks, the memory may also be managed by the slab allocator 103 instead of the page allocator 101 (this relationship is shown in fig. 1 in the form of arrow 107). The memory allocation granularity of the slab allocator 103 is finer, and the introduction of the slab allocator effectively avoids the problem of memory waste caused by allocating memory blocks with the size less than or equal to 0.5 memory pages.
However, in the prior art (e.g., linux operating system), the memory space allocated by the page allocator 101 (including the slab memory space) can only be 2 in generaln(0. ltoreq. n. ltoreq.11, i.e. at most 12 cases) contiguous memory pages. Therefore, the linux kernel needs to maintain 12 linked lists, and each linked list records information of one continuous idle page, that is, each item in the first linked list is 1 idle page, each item in the second linked list is 2 continuous idle pages, each item in the third linked list is 4 continuous idle pages, and so on. When memory pages need to be allocated for the application program, removing idle pages from the corresponding linked list; and when the memory pages are released, returning the corresponding memory pages to the corresponding linked list.
In this case, the allocation includes a non-2nThe process of memory space of one continuous memory page (e.g., an odd number of continuous memory pages greater than 1) is accompanied by splitting of the memory page, and memory waste caused by memory page allocation is caused. For example, if 65 contiguous memory pages are to be allocated, they can only be allocated from a linked list of 128 contiguous free pages. The remaining 63 memory pages are split and then placed into different linked lists (corresponding to 6 linked lists with n being 0-5), which is relatively complicated. Moreover, if such memory space is frequently applied, many fragmented pages (at least including 1 free page, that is, n is 0) may be generated.
Similarly, after releasing such memory space, it is further determined whether each of the smaller memory blocks obtained through splitting is idle, and only when all of the smaller memory blocks obtained through splitting are idle, the entire large memory block that is originally split (for example, the whole large memory block that includes 128 consecutive idle pages) can be released. The memory management method for the memory page structure in the prior art is also complicated to operate when the unused memory is released.
Therefore, at least in order to solve the above technical problems, a new technical solution needs to be proposed.
Disclosure of Invention
The memory management method suitable for the memory page structure comprises the following steps:
constructing various composite pages respectively comprising one memory page and a plurality of continuous memory pages with different quantities;
memory pages are managed based on a variety of compound pages.
The memory management method according to the present invention further includes:
and constructing a red-black tree of the idle compound pages for managing the idle compound pages by taking the number of the memory pages contained in the idle compound pages as a key, and indexing the starting addresses of the idle compound pages based on the value of the key of the red-black tree of the idle compound pages.
According to the memory management method, a red-black tree node data structure is defined in a memory page data structure for managing memory pages to associate the memory pages with an idle composite page red-black tree, wherein the red-black tree node data structure comprises: a pointer to the left child node, a pointer to the right child node, a pointer to the parent red-black tree node, and a data field containing a key and a start address of the memory page data structure instance corresponding to the current red-black tree node.
According to the memory management method of the present invention, a plurality of composite pages respectively including one memory page and a plurality of consecutive memory pages of different numbers are constructed by defining the following variables in a memory page data structure for managing memory pages: the memory page type in the composite page, the number of the memory pages in the composite page, the state of the memory pages in the composite page, and the address of the memory pages in the composite page, wherein a variable of the memory page type in the composite page is used for identifying whether the memory page is a first page of the composite page, a variable of the memory page number in the composite page is used for identifying the number of the memory pages in the composite page, a variable of the memory page state in the composite page is used for identifying whether the memory page is already allocated, and a variable of the memory page address in the composite page is used for identifying a start address of the memory page.
According to the memory management method of the present invention, the number of the plurality of consecutive memory pages includes non-2nWherein n is 0 or more.
The memory management method according to the present invention further includes:
by defining a tab memory block node data structure in a memory page data structure for managing memory pages, associating a memory page with a fully allocated tab memory block linked list and a partially allocated tab memory block linked list managed by an upper-layer tab allocator, wherein the tab memory block node data structure includes: a pointer to a previous slab memory chunk node, a pointer to a subsequent slab memory chunk node, and a data field containing the starting address of the memory page data structure instance associated with the current slab memory chunk node.
According to the present invention, a memory management device suitable for a memory page structure includes:
the composite page constructing module is used for constructing various composite pages respectively comprising one memory page and a plurality of continuous memory pages with different quantities;
and the compound page management module is used for managing the memory pages based on various compound pages.
The memory management device according to the present invention further includes:
and the idle compound page management module is used for constructing an idle compound page red-black tree for managing various idle compound pages by taking the number of the memory pages contained in the various idle compound pages as a key word, and indexing the starting addresses of the various idle compound pages based on the numerical value of the key word of the idle compound page red-black tree.
According to the memory management device of the present invention, the composite page constructing module is further configured to define the following variables in the memory page data structure for managing the memory pages, so as to construct a plurality of composite pages respectively including one memory page and a plurality of consecutive memory pages of different numbers: the memory page type in the composite page, the number of the memory pages in the composite page, the state of the memory pages in the composite page, and the address of the memory pages in the composite page, wherein a variable of the memory page type in the composite page is used for identifying whether the memory page is a first page of the composite page, a variable of the memory page number in the composite page is used for identifying the number of the memory pages in the composite page, a variable of the memory page state in the composite page is used for identifying whether the memory page is already allocated, and a variable of the memory page address in the composite page is used for identifying a start address of the memory page.
The memory management device according to the present invention further includes:
a page and slab association module, configured to associate a memory page with a fully allocated slab linked list and a partially allocated slab linked list managed by an upper slab allocator by defining a slab node data structure in a memory page data structure for managing the memory page, where the slab node data structure includes: a pointer to a previous slab memory chunk node, a pointer to a subsequent slab memory chunk node, and a data field containing the starting address of the memory page data structure instance associated with the current slab memory chunk node.
According to the technical scheme of the invention, fragmented pages caused by memory page allocation can be reduced, the operation of memory page management is simplified, and the management efficiency of the memory pages is improved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the invention and together with the description, serve to explain the principles of the invention. In the drawings, like reference numerals are used to indicate like elements. The drawings in the following description are directed to some, but not all embodiments of the invention. For a person skilled in the art, other figures can be derived from these figures without inventive effort.
Fig. 1 schematically shows a diagram of a two-layer memory management structure of the prior art.
Fig. 2 exemplarily shows a schematic flow chart of a memory management method applicable to a memory page structure according to the present invention.
Fig. 3 schematically shows a free composite page red-black tree according to the present invention.
Fig. 4 exemplarily shows a schematic view of a compound page according to the present invention.
FIG. 5 is a diagram illustrating exemplary red and black tree operations involved in a compound page allocation process according to the present invention.
FIG. 6 is a diagram illustrating an example operation of a memory page data structure involved in a compound page allocation process according to the present invention.
FIG. 7 is a diagram illustrating an example operation of a memory page data structure involved in a compound page release process according to the present invention.
FIG. 8 is a diagram illustrating exemplary red and black tree operations involved in a compound page release process according to the present invention.
FIG. 9 is a diagram illustrating the use of a slab node instance according to the present invention to associate memory pages with two types of memory chunk linked lists managed by an upper-layer slab allocator.
Fig. 10 schematically shows a block diagram of a memory management device suitable for a memory page structure according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
Fig. 1 schematically shows a diagram of a two-layer memory management structure of the prior art.
As described in the background section, at least in order to optimize the memory page management of the page allocator 101, a new technical solution needs to be proposed to reduce fragmented pages caused by memory page allocation, simplify the operation of memory page allocation, and improve the management efficiency of memory pages.
Fig. 2 exemplarily shows a schematic flow chart of a memory management method applicable to a memory page structure according to the present invention.
As shown in the solid line box of fig. 2, the memory management method applied to the memory page structure includes:
step S202: constructing various composite pages respectively comprising one memory page and a plurality of continuous memory pages with different quantities;
step S204: memory pages are managed based on a variety of compound pages.
Optionally, as shown in the dashed line box of fig. 2, the memory management method further includes:
step S206: and constructing a red-black tree of the idle compound pages for managing the idle compound pages by taking the number of the memory pages contained in the idle compound pages as a key, and indexing the starting addresses of the idle compound pages based on the value of the key of the red-black tree of the idle compound pages.
For example, when there are a plurality of homogeneous free compound pages, a single linked list may be included in the data field of the nodes of the red-black tree of the free compound pages, and each node in the single linked list stores the start address of each free compound page in the homogeneous free compound pages.
Fig. 3 schematically shows a free composite page red-black tree according to the present invention.
As shown in fig. 3, the free compound page red-black tree (i.e., free _ pages _ tree) is used to organize the free compound pages according to the type of compound page (i.e., the number of included memory pages). All free compound pages are added to the free compound page red-black tree whose key (i.e., key) is the number of memory pages that each compound page instance contains.
Although FIG. 3 shows only 7 different instances of free compound pages containing 1-7 memory pages, respectively, instances of free compound pages containing other numbers of memory pages may be added as desired.
For example, only the first page of the free composite page (see below, page _ t instance identified by MASTER, identified by solid box in FIG. 3) may be added to the free composite page red-black tree. When memory page space needs to be allocated, there may be multiple compound page allocation methods, for example:
1) composite pages with proper sizes can be searched for allocation and deleted from the red and black trees of the idle composite pages; if the composite page with proper size cannot be searched for allocation, then the composite page with the space larger than that of the memory page needing to be allocated is searched for, the memory page space needing to be allocated is split out, the rest memory page spaces are combined into another idle composite page with smaller space, the idle composite page is added into the idle composite page red-black tree again according to the value of the key word of the idle composite page, and the split original idle composite page is deleted from the idle composite page red-black tree.
2) The splitting and allocating operations can also be performed by directly searching a compound page having a larger memory page space than that to be allocated.
Alternatively, when the methods 1) and 2) are adopted to select a compound page larger than the memory page space to be allocated, the principle of the closest size can be adopted. For example, take the example of allocating a compound page containing 3 memory pages: an idle composite page containing 4 memory pages can be searched first; if the idle composite page containing 4 memory pages does not exist, searching the idle composite page containing 5 memory pages; and so on.
For example, the compound page may be located in a shm space (not shown), which may be a configurable-size memory space, such as 256M bytes, applied using a mmap function, and includes respective instances of page _ t and respective memory page spaces corresponding to the respective instances of page _ t. For the details of the shm space (i.e., a continuous memory space), reference is made to the related description in the co-pending patent application "a method and apparatus for managing memory pages" of the same applicant.
For example, the following data structure page _ pool _ t may be used to associate the shm space with a free composite page red-black tree (i.e., free _ pages _ tree).
Figure BDA0001585335450000071
Wherein, the shm _ array [1024] variable is used to store starting addresses pointing to different continuous memory spaces (optionally, sequentially storing the starting addresses of the respective continuous memory spaces in an array from low to high or from high to low); the shm _ num variable is used for storing the number of the continuous memory spaces; the shm _ array _ lock is a mutex lock or a spin lock variable and is used for realizing shared read-write operation of different processes on the continuous memory space; the free _ pages _ tree corresponds to the free composite page red-black tree described above.
The free composite page red-black tree may be disposed in a separate memory space (e.g., a space where an instance of the above-mentioned pages _ pool _ t structure for managing memory pages) other than the memory space where the memory pages (i.e., the composite pages) are located, or may be disposed in the memory space where the memory pages are located.
Optionally, a spin lock variable (not shown) for managing the free compound page may also be set (for example, in the pages _ pool _ t structure), so as to protect the operations of inserting, deleting, and searching the red and black trees of the free compound page, avoid collision, and implement shared protection.
Optionally, the memory page and the free composite page red-black tree are associated by defining a red-black tree node data structure (refer to a tree _ node in page _ t) in a memory page data structure (e.g., a page _ t structure described below) for managing the memory page, wherein the red-black tree node data structure comprises: a pointer to the left child node, a pointer to the right child node, a pointer to the parent red-black tree node, and a data field containing a key and a start address of the memory page data structure instance corresponding to the current red-black tree node.
Optionally, the multiple composite pages respectively including one memory page and a different number of multiple consecutive memory pages are constructed by defining the following variables in a memory page data structure for managing the memory pages: the memory page type in the composite page, the number of the memory pages in the composite page, the state of the memory pages in the composite page, and the address of the memory pages in the composite page, wherein a variable of the memory page type in the composite page is used for identifying whether the memory page is a first page of the composite page, a variable of the memory page number in the composite page is used for identifying the number of the memory pages in the composite page, a variable of the memory page state in the composite page is used for identifying whether the memory page is already allocated, and a variable of the memory page address in the composite page is used for identifying a start address of the memory page.
For example, a memory page data structure (page _ t) for managing memory pages may be defined as follows:
Figure BDA0001585335450000081
where tree _ node is used to associate a FREE composite page red-black tree (FREE _ pages _ tree), list _ node is used to associate a fully allocated list of slots and a partially allocated list of memory blocks managed by an upper-level slot allocator (i.e., slot allocator 103 in fig. 1) (described in more detail below), shm _ start is used to identify the starting address of the shm space where page _ t is located, state (i.e., the memory page state variable in the composite page) is used to identify whether a memory page has been allocated (e.g., the memory page may be identified as FREE by a constant value FREE and the page has been allocated by a constant value a LL allocated), type (i.e., the memory page type variable in the composite page) is used to identify whether the memory page is the first page of the composite page (e.g., the memory page may be identified as the first page of the composite page by a constant value mask, the avpage is not identified as the first page of the composite page by a constant value S L e.), the number of pages in the composite page (i.e., the number of contiguous memory pages, i.e., the number of memory pages in the composite page structure [16] used in the composite page).
Optionally, the number of the plurality of consecutive memory pages comprises not 2nWherein n is 0 or more.
Fig. 4 exemplarily shows a schematic view of a compound page according to the present invention.
As shown in fig. 4, the composite page may combine 5, 3, and 2 consecutive memory pages (pages) into one large memory block, which is used to allocate memory containing multiple consecutive memory pages for the application (i.e., construct multiple composite pages respectively containing one memory page and different numbers of multiple consecutive memory pages).
Although not shown in fig. 4, even when allocating memory containing one memory page, allocation is performed on a compound page basis (containing only 1 memory page) (i.e., memory pages are managed on a plurality of compound pages).
The top graph in fig. 4 shows a schematic block diagram of 1 example of a first compound page (more precisely, its corresponding respective page _ t instance) containing 5 contiguous memory pages, in this example, the 5 memory pages contain 1 MASTER page and 4S L AVE pages, and are both FREE (both values of the state variable are FREE).
The bottom picture in fig. 4 shows a schematic diagram of 1 example of a second type of composite page that has been allocated (the values of the state variables are all a LL allocated) and contains 3 consecutive memory pages, and 1 example of a third type of composite page that has not been allocated (the values of the state variables are all FREE) and contains 2 consecutive memory pages.
FIG. 5 is a diagram illustrating exemplary red and black tree operations involved in a compound page allocation process according to the present invention.
As shown in fig. 5, the state of the red-black tree before the allocation of the composite pages is shown in the left half of fig. 5, and in this case, the red-black tree includes 1 fourth composite page (including 1 memory page), 1 third composite page (including 2 continuous memory pages) shown in fig. 4, and 1 first composite page (including 5 continuous memory pages) shown in fig. 4.
When 3 contiguous memory pages need to be allocated (as shown by the arrows in fig. 5), for example, 1 new second type composite page may be split from the 1 first type composite page (including 5 contiguous memory pages) shown in fig. 5 according to the composite page allocation method 1 described above, and used for subsequent allocation.
Therefore, the state of the red-black tree after splitting (note: not allocating) the composite page is as shown in the right half of fig. 5, and at this time, the 1 fourth composite page (containing 1 memory page) before splitting the composite page, the 1 third composite page (containing 2 contiguous memory pages) before splitting the composite page, and the 1 newly generated third composite page (which is shown as the dashed box in the right half of fig. 5 and is derived from the 1 first composite page before splitting the composite page and is added to the tail of the corresponding single linked list of the third free composite page) and the 1 newly generated second composite page (which is shown as the rightmost node in the right half of fig. 5 and is derived from the 1 first composite page before splitting the composite page) which are newly split and added to the red-black tree are still included.
Finally, the newly generated 1 second compound page can be allocated (this state is not shown).
Preferably, when the memory pages are allocated, the composite page designating the number of allocated memory pages is searched from the red-black tree. And if the tree node corresponding to the required idle composite page exists in the red-black tree, checking whether a single linked list instance exists in the tree node, and if the single linked list instance exists, indicating that the tree node corresponds to a plurality of idle composite pages with the same number of pages which can be distributed. One compound page can be fetched from the end of the singly linked list instance and allocated (e.g., the lowest 1 third compound page in the middle of the right half of fig. 5 can be allocated to an application that needs 2 memory pages).
The operation avoids taking out the idle compound page from the head of the chain table for allocation, and can not cause the corresponding tree node to be removed from the tree, and can not cause the red and black trees to change, thereby not influencing the allocation efficiency. That is, when the free memory pages are allocated from the tail of the linked list, only the corresponding linked list nodes need to be removed from the tail of the linked list, and the red and black trees do not need to be changed.
FIG. 6 is a diagram illustrating an example operation of a memory page data structure involved in a compound page allocation process according to the present invention.
As shown in fig. 6, corresponding to the composite page allocation process in fig. 5, 1 first composite page is split (as shown by the arrow in fig. 6) into 1 allocated second composite page (corresponding to the top 3 page _ t instances below the arrow) and 1 unallocated third composite page (corresponding to the bottom 2 page _ t instances below the arrow).
FIG. 7 is a diagram illustrating an example operation of a memory page data structure involved in a compound page release process according to the present invention.
As shown in fig. 7, the states of the page _ t instances before the composite page is released are shown in the upper half of fig. 7, and the memory pages corresponding to the 2 nd to 4 th page _ t instances are the second type of composite pages (including 3 consecutive memory pages) shown in fig. 4 allocated out.
After this one second compound page is released, the state of each page _ t instance is shown in the lower half of FIG. 7. Since the 6 memory pages are consecutive, the 6 memory pages can be merged into a new, free fifth composite page (containing 6 memory pages corresponding to the 6 page _ t instances shown in the lower half of fig. 7).
FIG. 8 is a diagram illustrating exemplary red and black tree operations involved in a compound page release process according to the present invention.
As shown in fig. 8, corresponding to the composite page release process shown in fig. 7, the state of the red-black tree before the memory page release is shown in the left half of fig. 8, in which case 2 fourth composite pages (including 1 memory page), 1 third composite page (including 2 continuous memory pages) shown in fig. 4, and 1 second composite page (including 3 continuous memory pages) shown in fig. 4 are included.
When 3 contiguous memory pages are released (as indicated by arrows in fig. 7), as shown in the upper half of fig. 7, 1 fourth composite page, 5 th composite page _ t instance, and 6 th composite page corresponding to the 1 st page _ t instance (as indicated by the 1 st light-colored dashed box in the left half of fig. 8) and the 1 third composite page corresponding to the 6 th page _ t instance (as indicated by the 2 nd light-colored dashed box in the left half of fig. 8) are combined with the newly released 3 contiguous memory pages to form the new, free fifth composite page (containing 6 contiguous memory pages) and added to the red-black tree.
Therefore, the state of the red-black tree after the composite page release is performed is shown in the right half of fig. 8, and at this time, 1 of the 2 fourth composite pages (including 1 memory page) before the composite page release, the 1 second composite page (including 3 consecutive memory pages) before the composite page release, and the newly combined fifth composite page (as shown by the light dashed box in the right half of fig. 8) that is newly added to the red-black tree are still included.
According to the above-described aspect of the present invention, for example, it is possible to manage memory page groups that are not supported by the related art, that is, it is possible to manage non-2nA consecutive memory page of values of (e.g., 3, 5, 6, 10, 12, 13, etc.). Thus, fragmented pages due to memory page allocation can be reduced.
In addition, the compound page supports the combination of continuous memory pages with various numerical values, so that the splitting operation required when the memory pages are allocated in the prior art is greatly simplified; moreover, for example, when releasing the memory pages, the memory pages having the partnership do not need to wait for the memory pages to be released first and then released after being combined, but the memory pages can be released directly, so that the operation of releasing the memory pages is also simplified.
In summary, the above technical solution simplifies the operation of memory page management and improves the management efficiency of the memory pages.
Optionally, as shown in the dashed line box of fig. 2, the memory management method further includes:
step S208: by defining a slab memory block node data structure (refer to the list _ node in the page _ t structure described above) in a memory page data structure for managing memory pages, associating a memory page with a fully allocated slab memory block linked list and a partially allocated slab memory block linked list managed by an upper slab allocator, where the slab memory block node data structure includes: a pointer to a previous slab memory chunk node, a pointer to a subsequent slab memory chunk node, and a data field containing the starting address of the memory page data structure instance associated with the current slab memory chunk node.
FIG. 9 is a diagram illustrating the use of a slab node instance according to the present invention to associate memory pages with two types of memory chunk linked lists managed by an upper-layer slab allocator.
As shown in fig. 9, the slab grouping structure (i.e., slab _ pool in fig. 9) includes members of a slab _ groups array (not shown) for grouping 9 different slab blocks of management 1-9 levels (i.e., slab groups in fig. 9) for allocating and releasing (i.e., managing) chunk sizes of chunk of 8 bytes, 16 bytes, 32 bytes, 64 bytes, 128 bytes, 256 bytes, 512 bytes, 1024 bytes, 2048 bytes, respectively. Taking the level 3 slab block (i.e., whose chunk _ size is 32 bytes) as an example, two queues (i.e., slab _ full and slab _ partial) are managed separately, and all related (i.e., corresponding to fully allocated slab and partially allocated slab blocks, respectively) memory pages in the slab _ full or slab _ partial are connected by a doubly linked list (i.e., a list node) in the page _ t type object. As shown in fig. 9, all chunk blocks contained in each slab block in the slabs _ full linked list have been allocated (i.e., all bits in bitmap are 1 and are indicated in dark gray). In contrast, only a portion of chunk blocks in each chunk block of the slabs _ partial list are allocated out (i.e., a portion of bits in the bitmap are 1 and are represented in light gray).
According to the above technical solution of the present invention, the upper slab distributor 103 can be conveniently used in combination, and compared with the prior art described in the background art, the problem of memory waste can be further reduced.
Fig. 10 schematically shows a block diagram of a memory management device 1000 adapted to a memory page structure according to the present invention.
As shown in the solid line box of fig. 10, the memory management device 1000 applied to the memory page structure includes:
a composite page constructing module 1001 configured to construct a plurality of composite pages each including one memory page and a plurality of consecutive memory pages of different numbers;
a compound page management module 1003, configured to manage the memory pages based on the multiple compound pages.
Optionally, as shown in the dashed line box of fig. 10, the memory management device 1000 further includes:
the idle composite page management module 1005 is configured to use the number of the memory pages included in the multiple idle composite pages as a key to construct an idle composite page red-black tree for managing the multiple idle composite pages, and index the start addresses of the multiple idle composite pages based on the values of the key of the idle composite page red-black tree.
Optionally, the composite page building module 1001 is further configured to build a plurality of composite pages respectively including one memory page and a different number of multiple consecutive memory pages by defining the following variables in a memory page data structure for managing the memory pages: the memory page type in the composite page, the number of the memory pages in the composite page, the state of the memory pages in the composite page, and the address of the memory pages in the composite page, wherein a variable of the memory page type in the composite page is used for identifying whether the memory page is a first page of the composite page, a variable of the memory page number in the composite page is used for identifying the number of the memory pages in the composite page, a variable of the memory page state in the composite page is used for identifying whether the memory page is already allocated, and a variable of the memory page address in the composite page is used for identifying a start address of the memory page.
Optionally, as shown in the dashed line box of fig. 10, the memory management device 1000 further includes:
a page and slab association module 1007, configured to associate a memory page with a fully allocated slab link table and a partially allocated slab link table managed by an upper slab allocator by defining a slab block node data structure in a memory page data structure for managing the memory page, where the slab block node data structure includes: a pointer to a previous slab memory chunk node, a pointer to a subsequent slab memory chunk node, and a data field containing the starting address of the memory page data structure instance associated with the current slab memory chunk node.
According to the technical scheme of the invention, fragmented pages caused by memory page allocation can be reduced, the operation of memory page management is simplified, and the management efficiency of the memory pages is improved.
The above-described aspects may be implemented individually or in various combinations, and such variations are within the scope of the present invention.
Finally, it should be noted that: the above examples are only for illustrating the technical solutions of the present invention, and are not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (8)

1. A memory management method suitable for a memory page structure is characterized by comprising the following steps:
constructing various composite pages respectively comprising one memory page and a plurality of continuous memory pages with different quantities;
managing memory pages based on the plurality of composite pages;
by defining a tab memory block node data structure in a memory page data structure for managing memory pages, associating a memory page with a fully allocated tab memory block linked list and a partially allocated tab memory block linked list managed by an upper-layer tab allocator, wherein the tab memory block node data structure includes: a pointer to a previous slab memory chunk node, a pointer to a subsequent slab memory chunk node, and a data field containing the starting address of the memory page data structure instance associated with the current slab memory chunk node.
2. The memory management method of claim 1, further comprising:
and constructing a free composite page red-black tree for managing the various free composite pages by taking the number of the memory pages contained in the various free composite pages as a key, and indexing the starting addresses of the various free composite pages based on the numerical values of the key of the free composite page red-black tree.
3. The memory management method of claim 2, wherein the memory page and the free composite page red-black tree are associated by defining a red-black tree node data structure in a memory page data structure for managing memory pages, wherein the red-black tree node data structure comprises: a pointer to the left child node, a pointer to the right child node, a pointer to the parent red-black tree node, and a data field containing a key and a start address of the memory page data structure instance corresponding to the current red-black tree node.
4. A memory management method according to claim 1 or 2, wherein a plurality of composite pages each comprising one memory page and a different number of a plurality of consecutive memory pages are constructed by defining the following variables in a memory page data structure for managing memory pages: the memory device comprises a memory page type in a composite page, a memory page number in the composite page, a memory page state in the composite page, and a memory page address in the composite page, wherein a memory page type variable in the composite page is used for identifying whether a memory page is a first page of the composite page, a memory page number variable in the composite page is used for identifying the number of memory pages in the composite page, a memory page state variable in the composite page is used for identifying whether the memory page is already allocated, and a memory page address variable in the composite page is used for identifying a start address of the memory page.
5. The memory management method according to claim 1 or 2, wherein the number of the plurality of consecutive memory pages comprises not 2nWherein n is 0 or more.
6. A memory management device adapted to a memory page structure, comprising:
the composite page constructing module is used for constructing various composite pages respectively comprising one memory page and a plurality of continuous memory pages with different quantities;
a compound page management module for managing memory pages based on the plurality of compound pages;
a slab association module, configured to associate, by defining a slab memory block node data structure in a memory page data structure for managing memory pages, a memory page with a fully allocated slab memory block linked list and a partially allocated slab memory block linked list managed by an upper-layer slab allocator, where the slab memory block node data structure includes: a pointer to a previous slab memory chunk node, a pointer to a subsequent slab memory chunk node, and a data field containing the starting address of the memory page data structure instance associated with the current slab memory chunk node.
7. The memory management device according to claim 6, further comprising:
and the idle composite page management module is used for constructing an idle composite page red-black tree for managing the various idle composite pages by taking the number of the memory pages contained in the various idle composite pages as a key, and indexing the starting addresses of the various idle composite pages based on the numerical values of the key of the idle composite page red-black tree.
8. The memory management device according to claim 6 or 7, wherein the composite page construction module is further configured to construct a plurality of composite pages respectively including one memory page and a different number of multiple consecutive memory pages by defining the following variables in a memory page data structure for managing the memory pages: the memory device comprises a memory page type in a composite page, a memory page number in the composite page, a memory page state in the composite page, and a memory page address in the composite page, wherein a memory page type variable in the composite page is used for identifying whether a memory page is a first page of the composite page, a memory page number variable in the composite page is used for identifying the number of memory pages in the composite page, a memory page state variable in the composite page is used for identifying whether the memory page is already allocated, and a memory page address variable in the composite page is used for identifying a start address of the memory page.
CN201810169210.1A 2018-02-28 2018-02-28 Memory management method and device suitable for memory page structure Active CN110209489B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810169210.1A CN110209489B (en) 2018-02-28 2018-02-28 Memory management method and device suitable for memory page structure

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810169210.1A CN110209489B (en) 2018-02-28 2018-02-28 Memory management method and device suitable for memory page structure

Publications (2)

Publication Number Publication Date
CN110209489A CN110209489A (en) 2019-09-06
CN110209489B true CN110209489B (en) 2020-07-31

Family

ID=67778731

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810169210.1A Active CN110209489B (en) 2018-02-28 2018-02-28 Memory management method and device suitable for memory page structure

Country Status (1)

Country Link
CN (1) CN110209489B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111490906B (en) * 2020-06-29 2020-09-25 武汉思普崚技术有限公司 Method and device for analyzing gateway equipment policy and readable storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102880555A (en) * 2012-07-28 2013-01-16 福州大学 Memory algorithm facing real-time system
CN103455433A (en) * 2013-08-19 2013-12-18 曙光信息产业股份有限公司 Memory management method and system

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101638061B1 (en) * 2009-10-27 2016-07-08 삼성전자주식회사 Flash memory system and flash defrag method thereof
CN103019884B (en) * 2012-11-21 2015-07-01 北京航空航天大学 Memory page de-weight method and memory page de-weight device based on virtual machine snapshot
CN103150259B (en) * 2013-03-22 2016-03-30 华为技术有限公司 A kind of method for recovering internal storage and device
US9612949B2 (en) * 2013-06-13 2017-04-04 Arm Limited Memory allocation in a multi-core processing system based on a threshold amount of memory
CN103593300B (en) * 2013-11-15 2017-05-03 浪潮电子信息产业股份有限公司 Memory allocating and collecting method
CN106294190B (en) * 2015-05-25 2020-10-16 中兴通讯股份有限公司 Storage space management method and device
CN105302738B (en) * 2015-12-09 2018-09-11 北京东土科技股份有限公司 A kind of memory allocation method and device
CN105930280B (en) * 2016-05-27 2019-07-05 诸葛晴凤 A kind of efficient page organization and management method towards Nonvolatile memory
CN106874348B (en) * 2016-12-26 2020-06-16 贵州白山云科技股份有限公司 File storage and index method and device and file reading method
CN107707616B (en) * 2017-08-21 2019-02-12 贵州白山云科技股份有限公司 A kind of data transmission method and system
CN107515788A (en) * 2017-08-31 2017-12-26 郑州云海信息技术有限公司 A kind of method and device of Memory Allocation
CN110209595A (en) * 2018-02-28 2019-09-06 贵州白山云科技股份有限公司 A kind of method and device for managing internal memory page

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102880555A (en) * 2012-07-28 2013-01-16 福州大学 Memory algorithm facing real-time system
CN103455433A (en) * 2013-08-19 2013-12-18 曙光信息产业股份有限公司 Memory management method and system

Also Published As

Publication number Publication date
CN110209489A (en) 2019-09-06

Similar Documents

Publication Publication Date Title
KR101367450B1 (en) Performing concurrent rehashing of a hash table for multithreaded applications
US10642515B2 (en) Data storage method, electronic device, and computer non-volatile storage medium
CN106294190B (en) Storage space management method and device
EP2488950B1 (en) A tiered data management method and system for high performance data monitoring
US11314689B2 (en) Method, apparatus, and computer program product for indexing a file
JP2008041108A (en) Efficient storage of object in file system
US11074179B2 (en) Managing objects stored in memory
WO2017050064A1 (en) Memory management method and device for shared memory database
US10649967B2 (en) Memory object pool use in a distributed index and query system
CN114327917A (en) Memory management method, computing device and readable storage medium
CN107844436B (en) Organization management method, system and storage system for dirty data in cache
WO2016138839A1 (en) Bitmap-based storage space management system and method thereof
CN115712500A (en) Memory release method, memory recovery method, memory release device, memory recovery device, computer equipment and storage medium
CN115168304A (en) Data processing method, device, storage medium and equipment
CN110209489B (en) Memory management method and device suitable for memory page structure
KR100907477B1 (en) Apparatus and method for managing index of data stored in flash memory
CN116662019B (en) Request distribution method and device, storage medium and electronic device
US20110099347A1 (en) Managing allocation and deallocation of storage for data objects
CN106537321B (en) Method, device and storage system for accessing file
CN112346848A (en) Method, device and terminal for managing memory pool
US10169250B2 (en) Method and apparatus method and apparatus for controlling access to a hash-based disk
CN115374127B (en) Data storage method and device
CN110209594B (en) Memory management method and device suitable for slab structure
US20220391317A1 (en) Systems, methods, and apparatus for wear-level aware memory allocation
JPH0484346A (en) Storing area managing device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant