Memory allocation method and device

By dynamically adjusting the local cache capacity threshold, the problem of low memory allocation efficiency in load unbalanced scenarios is solved, and the memory allocation efficiency is improved, memory competition is reduced, and IO delay is improved.

CN118897737BActive Publication Date: 2024-12-20INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411384755.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2024-12-20
Estimated Expiration
2044-09-30

AI Technical Summary

Technical Problem

In high concurrency scenarios with unbalanced load, business threads lead to low memory allocation efficiency through memory allocation in fixed capacity local caches, affecting IO delay.

Method used

By dynamically adjusting the capacity threshold of the local cache, the preset capacity threshold is calculated based on the number of times the business thread applies and releases memory to the system, and the memory allocation is optimized to ensure that the cache capacity of each business thread is adapted to the current load and improve memory allocation efficiency.

Benefits of technology

It effectively improves memory allocation efficiency, reduces memory competition, and improves IO processing performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118897737B_ABST
    Figure CN118897737B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a memory allocation method and device, wherein the method includes: upon receiving a memory allocation request from a target business thread, determining the memory request amount corresponding to the memory allocation request; if the memory request amount is greater than the first memory amount that can be allocated in the local cache, allocating the number of the memory corresponding to the first memory amount to the target business thread; applying for a first amount of memory from the target system to the local cache according to the first capacity threshold corresponding to the local cache; allocating a second amount of memory to the target business thread according to the number of the first amount of memory in the local cache, so that the target business thread performs business processing based on the allocated memory. Through this application, the problem that the business thread in the related art implements memory allocation through the memory in the local cache of fixed capacity, resulting in relatively low memory allocation efficiency in load-unbalanced business scenarios is solved, thereby achieving the effect of improving memory allocation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the computer field, and in particular, to a memory allocation method and device. Background Art

[0002] In the protocol stack process of the storage system, the business threads that process IO have very high latency requirements. The number of these business threads may be large depending on the current business scenario, usually dozens or even hundreds. If multiple business threads apply for memory from the system at the same time, there will inevitably be a lot of competition in the memory allocation process. Moreover, as the number of business threads increases, this competition will become more and more serious, which will inevitably lead to too long memory allocation time for some threads, affecting IO latency.

[0003] In order to increase the efficiency of memory allocation in high-concurrency scenarios, the current general strategy is to reserve some local cache to reduce competition in the allocation process. However, this simple way of reserving cache is difficult to achieve significant results in high-concurrency business scenarios with unbalanced loads. Summary of the invention

[0004] An embodiment of the present application provides a memory allocation method and device to at least solve the problem in the related art that a business thread implements memory allocation through memory in a local cache of fixed capacity, resulting in relatively low memory allocation efficiency in load-unbalanced business scenarios.

[0005] According to an embodiment of the present application, a memory allocation method is provided, comprising: upon receiving a memory allocation request from a target business thread, determining a memory request amount corresponding to the memory allocation request; if the memory request amount is greater than a first allocatable memory amount of a local cache corresponding to the target business thread, allocating a memory number corresponding to the first memory amount to the target business thread; applying for a first amount of memory from a target system to the local cache according to a first capacity threshold corresponding to the local cache, wherein the first capacity threshold is calculated based on the number of times the target business thread applies for memory from the target system, the number of times memory is released to the target system, and a preset first preset capacity threshold; allocating a second amount of memory to the target business thread according to the number of the first amount of memory in the local cache, so that the target business thread performs business processing based on the allocated memory, wherein the second amount is determined based on the difference between the first memory amount and the memory request amount.

[0006] In an exemplary embodiment, after determining the memory request amount corresponding to the memory allocation request, the method also includes: determining whether the memory request amount is less than or equal to the first memory amount in the local cache; if the memory request amount is less than or equal to the first memory amount in the local cache, allocating the memory amount corresponding to the memory allocation request to the target business thread according to the number corresponding to the memory in the local cache.

[0007] In an exemplary embodiment, after applying for a first amount of memory from the target system to the local cache according to the first capacity threshold, the method further includes: updating a first target quantity corresponding to the target business thread, wherein the first target quantity is the number of times the target business thread applies for memory from the target system.

[0008] In an exemplary embodiment, after allocating a second amount of memory to the target business thread based on the number of the first amount of memory in the local cache so that the target business thread performs business processing based on the allocated memory, the method further includes: if a memory release request from the target business thread is received, determining the memory release amount corresponding to the memory release request; and releasing the memory corresponding to the memory release amount based on the memory release amount and the allocatable second memory amount in the local cache.

[0009] In an exemplary embodiment, the memory corresponding to the memory release amount is released based on the memory release amount and the second allocatable memory amount in the local cache, including: obtaining the current second capacity threshold of the local cache, wherein the second capacity threshold is calculated based on the number of times the target business thread applies for memory, the number of times memory is released, and the first capacity threshold; and the memory corresponding to the memory release amount is released based on the second capacity threshold, the memory release amount, and the second memory amount.

[0010] In an exemplary embodiment, the memory corresponding to the memory release amount is released based on the second capacity threshold, the memory release amount and the second memory amount, including: calculating the difference between the second capacity threshold and the second memory amount to obtain a first difference; determining whether the memory release amount is less than or equal to the first difference; if the memory release amount is less than or equal to the first difference, releasing the memory corresponding to the memory release amount to the local cache.

[0011] In an exemplary embodiment, after determining whether the memory release amount is less than or equal to the first difference, the method further includes: if the memory release amount is greater than the first difference, releasing the memory of the first difference corresponding to the memory release request to the local cache; releasing a third amount of memory in the local cache to the target system, and releasing a fourth amount of memory corresponding to the memory release request to the local cache, wherein the third amount is calculated based on the second capacity threshold, and the fourth amount is calculated based on the first difference and the memory release amount.

[0012] In an exemplary embodiment, after releasing the third amount of memory in the local cache to the target system, the method further includes: updating a second target amount corresponding to the target business thread, wherein the second target amount is the number of times the target business thread releases memory to the target system.

[0013] In an exemplary embodiment, before determining the memory request amount corresponding to the memory allocation request, the method also includes: granularly dividing the memory corresponding to the target system according to the data read / write scenario corresponding to the target system to obtain multiple divided memories; numbering the multiple divided memories, and establishing a mapping relationship between the number and the memory address of the memory corresponding to the number, so as to realize memory allocation based on the number.

[0014] In an exemplary embodiment, before determining the memory request amount corresponding to the memory allocation request, the method also includes: at a preset time point, obtaining a first target number of the target business thread in a first time period and a second target number in the first time period, wherein the first target number is the number of times the target business thread applies for memory from the target system in the first time period, and the second target number is the number of times the target business thread releases memory to the target system in the first time period; obtaining the first target number of the target business thread in the second time period and the second target number in the second time period; and calculating based on the first target number in the first time period, the second target number in the first time period, the first target number in the second time period, the second target number in the second time period and the first preset capacity threshold to obtain the first capacity threshold.

[0015] In an exemplary embodiment, the first capacity threshold is obtained by calculating based on the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period, and the first preset capacity threshold, including: calculating based on the first target quantity in the first time period and the second target quantity in the first time period to obtain a first value; calculating based on the first target quantity in the second time period and the second target quantity in the second time period to obtain a second value; calculating based on the first value, the second value, and the first preset capacity threshold to obtain the first capacity threshold.

[0016] In an exemplary embodiment, the calculation based on the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold includes: if the second value is greater than the first value, using a first calculation method to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold; if the second value is less than the first value, using a second calculation method to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold; if the second value is equal to the first value, setting the first preset capacity threshold to the first capacity threshold.

[0017] In an exemplary embodiment, the first calculation method is used to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold, including: calculating the difference between the second value and the first value to obtain a second difference, and summing the second difference and a preset target value to obtain a third value; calculating the ratio between the third value and the first value to obtain a first ratio, and calculating the product between the first ratio and the first preset capacity threshold to obtain a first product; determining the first capacity threshold based on the numerical relationship between the first product and the first preset capacity threshold and the second preset capacity threshold.

[0018] In an exemplary embodiment, the second calculation method is used to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold, including: calculating the difference between the second value and the first value to obtain a second difference, and performing a difference calculation between the second difference and a preset target value to obtain a fourth value; calculating the ratio between the fourth value and the first value to obtain a second ratio, and calculating the product between the second ratio and the first preset capacity threshold to obtain a second product; determining the first capacity threshold based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold.

[0019] In an exemplary embodiment, the first capacity threshold is determined based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold, including: if the second product is greater than or equal to the first preset capacity threshold and less than or equal to the second preset capacity threshold, the second product is determined as the first capacity threshold; if the second product is less than the first preset capacity threshold, the first preset capacity threshold is determined as the first capacity threshold; if the second product is greater than the second preset capacity threshold, the second preset capacity threshold is determined as the first capacity threshold.

[0020] In an exemplary embodiment, after the first capacity threshold is obtained by calculating based on the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold, the method further includes: if the first capacity threshold is not equal to the first preset capacity threshold, clearing the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold.

[0021] In an exemplary embodiment, after the first capacity threshold is calculated based on the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold, the method further includes: if the first capacity threshold is equal to the first preset capacity threshold, setting the first target quantity in the first time period to be the same as the first target quantity in the second time period, and clearing the first target quantity in the second time period; setting the second target quantity in the first time period to be the same as the second target quantity in the second time period, and clearing the second target quantity in the second time period.

[0022] According to another embodiment of the present application, a memory allocation device is provided, comprising: a first determination unit, for determining a memory request amount corresponding to the memory allocation request when receiving a memory allocation request of a target business thread; a first allocation unit, for allocating a memory number corresponding to the first memory amount to the target business thread if the memory request amount is greater than a first memory amount that can be allocated in a local cache corresponding to the target business thread; a request unit, for applying for a first amount of memory from a target system to the local cache according to a first capacity threshold corresponding to the local cache, wherein the first capacity threshold is calculated based on the number of times the target business thread applies for memory from the target system, the number of times memory is released to the target system, and a preset first preset capacity threshold; a second allocation unit, for allocating a second amount of memory to the target business thread according to the number of the first amount of memory in the local cache, so that the target business thread performs business processing based on the allocated memory, wherein the second amount is determined based on the difference between the first memory amount and the memory request amount.

[0023] In an exemplary embodiment, a judgment unit is used to judge whether the memory request amount corresponding to the memory allocation request is less than or equal to the first memory amount in the local cache after determining the memory request amount corresponding to the memory allocation request; a third allocation unit is used to allocate the memory amount corresponding to the memory allocation request to the target business thread according to the number corresponding to the memory in the local cache if the memory request amount is less than or equal to the first memory amount in the local cache.

[0024] In an exemplary embodiment, the device also includes: a first update unit, which is used to update a first target quantity corresponding to the target business thread after applying for a first amount of memory from the target system to the local cache according to the first capacity threshold, wherein the first target quantity is the number of times the target business thread applies for memory from the target system.

[0025] In an exemplary embodiment, the device also includes: a second determination unit, for allocating a second amount of memory to the target business thread based on the number of the first amount of memory in the local cache, so that the target business thread performs business processing based on the allocated memory, and if a memory release request of the target business thread is received, determining the memory release amount corresponding to the memory release request; and a first release unit, for releasing the memory corresponding to the memory release amount based on the memory release amount and the allocable second memory amount in the local cache.

[0026] In an exemplary embodiment, a first release unit includes: an acquisition subunit, used to obtain a current second capacity threshold of the local cache, wherein the second capacity threshold is calculated based on the number of times the target business thread applies for memory, the number of times memory is released, and the first capacity threshold; and a release subunit, used to release the memory corresponding to the memory release amount based on the second capacity threshold, the memory release amount, and the second memory amount.

[0027] In an exemplary embodiment, the release subunit includes: a calculation module, used to calculate the difference between the second capacity threshold and the second memory amount to obtain a first difference; a judgment module, used to judge whether the memory release amount is less than or equal to the first difference; and a release module, used to release the memory corresponding to the memory release amount to the local cache if the memory release amount is less than or equal to the first difference.

[0028] In an exemplary embodiment, the device also includes: a second release unit, which is used to release the memory of the first difference corresponding to the memory release request to the local cache after determining whether the memory release amount is less than or equal to the first difference, if the memory release amount is greater than the first difference; a third release unit, which is used to release a third amount of memory in the local cache to the target system, and release a fourth amount of memory corresponding to the memory release request to the local cache, wherein the third amount is calculated based on the second capacity threshold, and the fourth amount is calculated based on the first difference and the memory release amount.

[0029] In an exemplary embodiment, the device also includes: a second update unit, used to update a second target quantity corresponding to the target business thread after releasing a third amount of memory in the local cache to the target system, wherein the second target quantity is the number of times the target business thread releases memory to the target system.

[0030] In an exemplary embodiment, the device also includes: a partitioning unit, which is used to granularly partition the memory corresponding to the target system according to the data read / write scenario corresponding to the target system before determining the memory request amount corresponding to the memory allocation request, so as to obtain multiple partitioned memories; a numbering unit, which is used to number the multiple partitioned memories and establish a mapping relationship between the number and the memory address of the memory corresponding to the number, so as to realize memory allocation based on the number.

[0031] In an exemplary embodiment, the device also includes: a first acquisition unit, used to obtain, at a preset time point, a first target number of the target business thread in a first time period and a second target number in the first time period before determining the memory request amount corresponding to the memory allocation request, wherein the first target number is the number of times the target business thread applies for memory from the target system in the first time period, and the second target number is the number of times the target business thread releases memory to the target system in the first time period; a second acquisition unit, used to obtain the first target number of the target business thread in the second time period and the second target number in the second time period; a calculation unit, used to calculate based on the first target number in the first time period, the second target number in the first time period, the first target number in the second time period, the second target number in the second time period and the first preset capacity threshold to obtain the first capacity threshold.

[0032] In an exemplary embodiment, the calculation unit includes: a first calculation subunit, used to calculate based on a first target quantity within a first time period and a second target quantity within the first time period to obtain a first value; a second calculation subunit, used to calculate based on the first target quantity within the second time period and the second target quantity within the second time period to obtain a second value; a third calculation subunit, used to calculate based on the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold.

[0033] In an exemplary embodiment, the third calculation subunit includes: a first calculation module, which is used to use a first calculation device to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold if the second value is greater than the first value; a second calculation module, which is used to use a second calculation device to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold if the second value is less than the first value; and a setting module, which is used to set the first preset capacity threshold to the first capacity threshold if the second value is equal to the first value.

[0034] In an exemplary embodiment, the first calculation module includes: a first calculation submodule, used to calculate the difference between the second value and the first value to obtain a second difference, and sum the second difference and a preset target value to obtain a third value; a second calculation submodule, used to calculate the ratio between the third value and the first value to obtain a first ratio, and calculate the product between the first ratio and the first preset capacity threshold to obtain a first product; a first determination submodule, used to determine the first capacity threshold based on the numerical relationship between the first product and the first preset capacity threshold and the second preset capacity threshold.

[0035] In an exemplary embodiment, the second calculation module includes: a third calculation submodule, used to calculate the difference between the second value and the first value to obtain a second difference, and perform a difference calculation between the second difference and a preset target value to obtain a fourth value; a fourth calculation submodule, used to calculate the ratio between the fourth value and the first value to obtain a second ratio, and calculate the product between the second ratio and the first preset capacity threshold to obtain a second product; a second determination submodule, used to determine the first capacity threshold based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold.

[0036] In an exemplary embodiment, the second determination submodule includes: a first determination submodule, used to determine the second product as the first capacity threshold if the second product is greater than or equal to the first preset capacity threshold and less than or equal to the second preset capacity threshold; a second determination submodule, used to determine the first preset capacity threshold as the first capacity threshold if the second product is less than the first preset capacity threshold; and a third determination submodule, used to determine the second preset capacity threshold as the first capacity threshold if the second product is greater than the second preset capacity threshold.

[0037] In an exemplary embodiment, the device also includes: a first processing unit, which is used to calculate the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold, and after obtaining the first capacity threshold, if the first capacity threshold is not equal to the first preset capacity threshold, then clear the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold.

[0038] In an exemplary embodiment, the device also includes: a second processing unit, for calculating based on the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold, after obtaining the first capacity threshold, if the first capacity threshold is equal to the first preset capacity threshold, setting the first target quantity in the first time period to be the same as the first target quantity in the second time period, and clearing the first target quantity in the second time period; a third processing unit, for setting the second target quantity in the first time period to be the same as the second target quantity in the second time period, and clearing the second target quantity in the second time period.

[0039] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0040] According to another embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.

[0041] Through the present application, since the target business thread adjusts the capacity setting of the local cache according to the number of times the target business thread applies for memory from the target system, the number of times the memory is released to the target system and the preset first preset capacity threshold during operation, the cache capacity of each business thread is adapted to the current load to maximize the benefits of the cache. Therefore, it is possible to solve the problem in the related technology that business threads implement memory allocation through memory in a local cache of fixed capacity, resulting in relatively low memory allocation efficiency in load-unbalanced business scenarios, thereby achieving the effect of improving memory allocation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 It is a hardware structure block diagram of a server device of a memory allocation method according to an embodiment of the present application;

[0043] Figure 2 is a flowchart of a memory allocation method according to an embodiment of the present application;

[0044] Figure 3 This is a schematic diagram of memory allocation and release according to an embodiment of the present application. Figure 1 ;

[0045] Figure 4 This is a schematic diagram of memory allocation and release according to an embodiment of the present application. Figure 2 ;

[0046] Figure 5 This is a schematic diagram of memory allocation and release according to an embodiment of the present application. Figure 3 ;

[0047] Figure 6 This is a schematic diagram of memory allocation and release according to an embodiment of the present application. Figure 4 ;

[0048] Figure 7 It is a structural block diagram of a memory allocation device according to an embodiment of the present application. DETAILED DESCRIPTION

[0049] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0050] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0051] The method embodiments provided in the embodiments of the present application can be executed in a server device or a similar computing device. Taking running on a server device as an example, Figure 1 1 is a hardware structure block diagram of a server device of a memory allocation method according to an embodiment of the present application. Figure 1 As shown, the server device may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned server device may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0052] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the memory allocation method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0053] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0054] In this embodiment, a memory allocation method is provided. Figure 2 is a flowchart of a memory allocation method according to an embodiment of the present application, such as Figure 2 As shown, the process includes the following steps:

[0055] Step S202, when receiving a memory allocation request of a target service thread, determining a memory request amount corresponding to the memory allocation request;

[0056] Step S204: if the memory request amount is greater than the first memory amount that can be allocated in the local cache corresponding to the target service thread, the memory number corresponding to the first memory amount is allocated to the target service thread;

[0057] Step S206, applying for a first amount of memory from the target system to the local cache according to a first capacity threshold corresponding to the local cache, wherein the first capacity threshold is calculated based on the number of times the target business thread applies for memory from the target system, the number of times memory is released to the target system, and a preset first preset capacity threshold;

[0058] Step S208, allocate a second amount of memory to the target business thread according to the number of the first amount of memory in the local cache, so that the target business thread performs business processing based on the allocated memory, wherein the second amount is determined based on the difference between the first amount of memory and the memory request amount.

[0059] In an optional embodiment, a local cache is set for each service thread in the protocol stack system (i.e., the aforementioned target system), and when the service thread applies for memory, it is allocated from its local cache first. Since the memory of the protocol stack system is limited, the size of the cache cannot be set too large. The loads of different service threads in different scenarios are different, and in the entire IO process, the application and release of the same block of memory are not necessarily on the same service thread, that is, the memory allocated to service thread-A may be released in service thread-B after the current IO is processed.

[0060] In the face of this high-concurrency scenario with unbalanced load, an initial value (i.e., a preset first preset capacity threshold) is set for the cache capacity of each business thread in the memory allocation method provided in the embodiment of the present application. For example, the initial value is 8. When each business thread applies for memory, it is allocated from its local cache first. If the business thread cache is empty, the business thread will apply for memory of 1 / 2 of the cache capacity from the system to the local cache of the business thread, and then allocate it from the local cache of the business thread. Each business thread will record the number of times it has applied for memory from the system (recorded as m) and the number of times it has released it to the system memory (recorded as n), and then adjust the local cache capacity setting according to the changes in m and n, so that the cache capacity of each business thread adapts to the current load.

[0061] In an optional embodiment, in order to improve memory allocation efficiency, in a high-concurrency storage system, the system global memory can also be divided and numbered, and a mapping relationship between the number and the memory address can be established to improve memory allocation efficiency in the form of cache numbers rather than memory contents. For example, the memory can be divided and numbered at the sector or page granularity, and then allocated at the page granularity.

[0062] In an optional embodiment, the schematic structure of the service cache may be as follows:

[0063] struct Local_cache {

[0064] long size;

[0065] long index;

[0066] long pages[];

[0067] long refill;

[0068] long giveback;

[0069] long t1,m1,n1;

[0070] long t2,m2,n2;

[0071] }

[0072] Among them, struct Local_cache represents the local cache structure, size represents the capacity threshold of the local cache, that is, the number of elements in the member pages array; pages is a dynamic array, each element of which is the number of memory divided by page granularity, that is, the page number. The number of elements in the pages array is controlled by size; index is the cursor of the pages array, indicating the current allocatable starting position. Long pages[] is used to record the page number, refill represents the number of times memory is requested from the system to the local cache, where the number of pages requested each time is half of the cache capacity, that is, size / 2. The member giveback represents the number of times memory is released from the local cache back to the system. m1 is the increase in the number of refills in the t1 time period, n1 is the increase in the number of givebacks in the t1 time period, and t1 represents the length of the previous statistical time period. m2 is the increase in the number of refills in the t2 time period, n2 is the increase in the number of givebacks in the t2 time period, and t2 represents the length of the current statistical time period.

[0073] In an optional embodiment, the capacity threshold of the service thread may be dynamically adjusted according to the number of refills and givebacks in the time period t1 and the number of refills and givebacks in the time period t2.

[0074] For the above-mentioned target business thread, the initial capacity of the local cache of the target business thread is a preset first preset capacity threshold. During the operation of the target business thread, it will record the number of times it applies for memory from the system and the number of times it releases memory to the system, and then adjust the first preset capacity threshold to the above-mentioned first capacity threshold based on the changes in the number of times it applies for memory and the number of times it releases memory to the system.

[0075] After adjusting the first preset capacity threshold to the above-mentioned first capacity threshold, when a memory allocation request from a target business thread is received, it is necessary to first determine the memory request amount corresponding to the memory allocation request based on the memory allocation request, so as to accurately determine whether the remaining memory in the local cache corresponding to the target business thread is sufficient to allocate the memory allocation request.

[0076] In an optional embodiment, after obtaining the memory request amount corresponding to the memory allocation request, it is determined whether the memory request amount is greater than the first memory amount that can be allocated in the local cache corresponding to the target business thread. If the memory request amount is greater than the first memory amount that can be allocated in the local cache corresponding to the target business thread, the memory number corresponding to the first memory amount is allocated to the target business thread, and at the same time, the first amount of memory is applied to the target system to be stored in the local cache according to the first capacity threshold corresponding to the local cache. It should be noted that the first amount can be half of the first capacity threshold.

[0077] After applying the first amount of memory to the local cache, a second amount of memory is allocated to the target service thread from the first amount of memory in the local cache, so that the target service thread performs service processing based on the allocated memory.

[0078] It should be noted that if after the target business thread applies for a first amount of memory to the local cache from the target system, if the memory in the local cache still cannot meet the memory required for the memory allocation request, the target business thread will apply for the first amount of memory to the local cache from the target system again until the memory in the local cache meets the memory required for the memory allocation request.

[0079] It should be noted that since the global memory of the system is divided into granularities and numbered, memory can be allocated directly according to the page encoding. For example, the local cache capacity of business thread thread-A is 8, that is, it can accommodate a maximum of 8 page pages. There are only 5 page pages in the current cache, that is, there are only 5 page pages available for allocation in the pages array of the Local_cache, and the 5 page pages available for allocation are numbered N1, Na, N3, N4, and Nx respectively. Then N1, Na, N3, N4, and Nx can be directly allocated to the corresponding business thread thread-A.

[0080] Through the above steps, since the target business thread adjusts the capacity setting of the local cache according to the number of times the target business thread applies for memory from the target system, the number of times the memory is released to the target system and the preset first preset capacity threshold during operation, the cache capacity of each business thread is adapted to the current load to maximize the benefits of the cache. Therefore, the problem in the related technology that business threads implement memory allocation through memory in the local cache of fixed capacity, resulting in relatively low memory allocation efficiency in load-unbalanced business scenarios, can be solved, thereby achieving the effect of memory allocation efficiency.

[0081] The execution subject of the above steps may be a server, a terminal, etc., but is not limited thereto.

[0082] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, after determining the memory request amount corresponding to the memory allocation request, the method also includes: determining whether the memory request amount is less than or equal to the first memory amount in the local cache; if the memory request amount is less than or equal to the first memory amount in the local cache, allocating the memory amount corresponding to the memory allocation request to the target business thread according to the number corresponding to the memory in the local cache.

[0083] In an optional embodiment, after determining the memory request amount corresponding to the memory allocation request, it is determined whether the allocatable memory in the local cache can satisfy the memory required by the memory allocation request. If the allocatable memory in the local cache can satisfy the memory required by the memory allocation request, that is, the memory request amount is less than or equal to the first memory amount in the local cache, the memory amount corresponding to the memory allocation request is directly allocated to the target service thread according to the number of the allocatable memory in the local cache. Allocating memory by number rather than by memory content can effectively improve memory allocation efficiency.

[0084] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, after applying for a first amount of memory from the target system to the local cache according to a first capacity threshold, the method also includes: updating the first target quantity corresponding to the target business thread, wherein the first target quantity is the number of times the target business thread applies for memory from the target system.

[0085] In an optional embodiment, in order to facilitate the subsequent adjustment of the capacity threshold of the local cache, after the target business thread applies for memory from the target system, the number of times the target business thread applies for memory from the target system (i.e., the first target number mentioned above) is updated, i.e., the number of refills in the local cache is increased by 1. By recording the number of times the business thread applies for memory from the target system, the load of the business thread can be accurately evaluated.

[0086] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, after allocating a second amount of memory to the target business thread based on the number of the first amount of memory in the local cache so that the target business thread performs business processing based on the allocated memory, the method also includes: if a memory release request is received from the target business thread, determining the memory release amount corresponding to the memory release request; and releasing the memory corresponding to the memory release amount based on the memory release amount and the allocable second memory amount in the local cache.

[0087] In an optional embodiment, in order to avoid the situation where the application and release of the same block of memory are not necessarily on the same business thread, in the memory allocation method provided in the embodiment of the present application, when a memory release request is received from the target business thread, the memory corresponding to the memory release amount is released according to the memory release amount corresponding to the memory release request and the allocatable second memory amount in the local cache, that is, it is first considered whether the local cache can accept the memory release amount corresponding to the memory release request.

[0088] In an optional embodiment, based on the memory release amount and the allocatable second memory amount in the local cache, the memory corresponding to the memory release amount is released, including: obtaining the current second capacity threshold of the local cache, wherein the second capacity threshold is calculated based on the number of times the target business thread applies for memory, the number of times the memory is released and the first capacity threshold; based on the second capacity threshold, the memory release amount and the second memory amount, the memory corresponding to the memory release amount is released.

[0089] In an optional embodiment, the current capacity threshold of the local cache corresponding to the target service thread is first determined, that is, the second capacity threshold is obtained. It should be noted that when the memory release request is received, the capacity threshold is not adjusted again, so the second capacity threshold may also be the first capacity threshold.

[0090] It should be noted that when a memory release request is received, if the capacity threshold is adjusted again, the corresponding second capacity threshold is calculated based on the number of times the target business thread applies for memory, the number of times the memory is released and the first capacity threshold.

[0091] After the second capacity threshold is obtained, the memory corresponding to the memory release amount is released according to the second capacity threshold, the memory release amount and the second memory amount.

[0092] In an optional embodiment, based on the second capacity threshold, the memory release amount and the second memory amount, the memory corresponding to the memory release amount is released, including the following steps: calculating the difference between the second capacity threshold and the second memory amount to obtain a first difference; judging whether the memory release amount is less than or equal to the first difference; if the memory release amount is less than or equal to the first difference, releasing the memory corresponding to the memory release amount to the local cache.

[0093] If the memory release amount is greater than the first difference, the memory of the first difference corresponding to the memory release request is released to the local cache; a third amount of memory in the local cache is released to the target system, and a fourth amount of memory corresponding to the memory release request is released to the local cache, wherein the third amount is calculated based on the second capacity threshold, and the fourth amount is calculated based on the first difference and the memory release amount.

[0094] In an optional embodiment, after obtaining the second capacity threshold, the amount of memory that the local cache can currently accommodate, that is, the above-mentioned first difference, is determined based on the second capacity threshold and the second memory amount, and then, it is determined whether the amount of memory released is less than or equal to the first difference, that is, whether the local cache can accommodate the above-mentioned memory to be released.

[0095] If the amount of memory released is less than or equal to the first difference, the memory corresponding to the direct memory release amount is released to the local cache. If the amount of memory released is greater than the first difference, the memory of the first difference corresponding to the memory release request is first released to the local cache, and then the third amount of memory in the local cache is released to the target system, and finally the fourth amount of memory corresponding to the memory release request is released to the local cache. In short, when the business thread has memory released, it is placed in its own local cache first. If the current cache is full, half of the memory in the cache will be released to the system at one time, and then the memory to be released will be placed in the local cache. It should be noted that the third amount can be half of the second capacity threshold, and the fourth amount is the difference between the first difference and the amount of memory released.

[0096] In an optional embodiment, the local cache capacity of service thread thread-A is 8, that is, it can accommodate 8 pages at most, and there are only 5 pages in the current cache, that is, there are only 5 pages available for allocation in the pages array of the Local_cache. Figure 3 As shown in the figure, the five page codes available for allocation (i.e., the memory numbers of the local cache that can be allocated as mentioned above) are recorded as N1, Na, N3, N4, and Nx respectively. These five page codes are not required to be in order. The last three blank boxes indicate that there are no pages available for allocation at this location. There are multiple memory allocations on the business thread thread-A, and three of the pages are allocated. Finally, the status of the cache is as follows Figure 4 As shown in the figure, the allocatable memory in the local cache is N1 and Na. The business thread thread-A then releases memory several times in succession, releasing a total of 6 pages. Finally, the status of the local cache is as follows Figure 5 As shown in the figure, the allocatable memory is N1, Na, Nx, Nv, Nz, Ny, N3 and Nw. The business thread thread-A will release another page numbered N5. However, the cache is full and cannot be directly put in. First, the last 4 pages in the cache are released back to the system at once, and the cache refill value is increased by 1. Then, page N5 is released to the local cache. Figure 6 shown.

[0097] In an optional embodiment, if pages are released to the local cache in the order of numbers, then when the memory in the local cache is released to the target system, the memory with the earliest number can be released to the target memory first.

[0098] The above memory release process can effectively avoid the problem that the application and release of the same memory block are not necessarily on the same business thread, thereby effectively avoiding the problem of memory contention.

[0099] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, after releasing a third amount of memory in the local cache to the target system, the method also includes: updating a second target quantity corresponding to the target business thread, wherein the second target quantity is the number of times the target business thread releases memory to the target system.

[0100] In an optional embodiment, in order to facilitate the subsequent adjustment of the capacity threshold of the local cache, after the target business thread applies for memory from the target system, the number of times the target business thread releases memory to the target system (i.e., the second target number mentioned above) is updated, that is, the number of givebacks in the local cache is increased by 1. By recording the number of times the business thread releases memory to the target system, the load of the business thread can be accurately evaluated.

[0101] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, before determining the memory request amount corresponding to the memory allocation request, the method also includes: granularly dividing the memory corresponding to the target system according to the data read / write scenario corresponding to the target system to obtain multiple divided memories; numbering the multiple divided memories, and establishing a mapping relationship between the numbers and the memory addresses of the memories corresponding to the numbers, so as to realize memory allocation based on the numbers.

[0102] In an optional embodiment, in order to further improve the efficiency of memory allocation, the memory corresponding to the target system is divided into granularities according to the data read / write scenario (i.e., IO scenario) corresponding to the target system, for example, divided into sectors or pages. Then, the multiple divided memories are numbered, and finally a mapping relationship is established between the numbers and the memory addresses of the memories corresponding to the numbers, so that there is a linear mapping relationship between the numbers and the memory addresses, and the numbers can be directly converted into addresses. Memory allocation is also allocated according to the sector or page granularity, and the numbers are also used in the allocation process. This not only meets the processing granularity of the IO scenario model, but also avoids complex address operations. The business module can use the memory very conveniently based on the linear mapping relationship between the numbers and the memory addresses.

[0103] By dividing the memory into granularities and numbering them, establishing a mapping relationship between numbers and memory addresses, and allocating memory in the form of cache numbers rather than memory contents, the memory allocation efficiency can be improved.

[0104] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, before determining the memory request amount corresponding to the memory allocation request, the method also includes: at a preset time point, obtaining a first target number of the target business thread in a first time period and a second target number in the first time period, wherein the first target number is the number of times the target business thread applies for memory from the target system in the first time period, and the second target number is the number of times the target business thread releases memory to the target system in the first time period; obtaining the first target number of the target business thread in the second time period and the second target number in the second time period; and calculating based on the first target number in the first time period, the second target number in the first time period, the first target number in the second time period, the second target number in the second time period and the first preset capacity threshold to obtain the first capacity threshold.

[0105] In an optional embodiment, in order to dynamically control the local cache capacity, in the memory allocation method provided in the embodiment of the present application, the following steps are used to calculate the first capacity threshold: at a preset time point, obtain the first target number m1 of the target business thread in the first time period (for example, t1) and the second target number n1 in the first time period, and obtain the first target number m2 of the target business thread in the second time period (for example, t2) and the second target number n1 in the second time period. Finally, the first capacity threshold is calculated based on the first target number in the first time period, the second target number in the first time period, the first target number in the second time period, the second target number in the second time period and the first preset capacity threshold.

[0106] In an optional embodiment, the business thread will count the refill and giveback of Local_cache at regular intervals, and save the relevant data in the t1, m1, n1, t2, m2 and n2 members of Local_cache. Among them, t1 represents the last statistical duration, m1 represents the increase in the number of refills in the t1 time period, and n1 represents the increase in the number of givebacks in the t1 time period; t2 represents the statistical duration of the current period, m2 represents the increase in the number of refills in the t2 time period, and n2 represents the increase in the number of givebacks in the t2 time period. According to the changes in m and n during these two time periods, the capacity value of the local cache (i.e., the size member of Local_cache) is adjusted.

[0107] In an optional embodiment, the adjustment method for the capacity value of the local cache can be determined according to the size relationship between m and n. For example, the first capacity threshold is calculated according to the ratio between m and n and the first preset capacity threshold.

[0108] Through the above steps, the local cache capacity of the business thread can be quickly iterated to the optimal value that adapts to the current load, greatly reducing the competition caused by constantly applying for and releasing memory from the system.

[0109] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, a first capacity threshold is obtained based on a first target quantity in a first time period, a second target quantity in the first time period, a first target quantity in a second time period, a second target quantity in the second time period, and a first preset capacity threshold, including: obtaining a first value by calculating based on the first target quantity in the first time period and the second target quantity in the first time period; obtaining a second value by calculating based on the first target quantity in the second time period and the second target quantity in the second time period; obtaining a first capacity threshold by calculating based on the first value, the second value, and the first preset capacity threshold.

[0110] In an optional embodiment, the first capacity threshold may be calculated by the following steps: a first numerical value is calculated based on a first target quantity within a first time period and a second target quantity within the first time period. For example, the sum of the first target quantity within the first time period and the second target quantity within the first time period is first calculated, and then the ratio of the sum to the first time period is calculated to obtain the above-mentioned first numerical value. For example, the first numerical value is: (m1+n1) / t1.

[0111] Then, a second value is obtained based on the first target number within the second time period and the second target number within the second time period. For example, the sum of the first target number within the second time period and the second target number within the second time period is first calculated, and then the ratio of the sum to the second time period is calculated to obtain the above-mentioned second value. For example, the second value is: (m2+n2) / t2.

[0112] Finally, the first capacity threshold is calculated based on the first value, the second value and the first preset capacity threshold. For example, the first capacity threshold is calculated based on the ratio between the first value and the second value and the first preset capacity threshold.

[0113] Through the above steps, the local cache capacity of the business thread can be quickly iterated to the optimal value that adapts to the current load, greatly reducing the competition caused by constantly applying for and releasing memory from the system.

[0114] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, a first capacity threshold is obtained by calculation based on a first numerical value, a second numerical value and a first preset capacity threshold, including: if the second numerical value is greater than the first numerical value, the first calculation method is used to calculate the first numerical value, the second numerical value and the first preset capacity threshold to obtain the first capacity threshold; if the second numerical value is less than the first numerical value, the second calculation method is used to calculate the first numerical value, the second numerical value and the first preset capacity threshold to obtain the first capacity threshold; if the second numerical value is equal to the first numerical value, the first preset capacity threshold is set as the first capacity threshold.

[0115] In an optional embodiment, the following steps can be used to calculate the first value, the second value, and the first preset capacity threshold to obtain the first capacity threshold: determine the size relationship between the first value and the second value, and determine the method for calculating the capacity threshold based on the size relationship between the first value and the second value: if the second value is greater than the first value, then use the first calculation method to calculate the first value, the second value, and the first preset capacity threshold to obtain the first capacity threshold. It should be noted that the first value and the second value represent the changes in memory application and memory release in the first time period and the second time period, respectively. When the second value is greater than the first value, it represents that the load in the second time period is greater than the load in the first time period. Therefore, it is necessary to increase the capacity threshold of the current local cache, that is, use the first calculation method to calculate the first value, the second value, and the first preset capacity threshold to obtain the first capacity threshold.

[0116] If the second value is less than the first value, the second calculation method is used to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold. It should be noted that when the second value is less than the first value, it indicates that the load in the second time period is less than the load in the first time period. Therefore, it is necessary to reduce the capacity threshold of the current local cache, that is, the first value, the second value and the first preset capacity threshold are calculated using the second calculation method to obtain the first capacity threshold.

[0117] If the second value is equal to the first value, it indicates that the current capacity threshold can adapt to the current load, and therefore, the first preset capacity threshold can still be set as the first capacity threshold.

[0118] The changes in memory application and memory release in two time periods can be used to accurately evaluate the load changes of the target business thread, thereby accurately adjusting the capacity threshold.

[0119] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, a first calculation method is used to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold, including: calculating the difference between the second value and the first value to obtain the second difference, and summing the second difference and the preset target value to obtain a third value; calculating the ratio between the third value and the first value to obtain the first ratio, and calculating the product between the first ratio and the first preset capacity threshold to obtain the first product; determining the first capacity threshold based on the numerical relationship between the first product and the first preset capacity threshold and the second preset capacity threshold.

[0120] In an optional embodiment, the first calculation method is used to calculate the first value, the second value and the first preset capacity threshold, including the following steps: first, the difference between the second value and the first value is calculated to obtain the second difference, then the second difference and the preset target value are summed to obtain the third value, then the ratio between the third value and the first value is calculated, and finally the product between the first ratio and the first preset capacity threshold is calculated to obtain the first product, and then the first capacity threshold is determined according to the numerical relationship between the first product and the first preset capacity threshold and the second preset capacity threshold. It should be noted that the first preset capacity threshold is a minimum value min_size. At the same time, because the system memory is limited, the capacity of the local cache is also upper bounded, which is recorded as max_size, i.e., the second preset capacity threshold mentioned above. The minimum and maximum values ​​are set in combination with the characteristics and specifications of the system itself.

[0121] In an optional embodiment, if (m2+n2) / t2 is greater than (m1+n1) / t1, the first capacity threshold is calculated using the following formula: size_new = (1+((m2+n2) / t2 - (m1+n1) / t1) / ((m1+n1) / t1))×size, where size_new is the first capacity threshold and size is the first preset capacity threshold.

[0122] In an optional embodiment, determining the first capacity threshold based on the numerical relationship between the first product and the first preset capacity threshold and the second preset capacity threshold includes: if size_new is greater than or equal to max_size, setting the capacity of the local cache (i.e., the size member of Local_cache) to max_size; if size_new is less than or equal to min_size, setting the capacity of the local cache (i.e., the size member of Local_cache) to min_size; if size_new is greater than min_size and less than max_size, setting the capacity of the local cache (i.e., the size member of Local_cache) to size_new.

[0123] By dynamically controlling the local cache capacity to adapt to memory allocation under different load pressures, the competition caused by constantly applying for and releasing memory in the system in high-concurrency scenarios is greatly reduced, and the memory allocation efficiency is improved.

[0124] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, a second calculation method is used to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold, including: calculating the difference between the second value and the first value to obtain the second difference, and performing a difference calculation between the second difference and the preset target value to obtain a fourth value; calculating the ratio between the fourth value and the first value to obtain the second ratio, and calculating the product between the second ratio and the first preset capacity threshold to obtain the second product; determining the first capacity threshold based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold.

[0125] In an optional embodiment, a second calculation method is used to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold, including: first calculating the difference between the second value and the first value, then performing a difference calculation on the difference between the second value and the first value and the preset target value, then calculating the ratio of the fourth value to the first value to obtain a second ratio, and finally calculating the product between the second ratio and the first preset capacity threshold to obtain a second product, and then determining the first capacity threshold based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold.

[0126] In an optional embodiment, if (m2+n2) / t2 is less than (m1+n1) / t1, the first capacity threshold is calculated using the following formula: size_new = (1-((m1+n1) / t1 - (m2+n2) / t2) / ((m1+n1) / t1))×size.

[0127] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, the first capacity threshold is determined based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold, including: if the second product is greater than or equal to the first preset capacity threshold and less than or equal to the second preset capacity threshold, the second product is determined as the first capacity threshold; if the second product is less than the first preset capacity threshold, the first preset capacity threshold is determined as the first capacity threshold; if the second product is greater than the second preset capacity threshold, the second preset capacity threshold is determined as the first capacity threshold.

[0128] In an optional embodiment, determining the first capacity threshold based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold includes: judging the size relationship between the second product and the first preset capacity threshold and the second preset capacity threshold; if size_new is greater than or equal to max_size, setting the capacity of the local cache (i.e., the size member of Local_cache) to max_size; if size_new is less than or equal to min_size, setting the capacity of the local cache (i.e., the size member of Local_cache) to min_size; if size_new is greater than min_size and less than max_size, setting the capacity of the local cache (i.e., the size member of Local_cache) to size_new.

[0129] Through the above steps, the local cache capacity of the business thread can be quickly iterated to the optimal value that adapts to the current load, greatly reducing the competition caused by constantly applying for and releasing memory from the system, so as to maximize the benefits of the cache and improve memory allocation efficiency.

[0130] In an optional embodiment, in the memory allocation method provided in the embodiment of the present application, after calculating based on the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold to obtain the first capacity threshold, the method also includes: if the first capacity threshold is not equal to the first preset capacity threshold, then clearing the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold.

[0131] If the first capacity threshold is equal to the first preset capacity threshold, the first target quantity in the first time period is set to be the same as the first target quantity in the second time period, and the first target quantity in the second time period is cleared to zero; the second target quantity in the first time period is set to be the same as the second target quantity in the second time period, and the second target quantity in the second time period is cleared to zero.

[0132] In an optional embodiment, after the capacity threshold of the local cache is adjusted, the memory allocation method provided in the embodiment of the present application further includes the following steps: If the size of Local_cache is adjusted, that is, the local cache capacity is adjusted, that is, the first capacity threshold is not equal to the first preset capacity threshold, then t1, m1, n1, t2, m2 and n2 will be cleared, and after the first capacity threshold is set, t1, m1, n1, t2, m2 and n2 will be re-counted, and the threshold can be adjusted again at the preset time point.

[0133] If the size of Local_cache does not change, that is, the local cache capacity remains unchanged, that is, the first capacity threshold is equal to the first preset capacity threshold, then t1=t2, m1=m2, n1=n2, and then t2, m2 and n2 are all cleared. That is, the first target number in the first time period is set to be the same as the first target number in the second time period, and the first target number in the second time period is cleared; the second target number in the first time period is set to be the same as the second target number in the second time period, and the second target number in the second time period is cleared. When there are new statistical data, the current new statistical data is assigned to t2, m2 and n2, and then the threshold can be adjusted again at the preset time point. Finally, the local cache capacity of the business thread can be quickly iterated to the optimal value that adapts to the current load.

[0134] In summary, in a high-concurrency storage system, the protocol stack process divides the global memory of the system into granularities and numbers it, establishes a mapping relationship between numbers and memory addresses, and improves memory allocation efficiency by caching numbers rather than memory contents. In addition, each business thread dynamically controls the local cache capacity to adapt to memory allocation under different load pressures. The local cache capacity of the business thread can be quickly iterated to the optimal value that adapts to the current load, greatly reducing the competition caused by constantly applying for and releasing memory from the system.

[0135] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.

[0136] In the present embodiment, a memory allocation device is also provided, and the device is used to implement the above-mentioned embodiment and preferred implementation mode, and the description that has been made will not be repeated. As used below, the term "module" can implement the combination of software and / or hardware of the predetermined function. Although the device described in the following embodiments is preferably implemented with software, the implementation of hardware, or the combination of software and hardware is also possible and conceived.

[0137] Figure 7 is a structural block diagram of a memory allocation device according to an embodiment of the present application, such as Figure 7 As shown, the device includes: a first determining unit 701, a first allocating unit 702, a requesting unit 703 and a second allocating unit 704.

[0138] The first determining unit 701 is used to determine the memory request amount corresponding to the memory allocation request when receiving the memory allocation request of the target service thread;

[0139] The first allocation unit 702 is configured to allocate the memory number corresponding to the first memory amount to the target service thread if the memory request amount is greater than the first memory amount that can be allocated in the local cache corresponding to the target service thread;

[0140] The request unit 703 is used to apply for a first amount of memory from the target system to the local cache according to a first capacity threshold corresponding to the local cache, wherein the first capacity threshold is calculated based on the number of times the target business thread applies for memory from the target system, the number of times the memory is released to the target system, and a preset first preset capacity threshold;

[0141] The second allocation unit 704 is used to allocate a second amount of memory to the target business thread according to the number of the first amount of memory in the local cache, so that the target business thread performs business processing based on the allocated memory, wherein the second amount is determined based on the difference between the first amount of memory and the memory request amount.

[0142] In the memory allocation device provided in the embodiment of the present application, since the target business thread adjusts the capacity setting of the local cache according to the number of times the target business thread applies for memory from the target system, the number of times the memory is released to the target system and the preset first preset capacity threshold during operation, the cache capacity of each business thread is adapted to the current load to maximize the benefits of the cache. Therefore, it can solve the problem in the related technology that the business threads implement memory allocation through the memory in the local cache of fixed capacity, resulting in relatively low memory allocation efficiency in load-unbalanced business scenarios, thereby achieving the effect of memory allocation efficiency.

[0143] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a judgment unit, used to judge whether the memory request amount is less than or equal to the first memory amount in the local cache after determining the memory request amount corresponding to the memory allocation request; a third allocation unit, used to allocate the memory amount corresponding to the memory allocation request to the target business thread according to the number corresponding to the memory in the local cache if the memory request amount is less than or equal to the first memory amount in the local cache.

[0144] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a first update unit, used to update the first target quantity corresponding to the target business thread after applying for a first amount of memory from the target system to the local cache according to a first capacity threshold, wherein the first target quantity is the number of times the target business thread applies for memory from the target system.

[0145] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a second determination unit, used to allocate a second amount of memory to the target business thread based on the number of the first amount of memory in the local cache, so that after the target business thread performs business processing based on the allocated memory, if a memory release request of the target business thread is received, the memory release amount corresponding to the memory release request is determined; a first release unit, used to release the memory corresponding to the memory release amount based on the memory release amount and the allocable second memory amount in the local cache.

[0146] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the first release unit includes: an acquisition subunit, used to obtain the current second capacity threshold of the local cache, wherein the second capacity threshold is calculated based on the number of times the target business thread applies for memory, the number of times the memory is released and the first capacity threshold; a release subunit, used to release the memory corresponding to the memory release amount according to the second capacity threshold, the memory release amount and the second memory amount.

[0147] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the release subunit includes: a calculation module, used to calculate the difference between the second capacity threshold and the second memory amount to obtain a first difference; a judgment module, used to judge whether the memory release amount is less than or equal to the first difference; a release module, used to release the memory corresponding to the memory release amount to the local cache if the memory release amount is less than or equal to the first difference.

[0148] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a second release unit, which is used to release the memory of the first difference corresponding to the memory release request to the local cache after determining whether the memory release amount is less than or equal to the first difference, if the memory release amount is greater than the first difference; a third release unit, which is used to release a third amount of memory in the local cache to the target system, and release a fourth amount of memory corresponding to the memory release request to the local cache, wherein the third amount is calculated based on the second capacity threshold, and the fourth amount is calculated based on the first difference and the memory release amount.

[0149] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a second update unit, used to update the second target quantity corresponding to the target business thread after releasing the third amount of memory in the local cache to the target system, wherein the second target quantity is the number of times the target business thread releases memory to the target system.

[0150] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a partitioning unit, used to granularly partition the memory corresponding to the target system according to the data read / write scenario corresponding to the target system before determining the memory request amount corresponding to the memory allocation request, so as to obtain multiple partitioned memories; a numbering unit, used to number the multiple partitioned memories, and establish a mapping relationship between the number and the memory address of the memory corresponding to the number, so as to realize memory allocation based on the number.

[0151] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a first acquisition unit, used to obtain, at a preset time point, a first target number of the target business thread in the first time period and a second target number in the first time period before determining the memory request amount corresponding to the memory allocation request, wherein the first target number is the number of times the target business thread applies for memory from the target system in the first time period, and the second target number is the number of times the target business thread releases memory to the target system in the first time period; a second acquisition unit, used to obtain the first target number of the target business thread in the second time period and the second target number in the second time period; a calculation unit, used to calculate based on the first target number in the first time period, the second target number in the first time period, the first target number in the second time period, the second target number in the second time period and the first preset capacity threshold to obtain the first capacity threshold.

[0152] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the calculation unit includes: a first calculation subunit, used to calculate based on a first target number within a first time period and a second target number within the first time period to obtain a first value; a second calculation subunit, used to calculate based on the first target number within the second time period and the second target number within the second time period to obtain a second value; a third calculation subunit, used to calculate based on the first value, the second value and a first preset capacity threshold to obtain a first capacity threshold.

[0153] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the third calculation subunit includes: a first calculation module, which is used to use the first calculation device to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold if the second value is greater than the first value; a second calculation module, which is used to use the second calculation device to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold if the second value is less than the first value; and a setting module, which is used to set the first preset capacity threshold to the first capacity threshold if the second value is equal to the first value.

[0154] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the first calculation module includes: a first calculation submodule, used to calculate the difference between the second value and the first value to obtain the second difference, and sum the second difference and the preset target value to obtain a third value; a second calculation submodule, used to calculate the ratio between the third value and the first value to obtain the first ratio, and calculate the product between the first ratio and the first preset capacity threshold to obtain the first product; a first determination submodule, used to determine the first capacity threshold based on the numerical relationship between the first product and the first preset capacity threshold and the second preset capacity threshold.

[0155] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the second calculation module includes: a third calculation submodule, used to calculate the difference between the second value and the first value to obtain the second difference, and perform a difference calculation between the second difference and the preset target value to obtain a fourth value; a fourth calculation submodule, used to calculate the ratio between the fourth value and the first value to obtain the second ratio, and calculate the product between the second ratio and the first preset capacity threshold to obtain the second product; a second determination submodule, used to determine the first capacity threshold based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold.

[0156] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the second determination submodule includes: a first determination submodule, used to determine the second product as the first capacity threshold if the second product is greater than or equal to the first preset capacity threshold and less than or equal to the second preset capacity threshold; a second determination submodule, used to determine the first preset capacity threshold as the first capacity threshold if the second product is less than the first preset capacity threshold; and a third determination submodule, used to determine the second preset capacity threshold as the first capacity threshold if the second product is greater than the second preset capacity threshold.

[0157] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a first processing unit, which is used to calculate based on the first target number in the first time period, the second target number in the first time period, the first target number in the second time period, the second target number in the second time period and the first preset capacity threshold, and after obtaining the first capacity threshold, if the first capacity threshold is not equal to the first preset capacity threshold, then clearing the first target number in the first time period, the second target number in the first time period, the first target number in the second time period, the second target number in the second time period and the first preset capacity threshold.

[0158] In an optional embodiment, in the memory allocation device provided in the embodiment of the present application, the device also includes: a second processing unit, for calculating based on the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold, after obtaining the first capacity threshold, if the first capacity threshold is equal to the first preset capacity threshold, then setting the first target quantity in the first time period to be the same as the first target quantity in the second time period, and clearing the first target quantity in the second time period; a third processing unit, for setting the second target quantity in the first time period to be the same as the second target quantity in the second time period, and clearing the second target quantity in the second time period.

[0159] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0160] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.

[0161] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0162] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0163] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0164] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.

[0165] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.

[0166] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.

[0167] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.

Claims

1. A memory allocation method, characterized in that: include: Upon receiving a memory allocation request from a target service thread, determining a memory request amount corresponding to the memory allocation request; If the memory request amount is greater than the first memory amount that can be allocated in the local cache corresponding to the target service thread, the memory number corresponding to the first memory amount is allocated to the target service thread; Applying a first amount of memory to the local cache from the target system according to a first capacity threshold corresponding to the local cache, wherein the first capacity threshold is calculated based on the number of times the target service thread applies for memory from the target system, the number of times memory is released to the target system, and a preset first preset capacity threshold; Allocate a second amount of memory to the target service thread according to the serial number of the first amount of memory in the local cache, so that the target service thread performs service processing based on the allocated memory, wherein the second amount is determined based on the difference between the first amount of memory and the memory request amount; Wherein, before determining the memory request amount corresponding to the memory allocation request, the method further includes: At a preset time point, obtain a first target number of the target business thread within a first time period and a second target number within the first time period, wherein the first target number is the number of times the target business thread applies for memory from the target system within the first time period, and the second target number is the number of times the target business thread releases memory to the target system within the first time period; Obtain a first target number of the target service threads within a second time period and a second target number within a second time period; The first capacity threshold is obtained by calculation based on the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold.

2. The method according to claim 1, characterized in that After determining the memory request amount corresponding to the memory allocation request, the method further includes: Determine whether the memory request amount is less than or equal to a first memory amount in the local cache; If the memory request amount is less than or equal to the first memory amount in the local cache, the memory amount corresponding to the memory allocation request is allocated to the target service thread according to the serial number corresponding to the memory in the local cache.

3. The method according to claim 1, characterized in that After applying for a first amount of memory from the target system to the local cache according to the first capacity threshold, the method further includes: A first target number corresponding to the target service thread is updated, wherein the first target number is the number of times the target service thread applies for memory from the target system.

4. The method according to claim 1, characterized in that: After allocating a second amount of memory to the target service thread according to the number of the first amount of memory in the local cache so that the target service thread performs service processing based on the allocated memory, the method further includes: If a memory release request of the target service thread is received, determining a memory release amount corresponding to the memory release request; According to the memory release amount and the second memory amount that can be allocated in the local cache, memory corresponding to the memory release amount is released.

5. The method according to claim 4, characterized in that The releasing process of the memory corresponding to the memory release amount according to the memory release amount and the second memory amount that can be allocated in the local cache includes: Obtaining a current second capacity threshold of the local cache, wherein the second capacity threshold is calculated based on the number of times the target service thread applies for memory, the number of times the target service thread releases memory, and the first capacity threshold; According to the second capacity threshold, the memory release amount and the second memory amount, memory corresponding to the memory release amount is released.

6. The method according to claim 5, characterized in that The releasing process of the memory corresponding to the memory release amount according to the second capacity threshold, the memory release amount and the second memory amount includes: Calculating a difference between the second capacity threshold and the second memory amount to obtain a first difference; Determine whether the memory release amount is less than or equal to the first difference; If the memory release amount is less than or equal to the first difference, the memory corresponding to the memory release amount is released to the local cache.

7. The method according to claim 6, characterized in that After determining whether the memory release amount is less than or equal to the first difference, the method further includes: If the memory release amount is greater than the first difference, releasing the memory of the first difference corresponding to the memory release request to the local cache; Release a third amount of memory in the local cache to the target system, and release a fourth amount of memory corresponding to the memory release request to the local cache, wherein the third amount is calculated based on the second capacity threshold, and the fourth amount is calculated based on the first difference and the memory release amount.

8. The method according to claim 7, characterized in that After releasing the third amount of memory in the local cache to the target system, the method further includes: An update process is performed on a second target quantity corresponding to the target service thread, wherein the second target quantity is the number of times the target service thread releases memory to the target system.

9. The method according to claim 1, characterized in that: Before determining the memory request amount corresponding to the memory allocation request, the method further includes: According to the data reading / writing scenario corresponding to the target system, the memory corresponding to the target system is divided into granularities to obtain a plurality of divided memories; The multiple divided memories are numbered, and a mapping relationship between the numbers and memory addresses of the memories corresponding to the numbers is established to implement memory allocation based on the numbers.

10. The method according to claim 1, characterized in that The calculating according to the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold to obtain the first capacity threshold includes: Calculating according to the first target quantity within the first time period and the second target quantity within the first time period to obtain a first value; Calculating according to the first target quantity in the second time period and the second target quantity in the second time period to obtain a second value; The first capacity threshold is obtained by performing calculation according to the first value, the second value and the first preset capacity threshold.

11. The method according to claim 10, characterized in that The calculating according to the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold includes: If the second value is greater than the first value, the first value, the second value and the first preset capacity threshold are calculated using a first calculation method to obtain the first capacity threshold; If the second value is less than the first value, a second calculation method is used to calculate the first value, the second value and the first preset capacity threshold to obtain the first capacity threshold; If the second value is equal to the first value, the first preset capacity threshold is set as the first capacity threshold.

12. The method according to claim 11, characterized in that The adopting a first calculation method to calculate the first value, the second value, and the first preset capacity threshold to obtain the first capacity threshold includes: Calculating the difference between the second value and the first value to obtain a second difference, and summing the second difference and a preset target value to obtain a third value; Calculating a ratio between the third value and the first value to obtain a first ratio, and calculating a product between the first ratio and the first preset capacity threshold to obtain a first product; The first capacity threshold is determined based on a numerical relationship between the first product and the first preset capacity threshold and the second preset capacity threshold.

13. The method according to claim 11, characterized in that The adopting a second calculation method to calculate the first value, the second value, and the first preset capacity threshold to obtain the first capacity threshold includes: Calculating the difference between the second value and the first value to obtain a second difference, and performing a difference calculation between the second difference and a preset target value to obtain a fourth value; Calculating a ratio between the fourth value and the first value to obtain a second ratio, and calculating a product between the second ratio and the first preset capacity threshold to obtain a second product; The first capacity threshold is determined based on a numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold.

14. The method according to claim 13, characterized in that The determining the first capacity threshold based on the numerical relationship between the second product and the first preset capacity threshold and the second preset capacity threshold includes: If the second product is greater than or equal to the first preset capacity threshold and less than or equal to the second preset capacity threshold, determining the second product as the first capacity threshold; If the second product is less than the first preset capacity threshold, determining the first preset capacity threshold as the first capacity threshold; If the second product is greater than the second preset capacity threshold, the second preset capacity threshold is determined as the first capacity threshold.

15. The method according to claim 12, characterized in that After obtaining the first capacity threshold by calculating based on the first target quantity within the first time period, the second target quantity within the first time period, the first target quantity within the second time period, the second target quantity within the second time period, and the first preset capacity threshold, the method further includes: If the first capacity threshold is not equal to the first preset capacity threshold, the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold are cleared.

16. The method according to claim 12, characterized in that After obtaining the first capacity threshold by calculating based on the first target quantity within the first time period, the second target quantity within the first time period, the first target quantity within the second time period, the second target quantity within the second time period, and the first preset capacity threshold, the method further includes: If the first capacity threshold is equal to the first preset capacity threshold, setting the first target quantity in the first time period to be the same as the first target quantity in the second time period, and clearing the first target quantity in the second time period to zero; The second target quantity in the first time period is set to be the same as the second target quantity in the second time period, and the second target quantity in the second time period is cleared to zero.

17. A memory allocation device, characterized in that: include: A first determining unit, configured to determine a memory request amount corresponding to a memory allocation request when receiving a memory allocation request of a target service thread; A first allocation unit is configured to allocate a memory number corresponding to the first memory amount to the target service thread if the memory request amount is greater than a first memory amount that can be allocated in the local cache corresponding to the target service thread; a request unit, configured to apply to the target system for a first amount of memory in the local cache according to a first capacity threshold corresponding to the local cache, wherein the first capacity threshold is calculated based on the number of times the target service thread applies for memory from the target system, the number of times memory is released to the target system, and a preset first preset capacity threshold; A second allocation unit is used to allocate a second amount of memory to the target service thread according to the serial number of the first amount of memory in the local cache, so that the target service thread performs service processing based on the allocated memory, wherein the second amount is determined based on the difference between the first amount of memory and the memory request amount; The device further includes: a first acquisition unit, used to acquire, at a preset time point, a first target quantity of the target business thread in a first time period and a second target quantity in the first time period before determining the memory request amount corresponding to the memory allocation request, wherein the first target quantity is the number of times the target business thread applies for memory from the target system in the first time period, and the second target quantity is the number of times the target business thread releases memory to the target system in the first time period; a second acquisition unit, used to acquire the first target quantity of the target business thread in the second time period and the second target quantity in the second time period; and a calculation unit, used to calculate based on the first target quantity in the first time period, the second target quantity in the first time period, the first target quantity in the second time period, the second target quantity in the second time period and the first preset capacity threshold to obtain the first capacity threshold.

18. An electronic 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 steps of the method described in any one of claims 1 to 16 are implemented.

19. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 16 are implemented.

Citation Information

Patent Citations

  • Memory control method for embedded systems

    CN102915276A

  • Data caching method and device, computer equipment and storage medium

    CN114721844A

  • Memory allocation method and device, electronic equipment, storage medium and product

    CN115269190A

  • Shared memory pool implementation method and system

    CN115599542A

  • Memory management method and device, medium and electronic equipment

    CN115599707A