WO2012034322A1 - 嵌入式系统内存池配置方法及装置 - Google Patents

嵌入式系统内存池配置方法及装置 Download PDF

Info

Publication number
WO2012034322A1
WO2012034322A1 PCT/CN2010/079278 CN2010079278W WO2012034322A1 WO 2012034322 A1 WO2012034322 A1 WO 2012034322A1 CN 2010079278 W CN2010079278 W CN 2010079278W WO 2012034322 A1 WO2012034322 A1 WO 2012034322A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory pool
memory
configuration
pool
configuration file
Prior art date
Application number
PCT/CN2010/079278
Other languages
English (en)
French (fr)
Inventor
赖颖军
黄海伦
Original Assignee
中兴通讯股份有限公司
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 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2012034322A1 publication Critical patent/WO2012034322A1/zh

Links

Classifications

    • 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/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping

Definitions

  • the present invention relates to a memory management technology, and in particular, to an embedded system memory pool configuration method and apparatus. Background technique
  • the memory management method of the memory pool set is often used.
  • the basic idea of this method is to divide the memory into several contiguous memory areas. Each memory area continues to be divided into several memory blocks of the same size. Each memory area is a memory pool, and all memory areas form a memory pool set. . When there is a memory allocation request, iterate through the entire memory pool set, find the memory pool with the best matching size, and allocate free memory blocks from it.
  • CN200610166525 shows an implementation method of a dynamic memory pool, the memory pool of which can be dynamic Expansion and recycling, no need for developer configuration, however, this memory management mechanism is complicated to implement.
  • this memory management mechanism is complicated to implement.
  • the embedded system processes a large amount of data, frequent expansion and recycling will inevitably lead to reduced efficiency of memory allocation and release, and higher requirements for real-time performance.
  • Embedded systems are not optimal. Summary of the invention
  • the invention provides an embedded system memory pool configuration method and device, which are used to solve the problem of automatically adjusting the memory pool configuration according to the use of memory by the embedded application.
  • An embedded system memory pool configuration method comprising:
  • Step A In the initialization phase of the embedded application, the memory pool configuration file is read, and the configuration cache of the corresponding size is requested according to the memory pool configuration data in the read memory pool configuration file, and the memory pool is configured. Data is written into the configuration cache, and a corresponding memory pool is established;
  • Step B In the running phase of the embedded application, the current usage value of the corresponding memory pool in the configuration cache is updated in real time according to the memory allocation/release condition, and when the current usage value of the memory pool is greater than the usage peak of the memory pool, the cache is configured.
  • the peak usage of the memory pool is updated to its current usage value;
  • Step C during the power-off or reset phase of the embedded application, when comparing the usage peaks recorded in the configuration cache for each memory pool is greater than the value recorded in the memory pool configuration file When the number of memory blocks is increased, the number of memory blocks recorded in the memory pool configuration file is updated to the peak usage.
  • configuration file update flag, the memory block size of each memory pool, and the number of memory blocks are recorded in the memory pool configuration file.
  • the configuration cache is divided into several configuration items according to the number of memory pools, and each configuration item corresponds to a memory pool configuration, including a memory block size of the memory pool, a current use value of the memory pool, and a memory pool. Use peaks.
  • the initial value of the current usage value of the memory pool in the configuration cache is zero, and the initial value of the usage peak of the memory pool is the number of memory blocks of the corresponding memory pool in the memory pool configuration file.
  • the real-time updating of the current usage value of the corresponding memory pool in the configuration cache according to the memory allocation situation includes:
  • Step B1 Determine whether the memory size requested by the embedded application is smaller than the memory block size of the maximum memory pool. If yes, perform step B2. Otherwise, use other preset policies for memory allocation.
  • Step B2 Find the best match from all memory pools. The memory pool is used as the current memory pool to determine whether there is a free memory block in the current memory pool. If yes, go directly to step B3. Otherwise, use another preset policy to allocate a new memory area and divide it into a memory pool. Memory block, perform step B3;
  • Step B3 Allocating a memory block from the current memory pool, adding 1 to the current use value of the current memory pool. If the current usage value after adding 1 is greater than the peak value of the current memory pool, the peak value of the memory pool in the cache is configured. The current usage value after adding 1.
  • step C specifically includes:
  • Step Cl determine whether there is a memory pool configuration file, and if yes, perform step C2; otherwise, the process ends;
  • Step C2 Read the configuration file update flag in the memory pool configuration file to determine whether the configuration file needs to be updated, and if yes, perform step C3; otherwise, close the memory pool configuration file;
  • Step C3 sequentially read the number of memory blocks of each memory pool in the memory pool configuration file, and close the memory pool configuration file after the memory pool uses the peak value.
  • An embedded system memory pool configuration device comprising:
  • a cache creation module configured to: in the power-on initialization phase of the embedded application, read the memory pool configuration file, and apply an appropriate size configuration cache according to the memory pool configuration data read into the memory pool configuration file, The memory pool configuration data is written into the configuration cache, and a corresponding memory pool is established;
  • the release status updates the current usage value of the corresponding memory pool in the configuration cache in real time, and updates the usage peak of the memory pool in the configuration cache to its current usage value when the current usage value of the memory pool is greater than the usage peak of the memory pool;
  • the configuration file update module is used to check the memory pool during the power-off or reset phase of the embedded application. When comparing the memory usage of each memory pool recorded in the configuration cache to be greater than the number of memory blocks recorded in the memory pool configuration file, the memory pool is used. The number of memory blocks recorded in the configuration file is updated to the usage peak.
  • configuration file update flag, the memory block size of each memory pool, and the number of memory blocks are recorded in the memory pool configuration file.
  • the configuration cache is divided into several configuration items according to the number of memory pools, and each configuration item corresponds to a memory pool configuration, including a memory block size of the memory pool, a current use value of the memory pool, and a memory pool. Use peaks.
  • the initial value of the current usage value of the memory pool in the configuration cache is zero, and the initial value of the usage peak of the memory pool is the number of memory blocks of the corresponding memory pool in the memory pool configuration file.
  • the invention can automatically adjust the memory configuration file according to the program using memory without upgrading the embedded application, improves the ease of use of the embedded system memory management module, reduces the maintenance difficulty, and is simple to implement, does not affect Efficient allocation and recycling of memory, suitable for embedded systems with high real-time requirements.
  • FIG. 1 is a schematic structural diagram of an embedded system according to an embodiment of the present invention.
  • FIG. 2 is a flowchart of an implementation principle of a method for configuring an embedded system memory pool according to an embodiment of the present invention
  • FIG. 3 is a flowchart of establishing a configuration cache in an embedded system memory pool configuration method according to an embodiment of the present invention
  • FIG. 4 is a flowchart of updating a configuration cache when a memory block is allocated in an embedded system memory pool configuration method according to an embodiment of the present invention
  • FIG. 5 is a flowchart of updating a configuration cache when a memory block is released in an embedded system memory pool configuration method according to an embodiment of the present disclosure
  • FIG. 6 is a flowchart of updating a memory pool configuration file in an embedded system memory pool configuration method according to an embodiment of the present invention
  • FIG. 7 is a structural block diagram of an apparatus for configuring an embedded system memory pool according to an embodiment of the present invention. detailed description
  • the present invention provides an embedded system memory pool configuration method and apparatus, which can be embedded in an embedded application without embedding an embedded application.
  • Applications use memory to automatically adjust the memory pool configuration, which improves the ease of use of embedded system memory management and reduces the difficulty of maintaining embedded applications.
  • FIG. 1 is a schematic structural diagram of an embedded system according to an embodiment of the present invention, which mainly includes a nonvolatile memory and an embedded CPU.
  • the nonvolatile memory is a physical medium for storing a memory pool configuration file.
  • This memory pool configuration file is used to record the data of the memory pool configuration, which records the configuration file update flag, the memory block size of each memory pool, and the number of memory blocks.
  • the embedded CPU is used to run embedded applications.
  • the embedded application is a software program running on an embedded CPU, and includes functional modules such as an embedded operating system kernel, a memory management module, a file system, and a nonvolatile memory driver.
  • the memory management module can implement memory allocation and release, and at the same time, record the current usage value and peak value of the memory pool.
  • the document System and non-volatile memory drivers are used to read and write memory pool configuration files stored on non-volatile memory.
  • FIG. 2 is a flowchart of an implementation principle of a method for configuring an embedded system memory pool according to an embodiment of the present invention, which mainly includes the following steps:
  • Step 20 During the power-on initialization phase of the embedded application, read the memory pool configuration file, obtain the number of memory pools, the memory block size of each memory pool, and the number of memory blocks.
  • Step 21 Initialize the configuration cache, and apply for a configuration cache of a corresponding size from the embedded operating system according to the obtained memory pool configuration data, and write the obtained memory pool configuration data into the configuration cache.
  • Step 22 Establish a corresponding memory pool according to the memory block size and the number of memory blocks of each memory pool in the configuration cache.
  • Step 23 In the running phase of the embedded application, update the current usage value of the corresponding memory pool in the configuration cache in real time according to the memory allocation/release condition, and increase the current usage value of the memory pool by 1 when the memory is allocated; and the memory when the memory is released.
  • the current usage value of the pool is decremented by 1.
  • Step 24 Determine whether the current usage value of the memory pool is greater than the peak usage of the memory pool. If yes, update the usage peak of the memory pool in the configuration cache to its current usage value; otherwise, go to step 25.
  • Step 25 In the embedded application power off or reset phase, determine whether the memory pool configuration file needs to be updated. If the memory pool configuration file needs to be updated, write the peak value of each memory pool to the memory pool configuration file, when comparing each When the memory pool records the usage peak value in the configuration cache larger than the number of memory blocks recorded in the memory pool configuration file, the number of memory blocks recorded in the memory pool configuration file is updated to the use peak to end the current process; if no update is required The memory pool configuration file ends the current process.
  • FIG. 3 is a schematic diagram of a method for configuring a memory pool of an embedded system according to an embodiment of the present invention.
  • a flow chart of the configuration cache which mainly includes the following steps:
  • Step 101 Open the memory pool configuration file. If successful, proceed to step 102. Otherwise, proceed to step 103.
  • Step 102 Read the memory pool configuration file, obtain the number of memory pools, the memory block size of each memory pool, and the number of memory blocks, and calculate the size of the configuration cache according to the obtained memory pool configuration data.
  • Step 103 Use the default configuration in the embedded application as the actual memory pool configuration, and proceed to step 107.
  • Step 104 Applying configuration cache from the embedded operating system, the configuration cache is divided into several configuration items according to the number of memory pools, and each configuration item corresponds to a memory pool configuration, including the memory block size of the memory pool, and current usage. Value and usage peak value, the initial value of the current usage value of the memory pool in the configuration cache is zero, and the initial value of the memory pool usage peak value is the number of memory blocks of the corresponding memory pool in the memory pool configuration file.
  • Step 105 Read the memory block size and the number of memory blocks of each memory pool in the memory pool configuration file, and write them to the corresponding configuration items in the configuration cache.
  • Step 106 Close the configuration file and configure the configuration cache as the actual memory pool configuration.
  • Step 107 According to the actual memory pool configuration, the memory block size and the number of memory blocks of each memory pool are used to establish a corresponding number of memory pools in a continuous memory area.
  • FIG. 4 is a flowchart of updating a configuration cache when a memory block is allocated in an embedded system memory pool configuration method according to an embodiment of the present invention, which mainly includes the following steps:
  • Step 201 Determine whether the memory size requested by the embedded application is smaller than the memory block size of the maximum memory pool. If yes, go to step 202; otherwise, go to step 203.
  • Step 202 Traverse all memory pools, and find the best matching memory pool as the current memory pool.
  • Step 203 using other preset policies for memory allocation, for example, using malloc directly Request memory from the embedded operating system; then end the current allocation process.
  • Step 204 Determine whether there is a free memory block in the current memory pool. If yes, go to step 206. Otherwise, go to step 205.
  • Step 205 Fill the current memory pool with water, that is, directly apply for a new memory area from the embedded operating system, and divide it into a memory block of the memory pool.
  • Step 206 Allocate a memory block from the current memory pool, and add 1 to the current usage value of the memory pool in the configuration cache.
  • Step 207 Determine whether the current usage value of the current memory pool is greater than the usage peak. If yes, proceed to step 208; otherwise, end the current allocation process.
  • Step 208 Set the usage peak of the memory pool in the configuration cache to its current usage value, and end the current allocation process.
  • FIG. 5 is a flowchart of updating a configuration cache when a memory block is released in an embedded system memory pool configuration method according to an embodiment of the present invention, which mainly includes the following steps:
  • Step 301 Determine whether the released memory block belongs to the memory pool in the configuration cache. If yes, go to step 302. Otherwise, go to step 303.
  • Step 302 Release the memory block, and decrement the current use value of the corresponding memory pool in the configuration cache by 1, and the process ends.
  • Step 303 using other policy release, the release process corresponds to the process assigned in step 203, for example, using free release, and the process ends.
  • FIG. 6 is a flowchart of updating a memory pool configuration file in an embedded system memory pool configuration method according to an embodiment of the present invention, which mainly includes the following steps:
  • Step 401 Determine whether there is a memory pool configuration file. If yes, proceed to step 402. Otherwise, the process ends.
  • Step 402 Read the configuration file update flag in the memory pool configuration file, determine whether the memory pool configuration file needs to be updated, and if yes, go to step 403; otherwise, go to step 407.
  • Step 403 Determine whether the memory pool traversal is over. If yes, proceed to step 407. Otherwise, proceed to step 404.
  • Step 404 The next memory pool is used as the current memory pool, and the number of memory blocks of the memory pool in the memory pool configuration file is read.
  • Step 405 Determine whether the number of memory blocks in the current memory pool in the memory pool configuration file is smaller than the usage peak value of the corresponding memory pool entry in the configuration cache. If yes, go to step 406; otherwise, go to step 403.
  • Step 406 Update the number of memory blocks of the current memory pool in the memory pool configuration file to the peak value of the memory pool in the configuration cache, and proceed to step 403.
  • Step 407 close the memory pool configuration file.
  • FIG. 7 is a structural block diagram of an apparatus for configuring an embedded system memory pool according to an embodiment of the present invention, which mainly includes:
  • the cache application module is configured to read the memory pool configuration file during the power-on initialization phase of the embedded application, and apply an appropriate size configuration cache according to the read memory pool configuration data, and write the memory pool configuration data to the storage pool configuration file.
  • the configuration cache is created, and the corresponding memory pool is established.
  • the cache update module is configured to update the current usage value of the corresponding memory pool in the configuration cache in real time according to the memory allocation/release status during the running phase of the embedded application, and when the current usage value of the memory pool is greater than the usage peak of the memory pool Updates the usage peak of the memory pool in the configuration cache to its current usage value.
  • the configuration file update module is configured to determine whether the memory pool configuration file needs to be updated during the power-off or reset phase of the embedded application, and if so, compare whether the usage peak recorded in the configuration cache of each memory pool is greater than the memory pool configuration file. The number of memory blocks recorded in , and if so, the number of memory blocks recorded in the memory pool configuration file is updated to the peak usage.
  • the configuration file update flag is recorded in the memory pool configuration file, and each memory pool is recorded.
  • the configuration cache is divided into several configuration items according to the number of memory pools.
  • Each configuration item corresponds to a memory pool configuration, including the memory block size of the memory pool, the current usage value and the peak value of use; and the current use of the memory pool in the configuration cache.
  • the initial value of the value is zero, and the initial value of the peak usage of the memory pool is the number of memory blocks in the corresponding memory pool in the memory pool configuration file.
  • the developer can create a memory pool configuration file according to the memory pool and the number of memory blocks that the embedded application may need, and simultaneously open the configuration.
  • the file update flag and then run through all the software test cases, you can get the best memory configuration that the embedded application actually needs. At this point, you can turn off the profile update flag and use the best memory configuration in the actual product version.

Description

嵌入式系统内存池配置方法及装置 技术领域
本发明涉及内存管理技术, 尤其涉及一种嵌入式系统内存池配置方法 及装置。 背景技术
在现有的嵌入式系统内存管理技术中, 为了满足高效分配和回收, 以 及尽可能减少内存碎片的需要, 往往釆用内存池集的内存管理方法。 此方 法的基本思想是将内存划分为若干个连续内存区域, 每个内存区域又继续 划分为若干个大小相同的内存块, 每个内存区域就是一个内存池, 所有内 存区域就组成一个内存池集。 当有内存分配申请时, 遍历整个内存池集, 找到大小最匹配的内存池, 从中分配空闲内存块。
基于上述内存管理方法的嵌入式应用, 开发人员需要先根据应用使用 内存情况, 预先估计各内存池的内存块数量, 然后在应用代码中做好配置, 并编译到最终的嵌入式应用程序中。 在实际中, 往往很难一次估计出应用 程序使用的内存数量, 通常是在反复测试后, 才能确定出最终的配置。 而 且, 一旦应用程序使用内存情况有变化, 也需要重新调整内存配置。 由于 嵌入式应用程序往往是烧录到非易失存储器中, 频繁调整配置就需要频繁 的烧录, 这给开发带来极大的不便。 而且, 常常出现发布版本的配置不合 适, 测试无法进行下去, 需要升级版本, 从而影响了测试进度。 因此, 这 种配置方式极不灵活。
现有的嵌入式系统内存管理相关专利技术中, 往往专注于内存池分配 和回收算法, 而很少提及如何解决内存池配置易用性问题。 专利
CN200610166525给出了一种动态内存池的实现方法,其内存池可以动态的 扩充和回收, 不需开发人员配置, 然而这种内存管理机制实现复杂, 在嵌 入式系统处理数据量大时, 频繁地扩充和回收必然导致内存分配和释放的 效率降低, 对于实时性要求较高的嵌入式系统不是最优选择。 发明内容
本发明提供一种嵌入式系统内存池配置方法及装置, 用以解决根据嵌 入式应用程序使用内存的情况自动调整内存池配置的问题。
本发明技术方案如下:
一种嵌入式系统内存池配置方法, 该方法包括:
步骤 A、 在嵌入式应用程序上电初始化阶段, 读取内存池配置文件, 根据读取到的所述内存池配置文件中的内存池配置数据申请相应大小的配 置緩存, 将所述内存池配置数据写入所述配置緩存中, 并建立相应的内存 池;
步骤 B、 在嵌入式应用程序运行阶段, 根据内存分配 /释放情况实时更 新配置緩存中相应内存池的当前使用值, 并在内存池的当前使用值大于内 存池的使用峰值时, 将配置緩存中内存池的使用峰值更新为其当前使用值; 步骤 C、 在嵌入式应用程序关电或复位阶段, 当比较出每个内存池在 配置緩存中记录的使用峰值大于在内存池配置文件中记录的内存块数时, 将内存池配置文件中记录的内存块数更新为所述使用峰值。
进一步地, 所述内存池配置文件中记录了配置文件更新标志、 每个内 存池的内存块大小和内存块数。
进一步地, 所述配置緩存按内存池个数等分为若干个配置项, 每个配 置项对应一个内存池的配置, 其中包括内存池的内存块大小, 内存池的当 前使用值及内存池的使用峰值。
进一步地, 所述配置緩存中内存池的当前使用值的初始值为零, 内存 池的使用峰值的初始值为内存池配置文件中相应内存池的内存块数。 进一步地, 所述根据内存分配情况实时更新配置緩存中相应内存池的 当前使用值的包括:
步骤 Bl、 判断嵌入式应用程序申请的内存大小是否小于最大内存池的 内存块大小, 若是, 执行步骤 B2, 否则, 使用其它预设策略进行内存分配; 步骤 B2、从所有内存池中查找最匹配的内存池,将其作为当前内存池, 判断当前内存池中是否有空闲内存块, 若有, 直接执行步骤 B3 , 否则, 使 用其它预设策略分配新的内存区域, 将其划分为本内存池的内存块, 执行 步骤 B3 ;
步骤 B3、从当前内存池分配内存块, 将当前内存池的当前使用值加 1 , 若加 1 后的当前使用值大于当前内存池的使用峰值, 则将配置緩存中该内 存池的使用峰值变换为加 1后的当前使用值。
进一步地, 所述步骤 C具体包括:
步骤 Cl、 判断是否存在内存池配置文件, 若是, 执行步骤 C2 , 否则, 流程结束;
步骤 C2、 读取内存池配置文件中配置文件更新标志, 判断是否需更新 配置文件, 若是, 执行步骤 C3 , 否则, 关闭内存池配置文件;
步骤 C3、 依次读取内存池配置文件中各内存池的内存块数, 将内存池 述使用峰值后, 关闭内存池配置文件。
一种嵌入式系统内存池配置装置, 该装置包括:
配置緩存建立模块, 用于在嵌入式应用程序上电初始化阶段, 读取内 存池配置文件, 根据读取到所述内存池配置文件中的内存池配置数据申请 适当大小的配置緩存, 将所述内存池配置数据写入所述配置緩存中, 并建 立相应的内存池;
配置緩存更新模块, 用于在嵌入式应用程序运行阶段, 根据内存分配 / 释放情况实时更新配置緩存中相应内存池的当前使用值, 并在内存池的当 前使用值大于内存池的使用峰值时, 将配置緩存中内存池的使用峰值更新 为其当前使用值;
配置文件更新模块, 用于在嵌入式应用程序关电或复位阶段, 当比较 出每个内存池在配置緩存中记录的使用峰值大于在内存池配置文件中记录 的内存块数时, 将内存池配置文件中记录的内存块数更新为所述使用峰值。
进一步地, 所述内存池配置文件中记录了配置文件更新标志、 每个内 存池的内存块大小和内存块数。
进一步地, 所述配置緩存按内存池个数等分为若干个配置项, 每个配 置项对应一个内存池的配置, 其中包括内存池的内存块大小, 内存池的当 前使用值及内存池的使用峰值。
进一步地, 所述配置緩存中内存池的当前使用值的初始值为零, 内存 池的使用峰值的初始值为内存池配置文件中相应内存池的内存块数。
本发明有益效果如下:
本发明可以在不升级嵌入式应用程序的情况下, 根据程序使用内存的 情况自动调整内存配置文件, 提高了嵌入式系统内存管理模块的易用性, 降低了维护难度, 而且实现简单, 不影响内存的高效分配和回收, 适合于 实时性要求较高的嵌入式系统。 附图说明
图 1为本发明实施例中嵌入式系统的结构示意图;
图 2为本发明实施例中嵌入式系统内存池配置方法的实现原理流程图; 图 3 为本发明实施例所述嵌入式系统内存池配置方法中建立配置緩存 的流程图;
图 4为本发明实施例所述嵌入式系统内存池配置方法中分配内存块时 , 更新配置緩存的流程图; 图 5为本发明实施例所述嵌入式系统内存池配置方法中释放内存块时, 更新配置緩存的流程图;
图 6为本发明实施例所述嵌入式系统内存池配置方法中更新内存池配 置文件的流程图;
图 7为本发明实施例所述嵌入式系统内存池配置装置的结构框图。 具体实施方式
为克服现有技术中存在的嵌入式系统内存池配置不灵活的问题, 本发 明提供一种嵌入式系统内存池配置方法及装置, 本发明可以在不升级嵌入 式应用程序的情况下, 根据嵌入式应用程序使用内存的情况自动调整内存 池配置, 从而提高了嵌入式系统内存管理的易用性, 降低了嵌入式应用程 序的维护难度。
下面将结合本发明实施例中的附图, 对本发明实施例中的技术方案进 行清楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而不是全部的实施例。 基于本发明中的实施例, 本领域普通技术人员在没 有做出创造性劳动前提下所获得的所有其他实施例, 都属于本发明保护的 范围。
请参阅图 1 , 图 1为本发明实施例中嵌入式系统的结构示意图, 主要包 含非易失存储器和嵌入式 CPU。
其中, 非易失存储器为用于储存内存池配置文件的物理介质。 该内存 池配置文件用于记录内存池配置的数据, 其中记录了配置文件更新标志、 各内存池的内存块大小和内存块数。
其中, 嵌入式 CPU, 用于运行嵌入式应用程序。 该嵌入式应用程序为 运行在嵌入式 CPU上的软件程序, 包含嵌入式操作系统内核、 内存管理模 块、 文件系统和非易失存储器驱动等功能模块。 其中, 该内存管理模块可 以实现内存分配和释放, 同时, 记录内存池的当前使用值和峰值。 该文件 系统和非易失存储器驱动则用于对存储在非易失存储器上的内存池配置文 件进行读写操作。
本发明实施例提供了一种嵌入式系统内存池配置方法,请参阅图 2, 图 2为本发明实施例中嵌入式系统内存池配置方法的实现原理流程图,其主要 包括如下步骤:
步骤 20, 在嵌入式应用程序上电初始化阶段, 读取内存池配置文件, 获取内存池的个数、 每个内存池的内存块大小和内存块数。
步骤 21 , 初始化配置緩存, 并根据获取到的内存池配置数据从嵌入式 操作系统申请相应大小的配置緩存, 并将获取到的内存池配置数据写入配 置緩存中。
步骤 22, 根据配置緩存中各内存池的内存块大小和内存块数, 建立相 应的内存池。
步骤 23 , 在嵌入式应用程序运行阶段, 根据内存分配 /释放情况实时更 新配置緩存中相应内存池的当前使用值, 当分配内存时将内存池的当前使 用值加 1 ; 当释放内存时将内存池的当前使用值减 1。
步骤 24, 判断内存池的当前使用值是否大于内存池的使用峰值, 如果 是, 则将配置緩存中该内存池的使用峰值更新为其当前使用值; 否则, 执 行步骤 25。
步骤 25 , 在嵌入式应用程序关电或复位阶段, 判断是否需要更新内存 池配置文件, 如果需要更新内存池配置文件, 则将各内存池使用峰值写入 内存池配置文件, 当比较出每个内存池在配置緩存中记录的使用峰值大于 在内存池配置文件中记录的内存块数时, 将内存池配置文件中记录的内存 块数更新为所述使用峰值后结束当前流程; 如果不需要更新内存池配置文 件, 则结束当前流程。
请参阅图 3 ,图 3为本发明实施例所述嵌入式系统内存池配置方法中建 立配置緩存的流程图, 其主要包括如下步骤:
步骤 101 , 打开内存池配置文件, 如果成功, 则进入步骤 102, 否则, 进入步骤 103。
步骤 102, 读取内存池配置文件, 获取内存池的个数、 每个内存池的内 存块大小和内存块数, 根据获取到的这些内存池配置数据计算配置緩存的 大小。
步骤 103 , 使用嵌入式应用程序中的默认配置作为实际的内存池配置, 进入步骤 107。
步骤 104,从嵌入式操作系统中申请配置緩存, 配置緩存按内存池个数 等分为若干个配置项, 每个配置项对应一个内存池的配置, 其中包括内存 池的内存块大小、 当前使用值及使用峰值, 配置緩存中内存池的当前使用 值的初始值为零, 内存池的使用峰值的初始值为内存池配置文件中相应内 存池的内存块数。
步骤 105 , 读取内存池配置文件中各个内存池的内存块大小及内存块 数, 将其写入配置緩存中对应的配置项。
步骤 106, 关闭配置文件, 将配置緩存作为实际的内存池配置。
步骤 107,根据实际的内存池配置中, 各个内存池的内存块大小和内存 块数, 在连续的内存区域, 建立相应数量的内存池。
请参阅图 4,图 4为本发明实施例所述嵌入式系统内存池配置方法中分 配内存块时, 更新配置緩存的流程图, 其主要包括如下步骤:
步骤 201 ,判断嵌入式应用程序申请的内存大小是否小于最大内存池的 内存块大小, 如果是, 则进入步骤 202 , 否则, 进入步骤 203。
步骤 202, 遍历所有内存池, 从中查找最匹配的内存池, 将其作为当前 内存池。
步骤 203 , 使用其它预设策略进行内存分配, 例如, 使用 malloc直接 从嵌入式操作系统申请内存; 之后结束当前分配流程。
步骤 204, 判断当前内存池中是否有空闲的内存块, 如果有, 则进入步 骤 206, 否则, 进入步骤 205。
步骤 205 , 向当前内存池中注水, 即从嵌入式操作系统直接申请新内存 区域, 将其划分为本内存池的内存块。
步骤 206,从当前内存池分配内存块, 且将配置緩存中该内存池的当前 使用值加 1。
步骤 207 , 判断当前内存池的当前使用值是否大于使用峰值, 如果是, 则进入步骤 208 , 否则, 结束当前分配流程。
步骤 208 , 将配置緩存中该内存池的使用峰值设置为其当前使用值, 结 束当前分配流程。
请参阅图 5 ,图 5为本发明实施例所述嵌入式系统内存池配置方法中释 放内存块时, 更新配置緩存的流程图, 其主要包括如下步骤:
步骤 301 , 判断被释放的内存块是否属于配置緩存中的内存池, 如 果是, 则进入步骤 302 , 否则, 进入步骤 303。
步骤 302 ,释放内存块,将配置緩存中相应的内存池的当前使用值减 1 , 流程结束。
步骤 303 ,使用其它策略释放,此释放流程对应于步骤 203分配的流程, 例如, 使用 free释放, 流程结束。
请参阅图 6 ,图 6为本发明实施例所述嵌入式系统内存池配置方法中更 新内存池配置文件的流程图, 其主要包括如下步骤:
步骤 401 , 判断是否存在内存池配置文件, 如果是, 则进入步骤 402 , 否则, 此流程结束。
步骤 402 ,读取内存池配置文件中的配置文件更新标志, 判断是否需要 更新内存池配置文件, 如果是, 则进入步骤 403 , 否则, 进入步骤 407。 步骤 403 , 判断内存池遍历是否结束, 如果是, 则进入步骤 407, 否则, 进入步骤 404。
步骤 404, 将下一个内存池作为当前内存池,读取内存池配置文件中该 内存池的内存块数。
步骤 405 ,判断内存池配置文件中当前内存池的内存块数是否小于配置 緩存相应内存池项的使用峰值, 如果是, 则进入步骤 406, 否则, 进入步骤 403。
步骤 406,将内存池配置文件中当前内存池的内存块数更新为配置緩存 中该内存池的使用峰值, 进入步骤 403。
步骤 407, 关闭内存池配置文件。
相应地, 本发明实施例还提供了一种嵌入式系统内存池配置装置, 请 参阅图 7,图 7为本发明实施例所述嵌入式系统内存池配置装置的结构框图, 其主要包括:
配置緩存申请模块, 用于在嵌入式应用程序上电初始化阶段, 读取内 存池配置文件, 根据读取到的内存池配置数据申请适当大小的配置緩存, 将所述内存池配置数据写入所述配置緩存中, 并建立相应的内存池。
配置緩存更新模块, 用于在嵌入式应用程序运行阶段, 根据内存分配 / 释放情况实时更新配置緩存中相应内存池的当前使用值, 并在内存池的当 前使用值大于该内存池的使用峰值时, 将配置緩存中该内存池的使用峰值 更新为其当前使用值。
配置文件更新模块, 用于在嵌入式应用程序关电或复位阶段, 判断是 否需更新内存池配置文件, 若是, 则比较每个内存池在配置緩存中记录的 使用峰值是否大于在内存池配置文件中记录的内存块数, 如果是, 则将内 存池配置文件中记录的内存块数更新为所述使用峰值。
其中, 内存池配置文件中记录了配置文件更新标志、 每个内存池的内 存块大小和内存块数。
配置緩存按内存池个数等分为若干个配置项, 每个配置项对应一个内 存池的配置, 其中包括内存池的内存块大小, 当前使用值及使用峰值; 配 置緩存中内存池的当前使用值的初始值为零, 内存池的使用峰值的初始值 为内存池配置文件中相应内存池的内存块数。
釆用本发明实施例所述技术方案后, 在嵌入式应用程序的测试阶段, 开发人员即可根据嵌入式应用程序可能需要的内存池和内存块数, 创建内 存池配置文件, 同时, 打开配置文件更新标志, 然后运行完所有软件测试 用例, 便可以获取到嵌入式应用程序实际所需的最佳内存配置。 此时, 就 可以关闭配置文件更新标志, 在实际产品版本中使用最佳内存配置。 本发明的精神和范围。 这样, 倘若本发明的这些修改和变型属于本发明权 利要求及其等同技术的范围之内, 则本发明也意图包含这些改动和变型在 内。

Claims

权利要求书
1、 一种嵌入式系统内存池配置方法, 其特征在于, 该方法包括: 步骤 A、 在嵌入式应用程序上电初始化阶段, 读取内存池配置文件, 根据读取的所述内存池配置文件中的内存池配置数据申请相应大小的配置 緩存, 将所述内存池配置数据写入所述配置緩存中, 并建立相应的内存池; 步骤 B、 在嵌入式应用程序运行阶段, 根据内存分配 /释放情况实时更 新配置緩存中相应内存池的当前使用值, 并在内存池的当前使用值大于内 存池的使用峰值时, 将配置緩存中所述内存池的使用峰值更新为其当前使 用值;
步骤 C、 在嵌入式应用程序关电或复位阶段, 当比较出每个内存池在 配置緩存中记录的使用峰值大于在内存池配置文件中记录的内存块数时, 将内存池配置文件中记录的内存块数更新为所述使用峰值。
2、 根据权利要求 1所述的方法, 其特征在于, 所述内存池配置文件中 记录了配置文件更新标志、 每个内存池的内存块大小和内存块数。
3、 根据权利要求 1所述的方法, 其特征在于, 所述配置緩存按内存池 个数等分为若干个配置项, 每个配置项对应一个内存池的配置, 其中包括 内存池的内存块大小, 内存池的当前使用值及内存池的使用峰值。
4、 根据权利要求 3所述的方法, 其特征在于, 所述配置緩存中, 内存 池的当前使用值的初始值为零, 内存池的使用峰值的初始值为内存池配置 文件中相应内存池的内存块数。
5、 根据权利要求 1所述的方法, 其特征在于, 所述根据内存分配情况 实时更新配置緩存中相应内存池的当前使用值包括:
步骤 Bl、 判断嵌入式应用程序申请的内存大小是否小于最大内存池的 内存块大小, 若是, 则执行步骤 B2, 否则, 使用其它预设策略进行内存分 配; 步骤 B2、从所有内存池中查找最匹配的内存池,将其作为当前内存池, 判断当前内存池中是否有空闲内存块, 若有, 则直接执行步骤 B3 , 否则, 使用其它预设策略分配新的内存区域, 将其划分为本内存池的内存块, 执 行步骤 B3;
步骤 B3、从当前内存池分配内存块, 将当前内存池的当前使用值加 1 , 若加 1 后的当前使用值大于当前内存池的使用峰值, 则将配置緩存中内存 池的使用峰值变换为加 1后的当前使用值。
6、 根据权利要求 1所述的方法, 其特征在于, 所述步骤 C包括: 步骤 Cl、判断是否存在内存池配置文件,若是,则执行步骤 C2 ,否则, 流程结束;
步骤 C2、 读取内存池配置文件中配置文件更新标志, 判断是否需更新 配置文件, 若是, 则执行步骤 C3 , 否则, 关闭内存池配置文件;
步骤 C3、 依次读取内存池配置文件中各内存池的内存块数, 将内存池 述使用峰值后, 关闭内存池配置文件。
7、 一种嵌入式系统内存池配置装置, 其特征在于, 该装置包括: 配置緩存建立模块, 用于在嵌入式应用程序上电初始化阶段, 读取内 存池配置文件, 根据读取到的所述内存池配置文件中的内存池配置数据申 请适当大小的配置緩存, 将所述内存池配置数据写入所述配置緩存中, 并 建立相应的内存池;
配置緩存更新模块, 用于在嵌入式应用程序运行阶段, 根据内存分配 / 释放情况实时更新配置緩存中相应内存池的当前使用值, 并在内存池的当 前使用值大于内存池的使用峰值时, 将配置緩存中所述内存池的使用峰值 更新为其当前使用值;
配置文件更新模块, 用于在嵌入式应用程序关电或复位阶段, 当比较 出每个内存池在配置緩存中记录的使用峰值大于在内存池配置文件中记录 的内存块数时, 将内存池配置文件中记录的内存块数更新为所述使用峰值。
8、 根据权利要求 7所述的装置, 其特征在于, 所述内存池配置文件中 记录了配置文件更新标志、 每个内存池的内存块大小和内存块数。
9、 根据权利要求 7所述的装置, 其特征在于, 所述配置緩存按内存池 个数等分为若干个配置项, 每个配置项对应一个内存池的配置, 其中包括 内存池的内存块大小, 内存池的当前使用值及内存池的使用峰值。
10、 根据权利要求 9所述的装置, 其特征在于, 所述配置緩存中内存 池的当前使用值的初始值为零, 内存池的使用峰值的初始值为内存池配置 文件中相应内存池的内存块数。
PCT/CN2010/079278 2010-09-14 2010-11-30 嵌入式系统内存池配置方法及装置 WO2012034322A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201010280594.8A CN101937398B (zh) 2010-09-14 2010-09-14 嵌入式系统内存池配置方法及装置
CN201010280594.8 2010-09-14

Publications (1)

Publication Number Publication Date
WO2012034322A1 true WO2012034322A1 (zh) 2012-03-22

Family

ID=43390737

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2010/079278 WO2012034322A1 (zh) 2010-09-14 2010-11-30 嵌入式系统内存池配置方法及装置

Country Status (2)

Country Link
CN (1) CN101937398B (zh)
WO (1) WO2012034322A1 (zh)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102880550B (zh) * 2011-07-12 2014-12-17 北京东方通科技股份有限公司 基于约束校验的内存格式化方法
CN107153618A (zh) * 2016-03-02 2017-09-12 阿里巴巴集团控股有限公司 一种内存分配的处理方法及装置
CN106371896B (zh) * 2016-09-20 2019-08-23 Oppo广东移动通信有限公司 虚拟机内存配置方法及装置、移动终端
CN109254862B (zh) * 2018-08-21 2022-04-12 奇酷互联网络科技(深圳)有限公司 自动修复ddr翻转的方法、移动终端和存储介质
CN110209434B (zh) * 2019-04-23 2022-04-22 努比亚技术有限公司 一种内存管理方法、装置及计算机可读存储介质

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1570883A (zh) * 2003-07-15 2005-01-26 中兴通讯股份有限公司 嵌入式实时操作系统中非缓冲内存动态分配方法
CN1996258A (zh) * 2006-12-28 2007-07-11 武汉虹旭信息技术有限责任公司 一种动态内存池的实现方法
CN101221536A (zh) * 2008-01-25 2008-07-16 中兴通讯股份有限公司 嵌入式系统的内存管理方法及装置

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20060108431A (ko) * 2005-04-13 2006-10-18 삼성전자주식회사 가변적인 동적 메모리 관리 방법 및 이를 포함하는임베디드 시스템
CN101329655B (zh) * 2008-07-31 2011-09-28 北京天碁科技有限公司 一种内存管理方法和内存管理装置

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1570883A (zh) * 2003-07-15 2005-01-26 中兴通讯股份有限公司 嵌入式实时操作系统中非缓冲内存动态分配方法
CN1996258A (zh) * 2006-12-28 2007-07-11 武汉虹旭信息技术有限责任公司 一种动态内存池的实现方法
CN101221536A (zh) * 2008-01-25 2008-07-16 中兴通讯股份有限公司 嵌入式系统的内存管理方法及装置

Also Published As

Publication number Publication date
CN101937398B (zh) 2014-03-12
CN101937398A (zh) 2011-01-05

Similar Documents

Publication Publication Date Title
JP5468207B2 (ja) 相補性メモリ管理
US8595414B2 (en) Selectively combining commands for a system having non-volatile memory
US20140095555A1 (en) File management device and method for storage system
TWI389125B (zh) 記憶體儲存裝置及其控制方法
US7792882B2 (en) Method and system for block allocation for hybrid drives
US7543103B2 (en) Host apparatus
JP5976608B2 (ja) メモリデバイス
WO2016165597A1 (zh) 数据存储的处理方法及装置
US11422860B2 (en) Optimizing save operations for OS/hypervisor-based persistent memory
KR20120037786A (ko) 저장 장치, 그것의 락 모드 관리 방법, 및 그것을 포함하는 메모리 시스템
TW201415233A (zh) 使用適應性壓縮比之刷新指令之快速執行
WO2015121938A1 (ja) データ管理装置及び方法
WO2012034322A1 (zh) 嵌入式系统内存池配置方法及装置
US20180275889A1 (en) Append only streams for storing data on a solid state device
JP2008299848A (ja) 不揮発性メモリのデータ処理装置及びその処理方法
US11138104B2 (en) Selection of mass storage device streams for garbage collection based on logical saturation
US20230088790A1 (en) Using a common pool of blocks for user data and a system data structure
JP2011520176A (ja) 光ディスクドライブのように動作可能なメモリドライブ及びメモリドライブを光ディスクドライブに仮想化する方法
Son et al. An empirical evaluation of nvm express ssd
WO2019047612A1 (zh) 基于闪存的存储路径优化的键值存储管理方法
TWI529730B (zh) 資料儲存裝置與快閃記憶體控制方法
WO2018103010A1 (zh) 一种存储设备管理方法及用户终端
CN110312986B (zh) 用于在固态设备上存储数据的流的机会性使用
JP2013532880A (ja) メモリ領域を埋めるためのプロセッサ支援
US20180232154A1 (en) Append Only Streams For Storing Data On A Solid State Device

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: 10857178

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: 10857178

Country of ref document: EP

Kind code of ref document: A1