A memory pool optimization method and device for a multi-core system

By allocating a local memory pool for each core in a multi-core system and establishing a global memory pool in the system memory, the migration and capacity adjustment of memory objects are realized, the lock conflict problem and memory pool imbalance problem are solved, and the performance of multi-core systems is improved.

CN119576581BActive Publication Date: 2025-05-06BEIJING QINGWANG TECH CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510112871.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-23
Publication Date
2025-05-06
Estimated Expiration
2045-01-23

AI Technical Summary

Technical Problem

In multi-core systems, the lock conflict problem of memory pools leads to performance degradation. The existing technology cannot effectively adjust the memory pool capacity when memory objects are applied and released across cores, resulting in imbalance and performance bottlenecks.

Method used

Allocate a local memory pool for each core, and establish a global memory pool in the system memory. By migrating the memory objects между local memory pool and global memory pool, adjust the local memory pool capacity of each core to reduce lock conflicts.

Benefits of technology

By reducing the lock operation of system memory and reducing the frequency of memory access and operation, the stability and balance of the capacity of local memory pools of each core are achieved, and the performance of multi-core systems is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576581B_ABST
    Figure CN119576581B_ABST
Patent Text Reader

Abstract

This specification relates to the field of computer technology, and in particular to a method and device for optimizing the memory pool of a multi-core system. The method includes allocating a corresponding local memory pool to each core; establishing a global memory pool corresponding to the local memory pools of all cores in the system memory; migrating the memory objects in the global memory pool to the local memory pool that applied for the memory objects, or returning the memory objects released by the local memory pool to the global memory pool. Using the embodiments of this specification, when the local memory pool applies for and releases memory objects from the global memory pool, the system memory will not be locked, thereby reducing the access and operation to the system memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for optimizing a memory pool of a multi-core system. Background Art

[0002] In the conventional prior art, memory is maintained by the operating system. When software needs to use memory, it applies for and releases memory objects through the interface provided by the operating system. However, in some software with high performance and efficiency requirements, a memory pool is maintained in the software, and a batch of memory objects are uniformly applied for from the operating system and placed in the software's memory pool. When the software needs to use memory, it obtains memory objects from the memory pool. However, in a multi-core scenario, there will be concurrency of multiple threads and multiple execution flows, and a mutual exclusion mechanism (lock protection) needs to be added to the memory pool. The introduction of a lock mechanism will cause conflicts and thus reduce system performance.

[0003] In a multi-core system structure, each core (CPU, etc.) maintains its own memory pool. When the software running on the core applies for and releases memory, it only applies for and releases it in the local memory pool of the core, thus avoiding the performance degradation caused by lock conflicts. However, this existing technology is only applicable to the scenario where memory objects are applied for and released in the memory pool of the local core. If a memory object is applied for on one core and released on another core, the memory pools of the cores will be unbalanced. In the worst case (for example, each application is made from one core and released on another core), it is equivalent to completely eliminating the expected optimization effect of the memory pool, and there is still a serious lock conflict problem.

[0004] How to optimize the memory pool on a multi-core system is an urgent problem to be solved. Summary of the invention

[0005] To solve the problems in the prior art, the embodiments of this specification provide a method and device for optimizing the memory pool of a multi-core system, which solves the frequent lock conflicts between the local memory pool of each core and the system memory in the prior art.

[0006] The embodiment of this specification provides a method for optimizing a memory pool of a multi-core system, the method comprising:

[0007] Allocate a corresponding local memory pool for each core;

[0008] Create a global memory pool in system memory corresponding to the local memory pools of all cores;

[0009] Migrate the memory objects in the global memory pool to the local memory pool of the application memory object, or,

[0010] Return the memory objects released by the local memory pool to the global memory pool.

[0011] As a further aspect of the present specification, allocating a corresponding local memory pool to each core further includes maintaining the local memory pool using a stack, wherein the top and bottom of the stack both point to the bottom of the local memory pool in an initial state.

[0012] As a further aspect of the present specification, migrating the memory objects in the global memory pool to the local memory pool of the memory object further includes migrating the memory objects in the global memory pool to the local memory pool of the memory object if the number of unused memory objects in the local memory pool is lower than the local memory lower limit threshold.

[0013] As a further aspect of the present specification, before migrating the memory objects in the global memory pool to the local memory pool for applying for the memory objects, the method also includes checking the number of memory objects in the global memory pool; if the number of unused memory objects in the global memory pool is lower than the global memory lower limit threshold, locking the global memory pool, migrating the memory objects of the system memory to the global memory pool, and then releasing the locked state of the global memory.

[0014] As another further aspect of the present specification, migrating the memory objects of the system memory to the global memory pool further includes migrating the memory objects of the system memory to the global memory pool through an asynchronous work queue.

[0015] As another further aspect of the present specification, migrating the memory objects of the system memory to the global memory pool through the asynchronous work queue further includes applying for a predetermined number of memory objects from the system memory; after migrating the predetermined number of memory objects to the global memory pool, releasing the locked state of the global memory; after a predetermined time interval, locking the global memory pool, and repeating the aforementioned steps until the global memory pool meets a preset condition.

[0016] As another further aspect of the present specification, the predetermined number is less than the total number of memory objects applied for from the system memory.

[0017] As another further aspect of the present specification, the preset condition includes that the global memory pool is greater than a second threshold value.

[0018] As another further aspect of the present specification, migrating the memory objects in the global memory pool to the local memory pool for applying for memory objects further includes migrating a number of memory objects in the global memory pool related to the capacity of the local memory pool to the local memory pool.

[0019] As another further aspect of the present specification, migrating a number of memory objects in the global memory pool related to the capacity of the local memory pool to the local memory pool further includes migrating memory objects in the global memory pool equivalent to half of the capacity of the local memory pool to the local memory pool.

[0020] As another further aspect of the present specification, returning the memory object released by the local memory pool to the global memory pool further includes:

[0021] If the number of unused memory objects in the local memory pool is greater than the local memory upper limit threshold, the memory objects in the local memory pool are released to the global memory pool.

[0022] As another further aspect of the present specification, after releasing the memory objects of the local memory pool to the global memory pool, it also includes checking the number of memory objects in the global memory pool; if the number of memory objects in the global memory pool is higher than a first global memory upper limit threshold, locking the global memory pool, releasing the memory objects of the global memory pool to the system memory, and then unlocking the global memory.

[0023] As another further aspect of the present specification, determining whether the number of unused memory objects in the local memory pool is greater than the local memory upper limit threshold further includes determining whether the number of unused memory objects in the local memory pool is greater than the local memory upper limit threshold based on the total number of memory objects released by the process being executed by the core corresponding to the local memory pool and the number of unused memory objects in the local memory pool.

[0024] As another further aspect of the present specification, after releasing the memory objects of the local memory pool to the global memory pool, the method further includes releasing the memory objects occupied by the processes executed by the core corresponding to the local memory pool to the local memory pool.

[0025] As another further aspect of the present specification, releasing the memory objects of the local memory pool to the global memory pool further includes temporarily storing the memory objects stored locally in an overflow queue if the number of memory objects in the global memory pool is higher than a second global memory upper limit threshold.

[0026] As another further aspect of the present specification, after releasing the memory objects of the local memory pool to the global memory pool, if the number of memory objects in the global memory pool is higher than a first global memory upper limit threshold, the overflow queue is locked, and the memory objects in the overflow queue are preferentially released to the system memory, and then the locked state of the overflow queue is unlocked.

[0027] As another further aspect of the present specification, it also includes that after the memory objects in the overflow queue are released to the system memory, if the number of memory objects in the global memory pool is still higher than the first global memory upper limit threshold, the global memory pool is locked, and after the memory objects in the global memory pool are released to the system memory, the locked state of the global memory is released.

[0028] As another further aspect of the present specification, releasing the memory objects of the global memory pool to the system memory further includes releasing the memory objects of the global memory pool to the system memory through an asynchronous work queue.

[0029] As another further aspect of the present specification, releasing the memory objects of the global memory pool to the system memory through the asynchronous work queue further includes releasing a predetermined number of memory objects in the global memory to the system memory and releasing the locked state of the global memory; locking the global memory pool after a predetermined time interval, and repeating the aforementioned steps until the global memory pool meets a preset condition.

[0030] As another further aspect of the present specification, the predetermined number is less than the total number of memory objects released to the system memory.

[0031] The embodiment of the present specification also provides a memory pool optimization device for a multi-core system, the device comprising:

[0032] A local memory pool construction unit is used to allocate a corresponding local memory pool to each core;

[0033] A global memory pool construction unit is used to establish a global memory pool corresponding to the local memory pools of all cores in the system memory;

[0034] A memory object application unit, used for migrating memory objects in the global memory pool to apply for memory objects in a local memory pool;

[0035] A memory object releasing unit is used to return the memory objects released by the local memory pool to the global memory pool.

[0036] The embodiments of the present specification also provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the computer program.

[0037] The embodiments of this specification also provide a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed by a processor, the above method is implemented.

[0038] The embodiments of this specification also provide a computer program product, which includes a computer program. When the computer program is executed by a processor, the above method is implemented.

[0039] By using the embodiments of the present specification, when the local memory pool applies for and releases memory objects from the global memory pool, the system memory will not be locked, thereby reducing the access and operation to the system memory. Moreover, when different cores apply for and release memory objects, the local memory pool capacity of the corresponding core will interact with the global memory pool after the change, thereby adjusting the size and capacity of the local memory pool and maintaining the stability of the size and capacity of the local memory pool of each core. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0041] Figure 1 It is a flowchart of a memory pool optimization method for a multi-core system according to an embodiment of this specification;

[0042] Figure 2 The figure is a flow chart of a method for initializing a system memory according to an embodiment of the present specification;

[0043] Figure 3 The figure is a schematic diagram of the structure of the multi-core memory of the embodiment of this specification;

[0044] Figure 4 Shown is a flowchart of a memory object application according to an embodiment of this specification;

[0045] Figure 5 Shown is a flowchart of releasing a memory object according to an embodiment of this specification;

[0046] Figure 6 The figure shows a schematic diagram of the structure of a memory pool optimization device for a multi-core system according to an embodiment of the present specification;

[0047] Figure 7 A computer device provided by an embodiment of this specification is shown.

[0048] [Description of Reference Numerals]

[0049] 601. Local memory pool generation unit;

[0050] 602. Global memory pool generation unit;

[0051] 603, memory object application unit;

[0052] 604, memory object release unit;

[0053] 702. Computer equipment;

[0054] 704, processor;

[0055] 706. Memory;

[0056] 708, driving mechanism;

[0057] 710, input / output module;

[0058] 712. Input devices;

[0059] 714. Output devices;

[0060] 716. Presentation equipment;

[0061] 718. Graphical user interface;

[0062] 720, network interface;

[0063] 722. Communication link;

[0064] 724. Communication bus. DETAILED DESCRIPTION

[0065] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.

[0066] In the embodiments of this specification, a method for optimizing the memory pool of a multi-core system is provided. Figure 1 The flowchart of a memory pool optimization method for a multi-core system in an embodiment of the present specification is shown. In this figure, in addition to allocating a local memory pool to each core in the system memory, a global memory pool is also established in the system memory. When applying for or releasing a memory object, the local memory pool of each core does not directly interact with the system memory, but interacts with the global memory pool to complete the application or release of the memory object, thereby reducing the system memory operations that cause system performance bottlenecks, specifically including:

[0067] Step 101, allocating a corresponding local memory pool to each core;

[0068] Step 102, establishing a global memory pool corresponding to the local memory pools of all cores in the system memory;

[0069] Step 103: Migrate the memory objects in the global memory pool to the local memory pool for applying for the memory objects, or,

[0070] Return the memory objects released by the local memory pool to the global memory pool.

[0071] Through the method in the embodiments of this specification, when the local memory pool applies for and releases memory objects from the global memory pool, the system memory will not be locked, thereby reducing the access and operation to the system memory, and when different cores apply for and release memory objects, the local memory pool capacity of the corresponding core will interact with the global memory pool after the change, so as to adjust the size of the local memory pool and maintain the stability of the size of the local memory pool of each core.

[0072] In an embodiment of the present specification, three threshold values ​​of the global memory pool are set. When the number of memory objects in the global memory pool is lower than a first threshold value, memory objects in the system memory are migrated to the global memory pool until the number of memory objects in the global memory pool reaches the second threshold value; when the number of memory objects in the global memory pool is higher than a third threshold value, memory objects in the global memory pool are released to the system memory until the number of memory objects in the global memory pool reaches the second threshold value; wherein the first threshold value is smaller than the second threshold value, and the second threshold value is smaller than the third threshold value.

[0073] In this embodiment, the global memory pool may include three threshold values, wherein the first threshold value, the second threshold value and the third threshold value are 10%, 50% and 90% of the capacity of the global memory pool respectively (the three threshold values ​​may be other values). When the number of memory objects in the global memory pool is lower than 10%, it is necessary to apply for migration of memory objects from the system memory pool to the global memory pool until the number of memory objects in the global memory pool reaches about 50% (for example, slightly greater than the threshold value) and then stop applying for memory objects from the system memory; when the number of memory objects in the global memory pool is higher than 90%, the global memory pool releases memory objects to the system memory until the number of memory objects in the global memory pool reaches about 50% (for example, slightly less than the threshold value) and then stop releasing memory objects from the system memory; thereby achieving a balance in which the unused memory objects in the global memory pool are kept at about 50% to achieve balance.

[0074] In the embodiment of this specification, allocating a corresponding local memory pool to each core further includes:

[0075] The local memory pool is maintained by using a stack, and the top and bottom of the stack both point to the bottom of the local memory pool in an initial state.

[0076] In this embodiment, the local memory pool of each core is in array form, and the local memory pool in array form is maintained by stacking. In the initial state, the top and bottom of the local memory pool both point to the bottom of the local memory pool. As the number of unused memory objects in the local memory pool increases, the top of the stack continues to rise. When the corresponding core executes a process, it obtains a corresponding number of memory objects from the stack according to the needs of the process, and the top of the stack drops to the corresponding position. Among them, the local memory pool in array form can more efficiently realize the application and release of memory objects by the local memory pool.

[0077] In an embodiment of the present specification, migrating the memory object in the global memory pool to the local memory pool of the application memory object further includes:

[0078] If the number of unused memory objects in the local memory pool is lower than the local memory lower limit threshold, the memory objects in the global memory pool are migrated to the local memory pool for applying for memory objects.

[0079] In this embodiment, the number of unused memory objects in the local memory pool can be obtained based on the number of memory objects between the top and the bottom of the local memory pool stack. When the number of unused memory objects in the local memory pool is less than the local memory lower limit threshold, the local memory pool is triggered to apply for memory from the global memory pool.

[0080] In another embodiment, the local memory pool stack top may be compared with the local memory lower limit threshold, and when the stack top is less than or equal to the local memory lower limit threshold, the local memory pool is triggered to apply for memory from the global memory pool.

[0081] In the embodiment of the present specification, before migrating the memory object in the global memory pool to the local memory pool of the application memory object, the method further includes:

[0082] Checking the number of memory objects in the global memory pool;

[0083] If the number of unused memory objects in the global memory pool is lower than the global memory lower limit threshold, the global memory pool is locked, and after the memory objects of the system memory are migrated to the global memory pool, the locking state of the global memory is released.

[0084] In this embodiment, the steps in this embodiment can be performed before migrating the memory objects in the global memory pool to the local memory pool for applying for the memory objects, or after migrating the memory objects in the global memory pool to the local memory pool for applying for the memory objects. When the number of unused memory objects in the global memory pool is lower than the preset global memory lower limit threshold (i.e., the aforementioned first threshold value), it means that the number of unused memory objects in the global memory pool is insufficient. If the local memory pools of other cores also apply for memory objects from the global memory pool at the same time, the application may fail due to insufficient memory objects in the global memory pool, causing the execution process of the core to be affected. Therefore, it is necessary to expand the capacity of the global memory pool. Since the local memory pools of multiple cores may apply for memory objects from the global memory pool at the same time, when it is necessary to respond to the request of a local memory pool of a core to apply for memory objects, the global memory pool is locked, thereby avoiding the competition problem of the local memory pools of multiple cores. After the memory objects in the global memory pool are migrated to the local memory pool of a core, the locking state of the global memory pool is released. When the global memory pool is expanded, it is also necessary to lock the global memory pool, apply for memory objects from the operating system through the interface opened by the operating system, and the operating system migrates the memory objects in the system memory to the global memory pool. Since this process involves the operating system level, the response speed and processing speed are relatively slow, which is one of the reasons why the memory pool technology in the prior art affects the system efficiency. In addition, when the global memory pool applies for memory objects from the operating system, although the global memory pool is in a locked state, the local memory pool of each core is not in a locked state, that is, the process on each core is executed in the local memory pool and is not affected by the locking of the global memory pool. The local memory pool implemented in the form of a stack can also improve the efficiency of each core in executing the process.

[0085] In the embodiment of the present specification, after migrating the memory object of the system memory to the global memory pool, releasing the locked state of the global memory further includes:

[0086] Applying a predetermined number of memory objects to the system memory;

[0087] After migrating the predetermined number of memory objects to the global memory pool, releasing the locked state of the global memory;

[0088] After a predetermined time interval, the global memory pool is locked, and the above steps are repeated until the global memory pool reaches a preset condition.

[0089] In this embodiment, the asynchronous work queue is triggered when the memory objects of the system memory are migrated to the global memory pool. In the asynchronous work queue, a predetermined number of memory objects in the system memory are migrated to the global memory pool in multiple times. The following example illustrates that the total number of memory objects applied for by the global memory pool is 512. The asynchronous work queue applies for memory objects from the system memory in multiple times based on the total number. The number of memory objects applied for each time is a predetermined number, such as 128, or it can also be other numbers of memory objects. After the predetermined number of memory objects are migrated to the global memory pool, the locking state of the global memory pool is released, and the locking state of the system memory is also released. The asynchronous work queue is put to sleep for a predetermined time, such as 1 millisecond. During the sleep time, the global memory pool can also respond to requests from other cores' local memory pools to apply for or release memory objects, and the system memory can also process requests to apply for memory objects. After the sleep time interval, the global memory pool and the system memory are locked again, and the asynchronous work queue continues to migrate the remaining predetermined number of memory objects in the system memory to the global memory pool. After the asynchronous work queue repeats the above steps three times, the process of migrating 512 memory objects from the system memory to the global memory pool is completed.

[0090] By completing the migration of memory objects between the system memory and the global memory pool through an asynchronous work queue, the latency of system memory operations can be fully utilized, allowing the global memory pool to respond more to requests from the local memory pools of multiple cores to apply for or release memory objects.

[0091] The predetermined number is less than the total number of memory objects applied for from the system memory.

[0092] In this embodiment, only one possibility is limited. When the number of memory objects requested by the global memory pool from the system memory is small, the corresponding number of memory objects in the system memory can be migrated to the global memory pool at one time, without having to migrate the memory objects multiple times through the asynchronous work queue.

[0093] The preset condition includes that the global memory pool is greater than a second threshold value.

[0094] In this embodiment, after migrating the memory objects in the system memory to the global memory pool according to the number of memory objects applied for by the global memory pool, the migration can be stopped; or, as the memory objects in the system memory are migrated to the global memory pool, it can be determined in real time whether the number of memory objects in the global memory pool is greater than the capacity of all core local memory pools. When the number of memory objects in the global memory pool is greater than the capacity of all core local memory pools, the migration of the memory objects in the system memory to the global memory pool is stopped. This is because it takes a certain amount of time to migrate the memory objects in the system memory to the global memory pool through the asynchronous work queue. During this period of time, the global memory pool may release memory objects in the local memory pools of some cores, which increases the number of unused memory objects in the global memory pool. It is no longer necessary to apply for memory objects from the system memory. Therefore, the number of memory objects in the global memory pool can be determined in real time to control the process of migrating the memory objects in the system memory to the global memory pool.

[0095] In other embodiments, the preset condition may also be that the number of unused memory objects in the global memory pool is greater than half of the total capacity of the global memory pool. That is, when the number of unused memory objects in the global memory pool is greater than half of the total capacity of the global memory pool (i.e., the aforementioned second threshold value), the migration of memory objects of the system memory to the global memory pool is stopped.

[0096] In an embodiment of the present specification, migrating the memory object in the global memory pool to the local memory pool of the application memory object further includes:

[0097] Migrate a number of memory objects in the global memory pool that is related to the capacity of the local memory pool to the local memory pool.

[0098] In this step, a corresponding number of memory objects in the global memory pool can be migrated to the local memory pool according to the size of the local memory pool capacity. For example, memory objects in the global memory pool equivalent to half of the local memory pool capacity can be migrated to the local memory pool.

[0099] In other embodiments, memory objects in the global memory pool may be migrated to the local memory pool according to the number of memory objects applied for by the local memory pool. For example, if the local memory pool applies for 512 memory objects from the global memory pool, then the 512 memory objects in the global memory pool are migrated to the local memory pool.

[0100] In an embodiment of the present specification, returning the memory object released by the local memory pool to the global memory pool further includes:

[0101] If the number of unused memory objects in the local memory pool is greater than the local memory upper limit threshold, the memory objects in the local memory pool are released to the global memory pool.

[0102] In this embodiment, the number of unused memory objects in the local memory pool can be obtained according to the number of memory objects between the top and the bottom of the local memory pool stack. When the number of unused memory objects in the local memory pool is greater than the local memory upper limit threshold, the local memory pool is triggered to release memory to the global memory pool.

[0103] In another embodiment, the local memory pool stack top may be compared with a local memory upper limit threshold, and when the stack top is greater than or equal to the local memory upper limit threshold, the local memory pool is triggered to release memory to the global memory pool.

[0104] In the embodiment of the present specification, after releasing the memory object of the local memory pool to the global memory pool, the method further includes:

[0105] Checking the number of memory objects in the global memory pool;

[0106] If the number of memory objects in the global memory pool is higher than a first global memory upper limit threshold, the global memory pool is locked, and after the memory objects in the global memory pool are released to the system memory, the locked state of the global memory is released.

[0107] In this embodiment, the steps in this embodiment can be performed before releasing the memory objects in the local memory pool to the global memory pool, or after releasing the memory objects in the local memory pool to the global memory pool. When the number of unused memory objects in the global memory pool is higher than the preset first global memory upper limit threshold (i.e., the aforementioned third threshold value), it means that the number of unused memory objects in the global memory pool is too large. For example, the first global memory upper limit threshold is 80% of the global memory pool capacity, which occupies too much system memory. Therefore, the global memory pool needs to be released. Since the local memory pools of multiple cores may release memory objects to the global memory pool at the same time, when it is necessary to respond to the request of a local memory pool of a core to release memory objects, the global memory pool is locked, thereby avoiding the competition problem of the local memory pools of multiple cores. After releasing the memory objects in the local memory pool to the global memory pool, the lock state of the global memory pool is released. When releasing the global memory pool, it is also necessary to lock the global memory pool. Through the interface opened by the operating system, the memory object is released to the operating system. The operating system releases the memory object in the global memory pool to the system memory. Since this process involves the operating system level, the response speed and processing speed are relatively slow. This is also one of the reasons why the memory pool technology in the prior art affects the system efficiency. In addition, when the global memory pool releases the memory object to the operating system, although the global memory pool is in a locked state, the local memory pool of each core is not in a locked state. That is to say, the process on each core is executed in the local memory pool and is not affected by the locking of the global memory pool. This can also improve the efficiency of each core in executing the process.

[0108] In the embodiment of the present specification, the step of determining that the number of unused memory objects in the local memory pool is greater than the local memory upper limit threshold further includes:

[0109] According to the sum of the number of memory objects released by the process being executed by the core corresponding to the local memory pool and the number of unused memory objects in the local memory pool, it is determined whether it is greater than the local memory upper limit threshold.

[0110] In this embodiment, when the process being executed by the current core is completed, the memory objects occupied by the process will be returned to the local memory pool of the core. When the returned memory objects are memory objects applied for by the process in the local memory pools of other cores and returned in the local memory pool of the current core, the sum of the number of unused memory objects and released memory objects in the local memory pool of the current core may be greater than the local memory upper limit threshold, indicating that the number of unused memory objects in the local memory pool of the current core is large. In order to avoid inconsistent local memory pool capacities of different cores caused by such cross-core memory object returns, memory objects in the local memory pool that are greater than the local memory upper limit threshold can be released to the global memory pool.

[0111] In another embodiment, when the process being executed by the current core is about to be completed, the sum of the number of memory objects occupied by the process that is about to be completed and the number of unused memory objects in the local memory pool can be calculated. The sum may be greater than the local memory upper limit threshold, indicating that the number of memory objects in the local memory pool of the current core is large, and the memory objects in the local memory pool that are greater than the local memory upper limit threshold can be released to the global memory pool. Wherein, it can be judged whether it is about to be completed according to the type of work of the process being executed in the current core, for example, the completion time of the process being executed by the current core can be estimated according to the execution time of processes of different work types recorded in the log, for example, the work type of the process can include work types such as parsing messages, forwarding messages or converting messages, and different work types have corresponding process execution times. The processing completion time of the process being executed in the current core with the same work type is estimated according to the average time of the work type of the process executed in the history, or the task submitter can estimate a work end time by himself when submitting the task; wherein, the judgment of whether it is about to be completed can be judged according to a preset time value, for example, 0.1 milliseconds. It is also possible to estimate the completion time of the process currently being executed by the current core based on the work type of the process and the type of data being processed. In other words, the time required for the current core to execute the current process can be estimated by analyzing the historical work types of the process and the types of data being processed. For example, based on the time the current core spent processing type a data of type A work type in the historical records, it is possible to estimate the time required for the current core to execute the current process, thereby determining whether the process currently being executed by the current core is about to be completed.

[0112] In an embodiment of the present specification, releasing the memory object of the local memory pool to the global memory pool further includes:

[0113] If the number of memory objects in the global memory pool is higher than a second global memory upper limit threshold, the memory objects stored locally are temporarily stored in an overflow queue.

[0114] In this embodiment, when the local memory pool releases memory objects to the global memory pool, the number of memory objects in the global memory pool may exceed the second global memory upper limit threshold (or when the global memory pool is full), wherein the second global memory upper limit threshold may be greater than or equal to the first global memory upper limit threshold. For example, the second global memory upper limit threshold may be 100% of the capacity of the global memory pool. If you wait for the global memory pool to release memory objects to the system memory, you may have to wait for a long time. At this time, the memory objects released by the local memory pool may be temporarily stored in an overflow queue. The overflow queue is a queue in the form of a linked list, which is independent of the global memory pool and the local memory pool. The overflow queue in the form of a linked list can facilitate capacity expansion, and the overflow queue can ensure the efficiency of releasing memory objects from the local memory pool to the global memory pool.

[0115] In the embodiment of the present specification, after releasing the memory object of the local memory pool to the global memory pool, the method further includes:

[0116] If the number of memory objects in the global memory pool is higher than a first global memory upper limit threshold, the overflow queue is locked, and after the memory objects in the overflow queue are preferentially released to the system memory, the locking state of the overflow queue is released.

[0117] In an embodiment of the present specification, when the overflow queue is not empty and the number of unused memory objects in the global memory pool exceeds a first global memory upper limit threshold, memory objects are preferentially released from the overflow queue to the system memory. Since there is frequent interaction (i.e., applying for or releasing memory objects) between the global memory pool and the local memory pool of each core, when the overflow queue releases memory objects to the system memory, the global memory pool may no longer be higher than the first global memory upper limit threshold due to the interaction with the local memory pool of each core. In this case, there is no need to lock the global memory pool to release memory objects to the system memory, thereby avoiding the situation where the core execution process waits for the local memory pool action (applying for or releasing memory objects) after the global memory pool is locked.

[0118] After the memory objects in the overflow queue are released to the system memory, if the number of memory objects in the global memory pool is still higher than the first global memory upper limit threshold, the global memory pool is locked, and after the memory objects in the global memory pool are released to the system memory, the locked state of the global memory is released. When releasing the memory objects in the global memory pool to the system memory, it is continuously determined whether the number of memory objects in the global memory pool is higher than the first global memory upper limit threshold. If it is not higher than the first global memory upper limit threshold, the memory objects in the global memory pool are stopped from being released to the system memory, and the locked state of the global memory is released.

[0119] In an embodiment of the present specification, after releasing the memory objects of the global memory pool to the system memory, releasing the locked state of the global memory further includes:

[0120] Releasing a predetermined number of memory objects in the global memory to the system memory, and releasing the locked state of the global memory;

[0121] After a predetermined time interval, the global memory pool is locked, and the above steps are repeated until the global memory pool reaches a preset condition.

[0122] In this embodiment, the asynchronous work queue is triggered when the memory objects in the global memory pool are released to the system memory. In the asynchronous work queue, a predetermined number of memory objects in the global memory pool are migrated to the system memory in multiple times. The following example illustrates that the total number of memory objects to be released from the global memory pool is 512. The asynchronous work queue releases memory objects to the system memory in multiple times based on the total number. The number of memory objects released each time is a predetermined number, such as 128, or may be other numbers of memory objects. After the predetermined number of memory objects are released to the system memory, the locking state of the global memory pool is released, and the locking state of the system memory is also released. The asynchronous work queue is put to sleep for a predetermined time, such as 1 millisecond. During the sleep time, the global memory pool can also respond to requests from other cores' local memory pools to apply for or release memory objects, and the system memory can also process requests to apply for memory objects. After the sleep time interval, the global memory pool and the system memory are locked again, and the asynchronous work queue continues to release the remaining predetermined number of memory objects in the global memory pool to the system memory. After the asynchronous work queue repeats the above steps three times, the process of releasing 512 memory objects from the global memory pool to the system memory is completed.

[0123] The predetermined number is less than the total number of memory objects released to the system memory.

[0124] In this embodiment, only one possibility is limited. When the number of memory objects released from the global memory pool to the system memory is small, a corresponding number of memory objects in the global memory pool can be released to the system memory at one time without releasing the memory objects multiple times through the asynchronous work queue.

[0125] The preset condition includes that the global memory pool is smaller than a second threshold value.

[0126] In this embodiment, after releasing memory objects in the global memory pool to the system memory according to the number of memory objects released by the global memory pool, the release can be stopped; or, as the memory objects in the global memory pool are released to the system memory, it can be determined in real time whether the number of memory objects in the global memory pool is less than the capacity of all core local memory pools. When the number of memory objects in the global memory pool is less than the capacity of all core local memory pools, the release of memory objects in the global memory pool to the system memory is stopped. This is because it takes a certain amount of time to release memory objects in the global memory pool to the system memory through the asynchronous work queue. During this period of time, the global memory pool may reduce the number of unused memory objects in the global memory pool due to the application of memory objects by the local memory pools of some cores, and it is no longer necessary to release memory objects to the system memory. Therefore, the number of memory objects in the global memory pool can be determined in real time to control the process of releasing memory objects in the global memory pool to the system memory.

[0127] In other embodiments, the preset condition may also include that the number of unused memory objects in the global memory pool is less than half of the total capacity of the global memory pool, that is, when the number of unused memory objects in the global memory pool is less than half of the total capacity of the global memory pool (that is, the aforementioned second threshold value), the memory objects in the global memory pool are stopped from being released to the system memory.

[0128] like Figure 2 The flowchart of the method for initializing the system memory in the embodiment of the present specification is shown. In this figure, it is described that a local memory pool corresponding to each core and a global memory pool corresponding to all local memory pools are divided in the system memory. Through the coordinated interaction of the local memory pool and the global memory pool, the application and release of the memory objects in the local memory pool are completed, and the local memory pool of the core is dynamically adjusted, lock conflicts are reduced, and memory scheduling efficiency is improved. The method specifically includes:

[0129] Step 201: Initialize the local memory pool.

[0130] Step 202: Allocate a local memory pool to each core.

[0131] In this step, an array is allocated from the system memory to each core through the operating system as the local memory pool of the core, each element in the array is used to store a pointer to a memory object, and the number of elements in the array LocalMemPoolMaxNum is equivalent to the number of memory objects in the local memory pool, which can be a set number, for example, 512.

[0132] The local memory pool in the form of an array can effectively avoid the cache invalidation problem caused by the jump of the linked list.

[0133] Step 203: Use a stack to maintain the local memory pool.

[0134] In this step, in the initial state, both the top of the stack TOP and the bottom of the stack Bottom point to the prime group element 0.

[0135] The memory objects just released by the local memory pool are likely to still be in the cache. Allocating memory objects to the process from the top of the stack can avoid some cache invalidation.

[0136] Step 204: Set a local memory upper threshold and a local memory lower threshold of the local memory pool.

[0137] In this step, two thresholds of local memory pools are set, namely the local memory upper threshold (HighWaterMark) and the local memory lower threshold (LowWaterMark). When Top is higher than HighWaterMark, it means that the number of unused memory objects in the local memory pool exceeds the upper threshold of the local memory pool, and the trigger logic releases LocalMemPoolMaxNum / 2 memory objects in the local memory pool to the global memory pool; when Top is lower than LowWaterMark, it means that the number of unused memory objects in the local memory pool is lower than the lower threshold of the local memory pool, and the trigger logic applies to the global memory pool for LocalMemPoolMaxNum / 2 memory objects to the local memory pool. HighWaterMark can be 7 / 8 of the array size (i.e. 448 memory objects), and LowWaterMark can be 1 / 8 of the array size (i.e. 64).

[0138] The number of memory objects in the local memory pool that are triggered to be released (LocalMemPoolMaxNum / 2), or the number of memory objects in the global memory pool that are triggered to be applied for (LocalMemPoolMaxNum / 2) in the above embodiment are both configurable, or can be learned based on the similarity of the core processing processes in history, and the number of memory objects that are triggered to be released or applied for in history. For example, within a specified time period (or within the previous time period), the core processes a Class A process, and during this process, the local memory pool of the core has released or applied for memory objects, the number of memory objects released or applied for can be used as a reference value for the number of memory objects released or applied for when the core processes the same type of process in the current period.

[0139] The values ​​of the local memory upper threshold (HighWaterMark) and the local memory lower threshold (LowWaterMark) in the above embodiment are also configurable, or can be obtained by learning the strategy of applying for or releasing memory objects in the local memory pool in history, as described above, based on the number of local memory pool memory objects that are triggered to be released or the number of global memory pool memory objects that are triggered to be applied for. For example, it can be adjusted based on the frequency of applying for or releasing memory objects in the local memory pool in history. When the frequency is high, the local memory upper threshold is increased and the local memory lower threshold is lowered.

[0140] Step 205, initializing the global memory pool.

[0141] Step 206: Allocate a global memory pool for the local memory pools of all cores.

[0142] In this step, a circular array is allocated from the system memory as a global memory pool through the operating system. Each element in the circular array is used to store a pointer to a physical memory object. The number of elements in the circular array GlobalMemPoolMaxNum is the product of the number of cores determined in step 202 and the number of elements in the array of the local memory pool of the corresponding core, that is, the number of cores*LocalMemPoolMaxNum, that is, the total capacity of the global memory pool is equivalent to the sum of the local memory pool capacities of all cores. The system memory can be allocated to the circular array of the global memory pool through the kmalloc function of the operating system.

[0143] Step 207: Set a global memory upper threshold and a global memory lower threshold of the global memory pool.

[0144] In this step, the thresholds of the global memory pool are set, which are the first global memory upper limit threshold (GlobalHighWaterMark), the global memory lower limit threshold (GlobalLowWaterMark), and the second global memory upper limit threshold. When the number of unused memory objects in the global memory pool exceeds the GlobalHighWaterMark, the trigger logic releases a part of the unused memory objects in the global memory pool to the system memory; when the number of unused memory objects in the global memory pool is lower than the GlobalLowWaterMark, the trigger logic migrates the memory objects in the system memory to the global memory pool; when the number of unused memory objects in the global memory pool exceeds the second global memory upper limit threshold, the trigger logic temporarily stores the memory objects released by the local memory pool in the overflow queue.

[0145] You can also refer to the attached Figure 3FIG. 1 is a schematic diagram of a multi-core memory structure of an embodiment of the present specification. The structure of the multi-core memory is described in this figure. The memory setting of the structure and the aforementioned method can be used to optimize the memory of the multi-core system. Figure 2 You can also refer to the initialization of the local memory pool and the initialization of the global memory pool in Figure 3 In addition, the memory structure in the memory pool may also include an asynchronous work queue, which is used to divide the memory objects into small batches and apply or release them multiple times after a predetermined time interval when applying for and releasing memory objects between the global memory pool and the system memory, thereby avoiding the problem that the global memory pool and the system memory are in a locked state for a long time when applying for and releasing memory objects between the global memory pool and the system memory, thereby affecting the response speed.

[0146] exist Figure 3 It also includes an overflow queue for caching memory objects released by the local memory pool. When the local memory pools of multiple cores release a large number of memory objects, the global memory pool may be full (or reach a preset second global memory upper limit threshold, or other preset thresholds), or the asynchronous work queue has not yet been able to migrate the memory objects released from the global memory pool to the system memory, then the memory objects released by the local memory pool are temporarily stored in the overflow queue.

[0147] exist Figure 3 Different cores and their corresponding local memory pools are shown in the figure. In this embodiment, Core1, Core2, and Coren are used to represent core 1, core 2, and core n. In other embodiments, more cores may be included. In the local memory pool, the gray part represents the unused memory objects in the array. The number of unused memory objects in different local memory pools is different. The relationship between the top of the local memory pool stack TOP and the local memory upper limit threshold (HighWaterMark) and the local memory lower limit threshold (LowWaterMark) can be used to determine whether to apply for memory objects from the global memory pool or release memory objects.

[0148] like Figure 4 The flowchart of the memory object application of the embodiment of this specification is shown in this figure. The process of applying for a memory object from the local memory pool of the core to the global memory pool and the process of applying for a memory object from the global memory pool to the system memory are described in this figure. Figure 3 The memory structure diagram shown in the figure can be used to understand Figure 4 The steps of memory application method include:

[0149] Step 401, monitor the local memory pool in real time.

[0150] In this step, the top of the stack in the local memory pool is monitored.

[0151] Step 402: If the top of the local memory pool is less than or equal to the local memory lower limit threshold, proceed to step 403; otherwise, return to step 401 to continue monitoring the local memory pool.

[0152] Step 403: The local memory pool applies for a memory object from the global memory pool.

[0153] Step 404: Check the number of unused memory objects in the global memory pool.

[0154] Step 405 , if the number of unused memory objects in the global memory pool is less than or equal to the global memory lower limit threshold, proceed to step 408 , otherwise proceed to step 406 .

[0155] Step 406: Migrate a certain number of memory objects from the global memory pool to the local memory pool.

[0156] In this step, memory objects in the global memory pool equal to half the capacity of the local memory pool (LocalMemPoolMaxNum / 2) of the memory objects requested can be migrated to the local memory pool.

[0157] As another embodiment, the number of stack tops below the local memory lower limit threshold in the above step 402 may also be used as the number of memory objects that the local memory pool applies to the global memory pool.

[0158] Step 407: allocate the memory object in the local memory pool to the process that requested the memory object according to the needs of the process.

[0159] Step 408: The global memory pool applies for a memory object from the system memory pool.

[0160] In this step, the global memory pool may submit a request for a memory object to the operating system through an operating system interface.

[0161] Step 409: The system memory migrates a certain number of memory objects to the global memory pool through the asynchronous work queue.

[0162] In this step, the global memory pool and the system memory are locked. For example, the global memory pool can apply for a total of 256 memory objects from the operating system. The operating system can migrate the memory objects in the system memory to the global memory pool in batches through an asynchronous work queue. For example, after migrating 128 memory objects to the global memory pool each time, the locking state of the system memory and the global memory pool is released.

[0163] Step 410: put the asynchronous work queue to sleep for a predetermined time.

[0164] In this step, after migrating the memory objects of the system memory to the global memory pool through the asynchronous work queue, the asynchronous work queue can be put to sleep for 1 millisecond, that is, the memory objects are not continuously migrated to the global memory pool, but the lock state of the system memory and the global memory pool is released, and then a period of time is waited. During this time interval, the global memory pool can respond to other requests for operations, thereby making full use of the latency of migrating memory objects from the system memory and improving the operational efficiency of the global memory pool in responding to local memory pool applications or releasing memory objects from other cores.

[0165] Step 411, determining whether the number of unused memory objects in the global memory pool meets a preset condition.

[0166] In this step, it can be determined whether the number of unused memory objects in the global memory pool is greater than the sum of the capacities of all local memory pools, or it can be determined whether the number of unused memory objects in the global memory pool is greater than half of the total capacity of the global memory pool. If it is greater, it meets the preset conditions and proceeds to step 412; if it is not greater, it does not meet the preset conditions and returns to step 409 to continue the next round of memory object migration.

[0167] Step 412, ending the memory object application process.

[0168] like Figure 5 The flowchart of memory object release in the embodiment of this specification is shown. In this figure, the process of releasing memory objects from the local memory pool of the core to the global memory pool and the process of releasing memory objects from the global memory pool to the system memory are described. Figure 3 The memory structure diagram shown in the figure can be used to understand Figure 5 The steps of releasing memory include:

[0169] Step 501, monitor the local memory pool in real time.

[0170] In this step, the top of the stack in the local memory pool is monitored.

[0171] Step 502: If the top of the local memory pool is greater than or equal to the local memory upper limit threshold, proceed to step 503; otherwise, return to step 501 and continue monitoring the local memory pool.

[0172] Step 503: The local memory pool requests the global memory pool to release the memory object.

[0173] Step 504: Check the number of unused memory objects in the global memory pool.

[0174] Step 505 , if the number of unused memory objects in the global memory pool is greater than or equal to the first global memory upper limit threshold, proceed to step 508 , otherwise proceed to step 506 .

[0175] Step 506: Release a certain number of memory objects from the local memory pool to the global memory pool.

[0176] In this step, half the capacity of the local memory pool (LocalMemPoolMaxNum / 2) of memory objects can be released to the global memory pool.

[0177] As another embodiment, the number of stack tops exceeding the local memory upper limit threshold in the above step 502 may also be used as the number of memory objects released from the local memory pool to the global memory pool.

[0178] As another embodiment, if the global memory pool is full (i.e., the number of unused memory objects in the global memory pool is equal to the total capacity of the global memory pool) or the number of unused memory objects in the global memory pool is greater than the second global memory upper limit threshold, the local memory pool can temporarily store memory objects in the overflow queue.

[0179] Step 507: Memory objects occupied by processes that have been executed by the current core are released to the local memory pool.

[0180] This step may also be performed before step 501, and after the current core completes executing the process and the process releases the occupied memory objects to the local memory pool, the number of memory objects in the local memory pool is monitored.

[0181] Step 508: The global memory pool requests the system memory pool to release the memory object.

[0182] In this step, the global memory pool may submit a request to release the memory object to the operating system through the operating system interface.

[0183] Step 509: The global memory pool releases a certain number of memory objects to the system memory through the asynchronous work queue.

[0184] In this step, the global memory pool and the system memory are locked. The global memory pool can, for example, release a total of 256 memory objects to the operating system. The memory objects in the global memory pool are released to the system memory in batches through an asynchronous work queue. For example, after 128 memory objects are released to the system memory each time, the locked state of the system memory and the global memory pool is released.

[0185] In another embodiment, before the global memory pool releases memory objects to the system memory through the asynchronous queue, if the overflow queue is not empty, that is, there are unused memory objects in the overflow queue, then the memory objects are preferentially released from the overflow queue to the system memory through the asynchronous work queue; if all the memory objects in the overflow queue have been released, then the above step 509 is executed to release a certain number of memory objects in the global memory pool to the system memory through the asynchronous work queue.

[0186] Step 510: put the asynchronous work queue to sleep for a predetermined time.

[0187] In this step, after releasing the memory objects of the global memory pool (or overflow queue) to the system memory through the asynchronous work queue, the asynchronous work queue can be put to sleep for 1 millisecond, that is, the memory objects are not continuously released to the system memory, but the locking state of the system memory and the global memory pool is released, and then a period of time is waited. During this time interval, the global memory pool can respond to other requests for operations, thereby making full use of the fact that it takes a long time to release memory objects to the system memory, which affects the efficiency of the global memory pool in responding to the local memory pool applications of other cores or releasing memory objects.

[0188] Step 511, determining whether the number of unused memory objects in the global memory pool meets a preset condition.

[0189] In this step, it can be determined whether the number of unused memory objects in the global memory pool is less than the sum of the capacities of all local memory pools, or it can be determined whether the number of unused memory objects in the global memory pool is less than half of the total capacity of the global memory pool. If it is less, it meets the preset conditions and proceeds to step 512; if it is not less, it does not meet the preset conditions and returns to step 509 to continue the next round of memory object release.

[0190] Step 512, ending the memory object release process.

[0191] like Figure 6 The figure shows a schematic diagram of the structure of a memory pool optimization device for a multi-core system according to an embodiment of the present specification. The figure describes the structure of the logic components for executing the above method. The logic components for implementing the above method in this embodiment can be implemented by a general processor or a specially configured processor. The device specifically includes:

[0192] A local memory pool generating unit 601 , a global memory pool generating unit 602 , a memory object applying unit 603 and a memory object releasing unit 604 .

[0193] The local memory pool generating unit 601 is used to allocate a corresponding local memory pool to each core;

[0194] The global memory pool generating unit 602 is used to establish a global memory pool corresponding to the local memory pools of all cores in the system memory;

[0195] The memory object application unit 603 is used to migrate the memory object in the global memory pool to the local memory pool where the memory object is applied;

[0196] The memory object releasing unit 604 is used to return the memory objects released by the local memory pool to the global memory pool.

[0197] Through the device of the above-mentioned embodiment of this specification, when the local memory pool applies for and releases memory objects from the global memory pool, the system memory will not be locked, thereby reducing the access and operation to the system memory, and when different cores apply for and release memory objects, the local memory pool capacity of the corresponding core will interact with the global memory pool after the change, so as to adjust the size of the local memory pool and maintain the stability of the size of the local memory pool of each core.

[0198] like Figure 7 A computer device provided in an embodiment of this specification is shown. The memory pool optimization method of a multi-core system in an embodiment of this specification can be run on the computer device in this embodiment to execute the above method of this specification. The computer device 702 may include one or more processors 704, such as one or more central processing units (CPUs), and each processing unit may implement one or more hardware threads. The computer device 702 may also include any memory 706, which is used to store any kind of information such as code, settings, data, etc. Non-limiting, for example, the memory 706 may include any one or more combinations of the following: any type of RAM, any type of ROM, flash memory device, hard disk, optical disk, etc. More generally, any memory can use any technology to store information. Further, any memory can provide volatile or non-volatile retention of information. Further, any memory can represent a fixed or removable component of the computer device 702. In one case, when the processor 704 executes an associated instruction stored in any memory or a combination of memories, the computer device 702 can perform any operation of the associated instruction. The computer device 702 also includes one or more drive mechanisms 708 for interacting with any storage, such as a hard disk drive mechanism, an optical disk drive mechanism, etc.

[0199] The computer device 702 may also include an input / output module 710 (I / O) for receiving various inputs (via input devices 712) and for providing various outputs (via output devices 714). A specific output mechanism may include a presentation device 716 and an associated graphical user interface (GUI) 718. In other embodiments, the input / output module 710 (I / O), the input device 712, and the output device 714 may not be included, and the computer device 702 may be used as a computer device in a network. The computer device 702 may also include one or more network interfaces 720 for exchanging data with other devices via one or more communication links 722. One or more communication buses 724 couple the components described above together.

[0200] The communication link 722 may be implemented in any manner, for example, through a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 722 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc. governed by any protocol or combination of protocols.

[0201] The embodiment of the present specification also provides a computer-readable instruction, wherein when a processor executes the instruction, the program therein causes the processor to execute the method as described above.

[0202] It should be understood that in the various embodiments of this specification, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this specification.

[0203] It should also be understood that in the embodiments of this specification, the term "and / or" is only a description of the association relationship of the associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this specification generally indicates that the associated objects before and after are in an "or" relationship.

[0204] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this specification can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this specification.

[0205] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0206] In the several embodiments provided in this specification, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or it can be an electrical, mechanical or other form of connection.

[0207] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of this specification.

[0208] In addition, each functional unit in each embodiment of this specification may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0209] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this specification is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of this specification. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0210] Specific embodiments are used in this specification to illustrate the principles and implementation methods of this specification. The description of the above embodiments is only used to help understand the methods and core ideas of this specification. At the same time, for those skilled in the art, according to the ideas of this specification, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on this specification.

Claims

1. A memory pool optimization method for a multi-core system, characterized in that: The method includes, Allocate a corresponding local memory pool for each core in the system memory; Create a global memory pool in system memory corresponding to the local memory pools of all cores; Migrate the memory objects in the global memory pool to the local memory pool for applying for the memory objects, or, Returning the memory objects released by the local memory pool to the global memory pool; Before migrating the memory object in the global memory pool to the local memory pool where the memory object is applied for, Checking the number of memory objects in the global memory pool; If the number of unused memory objects in the global memory pool is lower than the global memory lower limit threshold, the global memory pool is locked, and after the memory objects of the system memory are migrated to the global memory pool, the locking state of the global memory is released.

2. The method according to claim 1, characterized in that The local memory pool corresponding to each core in the system memory further includes: The local memory pool is maintained by using a stack, and the top and bottom of the stack both point to the bottom of the local memory pool in an initial state.

3. The method according to claim 1, characterized in that: Migrating the memory object in the global memory pool to the local memory pool of the application memory object further includes: If the number of unused memory objects in the local memory pool is lower than the local memory lower limit threshold, the memory objects in the global memory pool are migrated to the local memory pool for applying for memory objects.

4. The method according to claim 3, characterized in that Migrating the memory objects of the system memory to the global memory pool further includes: The memory objects of the system memory are migrated to the global memory pool through an asynchronous work queue.

5. The method according to claim 4, characterized in that Migrating the memory objects of the system memory to the global memory pool via an asynchronous work queue further includes: Applying a predetermined number of memory objects to the system memory; After migrating the predetermined number of memory objects to the global memory pool, releasing the locked state of the global memory; After a predetermined time interval, the global memory pool is locked, and the above steps are repeated until the global memory pool reaches a preset condition.

6. The method according to claim 5, characterized in that The predetermined number is less than the total number of memory objects applied for from the system memory.

7. The method according to claim 5, characterized in that The preset condition includes that the global memory pool is greater than a second threshold value.

8. The method according to claim 3, characterized in that Migrating the memory object in the global memory pool to the local memory pool of the application memory object further includes: Migrate a number of memory objects in the global memory pool that is related to the capacity of the local memory pool to the local memory pool.

9. The method according to claim 8, characterized in that Migrating a number of memory objects in the global memory pool related to the capacity of the local memory pool to the local memory pool further includes: Memory objects in the global memory pool that are equivalent to half of the capacity of the local memory pool are migrated to the local memory pool.

10. The method according to claim 1, characterized in that Returning the memory object released by the local memory pool to the global memory pool further includes: If the number of unused memory objects in the local memory pool is greater than the local memory upper limit threshold, the memory objects in the local memory pool are released to the global memory pool.

11. The method according to claim 10, characterized in that After releasing the memory object of the local memory pool to the global memory pool, the method further includes: Checking the number of memory objects in the global memory pool; If the number of memory objects in the global memory pool is higher than a first global memory upper limit threshold, the global memory pool is locked, and after the memory objects in the global memory pool are released to the system memory, the locked state of the global memory is released.

12. The method according to claim 10, characterized in that The step of determining that the number of unused memory objects in the local memory pool is greater than the local memory upper limit threshold further includes: According to the sum of the number of memory objects released by the process being executed by the core corresponding to the local memory pool and the number of unused memory objects in the local memory pool, it is determined whether it is greater than the local memory upper limit threshold.

13. The method according to claim 12, characterized in that After releasing the memory object of the local memory pool to the global memory pool, the method further includes: The memory objects occupied by the processes that have been executed by the core corresponding to the local memory pool are released to the local memory pool.

14. The method according to claim 10, characterized in that Releasing the memory objects of the local memory pool to the global memory pool further includes: If the number of memory objects in the global memory pool is higher than a second global memory upper limit threshold, the memory objects stored locally are temporarily stored in an overflow queue.

15. The method according to claim 14, characterized in that After releasing the memory object of the local memory pool to the global memory pool, the method further includes: If the number of memory objects in the global memory pool is higher than a first global memory upper limit threshold, the overflow queue is locked, and after the memory objects in the overflow queue are preferentially released to the system memory, the locking state of the overflow queue is released.

16. The method according to claim 15, characterized in that It also includes, after the memory objects in the overflow queue are released to the system memory, if the number of memory objects in the global memory pool is still higher than the first global memory upper limit threshold, locking the global memory pool, releasing the memory objects in the global memory pool to the system memory, and then unlocking the global memory.

17. The method according to claim 11 or 16, characterized in that Releasing the memory objects of the global memory pool to the system memory further comprises: The memory objects of the global memory pool are released to the system memory through an asynchronous work queue.

18. The method according to claim 17, characterized in that Releasing the memory objects of the global memory pool to the system memory via an asynchronous work queue further includes: Releasing a predetermined number of memory objects in the global memory to the system memory, and releasing the locked state of the global memory; After a predetermined time interval, the global memory pool is locked, and the above steps are repeated until the global memory pool reaches a preset condition.

19. The method according to claim 18, characterized in that The predetermined number is less than the total number of memory objects released to the system memory.

20. The method according to claim 18, characterized in that The preset condition includes that the global memory pool is smaller than a second threshold value.

21. A memory pool optimization device for a multi-core system, characterized in that: The device comprises, A local memory pool construction unit is used to allocate a corresponding local memory pool for each core in the system memory; A global memory pool construction unit is used to establish a global memory pool corresponding to the local memory pools of all cores in the system memory; A memory object application unit, used for migrating memory objects in the global memory pool to a local memory pool where the memory objects are applied for; A memory object releasing unit, used for returning the memory objects released by the local memory pool to the global memory pool; The memory object application unit is also used to check the number of memory objects in the global memory pool; if the number of unused memory objects in the global memory pool is lower than the global memory lower limit threshold, the global memory pool is locked, and after the memory objects of the system memory are migrated to the global memory pool, the locked state of the global memory is released.

22. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 20 is implemented.

23. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method of any one of claims 1 to 20 is executed.

24. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 20 is implemented.

Citation Information

Patent Citations

  • Global memory sharing method, global memory sharing device and communication system

    CN103870333A

  • Multi-core lock-free memory allocation method and device and electronic equipment

    CN113467937A