Method for memory management and device therefor
By updating the record table of cached pages, recording the number of reads or writes for all cgroups and reallocating the data volume, the problem of inaccurate cached I/O rate limiting in cgroup technology is solved, achieving fairer and more accurate resource management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2020-09-30
- Publication Date
- 2026-04-24
AI Technical Summary
In existing Linux systems, cgroup technology has low accuracy in cached I/O traffic statistics, resulting in unfair and inaccurate cached I/O rate limiting.
By obtaining read and write requests from cgroups, the record table of the target cache page is updated, recording the number of reads or writes for all cgroups. Based on the updated record table, the first cgroup is rate-limited, and the amount of data is reallocated to improve the accuracy and fairness of the statistical results.
It improves the accuracy of cgroup traffic statistics, making rate limiting of cached I/O fairer and more accurate, and is suitable for resource management in physical hosts, virtual machines or containers.
Smart Images

Figure CN114327245B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer application technology, and more specifically, to a method and apparatus for memory management. Background Technology
[0002] With the continuous development of cloud technology, in order to save resources and improve server utilization, multiple processes of multiple tenants are often run on the same server in the cloud. These processes share various resources on the same server, but resource sharing can also bring about fairness issues. At this time, resource isolation can be used to detect and control the resource usage of different processes of different tenants, so as to ensure that tasks with higher priority receive sufficient resources, and to ensure that tasks with the same priority receive the same resources.
[0003] The reading and writing (input / output, I / O) of storage resources on a server, i.e., storage I / O, can be divided into direct I / O and buffered I / O. Direct I / O refers to reading and writing directly from the storage device, while buffered I / O utilizes memory as a cache for storage. When reading or writing data, the data first passes through the cache before being returned to the application or written to the storage device. In existing Linux systems, control group (cgroup) technology is used to throttling buffered I / O.
[0004] For cached I / O, it is necessary to perform traffic statistics on each cgroup and then throttling the cached I / O based on the results. However, the accuracy of cgroup traffic statistics is currently not high. Summary of the Invention
[0005] This application provides a memory management method and apparatus that can improve the accuracy of cgroup traffic statistics, thereby enabling fairer and more accurate rate limiting of cached I / O.
[0006] Firstly, a memory management method is provided, which includes:
[0007] Obtain read / write requests from a first control group cgroup, where the first cgroup is one of multiple cgroups. The read / write requests are used to request reading or writing target data in a target cache page. If a read or write operation is performed based on the read / write request, update the first record table of the target cache page according to the read or write operation to obtain an updated first record table. The read or write operation is used to read or write the target data in the target cache page. The first record table includes a second cgroup and the number of times the second cgroup has read or written the target data. The second cgroup is one of the multiple cgroups that has read or written the target data in the target cache page. Rate limiting is applied to the first cgroup based on the number of times the first cgroup has read or written the target data recorded in the updated first record table.
[0008] In this embodiment of the application, the updated first record table records all cgroups that have read and written the target data in the target cache page. All cgroups include the set of the first cgroup and the second cgroup, and the number of times each cgroup reads or writes the target data. This can improve the accuracy of cgroup traffic statistics. At this time, rate limiting of the first cgroup based on the updated first record table can make the rate limiting of the first cgroup more fair and accurate.
[0009] In the above scheme, the second cgroup is the cgroup among multiple cgroups that has read or written the target data in the target cache page. Therefore, if the first cgroup has accessed the target cache page before this access, the second cgroup may include the first cgroup. Similarly, if this access is the first access to the target cache page, the second cgroup can be empty.
[0010] This solution can be applied to physical hosts, virtual machines, or containers (e.g., Docker) to provide fine-grained management of data access and traffic usage of various cgroups within these systems.
[0011] In this scheme, each target cache page is associated with a record table. The record table is used to record the data read or written to the target cache page by each cgroup in the physical host, virtual machine or container (e.g. Docker) (each record table corresponds to only one action, read or write).
[0012] Typically, a cgroup can correspond to one or more processes (or threads, system logs, and other applications). By recording (or statistically analyzing) the data access and traffic usage of a cgroup, rate limiting can be implemented for the one or more processes (or threads, system logs, and other applications) corresponding to that cgroup.
[0013] Optionally, before updating the first record table of the target cache page according to the read or write operation to obtain the updated first record table, the method may further include: determining whether the first cgroup is rate-limited; if the first cgroup is not rate-limited, performing the read or write operation based on the read / write request.
[0014] Alternatively, it is possible to perform the read or write operation directly based on the read or write request without determining whether the first cgroup is rate-limited. This embodiment of the application does not limit this.
[0015] Furthermore, in this embodiment of the application, the order of the read or write operation and the update of the first record table is not limited.
[0016] For example, the read or write operation can be performed first based on the read or write request, and then the first record table can be updated according to the read or write operation to obtain the updated first record table.
[0017] Alternatively, when performing the read or write operation based on the read or write request, the first record table can be updated first according to the read or write operation to obtain the updated first record table, and then the read or write operation can be performed based on the read or write request.
[0018] Alternatively, when performing the read or write operation based on the read or write request, the first record table can be updated simultaneously according to the read or write operation, and the read or write operation can be performed based on the read or write request.
[0019] Furthermore, the rate limiting of the first cgroup can refer to: prohibiting the first cgroup from performing read or write operations in the cache (for example, the cache here can refer to all cache pages including the target cache page); or it can refer to limiting the speed at which the first cgroup performs read or write operations in the cache (for example, the cache here can refer to all cache pages including the target cache page).
[0020] For example, access records for each cached page in the operating system's page cache mechanism can be obtained (e.g., access records can indicate all processes that have accessed each cached page and their corresponding records). The first cgroup can correspond to one or more processes. In this case, the number of times the one or more processes read other cached pages can be determined by combining the access records, and rate limiting can be applied to the first cgroup based on the updated first record table and the reading of other cached pages.
[0021] In addition, rate limiting of the first cgroup can mean: rate limiting only read operations, or rate limiting only write operations, or rate limiting both read and write operations. This application embodiment does not limit this.
[0022] It should be noted that the above embodiments are merely examples and not limitations. Specific rate limiting methods can be found in existing technologies, and are not limited in this application.
[0023] In conjunction with the first aspect, in some implementations of the first aspect, the first record table is further used to indicate the amount of data read or written by the second cgroup. The step of updating the first record table of the target cache page according to the read / write request to obtain the updated first record table includes: reallocating the amount of data read or written by the second cgroup based on a preset strategy; and updating the first record table based on the read / write request and the reallocated amount of data read or written by the second cgroup to obtain the updated first record table.
[0024] In this embodiment of the application, based on a preset strategy, the amount of data (read or written) is redistributed among all cgroups that have read or written the target data in the target cache page, and the redistributed amount of data is recorded in the updated first record table. This makes the data volume statistics more fair and accurate. At this time, rate limiting of the first cgroup based on the updated first record table can make the rate limiting of the first cgroup more fair and accurate.
[0025] In conjunction with the first aspect, in some implementations of the first aspect, the reallocation of the amount of data read or written by the second cgroup based on a preset strategy includes: reallocating the amount of data read or written by each cgroup in the set of the first cgroup and the second cgroup.
[0026] For example, the average amount of data read or written by each cgroup in the collection is calculated based on the total number of cgroups in the collection. That is, if the total number of cgroups is 5, then the amount of data read or written by each cgroup is recorded as 1 / 5 of the total amount of target data.
[0027] In conjunction with the first aspect, in some implementations of the first aspect, the reallocation of the amount of data read or written by the second cgroup based on a preset strategy includes: reallocating the amount of data read or written by each cgroup in the merge of the first cgroup and the second cgroup in the updated first record table.
[0028] For example, the amount of data read or written by each cgroup in the collection can be calculated based on the percentage of the number of reads or writes of each cgroup in the collection to the total number of reads or writes. That is, if the total number of reads or writes of a cgroup is 100, and the number of reads or writes of a certain cgroup is 25, then the amount of data read or written by that cgroup is recorded as 1 / 4 of the total amount of target data.
[0029] In conjunction with the first aspect, in some implementations of the first aspect, the step of rate limiting the first cgroup based on the number of times the first cgroup reads or writes the target data recorded in the updated first record table includes: obtaining the amount of data read or written by the first cgroup based on the number of times the first cgroup reads or writes the target data recorded in the updated first record table, and instructing rate limiting of the first cgroup based on the amount of data read or written by the first cgroup.
[0030] Based on the number of times the first cgroup reads or writes the target data and the amount of data read or written by the first cgroup recorded in the updated first record table, rate limiting is applied to the first cgroup. This can be done by rate limiting based on the number of accesses to a single cache page. For example, when the number of accesses or the amount of data in the current record table has exceeded the upper limit, rate limiting is applied to the first cgroup. Alternatively, the total number of reads or writes to the first cgroup in all global record tables can be obtained based on the number of accesses or the amount of data in the current record table, or the total amount of data read or written, to determine whether to instruct the first cgroup to be limited.
[0031] In conjunction with the first aspect, in some implementations of the first aspect, after obtaining the request of the first control group cgroup to read the target data in the target cache page, the method further includes: if the target data does not exist in the target cache page, initializing the first record table; and reading the target data from the storage device into the target cache page.
[0032] In this embodiment of the application, when the target data does not exist in the target cache page, initializing the first record table is beneficial for the first record table to record information about the target data read by cgroup.
[0033] Optionally, in this embodiment of the application, the order of the three actions—initializing the first record table, reading the target data into the target cache page, and updating the first record table—is not limited.
[0034] For example, if the target data does not exist in the target cache page and the read / write request is used to request the reading of the target data in the target cache page, the first record table can be initialized first, the target data can be read from the storage device into the target cache page, and then the first record table can be updated.
[0035] Alternatively, if the target data does not exist in the target cache page and the read / write request is used to request the reading of the target data in the target cache page, the target data can be read from the storage device into the target cache page first, then the first record table can be updated, and then the first record table can be initialized.
[0036] It should be noted that the above embodiments are merely examples and not limitations. The order of the three actions—initializing the first record table, reading the target data into the target cache page, and updating the first record table—is not limited in this application embodiment.
[0037] In conjunction with the first aspect, in some implementations of the first aspect, after obtaining the request of the first control group cgroup to write the target data in the target cache page, the method further includes: if the target data does not exist in the target cache page, initializing the first record table; and writing the target data to the target cache page.
[0038] In this embodiment of the application, when the target data does not exist in the target cache page, initializing the first record table is beneficial for the first record table to record information about cgroups writing the target data.
[0039] Optionally, in this embodiment of the application, the order of the three actions—initializing the first record table, writing the target data to the target cache page, and updating the first record table—is not limited.
[0040] For specific methods, please refer to the description in the foregoing embodiments, which will not be repeated here.
[0041] Secondly, a memory management apparatus is provided, comprising:
[0042] An acquisition unit is configured to acquire read / write requests from a first control group cgroup, wherein the first cgroup is one of a plurality of cgroups, and the read / write request is used to request reading or writing target data in a target cache page; an update unit is configured to update a first record table of the target cache page according to the read / write operation performed based on the read / write request, thereby obtaining an updated first record table, wherein the read / write operation is used to read or write the target data in the target cache page, and the first record table includes a second cgroup and the number of times the second cgroup has read or written the target data, wherein the second cgroup is one of the plurality of cgroups that has read or written the target data in the target cache page; a rate limiting unit is configured to rate limit the first cgroup based on the number of times the first cgroup has read or written the target data recorded in the updated first record table.
[0043] In this embodiment of the application, the updated first record table records all cgroups that have read and written the target data in the target cache page. All cgroups may include the combination of the first cgroup and the second cgroup, and the number of times each cgroup reads or writes the target data, thereby improving the accuracy of cgroup traffic statistics results. At this time, rate limiting of the first cgroup based on the updated first record table can make the rate limiting of the first cgroup more fair and accurate.
[0044] In the above scheme, the second cgroup is the cgroup among multiple cgroups that has read or written the target data in the target cache page. Therefore, if the first cgroup has accessed the target cache page before this access, the second cgroup may include the first cgroup. Similarly, if this access is the first access to the target cache page, the second cgroup can be empty.
[0045] This solution can be applied to physical hosts, virtual machines, or containers (e.g., Docker) to provide fine-grained management of data access and traffic usage of various cgroups within these systems.
[0046] In this scheme, each target cache page is associated with a record table. The record table is used to record the data read or written to the target cache page by each cgroup in the physical host, virtual machine or container (e.g. Docker) (each record table corresponds to only one action, read or write).
[0047] Typically, a cgroup can correspond to one or more processes (or threads, system logs, and other applications). By recording (or statistically analyzing) the data access and traffic usage of a cgroup, rate limiting can be implemented for the one or more processes (or threads, system logs, and other applications) corresponding to that cgroup.
[0048] Optionally, before updating the first record table of the target cache page according to the read or write operation to obtain the updated first record table, the method may further include: determining whether the first cgroup is rate-limited; if the first cgroup is not rate-limited, performing the read or write operation based on the read / write request.
[0049] Alternatively, it is possible to perform the read or write operation directly based on the read or write request without determining whether the first cgroup is rate-limited. This embodiment of the application does not limit this.
[0050] Furthermore, in this embodiment of the application, the order of the read or write operation and the update of the first record table is not limited.
[0051] For example, the read or write operation can be performed first based on the read or write request, and then the first record table can be updated according to the read or write operation to obtain the updated first record table.
[0052] Alternatively, when performing the read or write operation based on the read or write request, the first record table can be updated first according to the read or write operation to obtain the updated first record table, and then the read or write operation can be performed based on the read or write request.
[0053] Alternatively, when performing the read or write operation based on the read or write request, the first record table can be updated simultaneously according to the read or write operation, and the read or write operation can be performed based on the read or write request.
[0054] Furthermore, the rate limiting of the first cgroup can refer to: prohibiting the first cgroup from performing read or write operations in the cache (for example, the cache here can refer to all cache pages including the target cache page); or it can refer to limiting the speed at which the first cgroup performs read or write operations in the cache (for example, the cache here can refer to all cache pages including the target cache page).
[0055] For example, access records for each cached page in the operating system's page cache mechanism can be obtained (e.g., access records can indicate all processes that have accessed each cached page and their corresponding records). The first cgroup can correspond to one or more processes. In this case, the number of times the one or more processes read other cached pages can be determined by combining the access records, and rate limiting can be applied to the first cgroup based on the updated first record table and the reading of other cached pages.
[0056] In addition, rate limiting of the first cgroup can mean: rate limiting only read operations, or rate limiting only write operations, or rate limiting both read and write operations. This application embodiment does not limit this.
[0057] It should be noted that the above embodiments are merely examples and not limitations. Specific rate limiting methods can be found in existing technologies, and are not limited in this application.
[0058] In conjunction with the second aspect, in some implementations of the second aspect, the first record table is further used to indicate the amount of data read or written by the second cgroup, and the update unit is specifically used to: reallocate the amount of data read or written by the second cgroup based on a preset strategy; and update the first record table based on the read / write request and the reallocated amount of data read or written by the second cgroup to obtain the updated first record table.
[0059] In this embodiment of the application, based on a preset strategy, the amount of data (read or written) is redistributed among all cgroups that have read or written the target data in the target cache page, and the redistributed amount of data is recorded in the updated first record table. This makes the data volume statistics more fair and accurate. At this time, rate limiting of the first cgroup based on the updated first record table can make the rate limiting of the first cgroup more fair and accurate.
[0060] In conjunction with the second aspect, in some implementations of the second aspect, the update unit is specifically used to: reallocate the amount of data read or written by each cgroup in the set of the first cgroup and the second cgroup.
[0061] In conjunction with the second aspect, in some implementations of the second aspect, the update unit is specifically used to: reallocate the amount of data read or written by each cgroup in the set of the first cgroup and the second cgroup in the updated first record table.
[0062] In conjunction with the second aspect, in some implementations of the second aspect, the rate limiting unit is specifically used to: obtain the amount of data read or written by the first cgroup based on the number of times the first cgroup reads or writes the target data recorded in the updated first record table, and rate limit the first cgroup based on the amount of data read or written by the first cgroup.
[0063] Based on the number of times the first cgroup reads or writes the target data and the amount of data read or written by the first cgroup recorded in the updated first record table, rate limiting is applied to the first cgroup. This can be done by rate limiting based on the number of accesses to a single cache page. For example, when the number of accesses or the amount of data in the current record table has exceeded the upper limit, rate limiting is applied to the first cgroup. Alternatively, the total number of reads or writes to the first cgroup in all global record tables can be obtained based on the number of accesses or the amount of data in the current record table, or the total amount of data read or written, to determine whether to instruct the first cgroup to be limited.
[0064] In conjunction with the second aspect, in some implementations of the second aspect, after obtaining the request from the first control group cgroup to read the target data in the target cache page, the read / write unit is further configured to: initialize the first record table if the target data does not exist in the target cache page; and read the target data from the storage device into the target cache page.
[0065] In this embodiment of the application, when the target data does not exist in the target cache page, initializing the first record table is beneficial for the first record table to record information about the target data read by cgroup.
[0066] Optionally, in this embodiment of the application, the order of the three actions—initializing the first record table, reading the target data into the target cache page, and updating the first record table—is not limited.
[0067] For example, if the target data does not exist in the target cache page and the read / write request is used to request the reading of the target data in the target cache page, the first record table can be initialized first, the target data can be read from the storage device into the target cache page, and then the first record table can be updated.
[0068] Alternatively, if the target data does not exist in the target cache page and the read / write request is used to request the reading of the target data in the target cache page, the target data can be read from the storage device into the target cache page first, then the first record table can be updated, and then the first record table can be initialized.
[0069] It should be noted that the above embodiments are merely examples and not limitations. The order of the three actions—initializing the first record table, reading the target data into the target cache page, and updating the first record table—is not limited in this application embodiment.
[0070] In conjunction with the second aspect, in some implementations of the second aspect, after obtaining the request from the first control group cgroup to write the target data into the target cache page, the read / write unit is further configured to: initialize the first record table if the target data does not exist in the target cache page; and write the target data into the target cache page.
[0071] In this embodiment of the application, when the target data does not exist in the target cache page, initializing the first record table is beneficial for the first record table to record information about cgroups writing the target data.
[0072] Optionally, in this embodiment of the application, the order of the three actions—initializing the first record table, writing the target data to the target cache page, and updating the first record table—is not limited.
[0073] For specific methods, please refer to the description in the foregoing embodiments, which will not be repeated here.
[0074] Thirdly, a memory management apparatus is provided, the apparatus comprising a storage medium and a central processing unit, the storage medium being a non-volatile storage medium storing a computer-executable program, the central processing unit being connected to the non-volatile storage medium and executing the computer-executable program to implement the method of the first aspect or any possible implementation thereof.
[0075] Fourthly, a chip is provided, the chip including a processor and a data interface, the processor reading instructions stored in a memory through the data interface to execute the method of the first aspect or any possible implementation thereof.
[0076] Optionally, as one implementation, the chip may further include a memory storing instructions, and the processor is configured to execute the instructions stored in the memory. When the instructions are executed, the processor is configured to perform the method in the first aspect or any possible implementation of the first aspect.
[0077] Fifthly, a computer-readable storage medium is provided, the computer-readable medium storing program code for execution by a device, the program code including instructions for performing the method of the first aspect or any possible implementation thereof.
[0078] Sixthly, a virtual machine is provided, the virtual machine including the memory management apparatus described in the second or third aspect above.
[0079] In a seventh aspect, a container is provided, the container including the memory management apparatus described in the second or third aspect above.
[0080] Eighthly, a host computer is provided, the host computer including the memory management apparatus described in the second or third aspect above.
[0081] Alternatively, as one implementation, the host can be a physical host, such as a server in the cloud.
[0082] In this embodiment of the application, the updated first record table records all cgroups that have read and written the target data in the target cache page. All cgroups may include the combination of the first cgroup and the second cgroup, and the number of times each cgroup reads or writes the target data, thereby improving the accuracy of cgroup traffic statistics results. At this time, rate limiting of the first cgroup based on the updated first record table can make the rate limiting of the first cgroup more fair and accurate. Attached Figure Description
[0083] Figure 1 This is an exemplary block diagram of cached I / O provided in one embodiment of this application.
[0084] Figure 2 This is a schematic block diagram illustrating a memory management method in an embodiment of this application.
[0085] Figure 3This is a schematic block diagram illustrating a memory management method provided in one embodiment of this application.
[0086] Figure 4 A schematic block diagram illustrating a memory management method provided in another embodiment of this application.
[0087] Figure 5 A schematic block diagram illustrating a memory management method provided in another embodiment of this application.
[0088] Figure 6 This is a schematic block diagram of a memory management apparatus provided in one embodiment of this application.
[0089] Figure 7 A schematic block diagram of a memory management apparatus provided for another embodiment of this application. Detailed Implementation
[0090] The technical solutions in this application will now be described with reference to the accompanying drawings.
[0091] Cloud computing refers to the process of bringing together multiple servers on a network to work together through cluster applications, network technologies, or distributed file systems, and providing data storage, data processing, and data analysis functions to the outside world through a system composed of multiple servers.
[0092] To conserve resources and improve server utilization, multiple processes from multiple tenants are often run on the same server in the cloud. These processes share various resources on the same server, such as computing resources (e.g., central processing unit (CPU) and graphics processing unit (GPU), storage resources (e.g., hard disk drive (HDD) and solid-state drive (SSD), memory resources (e.g., dynamic random access memory (DRAM) and non-volatile memory (NVM), and network resources (e.g., remote direct memory access (RDMA)). However, resource sharing can also raise fairness issues. Resource isolation can be used to monitor and control resource usage by different processes from different tenants, ensuring that higher-priority tasks receive sufficient resources and that tasks with the same priority receive the same amount of resources.
[0093] Currently, the reading and writing (input / output, I / O) of storage resources on servers, i.e., storage I / O, can be divided into direct I / O and buffered I / O. Buffered I / O can also be called normal I / O. Direct I / O refers to reading and writing directly from the storage device, while buffered I / O uses memory as a cache for storage. When reading and writing data, the data first passes through the cache before being returned to the application or written to the storage device.
[0094] For example, Figure 1 This is an exemplary block diagram of cached I / O provided in one embodiment of this application. Figure 1 As shown, the data requester 110 can be an application, process, or thread in a physical host, virtual machine, or container (e.g., Docker); the cache 120 can be a memory cache, for example, a memory cache can also be called a page cache, and a memory cache can include multiple cache pages, which can also be called memory pages; the storage device 130 can be a storage device, such as a hard disk or disk.
[0095] Data requester 110 can send a read request to cache 120. If the data to be read is in cache 120, data requester 110 can directly read the data from cache 120. If the data to be read is not in cache 120, cache 120 can read the data from storage device 130 and store it in cache 120. Subsequently, data requester 110 can read the data from cache 120.
[0096] In existing Linux systems, control groups (cgroups) can be used for resource isolation. For example, when using cgroups, administrators can first create a new cgroup and configure it to limit resource usage in areas such as CPU, memory, storage I / O (input / output), and devices. Subsequently, new applications can be created in this cgroup, or existing applications can be added to it, so that the cgroup can detect and restrict the application's use of system resources.
[0097] When using cgroups to rate limit cached I / O, it is necessary to perform traffic statistics on each cgroup and then rate limit (throttling) cached I / O based on the results of these statistics.
[0098] For example, in the prior art, when creating cache pages in the memory cache, it is first determined that each cache page in the memory cache belongs to a cgroup, and this ownership will not change until the memory page is released.
[0099] For a file node (inode), which is a file in the file system, it can include multiple cache pages. Based on the cgroup to which all cache pages in the inode belong, the cgroup that occupies the most cache pages among all cache pages is selected as the cgroup of the inode.
[0100] According to the current statistical method, all writeback I / O generated on this inode will be counted in the inode's cgroup, but this is obviously inaccurate.
[0101] For example, page1 is identified as belonging to cgroup1 when it is created, but after page1 is created, it is frequently used by cgroup2. In the end, all I / O of page1 will be incorrectly counted in cgroup1.
[0102] Similarly, since the cgroup of an inode is determined by the cgroup that occupies the most cache pages in that inode, if two cgroups in that inode each occupy half of the cache pages of that inode, then half of the I / O on that inode will be counted as errors.
[0103] Based on the above problems, this application proposes a memory management method that can improve the accuracy of cgroup traffic statistics, thereby making cache I / O rate limiting more fair and accurate.
[0104] The memory management method in this application embodiment can be applied to various scenarios where cgroups are used to isolate cached I / O resources (or to rate limit cached I / O), such as private cloud scenarios and public cloud scenarios. Alternatively, the memory management method in this application embodiment can also be used in other scenarios where cgroups are deployed on physical hosts, virtual machines, or containers (e.g., Docker) for resource isolation (or rate limiting). This application embodiment does not limit the specific application scenario.
[0105] Figure 2 This is a schematic block diagram of a memory management method 200 according to an embodiment of this application. The method 200 can be executed by a physical host, a virtual machine, or a container (e.g., Docker).
[0106] It should be understood that Figure 2 The steps or operations of method 200 are shown, but these steps or operations are merely examples, and other operations may be performed in the embodiments of this application. Figure 2Variations of the operations in Method 200, or not all steps need to be performed, or these steps can be performed in a different order.
[0107] S210, obtain read / write requests for the first control group cgroup.
[0108] The first cgroup can be one of multiple cgroups, and the read / write request can be used to request to read or write target data in the target cache page.
[0109] The target cache page can be one of multiple cache pages included in a file node (inode), and the multiple cgroups can correspond to the multiple cache pages.
[0110] Optionally, each of the plurality of cache pages can correspond to a record table that records cgroup read and write operations.
[0111] For example, the record table corresponding to each cache page can be used to record all cgroups that have read or written data in each cache page, as well as the number of times each cgroup has read or written the data.
[0112] Optionally, the first cgroup may correspond to one or more processes (or threads, system logs, and other applications, etc.). In other words, the read and write requests of the first cgroup can actually be considered to be triggered by the one or more processes (or threads, system logs, and other applications, etc.).
[0113] Alternatively, it can be understood that the first cgroup can be used to statistically analyze the read and write operations of its corresponding one or more processes (or threads, system logs, and other applications), and can perform resource isolation on the one or more processes (or threads, system logs, and other applications) based on the statistical results. For example, rate limiting can be applied to the one or more processes (or threads, system logs, and other applications).
[0114] Optionally, after obtaining the read / write request of the first cgroup, the method 200 may include the following two methods:
[0115] Method 1:
[0116] Determine whether the first cgroup is rate-limited; if the first cgroup is not rate-limited, perform read or write operations based on the read / write request; if the first cgroup is rate-limited, do not perform the read or write operations.
[0117] Method 2:
[0118] (Without determining whether the first cgroup is rate-limited) the read or write operation is performed directly based on the read or write request.
[0119] The method 200 can be adopted in any of the above-mentioned methods one and two, and is not limited in this embodiment.
[0120] Optionally, the record table for the record cgroup read / write operations corresponding to the target cache page can be a first record table.
[0121] The read or write operation can be used to read or write the target data in the target cache page.
[0122] For example, when the read / write request is used to request the reading of the target data in the target cache page, the read or write operation can be used to read the target data in the target cache page.
[0123] For example, when the read / write request is used to request writing the target data into the target cache page, the read or write operation can be used to write the target data into the target cache page.
[0124] In some possible implementations of this application, when the read / write request is used to request reading the target data from the target cache page, after obtaining the read / write request of the first control group cgroup, the read or write operation based on the read / write request can be divided into the following two cases, depending on whether the target data exists in the target cache page:
[0125] Scenario 1: The target data does not exist in the target cache page.
[0126] At this point, the first record table of the target cache page can be initialized, and the target data can be read from the storage device (e.g., disk or hard disk) into the target cache page.
[0127] The first record table may include a second cgroup and the number of times the second cgroup has read or written the target data. The second cgroup is the cgroup among the plurality of cgroups that has read or written the target data in the target cache page.
[0128] For a detailed description of the first record table, please refer to the embodiments in S220 below, which will not be repeated here.
[0129] Subsequently, the target data can be read from the target cache page based on the read / write requests of the first cgroup.
[0130] Scenario 2: The target data exists in the target cache page.
[0131] At this point, the target data can be read directly from the target cache page based on the read / write request of the first cgroup.
[0132] For a detailed description of scenarios one and two above, please refer to the following sections. Figure 3 The embodiments in Method 300 will not be described in detail here.
[0133] Optionally, in this embodiment of the application, the order of the three actions—initializing the first record table, reading the target data into the target cache page, and updating the first record table—is not limited.
[0134] For example, if the target data does not exist in the target cache page and the read / write request is used to request the reading of the target data in the target cache page, the first record table can be initialized first, the target data can be read from the storage device into the target cache page, and then the first record table can be updated.
[0135] Alternatively, if the target data does not exist in the target cache page and the read / write request is used to request the reading of the target data in the target cache page, the target data can be read from the storage device into the target cache page first, then the first record table can be updated, and then the first record table can be initialized.
[0136] It should be noted that the above embodiments are merely examples and not limitations. The order of the three actions—initializing the first record table, reading the target data into the target cache page, and updating the first record table—is not limited in this application embodiment.
[0137] In some possible implementations of this application, when the read / write request is used to request writing the target data into the target cache page, after obtaining the read / write request of the first control group cgroup, the read or write operation based on the read / write request can be divided into the following two cases, depending on whether the target data exists in the target cache page:
[0138] Scenario 3: The target data does not exist in the target cache page.
[0139] At this point, the first record table of the target cache page can be initialized, and the target data can be written to the target cache page.
[0140] Subsequently, under the condition that the preset conditions are met, the target data in the target cache page can be written back to the storage device.
[0141] Scenario 4: The target data exists in the target cache page.
[0142] At this point, it is no longer necessary to write the target data to the target cache page. The first record table can be updated directly based on the read and write requests of the first cgroup.
[0143] For a detailed description of scenarios three and four above, please refer to the following sections. Figure 4 The embodiments in Method 400 will not be described in detail here.
[0144] Optionally, in this embodiment of the application, the order of the three actions—initializing the first record table, writing the target data to the target cache page, and updating the first record table—is not limited.
[0145] For specific methods, please refer to the description in the foregoing embodiments, which will not be repeated here.
[0146] S220, when a read or write operation is performed based on the read or write request, the first record table of the target cache page is updated according to the read or write operation to obtain the updated first record table.
[0147] The first record table may include a second cgroup and the number of times the second cgroup reads the target data, wherein the second cgroup is the cgroup among the plurality of cgroups that has read the target data in the target cache page.
[0148] Alternatively, the first record table may also include a second cgroup and the number of times the second cgroup has written the target data, wherein the second cgroup is the cgroup among the plurality of cgroups that has written the target data in the target cache page.
[0149] As can be seen, the second cgroup may include one or more cgroups, and the second cgroup may also include the first cgroup.
[0150] Optionally, in this embodiment of the application, the order of the read or write operation and the update of the first record table is not limited.
[0151] For example, the read or write operation can be performed first based on the read or write request, and then the first record table can be updated according to the read or write operation to obtain the updated first record table.
[0152] Alternatively, when performing the read or write operation based on the read or write request, the first record table can be updated first according to the read or write operation to obtain the updated first record table, and then the read or write operation can be performed based on the read or write request.
[0153] Alternatively, when performing the read or write operation based on the read or write request, the first record table can be updated simultaneously according to the read or write operation, and the read or write operation can be performed based on the read or write request.
[0154] Optionally, updating the first record table of the target cache page according to the read or write operation to obtain the updated first record table may refer to:
[0155] The read or write operation is recorded in the first record table to obtain the updated first record table.
[0156] In other words, the updated first record table can be used to indicate the first cgroup and the second cgroup among the plurality of cgroups that have read the target data in the target cache page, and the number of times the first cgroup and the second cgroup have read the target data.
[0157] Optionally, the first record table can also be used to indicate the amount of data read or written by the second cgroup.
[0158] Accordingly, updating the first record table of the target cache page according to the read or write operation to obtain the updated first record table may include:
[0159] Based on a preset strategy, the amount of data read or written by the second cgroup is reallocated;
[0160] Based on the read / write request and the amount of data read or written by the second cgroup after reallocation, the first record table is updated to obtain the updated first record table.
[0161] Optionally, the reallocation of the amount of data read or written by the second cgroup based on a preset strategy may include:
[0162] Based on the number of cgroups in the combined set of the first cgroup and the second cgroup, the amount of data read or written by each cgroup in the combined set is reallocated.
[0163] In other words, the preset strategy can be to allocate the amount of data in each (read or written) cgroup according to the number of (read or written) cgroups.
[0164] For example, assuming the target data is 4 kilobytes (KB), cgroup1 reads the target data once, and cgroup2 reads the target data twice. In the case that the preset strategy is to allocate the amount of data (read or written) according to the number of cgroups (read or written), the amount of data read by cgroup1 is 4KB / 2 = 2KB, and the amount of data read by cgroup2 is also 4KB / 2 = 2KB.
[0165] Alternatively, the reallocation of the amount of data read or written by the second cgroup based on a preset strategy may also include:
[0166] Based on the number of reads or writes of each cgroup in the merge of the first cgroup and the second cgroup in the updated first record table, the amount of data read or written by each cgroup in the merge is reallocated.
[0167] In other words, the preset strategy can also be to allocate the amount of data in each (read or written) cgroup according to the number of times it has been read or written.
[0168] For example, assuming the target data is 4 kilobytes (KB), cgroup1 reads the target data once, cgroup2 reads the target data twice, and cgroup3 reads the target data once. In the case where the preset strategy can also allocate the amount of data in each (read or written) cgroup according to the number of times it has been read or written, the amount of data read by cgroup1 is 4KB / 4 = 1KB, the amount of data read by cgroup2 is (4KB / 4)*2 = 2KB, and the amount of data read by cgroup3 is 4KB / 4 = 1KB.
[0169] It should be noted that the above embodiments are merely examples and not limitations, and the specific content of the preset strategy in the embodiments of this application is not limited.
[0170] S230, the first cgroup is rate-limited based on the number of times the first cgroup reads or writes the target data recorded in the updated first record table.
[0171] Optionally, the amount of data read or written by the first cgroup can be obtained based on the number of times the first cgroup reads or writes the target data recorded in the updated first record table, and rate limiting can be applied to the first cgroup based on the amount of data read or written by the first cgroup.
[0172] Based on the number of times the first cgroup reads or writes the target data and the amount of data read or written by the first cgroup recorded in the updated first record table, rate limiting is applied to the first cgroup. This can be done by rate limiting based on the number of accesses to a single cache page. For example, when the number of accesses or the amount of data in the current record table has exceeded the upper limit, rate limiting is applied to the first cgroup. Alternatively, the total number of reads or writes to the first cgroup in all global record tables can be obtained based on the number of accesses or the amount of data in the current record table, or the total amount of data read or written, to determine whether to instruct the first cgroup to be limited.
[0173] Furthermore, the rate limiting of the first cgroup can refer to: prohibiting the first cgroup from performing read or write operations in the cache (for example, the cache here can refer to all cache pages including the target cache page); or it can refer to limiting the speed at which the first cgroup performs read or write operations in the cache (for example, the cache here can refer to all cache pages including the target cache page).
[0174] For example, access records for each cached page in the operating system's page cache mechanism can be obtained (e.g., access records can indicate all processes that have accessed each cached page and their corresponding records). The first cgroup can correspond to one or more processes. In this case, the number of times the one or more processes read other cached pages can be determined by combining the access records, and rate limiting can be applied to the first cgroup based on the updated first record table and the reading of other cached pages.
[0175] In addition, rate limiting of the first cgroup can mean: rate limiting only read operations, or rate limiting only write operations, or rate limiting both read and write operations. This application embodiment does not limit this.
[0176] It should be noted that the above embodiments are merely examples and not limitations. Specific rate limiting methods can be found in existing technologies, and are not limited in this application.
[0177] The following is combined Figure 3Taking the example that the read / write request of the first cgroup can be used to request the reading of target data in the target cache page (i.e., the read / write request is a read request), the memory management method in the embodiments of this application will be described in detail.
[0178] Figure 3 This is a schematic block diagram of a memory management method 300 according to an embodiment of this application. The method 300 can be executed by a physical host, a virtual machine, or a container (e.g., Docker).
[0179] It should be understood that Figure 3 The steps or operations of method 300 are shown, but these steps or operations are merely examples, and other operations may be performed in the embodiments of this application. Figure 3 Variations of the operations in method 300, or not all steps need to be performed, or these steps can be performed in a different order.
[0180] S310, retrieve read request.
[0181] The read request can be a read request for the first cgroup, and the read request can be used to request the reading of target data from the cache.
[0182] The first cgroup can correspond to one or more processes (or threads, system logs, and other applications, etc.). In other words, the read request can be considered to be triggered by a process, thread, system log, or other application, etc.
[0183] S320 determines whether the target data is in the cache.
[0184] The cache can be a memory cache, and the cache can include multiple cache pages, each of which can correspond to a record table.
[0185] For example, the record table corresponding to each cache page can be used to record the cgroup that has read the target data in each cache page and the number of times the cgroup has read the target data.
[0186] It should be noted that the record table records the cgroups that have read the target data in each cache page. In other words, the cgroup can refer to one or more cgroups.
[0187] The specific method for determining whether the target data is in the cache can refer to the existing technology, and is not limited to this embodiment.
[0188] like Figure 3As shown, if the target data is in the cache (for example, the target data may be in the target cache page among the plurality of cache pages included in the cache), then S330 is executed; otherwise, S340 is executed.
[0189] S330 reads target data from the target cache page.
[0190] Alternatively, the target data can be read directly from the target cache page based on the read request.
[0191] S340 reads the target data from the storage device into the target cache page.
[0192] Optionally, the target data can be read from a storage device (e.g., a disk or hard disk) into the target cache page, and then the target data can be read from the target cache page based on the read request.
[0193] S350, initialize the first record table.
[0194] Optionally, a first record table corresponding to the target cache page can be initialized.
[0195] S360, record the read operation in the first record table.
[0196] The read operation may refer to the operation in S330 and S340 described above, which reads the target data from the target cache page based on the read request.
[0197] Optionally, if the target data is in the target cache page, the first record table may include information for indicating a second cgroup among the plurality of cgroups that has read the target data in the target cache page, and the number of times the second cgroup has read the target data.
[0198] It should be noted that the second cgroup may refer to the cgroup among the plurality of cgroups that has read the target data in the target cache page. In other words, the second cgroup may include one or more cgroups.
[0199] For ease of description, the record table that records the read operation (i.e., the first record table that has recorded the read operation) can be referred to as the second record table.
[0200] Furthermore, the first record table may also include information indicating the amount of data read by the second cgroup. Correspondingly, the amount of data read by the first cgroup may also be recorded in the first record table; that is, the second record may also include information indicating the amount of data read by both the first and second cgroups.
[0201] S370, allocate data volume.
[0202] Optionally, based on a preset strategy, and in conjunction with the second record table, the amount of data that each cgroup (one or more cgroups) recorded in the second record table can read from the target data can be allocated.
[0203] For methods regarding data allocation, please refer to... Figure 2 The embodiments of method 200 are not described in detail here.
[0204] S380, End.
[0205] Subsequently, rate limiting can be applied to the first cgroup based on the second record table.
[0206] For a detailed description of rate limiting for the first cgroup, please refer to the embodiment in method 200, which will not be repeated here.
[0207] The following is combined Figure 4 Taking the example that the read / write request of the first cgroup can be used to request the writing of target data in the target cache page (i.e., the read / write request is a write request), the memory management method in the embodiment of this application will be described in detail.
[0208] Figure 4 This is a schematic block diagram of a memory management method 400 according to an embodiment of this application. The method 400 can be executed by a physical host, a virtual machine, or a container (e.g., Docker).
[0209] It should be understood that Figure 4 The steps or operations of method 400 are shown, but these steps or operations are merely examples, and other operations may be performed in the embodiments of this application. Figure 4 Variations of the operations in method 400, or not all steps need to be performed, or these steps can be performed in a different order.
[0210] S410, retrieve write request.
[0211] The write request can be a write request for the first cgroup, and the read request can be used to request the writing of target data in the cache.
[0212] The first cgroup can correspond to one or more processes (or threads, system logs, and other applications, etc.). In other words, the write request can be considered to be triggered by a process, thread, system log, or other application, etc.
[0213] S412, determine whether the target data is in the cache.
[0214] The cache can be a memory cache, and the cache can include multiple cache pages, each of which can correspond to a record table.
[0215] For example, the record table corresponding to each cache page can be used to record the cgroup that has written the target data in each cache page and the number of times the target data has been written to the cgroup.
[0216] It should be noted that the record table records the cgroups in each cache page that have written the target data. In other words, the cgroup can refer to one or more cgroups.
[0217] The specific method for determining whether the target data is in the cache can refer to the existing technology, and is not limited to this embodiment.
[0218] like Figure 3 As shown, if the target data is in the cache (for example, the target data may be in the target cache page among the plurality of cache pages included in the cache), then S420 is executed; otherwise, S416 is executed.
[0219] S414, Write target data to the target cache page.
[0220] Optionally, if the target data is in the target cache page in the cache, the target data can be written directly to the target cache based on the write request.
[0221] S416, Read the target data.
[0222] Optionally, the target data can be read from the storage device corresponding to the first cgroup.
[0223] S418, Initialize the first record table.
[0224] Optionally, a first record table corresponding to the target cache page can be initialized.
[0225] Next, S414 can be executed.
[0226] S420, record the write operation in the first record table.
[0227] The write operation can refer to the operation in S414 above, which involves writing the target data into the target cache page based on the write request.
[0228] Optionally, if the target data is in the target cache page, the first record table may include information for indicating a second cgroup among the plurality of cgroups that has written the target data to the target cache page, and the number of times the second cgroup has written the target data.
[0229] It should be noted that the second cgroup may refer to the cgroup among the plurality of cgroups that has written the target data in the target cache page. In other words, the second cgroup may include one or more cgroups.
[0230] For ease of description, the record table that records the write operation (i.e., the first record table that has recorded the write operation) can be referred to as the second record table.
[0231] Furthermore, the first record table may also include information indicating the amount of data written by the second cgroup.
[0232] Correspondingly, the amount of data written by the first cgroup can also be recorded in the first record table. That is, the second record can also include information indicating the amount of data written by the first cgroup and the second cgroup.
[0233] S422, allocate data volume.
[0234] Optionally, based on a preset strategy, the amount of data to be written to the target data can be allocated for each cgroup (one or more cgroups) recorded in the second record table, in conjunction with the second record table.
[0235] For methods regarding data allocation, please refer to... Figure 2 The embodiments of method 200 are not described in detail here.
[0236] S424, determine whether a write-back is needed.
[0237] Optionally, if preset conditions are met, it can be determined that the target data in the target cache page needs to be written back to the storage device.
[0238] The preset conditions are not limited in the embodiments of this application.
[0239] The specific method for determining whether a write-back is required can be found in existing technologies, but is not limited to this method in the embodiments of this application.
[0240] like Figure 4 As shown, if a write-back is required, S426 can be executed; otherwise, S430 can be executed.
[0241] S426, Settlement data volume.
[0242] Optionally, the data volume of each cgroup (e.g., the first cgroup and the second cgroup) can be calculated based on the data volume calculated in S422.
[0243] It should be noted that the settlement here can be understood as: recovering and compensating for the data volume of each cgroup. The specific settlement method can be found below. Figure 5 The embodiments in Method 500 will not be described in detail here.
[0244] S428, write the target data back to the storage device.
[0245] Optionally, the target data in the target cache page can be written back to the storage device.
[0246] S430, End.
[0247] Subsequently, rate limiting can be applied to the first cgroup based on the second record table.
[0248] For a detailed description of rate limiting for the first cgroup, please refer to the embodiment in method 200, which will not be repeated here.
[0249] Figure 5 This is a schematic block diagram of a memory management method 500 according to an embodiment of this application. The method 500 can be executed by a physical host, a virtual machine, or a container (e.g., Docker).
[0250] It should be understood that Figure 5 The steps or operations of method 500 are shown, but these steps or operations are merely examples, and other operations may be performed in the embodiments of this application. Figure 5 Variations of the operations in Method 500, or not all steps need to be performed, or these steps can be performed in a different order.
[0251] S510: Obtain the first read request of cgroup1, and read the target data based on the first read request.
[0252] The first read request is the first read request obtained, such as... Figure 5As shown, the target data is not in the cache (e.g., the target cache page in the cache) before cgroup1 requests to read the target data. Therefore, cgroup1 can read the target data into the target cache page by accessing the device.
[0253] Here, the access device can refer to the process, thread, system log, or other application that triggers the read request.
[0254] At the same time, a record table corresponding to the target cache page can be created, such as Figure 5 As shown, the record table may include the number of reads, writes, the amount of data read, and the amount of data written for each cgroup (the target cache page).
[0255] The I / O read volume is calculated in cgroup1 as 4KB.
[0256] For example, assuming the target data is 4 kilobytes (KB), after the first read request based on cgroup1 reads the target data from the target cache page, as... Figure 5 As shown, the first record table records that the amount of data read by cgroup1 is 4KB, and the number of times cgroup1 has been read is 1.
[0257] S520, obtain the second read request of cgroup2, and read the target data based on the second read request.
[0258] When cgroup2 requests to read the target data in the cache, since the target data has already been cached in the target cache page, cgroup2 can directly read the target data from the target cache page.
[0259] At this point, two cgroups (cgroup1 and cgroup2) have accessed the target data in the target cache page. In order to ensure the fairness and accuracy of traffic statistics (i.e. data statistics), it is necessary to recalculate the amount of data read by each cgroup (that has accessed the target cache page), that is, the two cgroups share the amount of data of the target data equally.
[0260] like Figure 5 As shown, at this time, the amount of data read by cgroup1 can be modified to 2KB in the first record table, and at the same time, the amount of data read by cgroup2 can be recorded as 2KB, and the number of reads of cgroup2 is 1.
[0261] However, since 4KB of data has already been included in cgroup1, 2KB of data needs to be compensated for cgroup1.
[0262] If the data volume of cgroup1 has been settled, the upper limit of the read allowable amount of cgroup1 can be increased by 2KB in the next time period; if it has not been settled, the upper limit of the read allowable amount of cgroup1 can be directly increased by 2KB in the current time period. Correspondingly, for cgroup2, the 2KB data volume is directly included in the current read data volume.
[0263] S530, obtain the third read request of cgroup3, and read the target data based on the third read request.
[0264] When cgroup3 requests to read the target data in the cache, since the target data has already been cached in the target cache page, cgroup3 can also directly read the target data from the target cache page.
[0265] At this point, three cgroups (cgroup1, cgroup2, and cgroup3) have accessed the target data in the target cache page. To ensure the fairness and accuracy of traffic statistics (i.e., data statistics), it is necessary to recalculate the amount of data read by each cgroup (that has accessed the target cache page), that is, the three cgroups share the amount of target data equally.
[0266] like Figure 5 As shown, at this time, the amount of data read by cgroup1 can be modified to 1.33KB in the first record table, the amount of data read by cgroup2 can be modified to 1.33KB, and at the same time, the amount of data read by cgroup3 can be recorded as 1.33KB, and the number of times cgroup3 has been read is 1.
[0267] S540, obtain the fourth read request of cgroup2, and read the target data based on the fourth read request.
[0268] When cgroup2 requests to read the target data from the cache again, since the target data has already been cached in the target cache page, cgroup2 can directly read the target data from the target cache page.
[0269] At this point, the amount of data read by each cgroup (cgroup1, cgroup2, and cgroup3) can be reallocated based on a preset strategy.
[0270] Assuming the preset strategy can allocate the data volume of each (read) cgroup based on the number of (read) cgroups, then the data volume can be allocated based on the number of cgroups accessing the target cache page. For example... Figure 5 As shown, at this time, the amount of data read by each cgroup remains unchanged, and there is no need to recover or compensate for the data volume.
[0271] like Figure 5 As shown, at this time, the number of reads of cgroup2 in the first record table can be modified to 2, and the amount of data read by each cgroup will not change.
[0272] Subsequently, the cgroups that access the target cache page and the amount of data read by the cgroup can be recorded in a similar manner, and the data volume of each cgroup can be recovered and compensated based on a preset strategy.
[0273] The first cgroup is rate-limited based on the first record table until the reading is completed or when rate limiting of access to the device is required.
[0274] For a detailed description of rate limiting for the first cgroup, please refer to the embodiment in method 200, which will not be repeated here.
[0275] Figure 6 This is a schematic block diagram of a memory management apparatus 600 provided in one embodiment of this application. It should be understood that... Figure 6 The memory management device 600 shown is merely an example; the device 600 of this application embodiment may also include other modules or units. It should be understood that the device 600 is capable of performing… Figure 2 , Figure 3 , Figure 4 and Figure 5 To avoid repetition, the steps in the method will not be described in detail here.
[0276] The acquisition unit 610 is used to acquire read and write requests of a first control group cgroup, wherein the first cgroup is one of a plurality of cgroups, and the read and write requests are used to request to read or write target data in a target cache page;
[0277] Update unit 620 is used to update the first record table of the target cache page according to the read or write operation based on the read or write request, so as to obtain the updated first record table. The read or write operation is used to read or write the target data in the target cache page. The first record table includes a second cgroup and the number of times the second cgroup has read or written the target data. The second cgroup is the cgroup among the plurality of cgroups that has read or written the target data in the target cache page.
[0278] The rate limiting unit 630 is used to rate limit the first cgroup based on the number of times the first cgroup reads or writes the target data recorded in the updated first record table.
[0279] Optionally, the first record table is further used to indicate the amount of data read or written by the second cgroup, and the update unit 620 is specifically used to: reallocate the amount of data read or written by the second cgroup based on a preset strategy; and update the first record table based on the read / write request and the reallocated amount of data read or written by the second cgroup to obtain the updated first record table.
[0280] Optionally, the update unit 620 is specifically used to: reallocate the amount of data read or written by each cgroup in the set based on the number of cgroups in the set of the first cgroup and the second cgroup.
[0281] Optionally, the update unit 620 is specifically used to: reallocate the amount of data read or written by each cgroup in the set of the first cgroup and the second cgroup in the updated first record table.
[0282] Optionally, the rate limiting unit 630 is specifically used to: obtain the amount of data read or written by the first cgroup based on the number of times the first cgroup reads or writes the target data recorded in the updated first record table, and to rate limit the first cgroup based on the amount of data read or written by the first cgroup.
[0283] Optionally, after obtaining the request from the first control group cgroup to read the target data in the target cache page, the update unit 620 is further configured to: initialize the first record table if the target data does not exist in the target cache page; and read the target data from the storage device into the target cache page.
[0284] Optionally, after obtaining the request from the first control group cgroup to write the target data into the target cache page, the update unit 620 is further configured to: initialize the first record table if the target data does not exist in the target cache page; and write the target data into the target cache page.
[0285] It should be understood that the memory management device 600 described herein is embodied in the form of a functional module. The term "module" here can be implemented in software and / or hardware, without specific limitation. For example, a "module" can be a software program, hardware circuitry, or a combination of both that implements the above-described functions. The hardware circuitry may include application-specific integrated circuits (ASICs), electronic circuitry, a processor (e.g., a shared processor, a proprietary processor, or a group processor, etc.) and memory for executing one or more software or firmware programs, integrated logic circuitry, and / or other suitable components supporting the described functions.
[0286] As an example, the memory management device 600 provided in this application embodiment may be a processor in a cloud server, or it may be a chip in a cloud server, for executing the methods described in this application embodiment.
[0287] Figure 7 This is a schematic block diagram of a memory management apparatus 800 according to an embodiment of this application. Figure 7 The illustrated device 800 includes a memory 801, a processor 802, a communication interface 803, and a bus 804. The memory 801, processor 802, and communication interface 803 are interconnected via the bus 804.
[0288] The memory 801 can be a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 801 can store programs. When the program stored in the memory 801 is executed by the processor 802, the processor 802 performs various steps of the memory management method of this embodiment. For example, it can execute... Figure 2 , Figure 3 , Figure 4 and Figure 5 The various steps of the illustrated embodiment.
[0289] The processor 802 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, used to execute relevant programs to implement the memory management method of the method embodiments of this application.
[0290] The processor 802 can also be an integrated circuit chip with signal processing capabilities. In implementation, each step of the memory management method in this embodiment can be accomplished through integrated logic circuits in the processor 802 or through software instructions.
[0291] The processor 802 described above can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0292] The steps of the method disclosed in the embodiments of this application can be directly manifested as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory 801. The processor 802 reads information from memory 801 and, in conjunction with its hardware, completes the functions required by the units included in the memory management apparatus in the embodiments of this application, or executes the memory management method of the method embodiments of this application. For example, it can execute... Figure 2 , Figure 3 , Figure 4 and Figure 5 The various steps / functions of the illustrated embodiment.
[0293] The communication interface 803 can use, but is not limited to, transceivers to enable communication between the device 800 and other devices or communication networks.
[0294] Bus 804 may include a pathway for transmitting information between various components of device 800 (e.g., memory 801, processor 802, communication interface 803).
[0295] It should be understood that the device 800 shown in the embodiments of this application may be a processor in a cloud server, or it may be a chip in a cloud server, for performing the methods described in the embodiments of this application.
[0296] It should be understood that the processor in the embodiments of this application can be a central processing unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0297] It should also be understood that the memory in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDR SDRAM), enhanced synchronous DRAM (ESDRAM), synchronous linked DRAM (SLDRAM), and direct rambus RAM (DR RAM).
[0298] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more sets of available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. A semiconductor medium can be a solid-state drive.
[0299] It should be understood that the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. A and B can be singular or plural. Additionally, the character " / " in this article generally indicates an "or" relationship between the preceding and following related objects, but it can also represent an "and / or" relationship. Please refer to the context for a more accurate understanding.
[0300] In this application, "at least one" means one or more, and "more than one" means two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or multiple items. For example, at least one of a, b, or c can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.
[0301] It should be understood that in the various embodiments of this application, the order of the above-mentioned processes does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0302] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0303] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0304] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0305] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0306] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0307] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0308] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A memory management method, characterized in that, include: Obtain read / write requests from a first control group cgroup, where the first cgroup is one of multiple cgroups, and the read / write requests are used to request reading or writing target data in a target cache page; When a read or write operation is performed based on the read or write request, the first record table of the target cache page is updated by updating the number of times the first cgroup reads or writes the target data in the target cache page, resulting in an updated first record table. The read or write operation is used to read or write the target data in the target cache page. The first record table includes a second cgroup and the number of times the second cgroup reads or writes the target data. The second cgroup is the cgroup among the plurality of cgroups that has read or written the target data in the target cache page. Rate limiting is applied to the first cgroup based on the number of times the first cgroup reads or writes the target data as recorded in the updated first record table.
2. The method according to claim 1, characterized in that, The first record table is also used to indicate the amount of data read or written by the second cgroup. The step of updating the first record table of the target cache page by updating the number of times the first cgroup reads or writes the target data in the target cache page, to obtain the updated first record table, includes: Based on a preset strategy, the amount of data read or written by the second cgroup is reallocated; Based on the read / write request and the amount of data read or written by the second cgroup after reallocation, the first record table is updated to obtain the updated first record table.
3. The method according to claim 2, characterized in that, The reallocation of the amount of data read or written by the second cgroup based on a preset strategy includes: Based on the number of cgroups in the combined set of the first cgroup and the second cgroup, the amount of data read or written by each cgroup in the combined set is reallocated.
4. The method according to claim 2, characterized in that, The reallocation of the amount of data read or written by the second cgroup based on a preset strategy includes: Based on the number of reads or writes of each cgroup in the merge of the first cgroup and the second cgroup in the updated first record table, the amount of data read or written by each cgroup in the merge is reallocated.
5. The method according to claim 4, characterized in that, The method of rate limiting the first cgroup based on the number of times the first cgroup reads or writes the target data recorded in the updated first record table includes: Based on the amount of data read or written by the first cgroup recorded in the updated first record table, an instruction is given to rate limit the first cgroup.
6. The method according to any one of claims 1 to 5, characterized in that, After obtaining the request from the first control group cgroup to read the target data in the target cache page, the method further includes: If the target data does not exist in the target cache page, initialize the first record table; The target data is read from the storage device into the target cache page.
7. The method according to any one of claims 1 to 5, characterized in that, After obtaining the request from the first control group cgroup to write the target data in the target cache page, the method further includes: If the target data does not exist in the target cache page, initialize the first record table; Write the target data to the target cache page.
8. A memory management device, characterized in that, include: The acquisition unit is used to acquire read and write requests of a first control group cgroup, wherein the first cgroup is one of multiple cgroups, and the read and write requests are used to request to read or write target data in a target cache page; An update unit is configured to, when a read or write operation is performed based on the read / write request, update the first record table of the target cache page by updating the number of times the first cgroup reads or writes the target data in the target cache page, thereby obtaining an updated first record table. The read or write operation is used to read or write the target data in the target cache page. The first record table includes a second cgroup and the number of times the second cgroup reads or writes the target data. The second cgroup is the cgroup among the plurality of cgroups that has read or written the target data in the target cache page. A rate limiting unit is used to rate limit the first cgroup based on the number of times the first cgroup reads or writes the target data as recorded in the updated first record table.
9. The apparatus according to claim 8, characterized in that, The first record table is also used to indicate the amount of data read or written by the second cgroup, and the update unit is specifically used for: Based on a preset strategy, the amount of data read or written by the second cgroup is reallocated; Based on the read / write request and the amount of data read or written by the second cgroup after reallocation, the first record table is updated to obtain the updated first record table.
10. The apparatus according to claim 9, characterized in that, The update unit is specifically used for: Based on the number of cgroups in the combined set of the first cgroup and the second cgroup, the amount of data read or written by each cgroup in the combined set is reallocated.
11. The apparatus according to claim 9, characterized in that, The update unit is specifically used for: Based on the number of reads or writes of each cgroup in the merge of the first cgroup and the second cgroup in the updated first record table, the amount of data read or written by each cgroup in the merge is reallocated.
12. The apparatus according to claim 11, characterized in that, The current limiting unit is specifically used for: Based on the amount of data read or written by the first cgroup recorded in the updated first record table, an instruction is given to rate limit the first cgroup.
13. The apparatus according to any one of claims 8 to 12, characterized in that, After the request to obtain the first control group cgroup request to read the target data in the target cache page, the update unit is further configured to: If the target data does not exist in the target cache page, initialize the first record table; The target data is read from the storage device into the target cache page.
14. The apparatus according to any one of claims 8 to 12, characterized in that, After the request to obtain the first control group cgroup request to write the target data in the target cache page is completed, the update unit is further configured to: If the target data does not exist in the target cache page, initialize the first record table; Write the target data to the target cache page.
15. A memory management apparatus, characterized in that, It includes a processor and a memory, the memory being used to store program instructions, and the processor being used to invoke the program instructions to perform the method of any one of claims 1 to 7.
16. A virtual machine, characterized in that, The virtual machine includes the apparatus of any one of claims 8 to 14.
17. A container, characterized in that, The container includes the device according to any one of claims 8 to 14.
18. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program instructions that, when executed by a processor, implement the method of any one of claims 1 to 7.
19. A chip, characterized in that, The chip includes a processor and a data interface, wherein the processor reads instructions stored in the memory through the data interface to execute the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
SSD-based (Solid State Disk) cache management method and system
CN102760101A
CGroup-based memory monitoring method and CGroup-based memory mnoitoring device
CN110879773A