WO2007109920A1 - Procédé de construction et d'utilisation d'un pool de mémoire - Google Patents

Procédé de construction et d'utilisation d'un pool de mémoire Download PDF

Info

Publication number
WO2007109920A1
WO2007109920A1 PCT/CN2006/000515 CN2006000515W WO2007109920A1 WO 2007109920 A1 WO2007109920 A1 WO 2007109920A1 CN 2006000515 W CN2006000515 W CN 2006000515W WO 2007109920 A1 WO2007109920 A1 WO 2007109920A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
memory block
free
block
pool
Prior art date
Application number
PCT/CN2006/000515
Other languages
English (en)
Chinese (zh)
Inventor
Chuan Ye
Xinghua Li
Yuanqing Shi
Original Assignee
Zte Corporation
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 Zte Corporation filed Critical Zte Corporation
Priority to PCT/CN2006/000515 priority Critical patent/WO2007109920A1/fr
Publication of WO2007109920A1 publication Critical patent/WO2007109920A1/fr

Links

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/04Addressing variable-length words or parts of words

Definitions

  • the present invention relates to memory pool construction and methods of use. Background technique
  • the current software system requires less memory copying, less memory loss and leakage, memory management and use to be more versatile, reduce software system development difficulty and development cost, and improve the efficiency and stability of the software system.
  • the Chinese patent publication CN03148892 proposes a memory management method in which a memory pool is created by an application, a memory pool is divided into a control domain for storing control information, a memory block storage area for placing data, and a usage state of each memory is indicated.
  • a chain of tokens that can be indexed by a memory block.
  • the application requests, returns, and modifies the information in the memory usage token chain from the memory pool based on the control information in the memory pool control domain.
  • This patent has a simple organization of the memory pool, and the structure of the memory block is single, which is likely to cause performance problems when the application uses the memory block.
  • the Chinese patent with the publication number CN02151120 also proposes a method of memory management.
  • the memory management method proposed by the patent includes the following steps:
  • Patent A does not mention the organization of the memory pool and how the application uses the memory block. It only describes the header information of the memory block and the construction of the data area. And when the method needs to increase the header information, the pointer is moved forward in the free area to increase the length of the header information, and then the header information is added. This invisibly reduces the available space in the data area, and the application may cause an exception such as memory out of bounds when using the memory block. Summary of the invention
  • the problem to be solved by the present invention is to propose a construction and use method of a memory pool to simplify memory management and avoid memory leaks and memory clutter.
  • the present invention provides a method of constructing and using a memory pool, including the following steps:
  • each memory pool includes one or more memory blocks of the same size, each memory pool has a management structure, and the memory blocks in the memory pool are saved and used.
  • Situation information and address information of the free memory block each memory block is divided into a data body and a memory header for marking the usage of the memory block;
  • the memory management module After receiving the memory request, uses the requested memory size plus the memory header size as the minimum memory block size to be allocated, and selects a memory pool that satisfies the requirements;
  • the memory management module receives the memory release request, indicating the memory block pointer to the data body to be returned, and biasing the pointer After shifting the length of a memory header, find the corresponding memory header;
  • the usage flag in the memory header is changed to idle, and the memory block usage information and the free memory block address information in the memory pool management structure to which the memory block belongs are updated, and the release ends.
  • the foregoing method may further have the following features: the free memory block in each memory pool adopts a queue structure of a unidirectional linked list or a doubly linked list, and the memory header of the free memory block records the memory of the next free memory block in the queue.
  • step (c) the free memory in the management structure is The free memory block pointed to by the block queue head pointer is allocated, and after the allocation, the free memory block queue head pointer is changed to the memory head of the next free memory block in the queue; when (f) the memory is released, the The free memory block queue tail pointer in the management structure is changed to point to the memory header of the newly added free memory block, and the last free memory block in the original queue is linked with the newly added free memory block.
  • the memory block size in each memory pool is 2 n bytes, and n is a positive integer.
  • the management structure of each memory pool is set in a specified area of the memory.
  • the foregoing method may further have the following features: in the step (b), selecting a memory in which the memory block is the smallest from a memory pool whose memory block size is larger than the minimum memory size to be allocated according to the minimum memory size to be allocated. If the pool is not selected, the application fails and ends.
  • the memory pool management structure further stores information about the number of reserved memory blocks, and the number of free memory blocks in the step (c) is greater than the number of reserved memory blocks. , it means there are free memory blocks that can be allocated. Otherwise, there are no free memory blocks available for allocation. .
  • the foregoing method may further have the following features: the step (e) further checks the validity of the memory block pointer to be returned, and after the memory pointer is offset by the length of the memory header, if the pointer is in the If the memory block to be returned is within the memory pool range, it is legal. Otherwise, it is illegal, and the error message is returned.
  • the foregoing method may further have the following features: In the process of applying for or releasing the memory, before the operation of the memory pool management structure or the memory block, the semaphore protection is added, and after the operation, the semaphore protection is released. .
  • the memory head is further configured to store information about a process or task that requests or returns a memory block in which the memory head is located.
  • the above method may further have the following features: In the step (f), first determining whether the usage flag in the memory header indicates that the memory block is "used", and if so, changing it to "Idle" and proceed with subsequent operations, otherwise, an error message is returned, ending. .
  • the method of the present invention details the organization of the memory pool and memory blocks and the steps by which the application uses the memory blocks. It simplifies the memory management requirements in the software system and can prevent memory leaks and memory clutter in the software system.
  • the header information of the memory block and the message data area are separated from each other, and the addition or subtraction of the header information does not affect the memory block message data area.
  • the method of the present invention can be used, for example, in mobile terminals, network side switching devices, and the like, particularly supporting subsystems. BRIEF abstract
  • FIG. 1 is a schematic structural diagram of a memory pool structure according to an embodiment of the present invention.
  • FIG. 2 is a flow chart of a user applying for a memory block according to an embodiment of the present invention.
  • FIG. 3 is a flowchart of a user releasing a memory block according to an embodiment of the present invention.
  • Each memory pool includes multiple memory blocks.
  • the memory block UB size UBBlockSize in the same memory pool TJJBPool is the same.
  • the size of the memory block in each memory pool increases from 16 bytes in multiples of 2, such as 16 bytes, 32 words. Section, 64 bytes, ..., 8192 bytes.
  • a memory pool management structure is set for each memory pool in the specified area of memory, which includes the following information:
  • UReserverCount The number of memory blocks reserved by the memory pool (UBReserverCount), a certain number of memory blocks can be reserved to warn in advance when there is a certain number of free memory blocks to prevent system errors. This information is optional.
  • Free memory block queue tail pointer (UBFreeTail), the memory header pointing to the last free memory block in the free memory block list (refer to the first address of the memory header, the same below);
  • Each memory pool contains a number of memory blocks in a contiguous memory space, each memory block consisting of a memory header (UBHead) and an adjacent data body (UserDataPtr), one memory block data area immediately following the next memory block Memory header.
  • the data body is a memory area that can be used by the user for application.
  • the user program obtains the allocated data body pointer (pointing to its first address) by calling the interface of the application memory block (ie, the API function provided by the memory management module), and can be in the memory area. In the middle of the operation.
  • the memory header (UBHead) of all memory blocks is the same size and contains the following information:
  • the index value of the memory pool where the memory block is located can be quickly located in the memory pool according to the index value when the memory block is returned, avoiding traversing the memory pool from beginning to end in the memory management module, thereby improving the operation efficiency;
  • the memory block uses the flag (MEM_BLOCKJJSED), which is used or idle; ..
  • next memory head pointer For a free memory block, the pointer should point to the memory head pointer of the next free memory block to form a singly linked list of free memory blocks. In another embodiment, a singly linked list of memory blocks that are already allocated by the application may be added.
  • the free memory blocks in the memory pool are organized by means of a singly linked list.
  • all the memory blocks are idle, and the pointers in the memory header of each memory block point downwards.
  • An adjacent memory block when allocating memory, is allocated from the first free memory block in the free memory block list, and the free memory block queue header pointer in the memory pool management structure is modified to point to the linked list.
  • the memory head of the next free memory block When the memory is released, it will be released
  • the memory block is added to the end of the free memory block, and the free memory block queue tail pointer in the memory pool management structure and the memory head pointer in the original free memory block memory header in the linked list are modified to point to the newly added memory block.
  • the memory header of a free memory block When the initial unallocated, all the memory blocks are idle, and the pointers in the memory header of each memory block point downwards.
  • An adjacent memory block when allocating memory, is allocated from the first free memory block in the free memory block list, and the free memory block queue header pointer in
  • two memory head pointers may also be set in the memory header of each memory block, so that the two pointers in the free memory block point to the memory block and the next memory block memory of the previous memory block respectively.
  • the header thus forming a doubly linked list of free memory blocks, is more flexible when allocating free memory blocks.
  • the memory management module implements the following processing flow. As shown in FIG. 2, the following steps are included:
  • Step 100 the user (referring to the application) makes a memory application request, and the input parameter indicates the size of the memory block to be used;
  • Step 110 After receiving the request for the memory, the memory management module determines the legality of the input parameter, and adds the requested memory size and the memory header size as the minimum memory size to be allocated, and determines whether the memory size is Greater than the size of the existing maximum memory block (8192 bytes), if yes, perform the next step, otherwise the allocation fails and ends;
  • Step 120 Select, according to the minimum memory size to be allocated, a memory pool in which the memory block is the smallest from a memory pool whose memory block size is larger than the minimum memory size to be allocated;
  • Step 130 adding semaphore protection to prevent other applications from simultaneously operating the memory;
  • Step 140 determining whether the number of free memory blocks in the selected memory pool management structure is too larger than the number of memory blocks reserved in the memory pool, if , the next step, otherwise, the allocation fails, the end; the reason for reserving the memory block is: a, for some operating systems without memory boundary checking, such as vxworks, threadx, etc., once the application uses the memory block out of bounds, you can write We reserve the memory block to prevent the system from crashing. b. Although the reserved memory block is not used, the reserved value can be used as the threshold used by the memory pool. Once the threshold is reached, the system can alert and not The system is running abnormally because the memory blocks in the memory pool are exhausted.
  • Step 150 Find a free memory block queue head pointer from the management structure of the memory pool, and locate a memory head start position of the first free memory block in the free memory block linked list.
  • Step 160 Fill in the information in the memory header, including the process (or task) information (GetUser) of applying for the memory block, and set the memory block usage flag (MEM_BLOCK_USED) to be used;
  • Step 170 update the memory.
  • the information in the pool management structure updates the free memory block queue head pointer in the management structure to the next memory head pointer in the memory block memory header, and decrements the number of free memory blocks, and the number of successfully allocated memory blocks is incremented. ; - Step 180, release semaphore protection;
  • Step 190 Return the allocated memory block address, which should be the data body pointer of the allocated free memory block, and end.
  • Step 200 the user proposes a memory release request, indicating a memory block pointer (pointing to the data body) to be returned, and the pointer points to the memory block data body;
  • Step 210 The memory management module checks the validity of the memory pointer to be returned, offsets the input memory pointer by a length of the memory header, and determines whether the memory head pointer is within the memory pool of the memory block to be returned. If yes, go to the next step, otherwise, return an error message and end;
  • Step 220 Find a corresponding memory head according to the offset memory head pointer.
  • Step 230 determining whether the memory block usage flag indicates that the memory block is available, and if yes, returning an error message, ending, otherwise, performing the next step;
  • step 240 calling the system semaphore call (VOS_Sema-P) to enter the semaphore protection of the memory management module;
  • Step 250 Set a memory block usage flag in the memory head pointer to be idle, and fill in the memory head pointer to fill in the process (or task) information of the memory block;
  • Step 260 Update the free memory block queue tail pointer in the corresponding memory pool management structure to the memory head pointer, add one to the number of free memory blocks in the management structure, and make the last free memory block memory in the original free memory block linked list.
  • the next memory head pointer in the header points to the memory header newly added to the free memory block, that is, the last free memory block in the original queue is linked with the newly added free memory block;
  • Step 270 calling the system semaphore call to release the semaphore protection, and ending.
  • the method of the present invention describes the organization structure of the memory pool and the memory block and the method of using the memory block by the application, which simplifies the memory management requirements in the software system, and can prevent memory leakage and memory confusion in the software system, and can be used, for example.
  • the network side switching device In the supporting subsystem of the mobile terminal, the network side switching device, and the like.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Storage Device Security (AREA)

Abstract

L'invention concerne un procédé de construction et d'utilisation d'un pool de mémoire, qui divise la mémoire en plusieurs pools de mémoire, les pools de mémoire possédant plusieurs blocs de mémoire de même taille. Chaque pool de mémoire comprend une structure de gestion, chaque bloc de mémoire est divisé en une en-tête de mémoire et un corps de données. L'en-tête de mémoire enregistre les informations d'utilisation du bloc de mémoire. Lorsque le système reçoit une demande pour la mémoire, il choisit un pool de mémoire propre basé sur la taille totale de la mémoire demandée et de l'en-tête de mémoire. Une fois que le bloc de mémoire libre pouvant être attribué est choisi, le système met à jour l'état d'utilisation de l'en-tête de mémoire et les informations d'utilisation du bloc de mémoire dans la structure de gestion et les informations d'adresse du bloc de mémoire libre. Ensuite, il renvoie le pointeur du corps de données du bloc de mémoire libre à l'utilisateur et achève l'application de la mémoire. Lors de la libération de la mémoire, le système déplace le pointeur du bloc de mémoire libéré d'une longueur d'en-tête de mémoire, et le pointe sur une en-tête de mémoire correspondante. Le système réécrit l'état d'utilisation de cette en-tête de mémoire comme étant libre, et met à jour l'état d'utilisation du bloc de mémoire et de l'adresse du bloc de mémoire libre dans la structure de gestion. Cette invention permet de simplifier la gestion de la mémoire, ainsi que d'empêcher la fuite et la confusion de la mémoire.
PCT/CN2006/000515 2006-03-27 2006-03-27 Procédé de construction et d'utilisation d'un pool de mémoire WO2007109920A1 (fr)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2006/000515 WO2007109920A1 (fr) 2006-03-27 2006-03-27 Procédé de construction et d'utilisation d'un pool de mémoire

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2006/000515 WO2007109920A1 (fr) 2006-03-27 2006-03-27 Procédé de construction et d'utilisation d'un pool de mémoire

Publications (1)

Publication Number Publication Date
WO2007109920A1 true WO2007109920A1 (fr) 2007-10-04

Family

ID=38540774

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2006/000515 WO2007109920A1 (fr) 2006-03-27 2006-03-27 Procédé de construction et d'utilisation d'un pool de mémoire

Country Status (1)

Country Link
WO (1) WO2007109920A1 (fr)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106528439A (zh) * 2016-10-20 2017-03-22 腾讯科技(深圳)有限公司 管理内存池的方法及装置
CN110413521A (zh) * 2019-07-24 2019-11-05 杭州迪普信息技术有限公司 一种堆内存的写越界检测方法和装置
CN111459417A (zh) * 2020-04-26 2020-07-28 中国人民解放军国防科技大学 一种面向NVMeoF存储网络的无锁传输方法及系统
CN112214313A (zh) * 2020-09-22 2021-01-12 深圳云天励飞技术股份有限公司 内存分配方法及相关设备
CN112817766A (zh) * 2021-02-22 2021-05-18 北京青云科技股份有限公司 一种内存管理方法、电子设备及介质
CN112988609A (zh) * 2019-12-02 2021-06-18 杭州海康机器人技术有限公司 数据处理方法、装置、存储介质和客户端

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1527206A (zh) * 2003-03-03 2004-09-08 华为技术有限公司 一种内存池管理的方法
US6889288B2 (en) * 2002-12-02 2005-05-03 Emc Corporation Reducing data copy operations for writing data from a network to storage of a cached data storage system by organizing cache blocks as linked lists of data fragments
US20050283584A1 (en) * 2003-04-30 2005-12-22 Tianlong Chen Invariant memory page pool and implementation thereof

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6889288B2 (en) * 2002-12-02 2005-05-03 Emc Corporation Reducing data copy operations for writing data from a network to storage of a cached data storage system by organizing cache blocks as linked lists of data fragments
CN1527206A (zh) * 2003-03-03 2004-09-08 华为技术有限公司 一种内存池管理的方法
US20050283584A1 (en) * 2003-04-30 2005-12-22 Tianlong Chen Invariant memory page pool and implementation thereof

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106528439A (zh) * 2016-10-20 2017-03-22 腾讯科技(深圳)有限公司 管理内存池的方法及装置
CN106528439B (zh) * 2016-10-20 2018-07-06 腾讯科技(深圳)有限公司 管理内存池的方法及装置
CN110413521A (zh) * 2019-07-24 2019-11-05 杭州迪普信息技术有限公司 一种堆内存的写越界检测方法和装置
CN110413521B (zh) * 2019-07-24 2023-01-24 杭州迪普信息技术有限公司 一种堆内存的写越界检测方法和装置
CN112988609A (zh) * 2019-12-02 2021-06-18 杭州海康机器人技术有限公司 数据处理方法、装置、存储介质和客户端
CN112988609B (zh) * 2019-12-02 2023-05-02 杭州海康机器人股份有限公司 数据处理方法、装置、存储介质和客户端
CN111459417A (zh) * 2020-04-26 2020-07-28 中国人民解放军国防科技大学 一种面向NVMeoF存储网络的无锁传输方法及系统
CN111459417B (zh) * 2020-04-26 2023-08-18 中国人民解放军国防科技大学 一种面向NVMeoF存储网络的无锁传输方法及系统
CN112214313A (zh) * 2020-09-22 2021-01-12 深圳云天励飞技术股份有限公司 内存分配方法及相关设备
CN112817766A (zh) * 2021-02-22 2021-05-18 北京青云科技股份有限公司 一种内存管理方法、电子设备及介质
CN112817766B (zh) * 2021-02-22 2024-01-30 北京青云科技股份有限公司 一种内存管理方法、电子设备及介质

Similar Documents

Publication Publication Date Title
KR101620773B1 (ko) 복합식 비휘발성 저장 디바이스를 위한 데이터 이송
WO2007109920A1 (fr) Procédé de construction et d'utilisation d'un pool de mémoire
US8347050B2 (en) Append-based shared persistent storage
US8352681B2 (en) Storage system and a control method for accelerating the speed of copy processing
CN106484311B (zh) 一种数据处理方法及装置
CN107066498B (zh) 键值kv存储方法和装置
CN108874298B (zh) 一种数据存储的方法及装置
CN111949605A (zh) 用于实现文件系统的方法、设备和计算机程序产品
US20140351547A1 (en) Linked list for lock-free memory allocation
CN109995813A (zh) 一种分区扩展方法、数据存储方法及装置
US20190324814A1 (en) Resource release method, resource allocation method, devices, and computer program products
JP2007108981A (ja) ストレージ装置及びボリューム間のデータ交換方法
CN112214313A (zh) 内存分配方法及相关设备
CN107346265B (zh) 实现QoS的方法与装置
JP2021510222A (ja) データ処理方法、装置、およびコンピューティングデバイス
US20080162830A1 (en) Methods, systems, and computer program products for providing memory management with constant defragmentation time
CN105138481A (zh) 存储数据的处理方法、装置和系统
JP2016533588A (ja) 記憶処理方法、装置及び端末
CN111435286B (zh) 一种数据存储方法、装置和系统
US9021492B2 (en) Dual mode reader writer lock
CN114442910A (zh) 管理存储系统的方法、电子设备和计算机程序产品
US11144243B2 (en) Method and device for managing redundant array of independent disks and computer program product
JP2022042271A (ja) メモリシステムおよび制御方法
EP3249540A1 (fr) Procédé d'écriture de multiples copies dans un dispositif de stockage et dispositif de stockage
CN111124294A (zh) 一种扇区映射信息的管理方法及装置、存储介质和设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 06722167

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 06722167

Country of ref document: EP

Kind code of ref document: A1