Memory management method and device, computer device, storage medium and program product

By using small-capacity memory pages to allocate memory pages on demand in storage instances, the problem of memory waste in traditional storage instances is solved, achieving efficient memory utilization and stable management, and adapting to different business workloads.

CN123137932APending Publication Date: 2026-11-20DAWNING INFORMATION IND (BEIJING) CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611508152.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-24
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Traditional storage instances pre-set the size and number of individual memory tables during creation, leading to low memory utilization and wasted memory.

Method used

Using small-capacity memory pages as the basic unit of memory allocation, memory pages are allocated gradually as needed based on the actual amount of data written, replacing the traditional method of pre-allocating large blocks of contiguous memory, thus achieving dynamic management and sharing of memory.

Benefits of technology

It improves memory utilization, reduces memory idle waste, enhances system stability and resource utilization, and increases the ability to adapt to different business loads.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123137932A_ABST
    Figure CN123137932A_ABST
Patent Text Reader

Abstract

The application relates to a memory management method and device, computer equipment, a storage medium and a program product. Since a small storage capacity memory page is used as a basic unit of memory allocation, a large block continuous memory pre-allocation mode in the prior art is replaced, a storage instance does not need to occupy an integral fixed memory at the time of creation, but a memory page is gradually allocated on demand according to an actual data writing amount, so that too much memory is not occupied when a business load is low, memory idling and waste are fundamentally reduced, and the memory utilization is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data storage technology, and in particular to a memory management method, apparatus, computer equipment, storage medium, and program product. Background Technology

[0002] In storage database applications, a storage instance is a service process running in memory, responsible for receiving read and write requests, caching data in memory tables, and ultimately flushing the data to the disk database file. A storage instance contains multiple memory tables, and the number and size of these memory tables determine the storage instance's data absorption capacity and peak write performance.

[0003] In traditional technologies, the size and number of individual memory tables are typically pre-set when creating a storage instance. This results in a single storage instance occupying a fixed amount of memory. When the actual memory used by a storage instance is much less than the pre-set fixed amount, it leads to memory waste and low memory utilization. Summary of the Invention

[0004] Therefore, it is necessary to provide a memory management method, apparatus, computer equipment, storage medium, and program product that can improve memory utilization in response to the above-mentioned technical problems.

[0005] Firstly, this application provides a memory management method, including:

[0006] After obtaining the data to be written, the remaining storage space of the storage instance used to store the data to be written is obtained; wherein, the storage instance includes at least one memory page;

[0007] If the remaining storage space is less than the storage space required for the data to be written, then a new memory page is allocated to the storage instance; and,

[0008] The data to be written is written to the free storage space in the memory pages included in the storage instance.

[0009] In the above embodiments, since small-capacity memory pages are used as the basic unit of memory allocation, replacing the traditional method of pre-allocating large blocks of contiguous memory, the storage instance does not need to occupy a whole block of fixed memory when it is created. Instead, memory pages are allocated gradually as needed based on the actual amount of data written. This ensures that it does not occupy too much memory when the business load is low, fundamentally reducing memory idle waste and thus improving memory utilization.

[0010] In one embodiment, allocating new memory pages to the storage instance includes:

[0011] Obtain the preset storage capacity of the storage instance;

[0012] The actual storage capacity of the storage instance is determined based on the memory pages included in the storage instance;

[0013] If the actual storage capacity is less than the preset storage capacity, allocate new memory pages to the storage instance.

[0014] In the above embodiments, by setting a preset storage capacity for each storage instance and verifying the relationship between the actual storage capacity and the preset storage capacity before allocating memory pages each time, it is ensured that each storage instance has a certain amount of memory to handle the business load, and the problem of a single storage instance occupying public memory resources without limit is avoided. This ensures the fairness of memory allocation and the overall stability of the storage system in the scenario of multiple storage instances coexisting.

[0015] In one embodiment, the preset storage capacity is determined according to any of the following methods:

[0016] The preset number of memory pages corresponding to the storage instance;

[0017] The preset number of memory pages corresponding to the storage instance, and the storage space expansion coefficient;

[0018] The storage capacity and number of memory tables corresponding to the storage instance; wherein, a memory table includes at least one memory page;

[0019] The storage capacity and number of memory tables corresponding to the storage instance, as well as the storage space expansion coefficient.

[0020] The above embodiments provide a variety of different preset storage capacity determination methods. On the one hand, they can adapt to different configuration habits, business scenarios and management granularity requirements, making them more widely applicable. On the other hand, the introduction of a storage space expansion coefficient makes the memory limit of the storage instance expandable instead of fixed. This achieves fair allocation of basic memory quotas among multiple instances and allows busy instances to temporarily borrow idle resources from the public memory pool to cope with data peaks, thereby improving the overall system's ability to withstand business fluctuations and memory resource utilization.

[0021] In one embodiment, the preset number of memory pages corresponding to the storage instance and the storage capacity of a single memory page, as well as the storage capacity and number of memory tables corresponding to the storage instance, are determined based on the storage capacity of the storage system in which the storage instance resides.

[0022] In the above embodiments, since the memory configuration parameters of the storage instance are controlled by the storage capacity of the storage system, the total memory usage will not exceed the total memory capacity of the storage system, thus achieving controllable management of the total memory and improving the stability and predictability of the system resources.

[0023] In one embodiment, allocating new memory pages to the storage instance includes:

[0024] Select a free memory page from the memory pages included in the target storage pool as a new memory page for the storage instance; wherein the memory pages in the target storage pool have the same storage capacity.

[0025] In the above embodiments, memory pages are managed by a target storage pool with uniform granularity. All storage instances share the same memory resource pool, which allows memory pages to be shared between different storage instances. Furthermore, memory pages of uniform size do not generate memory fragmentation during the allocation and release process, thereby improving the recycling rate and allocation efficiency of memory resources.

[0026] In one embodiment, the target storage pool is one of multiple storage pools in the storage system where the storage instance resides, and the storage capacity of memory pages varies in different storage pools.

[0027] In the above embodiments, because the storage capacity of memory pages in different storage pools varies, a memory management system with multiple granularities coexisting is formed. Memory pages within the same storage pool have consistent specifications, and memory pages can be shared between storage instances. This design enables the storage system to support memory management at multiple granularities simultaneously within the same physical system, improving the storage system's adaptability to different business workloads.

[0028] In one embodiment, the method further includes:

[0029] In response to storing the written data in the target memory page included in the storage instance to persistent storage space, the target memory page is released and placed in the target storage pool.

[0030] In the above embodiments, once the data in the memory table is successfully persisted to the persistent storage space, the corresponding memory pages are promptly released and returned to the common target storage pool, enabling memory resources to be reused cyclically and avoiding long-term occupation of memory resources. Furthermore, the released memory pages enter the common target storage pool and can be requested and used by other busy storage instances, realizing the dynamic flow of memory between different instances. This allows idle memory from idle instances to be supplied to busy instances, improving the memory utilization efficiency and throughput of the storage system.

[0031] In one embodiment, the method further includes:

[0032] If the remaining storage space is greater than or equal to the storage space required for the data to be written, then the data to be written is written into the remaining storage space.

[0033] In the above embodiments, by judging the remaining storage space before writing, new memory pages are allocated only when the remaining storage space is insufficient, and existing free space is reused directly when the remaining storage space is sufficient. This avoids frequent memory allocation and release operations, reduces system call overhead and management overhead, and improves performance in normal writing scenarios.

[0034] Secondly, this application also provides a memory management device, comprising:

[0035] The acquisition module is used to acquire the data to be written, and then acquire the remaining storage space of the storage instance used to store the data to be written; wherein the storage instance includes at least one memory page;

[0036] An allocation module is configured to allocate new memory pages to the storage instance if the remaining storage space is less than the storage space required by the data to be written; and,

[0037] The write module is used to write the data to be written into the free storage space in the memory pages included in the storage instance.

[0038] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:

[0039] After obtaining the data to be written, the remaining storage space of the storage instance used to store the data to be written is obtained; wherein, the storage instance includes at least one memory page;

[0040] If the remaining storage space is less than the storage space required for the data to be written, then a new memory page is allocated to the storage instance; and,

[0041] The data to be written is written to the free storage space in the memory pages included in the storage instance.

[0042] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:

[0043] After obtaining the data to be written, the remaining storage space of the storage instance used to store the data to be written is obtained; wherein, the storage instance includes at least one memory page;

[0044] If the remaining storage space is less than the storage space required for the data to be written, then a new memory page is allocated to the storage instance; and,

[0045] The data to be written is written to the free storage space in the memory pages included in the storage instance.

[0046] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:

[0047] After obtaining the data to be written, the remaining storage space of the storage instance used to store the data to be written is obtained; wherein, the storage instance includes at least one memory page;

[0048] If the remaining storage space is less than the storage space required for the data to be written, then a new memory page is allocated to the storage instance; and,

[0049] The data to be written is written to the free storage space in the memory pages included in the storage instance.

[0050] The aforementioned memory management methods, devices, computer equipment, storage media, and program products, by using small-capacity memory pages as the basic unit of memory allocation, replace the traditional method of pre-allocating large blocks of contiguous memory. Storage instances do not need to occupy a whole block of fixed memory at creation time, but rather allocate memory pages gradually as needed based on the actual amount of data written. This ensures that excessive memory is not occupied when the business load is low, fundamentally reducing memory idle waste and thus improving memory utilization. Attached Figure Description

[0051] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0052] Figure 1A This is a diagram illustrating the application environment of a memory management method in one embodiment;

[0053] Figure 1B This is a comparison diagram of memory table management in one embodiment;

[0054] Figure 1C This is a schematic diagram of memory page flow in one embodiment;

[0055] Figure 2 This is a flowchart illustrating a memory management method in one embodiment;

[0056] Figure 3 A schematic diagram illustrating the process of allocating new memory pages to a storage instance in one embodiment;

[0057] Figure 4 This is a schematic diagram of memory table expansion in one embodiment;

[0058] Figure 5 This is a schematic diagram illustrating how the size of the memory table varies with the number of storage pools in one embodiment;

[0059] Figure 6 This is a block diagram of a memory management device in one embodiment;

[0060] Figure 7 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0061] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0062] The memory management method provided in this application embodiment can be applied to, for example, Figure 1A The application environment shown is an example of a storage system with a Log-Structured-Merge-Tree (LSM-Tree) architecture. Figure 1A The storage system is shown to include multiple storage pools, such as storage pool-0 to storage pool-n. Each storage pool deploys multiple independent storage instances, namely key-value database (KVDB) instance-0 to KVDB instance-n. Each KVDB instance contains multiple memory tables, such as multiple readable and writable active memory tables (Memtable) and read-only memory tables (Imtable).

[0063] For example, see Figure 1B , Figure 1B A comparison diagram of memory table management is provided, using a memory table size of 256KB and a memory page size of 8KB as an example. The conventional management mode involves a KVDB instance requesting a single 256KB block of contiguous memory, which is then managed uniformly by a management structure. In this embodiment, the original 256KB block of memory is split into multiple independent 8KB memory pages. These pages have independent physical addresses and are non-contiguous, logically concatenated to form a complete 256KB memory table. This breaks the limitation of traditional solutions that rely on contiguous large blocks of memory, enabling individual allocation, release, and cross-instance cyclical reuse of memory pages.

[0064] The memory management method provided in this application embodiment allows memory page resources to be dynamically transferred and allocated on demand between different KVDB instances under the same storage pool, realizing cross-instance scheduling and reuse of memory resources. This solves the problem of total memory expansion and idle waste caused by traditional pre-allocated large blocks of memory in multi-storage pool scenarios.

[0065] For example, see Figure 1C , Figure 1C A schematic diagram of memory page flow is provided, using an 8KB memory page size as an example. Figure 1C This paper illustrates a scheduling architecture for multiple KVDB instances that dynamically transfers memory pages based on an 8KB granularity shared memory pool. The shared memory pool serves as a carrier of shared memory resources for all instances, allocating 8KB memory pages to multiple independent instances such as KVDB instance-0, KVDB instance-1, and KVDB instance-2. Each instance contains a Memtable and an Imtable. Memory pages can flow and be scheduled between the shared memory pool and different KVDB instances, as well as between different KVDB instances. When the Imtable of an instance is written to disk and the memory pages are released, the released 8KB memory pages can be directly transferred to other KVDB instances with higher loads, thereby achieving cyclic reuse of memory resources among multiple instances and improving overall memory utilization.

[0066] This method can be executed by a server, which has deployed features such as... Figure 1A The storage system shown can be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server providing cloud computing services.

[0067] In one exemplary embodiment, such as Figure 2 As shown, a memory management method is provided. Taking the application of this method to a server as an example, the method includes the following steps:

[0068] S201, after obtaining the data to be written, obtain the remaining storage space of the storage instance used to store the data to be written.

[0069] Each storage instance includes at least one memory page.

[0070] For example, when the storage system receives a write request from a client, it parses the content of the data to be written and the identification information of the corresponding storage instance from the write request.

[0071] A storage instance is a service process or service unit that runs in the memory of a storage system. It is responsible for receiving read and write requests, caching data in memory, and finally flushing the data to persistent storage space, such as disk database files.

[0072] Each storage instance is assigned a unique identifier upon creation to distinguish multiple storage instances existing simultaneously in the storage system. Each storage instance contains at least one memory page, which is the basic unit for memory management in the storage system. Each memory page has a fixed storage capacity, such as a contiguous memory region of 4KB, 8KB, 64KB, 1MB, or other preset sizes.

[0073] Different storage instances can contain the same or different numbers of memory pages. Memory pages within the same storage instance may not be physically contiguous. These memory pages can be uniformly managed and indexed through the storage instance's management structure. The management structure records information such as pointers or indexes to all currently allocated memory pages in the storage instance, the amount of storage used for each memory page, and pointers to currently active memory pages being written to.

[0074] When a storage instance receives data to be written, it can first calculate the total unused storage space across all memory pages, i.e., the remaining storage space, based on information recorded in the management structure. This calculation can be done by iterating through all memory pages, subtracting the used capacity of each page from its storage capacity, and then summing the results to obtain the remaining storage space. Alternatively, it can be done by directly reading the pre-maintained total remaining space field from the management structure. The purpose of obtaining the remaining storage space is to determine whether the current storage instance has sufficient free capacity to accommodate the data to be written, thereby deciding whether to request new memory pages from the storage pool to expand the storage space.

[0075] S202, if the remaining storage space is less than the storage space required for the data to be written, then allocate a new memory page for the storage instance.

[0076] For example, the remaining storage space can be compared with the storage space required for the data to be written. The storage space required for the data to be written can be determined based on the actual size of the data. For example, if the data to be written is a key-value pair, the required storage space is the length of the key plus the length of the value plus metadata such as timestamps, checksums, etc.

[0077] If the remaining storage space is less than the storage space required for the data to be written, it means that the sum of all free areas in the existing memory pages of the current storage instance is insufficient to accommodate the new data, and new memory pages need to be allocated to the storage instance to expand its storage capacity.

[0078] In some alternative implementations, a free memory page can be selected from the memory pages included in the target storage pool as a new memory page for the storage instance; wherein the memory pages in the target storage pool have the same storage capacity.

[0079] For example, a storage system can organize and manage memory pages in units of storage pools. Each storage pool is an independent memory resource management container containing multiple memory pages, and all memory pages within the same storage pool have the same storage capacity. Within a storage pool, all memory pages are managed using a unified data structure. For instance, a free linked list can be used to chain together all free memory pages, with each free memory page storing a pointer to the next free memory page; alternatively, a bitmap can be used, employing a binary bit array to record the allocation status of each memory page, where 0 represents free and 1 represents allocated.

[0080] When allocating new memory pages to a storage instance, the target storage pool to which the storage instance belongs can be determined first. Each storage instance is assigned to a specific storage pool upon creation, and this affiliation is stored in the storage instance's configuration information. The memory pages stored in the target storage pool to which the storage instance belongs are of the same size, and the total size of the memory pages included in the storage instance is the same as the size of the memory pages stored in its target storage pool.

[0081] In some alternative implementations, the target storage pool is one of multiple storage pools in the storage system where the storage instance resides, and the storage capacity of memory pages varies in different storage pools.

[0082] For example, a storage system can contain multiple storage pools, each of which is an independent memory resource management container serving one or more storage instances belonging to that pool. Each storage pool independently manages its internal memory pages, and memory page management between different storage pools does not interfere with each other. Memory pages in different storage pools can have different storage capacities; for example, memory pages in storage pool A have a storage capacity of 4KB, memory pages in storage pool B have a storage capacity of 1MB, and memory pages in storage pool C have a storage capacity of 2MB, etc.

[0083] Different storage pools employ memory pages of varying granularities to adapt to diverse business workloads. In practical storage applications, different storage instances may handle different types of business data. For example, some businesses primarily handle small data blocks, such as user session information and cache entries, where the amount of data written each time is small. Using small memory pages (e.g., 4KB) can reduce memory waste. Conversely, some businesses primarily handle large data blocks, such as log files and large object storage, where the amount of data written each time is large. Using large memory pages (e.g., 2MB) can reduce memory allocation frequency and management overhead, thereby improving allocation efficiency and data write throughput.

[0084] For example, when each storage instance is created, the user or storage system can specify the storage pool to which the storage instance belongs, based on the expected business load type of the storage instance. The memory pages required by the storage instance during operation are allocated from its respective storage pool, and are also returned to the storage pool when released.

[0085] In this way, because the storage capacity of memory pages differs across storage pools, a memory management system with multiple granularities coexisting is formed. Memory pages within the same storage pool have consistent specifications, and memory pages can be shared between storage instances. This design enables the storage system to support multiple granularities of memory management simultaneously within the same physical system, improving the storage system's adaptability to different business workloads.

[0086] After determining the target storage pool, the storage system selects a currently free memory page from the pool's set of free memory pages. For example, it can retrieve the first free page from the head of the free list, select physically contiguous free pages to optimize cache locality, or select a recently released free page to improve cache hit rate. The selected free memory page is removed from the storage pool's free set, marked as allocated, and then its pointer or index is passed to the storage instance's management structure, which adds the memory page to the storage instance's memory page list.

[0087] Since all memory pages in the same storage pool have the same storage capacity, the storage capacity provided by each memory page is consistent regardless of which storage instance it is allocated to. This also allows memory pages released back to the storage pool to be reassigned and used by other storage instances, creating conditions for the flow and sharing of memory pages between different storage instances.

[0088] In this way, by managing memory pages through a target storage pool with uniform granularity, all storage instances share the same memory resource pool, enabling memory pages to be shared between different storage instances. Furthermore, memory pages of uniform size do not generate memory fragmentation during allocation and release, improving the recycling rate and allocation efficiency of memory resources.

[0089] It's important to note that allocating new memory pages to a storage instance is not unlimited; it must be done within the storage instance's preset storage capacity constraints. For example, if the actual storage capacity of a storage instance has reached its preset storage capacity limit, no new memory pages will be allocated even if there is insufficient remaining storage space. In this case, the storage instance can trigger a data flush operation to write the data in the memory page to persistent storage to release the memory page, or return a write failure or wait-to-retry response to the client.

[0090] S203, write the data to be written to the free storage space in the memory pages included in the storage instance.

[0091] Free storage space refers to the free storage space within the memory pages of a storage instance.

[0092] The data to be written is written to the free storage space of the storage instance. Free storage space refers to the storage area in all memory pages of the storage instance that has not yet been occupied by data.

[0093] For example, a storage instance typically maintains a pointer to a currently active memory page, which points to the memory page currently being used for writing data. When data needs to be written, it is first determined whether the remaining space of the currently active memory page is sufficient to accommodate the data to be written. If it is sufficient, the data is directly written to the free area of ​​that memory page, and the used amount of that memory page and the total remaining storage space in the management structure are updated. If the remaining space of the currently active memory page is insufficient to accommodate the data to be written, the system searches for memory pages with sufficient remaining space in other memory pages of the storage instance. If a page is found, the data is written to that page. If the remaining space of all memory pages is insufficient to accommodate the data to be written individually, and the total remaining storage space is greater than the storage space required for the data to be written (i.e., the data can be written in segments to multiple memory pages), then the data can be split into multiple parts and written to the free areas of different memory pages respectively.

[0094] After the data is written, update the information such as the amount of memory pages used and the total remaining storage space in the management structure, and return a write success response to the client.

[0095] In this way, the storage instance dynamically manages storage space in units of memory pages. Data to be written is written to the free area of ​​one or more memory pages, thus realizing the caching of data in memory.

[0096] In the above embodiments, since small-capacity memory pages are used as the basic unit of memory allocation, replacing the traditional method of pre-allocating large blocks of contiguous memory, the storage instance does not need to occupy a whole block of fixed memory when it is created. Instead, memory pages are allocated gradually as needed based on the actual amount of data written. This ensures that it does not occupy too much memory when the business load is low, fundamentally reducing memory idle waste and thus improving memory utilization.

[0097] In some alternative implementations, if the remaining storage space is greater than or equal to the storage space required for the data to be written, then the data to be written is written to the remaining storage space.

[0098] For example, when a storage instance receives data to be written, if the remaining storage space is greater than or equal to the storage space required by the data to be written, it means that there is enough free space in the memory pages allocated by the current storage instance to accommodate the new data. Therefore, there is no need to trigger a new memory page allocation operation, and the data to be written can be directly written to the remaining storage space.

[0099] When writing data to the remaining storage space, it is necessary to ensure the atomicity of the write operation and data consistency to prevent data corruption due to exceptions during the write process. For example, this can be achieved by logging before writing, using transaction mechanisms, or employing atomic data update operations.

[0100] In the above embodiments, by judging the remaining storage space before writing, new memory pages are allocated only when the remaining storage space is insufficient, and existing free space is reused directly when the remaining storage space is sufficient. This avoids frequent memory allocation and release operations, reduces system call overhead and management overhead, and improves performance in normal writing scenarios.

[0101] In some alternative implementations, see [link to relevant documentation]. Figure 3 , Figure 3 A flowchart illustrating the process of allocating new memory pages for a storage instance is provided, specifically including the following steps:

[0102] S301, Get the preset storage capacity of the storage instance.

[0103] The preset storage capacity is the maximum memory usage limit pre-configured for each storage instance in the storage system, used to constrain the maximum amount of memory that the storage instance can occupy. The preset storage capacity can be determined based on a variety of factors, including but not limited to the total memory capacity of the storage system, the number of storage pools in the storage system, the number of storage instances in each storage pool, the business priority and expected load of each storage instance, and parameters specified by the user through the configuration interface.

[0104] The preset storage capacity can be expressed in bytes, such as 2GB, or in the number of memory pages, such as 128 memory pages, or in the storage capacity and number of memory tables, such as 8KB per memory table and a total of 8 memory tables.

[0105] For example, a field can be pre-set in the management structure of a storage instance to store a preset storage capacity value. This field is written when the storage instance is initialized and remains unchanged throughout the entire lifecycle of the storage instance, unless the storage system triggers a dynamic adjustment policy.

[0106] Based on this, the preset storage capacity of the storage instance can be directly read from this field. The preset storage capacity is used to prevent a single storage instance from consuming system memory without restraint due to business peaks, and to ensure that multiple storage instances can share memory resources relatively fairly in the same storage system.

[0107] S302, determine the actual storage capacity of the storage instance based on the memory pages included in the storage instance.

[0108] Actual storage capacity refers to the sum of the storage capacities of all memory pages currently allocated and occupied by the storage instance. Each memory page has a fixed storage capacity when allocated. The management structure of the storage instance records information about all memory pages currently allocated to the storage instance, including the pointer, size, and usage of each memory page.

[0109] When determining the actual storage capacity, one can either iterate through the list of memory pages in the management structure and sum the storage capacity of each memory page to obtain the total; or one can directly maintain a counter field for the actual storage capacity in the management structure, increment this field each time a new memory page is allocated, and subtract this field each time a memory page is released, thus allowing direct reading of this field to obtain the actual storage capacity.

[0110] S303 allocates new memory pages to the storage instance when the actual storage capacity is less than the preset storage capacity.

[0111] For example, the actual storage capacity read from the management structure can be compared with the preset storage capacity. If the actual storage capacity is less than the preset storage capacity, it means that the total memory currently occupied by the storage instance has not yet reached the storage capacity limit and there is still room for expansion. New memory pages can be allocated to the storage instance to increase storage capacity.

[0112] If the actual storage capacity has reached or exceeded the preset storage capacity, it means that the amount of memory occupied by the storage instance has reached or exceeded the storage capacity limit, and no new memory pages will be allocated to the storage instance at this time.

[0113] In the above embodiments, by setting a preset storage capacity for each storage instance and verifying the relationship between the actual storage capacity and the preset storage capacity before allocating memory pages each time, it is ensured that each storage instance has a certain amount of memory to handle the business load, and the problem of a single storage instance occupying public memory resources without limit is avoided. This ensures the fairness of memory allocation and the overall stability of the storage system in the scenario of multiple storage instances coexisting.

[0114] In some optional implementations, the preset storage capacity is determined according to any of the following methods:

[0115] Method 1: Preset number of memory pages corresponding to the storage instance.

[0116] For example, the preset storage capacity can be determined based on the preset number of memory pages corresponding to the storage instance. The storage system can pre-configure an upper limit for the number of memory pages for each storage instance, which represents the maximum number of memory pages that the storage instance can occupy. The preset storage capacity equals the preset number of memory pages multiplied by the storage capacity of a single memory page.

[0117] Method 2: The preset number of memory pages corresponding to the storage instance, and the storage space expansion coefficient.

[0118] For example, the preset storage capacity can be determined based on the preset number of memory pages corresponding to the storage instance and the storage space expansion factor. In addition to configuring a basic upper limit on the number of memory pages for each storage instance, the storage system can also configure an expansion factor, such as a value of 1, 2, 3, or 4. The preset storage capacity equals the preset number of memory pages multiplied by the storage capacity of a single memory page, and then multiplied by the expansion factor.

[0119] The purpose of the expansion factor is to give storage instances a certain degree of flexibility in expanding their storage capacity. For example, if the size of a single memory page in a storage system is 8KB, and the default number of memory pages for a storage instance is 10, with an expansion factor of 2, then the default storage capacity of this storage instance is 10 × 8KB × 2 = 160KB. That is, this storage instance can actually occupy a maximum of 20 memory pages, which is equivalent to doubling the capacity from the basic 10 memory pages.

[0120] This method of determination is suitable for scenarios with large fluctuations in business load. During peak business periods, storage instances can temporarily borrow more memory pages to cope with sudden write traffic, while during trough periods, excess memory pages are released through the normal data sinking mechanism, which ensures peak performance without causing permanent memory waste.

[0121] Method 3: The storage capacity and number of memory tables corresponding to the storage instance; wherein, a memory table includes at least one memory page.

[0122] For example, the preset storage capacity can be determined based on the storage capacity and number of memory tables corresponding to the storage instance. Each storage instance can contain multiple memory tables, such as Memtable and ImmTable. Each memory table consists of at least one memory page, and the storage capacity of a memory table is the sum of the storage capacities of all the memory pages contained in that memory table. The preset storage capacity is equal to the storage capacity of a single memory table multiplied by the number of memory tables. For example, if the storage capacity of each memory table is configured to be 2MB, and the storage instance contains 8 memory tables, then the preset storage capacity of the storage instance is 2MB × 8 = 16MB.

[0123] Method 4: The storage capacity and number of memory tables corresponding to the storage instance, as well as the storage space expansion coefficient.

[0124] For example, the preset storage capacity can be determined based on the storage capacity and number of memory tables corresponding to the storage instance, as well as the storage space expansion factor. The preset storage capacity equals the storage capacity of a single memory table multiplied by the number of memory tables, and then multiplied by the expansion factor. For instance, if each memory table has a storage capacity of 2MB, the storage instance contains 4 memory tables, and the expansion factor is 3, then the preset storage capacity of this storage instance is 2MB × 4 × 3 = 24MB. This method provides expansion space for the instance during peak load periods, balancing ease of management with flexibility in expansion.

[0125] For example, see Figure 4 , Figure 4 A schematic diagram of memory table expansion is provided, taking a storage instance configured with one Memtable for receiving written data and seven Imtables as an example, with an expansion factor of 4. When the storage system write pressure is high and the speed of writing Imtables to disk cannot keep up with the speed of switching and generating new memory tables, the number of Imtables can be dynamically expanded, up to a maximum of 4 times the initial number.

[0126] However, a single KVDB instance cannot be expanded indefinitely, otherwise it may severely squeeze the memory of idle KVDB instances, causing idle KVDB instances to be unable to obtain effective memory when the pressure increases. Therefore, an upper limit on the number of memory tables can be set, for example, to 64. When expanding the memory tables in a KVDB instance, the smaller value between the number of memory tables determined based on the expansion coefficient and the upper limit on the number of memory tables can be selected.

[0127] In this way, the write pause problem caused by disk write blockage can be alleviated by temporarily expanding the read-only memory table queue. After the system IO pressure drops and the excess Imtable is written to disk, the expanded memory table resources can be released.

[0128] The above embodiments provide a variety of different preset storage capacity determination methods. On the one hand, they can adapt to different configuration habits, business scenarios and management granularity requirements, making them more widely applicable. On the other hand, the introduction of a storage space expansion coefficient makes the memory limit of the storage instance expandable instead of fixed. This achieves fair allocation of basic memory quotas among multiple instances and allows busy instances to temporarily borrow idle resources from the public memory pool to cope with data peaks, thereby improving the overall system's ability to withstand business fluctuations and memory resource utilization.

[0129] In some optional implementations, the preset number of memory pages corresponding to the storage instance, the storage capacity of a single memory page, and the storage capacity and number of memory tables corresponding to the storage instance are determined based on the storage capacity of the storage system in which the storage instance resides.

[0130] For example, parameters such as the preset number of memory pages corresponding to a storage instance, the storage capacity of a single memory page, and the storage capacity and number of memory tables can be determined based on the total storage capacity of the storage system in which the storage instance resides. For instance, when deploying a storage system, the total physical memory capacity is a fixed configuration parameter, and the target upper limit of data storage that the storage system can support is determined. Since this data is initially written to memory tables and then permanently stored on persistent storage media, the total memory required by the storage system for memory tables also has a fixed upper limit to meet overall storage needs.

[0131] Based on this, during initialization, the storage system can determine the preset number of memory pages corresponding to each storage instance and the storage capacity of a single memory page, as well as the storage capacity and number of memory tables corresponding to each storage instance, according to factors such as the total memory capacity of the storage system, the expected maximum number of storage pools, the expected maximum number of storage instances in each storage pool, and the expected load of each storage instance.

[0132] For example, the storage capacity of a single memory page can be determined first. The choice of storage capacity needs to strike a balance between memory utilization efficiency and allocation management overhead. Too small a granularity leads to a large management structure and increased allocation frequency; too large a granularity leads to memory waste. Therefore, an appropriate storage capacity can be selected based on factors such as the number of storage instances, for example, 8KB.

[0133] Once the storage capacity of a single memory page is determined, the average available memory per storage instance can be calculated based on the total memory capacity and the expected total number of storage instances. For example, if the total memory is 64GB and the expected maximum number of storage instances is 64, then the average available memory per storage instance is 1GB. The preset number of memory pages per storage instance can then be determined based on this average value.

[0134] The storage capacity and number of memory tables can be configured based on the preset number of memory tables after determining the preset storage capacity of the storage instance. For example, each storage instance can have a maximum of 8 memory tables. The storage capacity of each memory table can be obtained by dividing the preset storage capacity by the number of memory tables.

[0135] Furthermore, when a new storage pool is created in the storage system, the total memory capacity of the storage system is shared among more storage pools and storage instances due to the increased number of storage pools. Therefore, the preset storage capacity of each storage instance needs to be recalculated. For example, if the storage system originally had only one storage pool, and the preset storage capacity of each storage instance was allocated as half of the total memory capacity; after a second storage pool is created, the total memory capacity is shared between the two storage pools, and the preset storage capacity of each storage instance may need to be adjusted to half of its original value to ensure that the total memory usage does not exceed the physical memory limit.

[0136] For example, see Figure 5 , Figure 5 A diagram illustrating how the size of the memory table changes with the number of storage pools is provided. Assuming there is only one storage pool initially, the memory table's capacity is 256KB. Whenever a new storage pool is created, its capacity is evenly distributed across all pools. For example, when there are two storage pools, the memory table in a single pool is 128KB; when there are three, the capacity is calculated as one-third of the original length (85.3KB), then aligned upwards to an integer multiple of 8KB granularity (88KB); and when there are four, the memory table in a single pool is 64KB. If a storage pool is destroyed or reduced, the memory table capacity of the remaining pools is redistributed and gradually increases. Eventually, when only one storage pool remains, the memory table returns to its initial capacity of 256KB, thus achieving a balanced distribution of global memory resources.

[0137] This dynamic adjustment mechanism ensures that no matter how many storage pools and storage instances are created in the storage system, the sum of the preset storage capacities of each storage instance will never exceed the planned upper limit of the total memory capacity of the storage system.

[0138] In the above embodiments, since the memory configuration parameters of the storage instance are controlled by the storage capacity of the storage system, the total memory usage will not exceed the total memory capacity of the storage system, thus achieving controllable management of the total memory and improving the stability and predictability of the system resources.

[0139] In some optional implementations, if there are freed memory pages in the storage instance, the freed memory pages need to be returned to the target storage pool.

[0140] For example, in response to storing the written data in the target memory page included in the storage instance to persistent storage, the target memory page is released and placed in the target storage pool.

[0141] Memory pages in a storage instance are used to cache data to be written, but this data ultimately needs to be stored in persistent storage, such as disks or solid-state drives, to ensure data persistence and reliability. Once the data in a memory page is successfully flushed to persistent storage, the cached data copy in that memory page no longer needs to be retained, and the memory page can be released and reclaimed for use by other storage instances.

[0142] For example, the storage system runs a data flushing thread in the background. This thread periodically checks the usage and data residency time of memory pages in each storage instance. When the usage of a memory page reaches a threshold (e.g., it is full) or the data residency time exceeds a preset time threshold, a data flushing operation for that memory page is triggered. During the data flushing process, the storage system reads all valid data from the memory page, encodes and compresses it according to the format requirements of the persistent storage space, and writes it to the underlying storage device. After the write is complete, the persistent storage space returns a confirmation message indicating successful write, and the storage system then confirms that the data in the memory page has been safely persisted. At this point, the memory page is the target memory page.

[0143] After confirming that the data has been persisted, a memory page release operation can be performed. This involves first removing the record of the target memory page from the storage instance's management structure, including deleting the page pointer from the memory page list and subtracting the page's storage capacity and used amount from the management structure. Then, the data in the memory page is cleaned up, for example, by zeroing out the page content or marking it as invalid. Finally, the memory page is returned to the free memory page queue of its target storage pool.

[0144] In the above embodiments, once the data in the memory table is successfully persisted to the persistent storage space, the corresponding memory pages are promptly released and returned to the common target storage pool, enabling memory resources to be reused cyclically and avoiding long-term occupation of memory resources. Furthermore, the released memory pages enter the common target storage pool and can be requested and used by other busy storage instances, realizing the dynamic flow of memory between different instances. This allows idle memory from idle instances to be supplied to busy instances, improving the memory utilization efficiency and throughput of the storage system.

[0145] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0146] Based on the same inventive concept, this application also provides a memory management device for implementing the memory management method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more memory management device embodiments provided below can be found in the limitations of the memory management method described above, and will not be repeated here.

[0147] In one exemplary embodiment, such as Figure 6 As shown, a memory management device is provided, comprising:

[0148] The acquisition module 10 is used to acquire the remaining storage space of the storage instance used to store the data to be written after acquiring the data to be written; wherein, the storage instance includes at least one memory page;

[0149] The allocation module 20 is configured to allocate new memory pages to the storage instance if the remaining storage space is less than the storage space required for the data to be written; and,

[0150] The write module 30 is used to write the data to be written into the free storage space in the memory pages included in the storage instance.

[0151] In the above embodiments, since small-capacity memory pages are used as the basic unit of memory allocation, replacing the traditional method of pre-allocating large blocks of contiguous memory, the storage instance does not need to occupy a whole block of fixed memory when it is created. Instead, memory pages are allocated gradually as needed based on the actual amount of data written. This ensures that it does not occupy too much memory when the business load is low, fundamentally reducing memory idle waste and thus improving memory utilization.

[0152] In one embodiment, the allocation module 20 is specifically used for:

[0153] Obtain the preset storage capacity of the storage instance; determine the actual storage capacity of the storage instance based on the memory pages included in the storage instance; if the actual storage capacity is less than the preset storage capacity, allocate new memory pages to the storage instance.

[0154] In one embodiment, the device further includes a determining module configured to determine a preset storage capacity according to any of the following methods:

[0155] The preset number of memory pages corresponding to the storage instance;

[0156] The preset number of memory pages corresponding to the storage instance, and the storage space expansion factor;

[0157] The storage capacity and number of memory tables corresponding to the storage instance; wherein, a memory table includes at least one memory page;

[0158] The storage capacity and number of memory tables corresponding to the storage instance, as well as the storage space expansion factor.

[0159] In one embodiment, the preset number of memory pages corresponding to the storage instance and the storage capacity of a single memory page, as well as the storage capacity and number of memory tables corresponding to the storage instance, are determined based on the storage capacity of the storage system where the storage instance resides.

[0160] In one embodiment, the allocation module 20 is specifically used for:

[0161] Select a free memory page from the memory pages included in the target storage pool as the new memory page for the storage instance; wherein the memory pages in the target storage pool have the same storage capacity.

[0162] In one embodiment, the target storage pool is one of multiple storage pools in the storage system where the storage instance resides, and the storage capacity of memory pages varies in different storage pools.

[0163] In one embodiment, the device further includes a placement module for:

[0164] In response to storing the written data in the target memory page included in the storage instance to persistent storage, the target memory page is released and placed in the target storage pool.

[0165] In one embodiment, the writing module 30 is further configured to:

[0166] If the remaining storage space is greater than or equal to the storage space required for the data to be written, then the data to be written will be written to the remaining storage space.

[0167] Each module in the aforementioned memory management device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0168] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 7 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores data that is written to the computer device. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a memory management method.

[0169] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0170] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the memory management method described in any of the above embodiments.

[0171] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the memory management method described in any of the above embodiments.

[0172] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the memory management method described in any of the above embodiments.

[0173] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.

[0174] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.

[0175] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0176] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A memory management method, characterized in that, The method includes: After obtaining the data to be written, the remaining storage space of the storage instance used to store the data to be written is obtained; wherein, the storage instance includes at least one memory page; If the remaining storage space is less than the storage space required for the data to be written, then a new memory page is allocated to the storage instance; and, The data to be written is written to the free storage space in the memory pages included in the storage instance.

2. The method according to claim 1, characterized in that, The process of allocating new memory pages to the storage instance includes: Obtain the preset storage capacity of the storage instance; The actual storage capacity of the storage instance is determined based on the memory pages included in the storage instance; If the actual storage capacity is less than the preset storage capacity, allocate new memory pages to the storage instance.

3. The method according to claim 2, characterized in that, The preset storage capacity is determined according to any of the following methods: The preset number of memory pages corresponding to the storage instance; The preset number of memory pages corresponding to the storage instance, and the storage space expansion coefficient; The storage capacity and number of memory tables corresponding to the storage instance; wherein, a memory table includes at least one memory page; The storage capacity and number of memory tables corresponding to the storage instance, as well as the storage space expansion coefficient.

4. The method according to claim 3, characterized in that, The preset number of memory pages corresponding to the storage instance and the storage capacity of a single memory page, as well as the storage capacity and number of memory tables corresponding to the storage instance, are determined based on the storage capacity of the storage system in which the storage instance resides.

5. The method according to any one of claims 1-4, characterized in that, The process of allocating new memory pages to the storage instance includes: Select a free memory page from the memory pages included in the target storage pool as a new memory page for the storage instance; wherein the memory pages in the target storage pool have the same storage capacity.

6. The method according to claim 5, characterized in that, The target storage pool is one of multiple storage pools in the storage system where the storage instance is located, and the storage capacity of memory pages varies in different storage pools.

7. The method according to claim 5, characterized in that, The method further includes: In response to storing the written data in the target memory page included in the storage instance to persistent storage space, the target memory page is released and placed in the target storage pool.

8. The method according to any one of claims 1-4, characterized in that, The method further includes: If the remaining storage space is greater than or equal to the storage space required for the data to be written, then the data to be written is written into the remaining storage space.

9. A memory management device, characterized in that, The device includes: The acquisition module is used to acquire the data to be written, and then acquire the remaining storage space of the storage instance used to store the data to be written; wherein the storage instance includes at least one memory page; An allocation module is configured to allocate new memory pages to the storage instance if the remaining storage space is less than the storage space required by the data to be written; and, The write module is used to write the data to be written into the free storage space in the memory pages included in the storage instance.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 8.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.

12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.