Data read-write speed limiting method and device, electronic equipment and storage medium
By establishing the correspondence between target processes, controllers, and subsystems in Cgroup v1, and using blkio cgroup to limit the write-back speed of target page memory, the problem of cache read/write speed limitation in Cgroup v1 is solved, achieving effective speed limitation of cache read/write and optimization of memory usage.
Patent Information
- Application Number
- CN202411419623.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-11
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2044-10-11
AI Technical Summary
Cgroup v1 cannot effectively limit write-back speed when performing cached reads and writes on block devices, leading to excessive memory usage and performance degradation.
By establishing a correspondence between target processes, controllers, and subsystems in Cgroup v1, and using blkio cgroup to limit the write-back speed of target page memory, the limitation of Cgroup v1 in not being able to limit the write-back speed of cache reads and writes is overcome.
It effectively limits the rate of cache read and write operations, improves the versatility of Cgroup v1 applications and the accuracy of write-back speed, and avoids the problem of exceeding memory usage limits.
Smart Images

Figure CN119597683B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, more particularly, to a data read-write speed limiting method and device, electronic equipment and storage medium. BACKGROUND
[0002] At present, the first version of control groups (Control groups v1, Cgroup v1) is applied in a large number of Linux kernels, and when the blkio cgroup in the Cgroup v1 subsystem limits the write-back speed of the block device, it only has a certain limiting effect on the direct IO (Direct IO) without cache read-write, but the blkio cgroup block device write-back speed limiting function will be invalid for the Buffered IO (Buffered IO) cache read-write. SUMMARY
[0003] In view of the above problems, the present application provides a data read-write speed limiting method and device, electronic equipment and storage medium.
[0004] In a first aspect, an embodiment of the present application provides a data read-write speed limiting method, which comprises: when a target page memory generated by a target process in a first version of control groups (Cgroup v1) is written back, determining a target controller corresponding to the target page memory based on a first correspondence relationship, the target page memory being generated when the target process performs cache read-write, the Cgroup v1 being pre-configured to enable write-back limitation of cache read-write, and the first correspondence relationship being determined according to a controller (memory cgroup) of a control group to which the target process belongs; determining a target subsystem corresponding to the target controller based on a second correspondence relationship, the second correspondence relationship being determined based on a subsystem controller (blkcg_css) of a control group to which the target process belongs when the target page memory is generated, and the target subsystem being a blkio cgroup corresponding to the blkcg_css; limiting the write-back speed of data in the target page memory to a target memory based on the target subsystem.
[0005] In a second aspect, an embodiment of the present application provides a speed limiting device for data read and write, the device comprising: a target controller determination module configured to determine a target controller corresponding to a target page memory generated by a target process in a first version of a control group (Cgroup v1) when performing write back on the target page memory, the target page memory being generated when the target process performs cache read and write, the Cgroup v1 being pre-configured to enable write back limitation of cache read and write, and the first correspondence being determined according to a controller memorycgroup of a control group to which the target process belongs; a target subsystem determination module configured to determine a target subsystem corresponding to the target controller based on a second correspondence, the second correspondence being determined based on a subsystem controller blkcg_css of a control group to which the target process belongs when the target page memory is generated, and the target subsystem being a subsystem blkio cgroup corresponding to the blkcg_css; and a speed limitation module configured to limit a write back speed of data in the target page memory to a target memory based on the target subsystem.
[0006] In a third aspect, an embodiment of the present application provides an electronic device, comprising: one or more processors; a memory; and one or more application programs stored in the memory and configured to be executed by the one or more processors, the one or more programs being configured to perform the speed limiting method for data read and write provided in the first aspect.
[0007] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, the computer readable storage medium storing program codes, the program codes being executable by a processor to perform the speed limiting method for data read and write provided in the first aspect.
[0008] The scheme provided in the present application enables write back limitation of cache read and write in the Cgroup v1, and obtains a target controller currently belonging to a target process based on a first correspondence between a controller and a control group in which the target process is located, determines a target subsystem currently belonging to the target process based on a second correspondence between the controller and a subsystem controller, and finally determines a write back speed of data in a target page memory to a target memory according to the target subsystem. The write back speed of the target page memory is limited by determining the target subsystem corresponding to the target process when the write back limitation of cache read and write is enabled in the Cgroup v1, which breaks the limitation that the write back speed of the page memory cannot be limited in the Cgroup v1, and realizes speed limitation of cache read and write in the Cgroup v1. BRIEF DESCRIPTION OF DRAWINGS
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A schematic diagram of the internal management hierarchy of the control group in the first version is shown.
[0011] Figure 2 A flowchart illustrating a data read / write rate limiting method provided in an embodiment of this application is shown.
[0012] Figure 3 A flowchart illustrating a data read / write rate limiting method provided in another embodiment of this application is shown.
[0013] Figure 4 A schematic diagram illustrating the process of establishing a first correspondence and a second correspondence provided in another embodiment of this application is shown.
[0014] Figure 5 A flowchart illustrating a data read / write rate limiting method provided in yet another embodiment of this application is shown.
[0015] Figure 6 This diagram illustrates the kernel process for enabling control group write-back functionality in the Linux kernel.
[0016] Figure 7 This diagram illustrates the process of limiting the write-back speed of Buffered IO in the Linux kernel.
[0017] Figure 8 A structural block diagram of the data read / write rate limiting device provided in an embodiment of this application is shown.
[0018] Figure 9 A structural block diagram of an electronic device for performing a data read / write rate limiting method according to an embodiment of this application is shown.
[0019] Figure 10 This application illustrates a storage medium for storing or carrying program code that implements a data read / write rate limiting method according to an embodiment of this application. Detailed Implementation
[0020] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0021] Please see Figure 1 ,Figure 1 A schematic diagram of the internal management hierarchy of the control group in the first version is shown. Figure 1 In this architecture, each subsystem or controller is independent of the others. For example, there's the CPU subsystem for tracking CPU usage, the memory cgroup controller for managing and limiting memory resource usage by processes or process groups, and the blkio cgroup subsystem for managing and controlling device block I / O. Specifically, `cpuacct` manages and limits the memory resource usage of a process or process group within that subsystem. `memory cgroup` manages and limits the system memory resource usage of processes or process groups. `memory cgroup` provides a mechanism to monitor and control the allocation, use, and release of memory by processes for resource management and performance optimization. `blkio cgroup` limits and monitors I / O operations on block devices. `blkio cgroup` allows system administrators to limit I / O operations of different processes or process groups to ensure fair allocation of system resources and performance optimization. By using `blkio cgroup`, users can allocate specific I / O bandwidth and I / O priorities to each cgroup. This prevents a process or process group from consuming excessive disk bandwidth, thus affecting the performance of other processes.
[0022] Due to a design flaw in Cgroup v1, dirty pages generated by Buffered I / O are written back page by page. This means the process can only trace back to the memory cgroup to which the page belongs, not the associated blkio cgroup. Therefore, I / O rate limiting cannot be applied to write-backs. When the memory cgroup and blkio cgroup are not cooperating, the memory cgroup determines the root blkio cgroup (root blkio cgroup, root blkcg). The root blkcg does not rate-limit buffered I / O write-backs by default, meaning that Cgroup v1 does not rate-limit dirty page write-backs. When writing large files using Buffered I / O, a large number of dirty pages are generated quickly, but dirty page write-backs are relatively slow, leading to memory usage exceeding limits. Normally, when the dirty page write-back rate is much lower than the dirty page generation rate, the process should be forced to sleep, and a rate limit should be applied to its dirty page generation rate.
[0023] To address the problems in the background art, the inventors have proposed a data read / write rate limiting method, apparatus, electronic device, and storage medium provided in the embodiments of this application. When enabling write-back limiting for cache read / write in Cgroup v1, the target controller to which the target process currently belongs is obtained based on a first correspondence between the controller and the control group to which the target process belongs. Then, the target subsystem to which the target process currently belongs is determined based on a second correspondence between the controller and the subsystem controller. Finally, the write-back speed when writing data from the target page memory back to the target memory is determined according to the target subsystem. By determining the target subsystem corresponding to the target process to limit the write-back speed of the target page memory when cache read / write limiting is enabled in Cgroup v1, the limitation that Cgroup v1 cannot limit the write-back speed of page memory is overcome, and rate limiting for cache read / write in Cgroup v1 is achieved.
[0024] The data read / write rate limiting method, apparatus, electronic device, and storage medium provided in the embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0025] Please see Figure 2 , Figure 2 A flowchart illustrating the data read / write rate limiting method provided in an embodiment of this application is shown. This data read / write rate limiting method can be applied to, for example... Figure 8 The data read / write rate limiting device 300 and the electronic device 100 equipped with the data read / write rate limiting device 300 are shown. Figure 9 ).
[0026] The data read / write rate limiting method may specifically include the following steps:
[0027] Step S110: When writing back the target page memory generated by the target process in the first version of control group Cgroup v1, the target controller corresponding to the target page memory is determined based on the first correspondence. The target page memory is generated when the target process performs cache read and write. The Cgroup v1 is pre-configured and has enabled cache read and write write-back restrictions. The first correspondence is determined according to the controller memorycgroup of the control group to which the target process belongs.
[0028] Cgroups are a feature in the Linux kernel used to limit and manage resources for process groups. Cgroup v1 is the first version of Cgroups. In Cgroup v1, each Cgroup is a directory that can contain sub-Cgroups and processes. By setting parameters in files within the Cgroup directory, resource limits can be imposed on process groups within a Cgroup, such as those related to the Central Processing Unit (CPU), memory, and disk input / output (I / O).
[0029] Buffered input / output (Buffered I / O) performs data transfer using buffers in the Linux kernel. In Buffered I / O, data is first read into the kernel's buffer and then copied from the buffer to the application's memory space; alternatively, data is first read from the application's memory space into the kernel's buffer and then copied from the kernel's buffer to the application. Because of the use of buffers, Buffered I / O can provide higher performance and throughput, as data can be processed in batches in memory, reducing frequent accesses to block devices (devices providing persistent data storage, such as hard drives, solid-state drives (SSDs), or flash memory). Buffered I / O also allows for random access and file navigation.
[0030] Furthermore, a buffer is a portion of memory space used to temporarily store data transferred from one location to another. In short, a buffer is a reserved memory space used to buffer input or output data. The buffer can be a page memory area or a cache file; in this embodiment, the buffer is preferably a page memory area.
[0031] Because subsystems in Cgroup v1 are independent, when using Buffered I / O for a process or process group within Cgroup v1, the write-back of page memory generated by Buffered I / O is done page by page, and can only be traced back to the memory cgroup corresponding to that page memory. It's not possible to limit the write-back rate of page memory through the memory cgroup. Therefore, to enable write-back rate limiting for Buffered I / O page memory in Cgroup v1, write-back restrictions for Buffered I / O in Cgroup v1 need to be enabled. This can be achieved by modifying the Linux kernel to enable write-back restrictions for Buffered I / O in Cgroup v1.
[0032] In this embodiment, the first correspondence refers to the correspondence between the control group where the target process is located and the controller. When a corresponding target page memory is generated in the target process, the controller corresponding to the control group where the target process is located is used as the target controller corresponding to the target page memory.
[0033] Step S120: Based on the second correspondence, determine the target subsystem corresponding to the target controller. The second correspondence is determined when the target page memory is generated based on the subsystem controller blkcg_css of the control group to which the target process belongs. The target subsystem is the subsystem blkio cgroup corresponding to blkcg_css.
[0034] The subsystem controller blkcg_css (Block IO Controller Group Control Set) is a subsystem of the blkio cgroup subsystem, used to manage and configure the blkio cgroup. blkcg_css allows users to create, delete, and manage block I / O control groups, as well as assign resource limits and parameters to these control groups. In Linux, one blkcg_css corresponds to one blkio cgroup.
[0035] In this embodiment of the application, once the blkcg_css corresponding to the target controller is determined according to the second correspondence, the target subsystem corresponding to the target controller can be determined according to the blkcg_css.
[0036] Step S130: Based on the target subsystem, limit the write-back speed of data written back from the target page memory to the target memory.
[0037] In this embodiment, the blkio cgroup subsystem can be used to restrict and monitor I / O operations on block devices. Therefore, administrators can restrict write-backs to target page memory based on the restriction information within the blkio cgroup.
[0038] For example, when writing back large files at high speed, the write-back speed of block devices is limited in conjunction with memory constraints. For instance, if the memory limit is 100MB, the write-back limit for block devices is 10MBps. When writing a 1GB file, if the process generates dirty pages too quickly, it is limited by the kernel's dirty page balancing (balance_dirty_pages_ratelimited) and pauses, waiting for the write-back thread to write back and release the dirty pages. This process is constantly suppressed by the memory rate limit, pausing after generating dirty pages too quickly, resulting in a relatively long exit time. Furthermore, the write-back thread's writing back of dirty pages is also subject to precise block I / O rate limiting, almost degenerating buffered I / O into direct I / O.
[0039] The solution provided in this embodiment, when enabling write-back restrictions for cache read / write in Cgroup v1, obtains the target controller to which the target process currently belongs based on a first correspondence between the controller and the control group to which the target process belongs. Then, it determines the target subsystem to which the target process currently belongs based on a second correspondence between the controller and the subsystem controller. Finally, it adjusts the write-back speed based on the target subsystem when writing data from the target page memory back to the target memory. By determining the target subsystem corresponding to the target process to limit the write-back speed of the target page memory when enabling write-back restrictions for cache read / write in Cgroup v1, the limitation of Cgroup v1's inability to limit the write-back speed of page memory is overcome, improving the versatility of Cgroup v1 applications. Furthermore, since the second correspondence is established in real-time when the target page memory is generated, the flexibility and accuracy of establishing the second correspondence are improved.
[0040] Please see Figure 3 , Figure 3 A flowchart illustrating a data read / write rate limiting method provided in another embodiment of this application is shown.
[0041] Step S210: When the target process performs cache read / write, the target page memory is generated. The target page memory is then used for memory accounting to record the correspondence between the target process and the target controller, which serves as the first correspondence.
[0042] Memory accounting is used to track and record the amount of memory used by processes in each cgroup. Therefore, memory accounting can be used to track and record the amount of memory used by the target page memory. This allows for the adjustment of the target controller corresponding to the target process based on the amount of memory used by the target page memory. Finally, when submitting the memory accounting for the target page memory, the target controller corresponding to the target process is determined, thus establishing the correspondence between the target process and the target controller, which serves as the primary correspondence.
[0043] Step S220: When the target process performs cache read / write, the target page memory is generated, and the target control group to which the target process currently belongs is determined.
[0044] Step S230: Determine the memory cgroup to which the target process currently belongs and the blkcg_css to which the target process currently belongs, based on the control group identifier corresponding to the target control group.
[0045] The control group identifier includes, but is not limited to, the controller identifier, the subsystem identifier, and other identifiers such as the subsystem controller identifier.
[0046] Since Cgroup v1 uses control groups to control and manage process groups, the subsystem and / or subsystem controller corresponding to the target process can be determined based on the control group identifier of the target control group to which the target process belongs.
[0047] For example, taking target process p as an example, the control group of target process p is obtained. The controller identifier corresponding to blkcg_css is io_cgrp_id, and the controller identifier corresponding to memory cgroup is memory_cgrp_id. The corresponding subsystem is obtained based on the controller identifier and the kernel's called or query function. For example, the function is task_css. task_css(p, io_cgrp_id) is used to obtain the blkcg_css corresponding to target process p, and task_css(p, memory_cgrp_id) is used to obtain the memcg_css corresponding to target process p. Since in Cgroup v1, memcg_css corresponds to memorycgroup, the memory cgroup corresponding to target process p is determined based on memcg_css.
[0048] Step S240: Determine the memory cgroup to which the target process currently belongs as the target controller, and determine the blkcg_css to which the target process currently belongs as the target subsystem controller, and establish a correspondence between the target controller and the target subsystem controller as the second correspondence.
[0049] In this embodiment of the application, after determining the memory cgroup and blkcg_css to which the target process currently belongs, in order to determine the blkio cgroup corresponding to the memory cgroup to which the target process currently belongs to implement write-back restrictions on the target process, a correspondence between the memory cgroup and blkcg_css is first established as a second correspondence, and then the blkio cgroup corresponding to the memory cgroup is determined according to the second correspondence.
[0050] In some implementations, establishing the second correspondence further includes: in response to a modification of the memory cgroup currently belonging to the target process, determining the modified memory cgroup as the target controller; in response to a modification of the blkcg_css belonging to the target process, obtaining the modified blkcg_css as the target subsystem controller; determining the modified memory cgroup as the target controller and the modified blkcg_css as the target subsystem controller, and re-establishing the second correspondence.
[0051] In this embodiment of the application, when the memory cgroup and blkcg_css corresponding to the target process are modified by the administrator, the modified memory cgroup and blkcg_css can also be used as the new target controller and target subsystem controller after the target process generates the target page memory during cache read and write. Finally, the second correspondence is re-established based on the new target controller and target subsystem controller.
[0052] In other feasible implementations, when only one of the memory cgroup and blkcg_css corresponding to the target process is changed by the administrator, the modified subsystem controller or controller will be identified as the new target subsystem controller or controller after the target process generates target page memory during cache read / write operations. This re-establishes the second correspondence, enabling flexible correspondence between memory cgroup and blkcg_css after the target process generates target page memory. This avoids improper write-back restrictions caused by memory cgroup only corresponding to a single blkcg_css, and improves the accuracy of write-back restrictions on target page memory.
[0053] Step S250: When writing back the target page memory generated by the target process in the first version of control group Cgroup v1, the target controller corresponding to the target page memory is determined based on the first correspondence. The target page memory is generated when the target process performs cache read and write. The Cgroup v1 is pre-configured and has enabled cache read and write write-back restrictions. The first correspondence is determined according to the controller memorycgroup of the control group to which the target process belongs.
[0054] For a detailed explanation of step S250, please refer to step S110 in the foregoing embodiments, which will not be repeated here.
[0055] Step S260: Based on the second correspondence, determine the target subsystem controller corresponding to the target controller.
[0056] Step S270: Determine the target subsystem corresponding to the target controller based on the correspondence between the target subsystem controller and the target subsystem.
[0057] In this embodiment of the application, a subsystem controller corresponds to a subsystem. Therefore, once the target subsystem controller corresponding to the target controller is determined, the target subsystem corresponding to the target controller can be determined based on the target subsystem controller.
[0058] Step S280: Based on the target subsystem, limit the write-back speed of data written back from the target page memory to the target memory.
[0059] For a detailed explanation of step S280, please refer to step S130 in the foregoing embodiments, which will not be repeated here.
[0060] For example, please refer to Figure 4 , Figure 4 This illustration shows a schematic diagram of the establishment process of the first and second correspondence relationships provided in another embodiment of this application. When process pid_x uses Buffered IO to write a file, dirty pages are generated. At this time, memory accounting is performed on the dirty pages to record the system memory consumed by process pid_x when writing files using Buffered IO. Then, the memory cgroup and blkcg_css to which process pid_x currently belongs are obtained. Based on the memory cgroup and blkcg_css, the second correspondence relationship is established. At this time, the memory accounting of pid_x is submitted, and the first correspondence relationship is determined based on the submitted memory accounting.
[0061] The solution provided in this embodiment establishes a second correspondence between the target controller and the target subsystem controller in real time when the target page memory is generated, which improves the accuracy of the second correspondence and thus improves the accuracy of the target subsystem determination, making it more accurate to limit the write-back speed of the target page memory based on the target subsystem.
[0062] Please see Figure 5 , Figure 5 This illustration shows a flowchart of a data read / write rate limiting method according to another embodiment of this application. The data read / write rate limiting method may specifically include the following steps:
[0063] Step S310: Obtain the index node information of the target index node corresponding to the target process.
[0064] In Linux, inodes are used to store file attribute information. Inodes include, but are not limited to, file attribute information such as the file's byte count, read, write, and execute permissions, and the file's control group information.
[0065] In this embodiment of the application, obtaining the inode information of the target inode corresponding to the target process is to obtain relevant file attribute information about the target process.
[0066] In some implementations, obtaining the inode information of the target inode corresponding to the target process includes: obtaining the dirty page count information of the target memory in the target inode without determining whether the memory cgroup and blkio cgroup of the Cgroup v1 are enabled; obtaining the control group write-back information of the target memory; obtaining the control group write-back information corresponding to the file system in the target inode; and determining the inode information based on the dirty page count information of the target memory, the control group write-back information of the target memory, and the control group write-back information corresponding to the file system.
[0067] In related technologies, due to the design of Cgroup v1, the control group write-back function in Cgroup v1 is directly disabled when enabling / determining the Cgroup v1 memory cgroup and blkio cgroup. Therefore, when enabling the control group write-back function in Cgroup v1, it is not necessary to enable / determine the Cgroup v1 memory cgroup and blkio cgroup. In the embodiments of this application, the way to avoid enabling / determining the Cgroup v1 memory cgroup and blkio cgroup can be to directly delete the relevant functions involving enabling / determining the Cgroup v1 memory cgroup and blkio cgroup, and then compile the Linux kernel after deletion to ensure that enabling / determining the Cgroup v1 memory cgroup and blkio cgroup is not required.
[0068] A dirty page is a page that has been modified in the buffer but has not yet been flushed to memory or the database. Dirty page count information indicates whether the memory supports dirty page counting.
[0069] The file system includes, but is not limited to, information such as various types of files, data in files, and the structure of the file system. All files, directories, symbolic links, and file protection information seen by Linux users and programs are stored in the file system.
[0070] The control group write-back function enables write-back restrictions on dirty pages. The control group write-back information for memory indicates whether the target memory supports the control group write-back function, while the control group write-back information for the file system indicates whether the file system in which the target process resides supports the control group write-back function.
[0071] In this embodiment, when the memory cgroup and blkio cgroup of Cgroup v1 are not enabled, the control group write-back function for Cgroup v1 is jointly determined based on the dirty page count information of the target memory corresponding to the target process, the control group write-back information of the memory, and the control group write-back information of the file system. For example, when the memory cgroup and blkio cgroup of Cgroup v1 are not enabled, if the dirty page count information indicates that the memory supports dirty page counting, the control group write-back information of the memory indicates that the memory supports the control group write-back function, and the control group write-back information of the file system also indicates that the file system supports the control group write-back function, then the control group write-back function for Cgroup v1 is enabled. If any of the dirty page count information, the control group write-back information of the memory, or the control group write-back information of the file system indicates that the control group write-back function is not supported, then the control group write-back function for Cgroup v1 is not enabled. Since writing data from dirty pages back to memory is performed periodically in Linux, the determination of whether Cgroup v1 has enabled control group write-back can be performed during each write-back to improve the timeliness and accuracy of the determination results.
[0072] For example, please refer to Figure 6 , Figure 6 This diagram illustrates the kernel flow for enabling control group write-back functionality in Linux. It requires determining whether the memory cgroup and blkio cgroup of Cgroup v1 are enabled in the default hierarchy within the inode's control group write-back enabling function (inode_cgwb_enabled). Only if both memory cgroup and blkio cgroup are disabled will the process proceed to determine whether the block device supports dirty page counting, control group write-back, and file system support control group write-back. Only then can the inode's control group write-back functionality be enabled. Therefore, enabling it requires ensuring that the memory cgroup and blkio cgroup of Cgroupv1 are enabled in the default hierarchy within the inode's control group write-back enabling function. The step determining whether memory cgroup and blkio cgroup are enabled in the default hierarchy can be removed from the enabling function, such as... Figure 6 The determination steps within the dashed box in the middle do not require enabling the memory cgroup and blkio cgroup of Cgroup v1, thus ensuring that the memory cgroup and blkio cgroup of Cgroup v1 are enabled.
[0073] In one feasible approach, when Cgroup v1 enables the control group write-back function, it can obtain the current dirty page count and determine whether to continue generating dirty pages based on this count. The dirty page count reflects the current I / O load of the memory or database. A high dirty page count means the system is experiencing a large number of write operations that have not yet been persisted to memory or the database. Maintaining a high dirty page count for an extended period can lead to system performance degradation and even data loss. When the system is at a high dirty page count, dirty page generation can be paused to avoid increasing the system load. When the system is at a low dirty page count, dirty page generation will not affect the system, so normal dirty page generation can continue. Determining the current dirty page count before dirty page generation ensures normal system operation.
[0074] Step S320: If the index node information indicates that the target index node has enabled the control group write-back function, determine that the target process has enabled the cache read-write write-back restriction.
[0075] Step S330: If it is determined that the target process has enabled the write-back restriction for cache read and write, then when writing back the target page memory generated by the target process in the first version of control group Cgroup v1, the target controller corresponding to the target page memory is determined based on the first correspondence.
[0076] In this embodiment of the application, after determining that the target process has enabled the write-back restriction for cache read / write based on the inode information corresponding to the target process,
[0077] Step S340: Based on the second correspondence, determine the target subsystem corresponding to the target controller. The second correspondence is determined when the target page memory is generated based on the subsystem controller blkcg_css of the control group to which the target process belongs. The target subsystem is the subsystem blkio cgroup corresponding to blkcg_css.
[0078] Step S350: Based on the target subsystem, limit the write-back speed of data written back from the target page memory to the target memory.
[0079] For a detailed explanation of steps S340 to S350, please refer to steps S120 to S130 in the foregoing embodiments, which will not be repeated here.
[0080] In the embodiments of this application, the write-back restriction of Cgroup v1 for cached read and write is enabled based on the file attribute information in the inode. Only the file attribute information (kernel information) needs to be modified to enable the write-back restriction of Cgroup v1, thereby enabling a large number of existing low-version Linux servers to support the IO rate limiting function of block devices and improving the versatility of Cgroup v1.
[0081] Please see Figure 7 , Figure 7 This diagram illustrates the process of limiting the write-back speed of Buffered I / O in the Linux kernel. In conjunction with the aforementioned embodiment, when performing a write-back of Buffered I / O in the Linux kernel, the kernel's write-back process creates a control group write-back subsystem (cgroup writeback) corresponding to that process. It can determine the memory cgroup to which the write-back process currently belongs and obtain its blkcg_css. Then, it determines the version of the control group. If the control group version is version one, it determines the blkio cgroup corresponding to the write-back process based on blkcg_css and the memory cgroup. It then limits the write-back speed of the control group write-back subsystem according to the blkio cgroup parameters and binds cgroup writeback to blkcg_css. In subsequent write-back processes, it continues to limit the write-back speed using the blkio cgroup parameters. If the control group version is version two, it limits the write-back speed of Buffered I / O according to the write-back speed limiting logic of version two control groups.
[0082] Please see Figure 8The diagram shows a structural block diagram of a data read / write rate limiting device 300 provided in an embodiment of this application. The data read / write rate limiting device 300 is applied to the electronic device 100. The data read / write rate limiting device 300 includes: a target controller determination module 310, used to determine the target controller corresponding to the target page memory based on a first correspondence when writing back to the target page memory generated by the target process in the first version of the control group Cgroup v1. The target page memory is generated when the target process performs cache read / write operations. The Cgroup v1 is pre-configured and cache read / write write-back restrictions are enabled. The first correspondence is determined based on the controller memory cgroup of the control group to which the target process belongs; a target subsystem determination module 320, used to determine the target subsystem corresponding to the target controller based on a second correspondence. The second correspondence is determined based on the subsystem controller blkcg_css of the control group to which the target process belongs when the target page memory is generated. The target subsystem is the subsystem blkio cgroup corresponding to blkcg_css; and a speed limiting module 330, used to limit the write-back speed of data written back from the target page memory to the target memory based on the target subsystem.
[0083] In some embodiments of this application, the data read / write rate limiting device 300 further includes: a target control group determination module, used to determine the target control group to which the target process currently belongs when the target process generates the target page memory during cache read / write; an information determination module, used to determine the memory cgroup to which the target process currently belongs and the blkcg_css to which the target process currently belongs based on the control group identifier corresponding to the target control group; and a second correspondence establishment module, used to determine the memory cgroup to which the target process currently belongs as the target controller and the blkcg_css to which the target process currently belongs as the target subsystem controller, and establish a correspondence between the target controller and the target subsystem controller as the second correspondence.
[0084] In some embodiments of this application, the data read / write rate limiting device 300 further includes: a target controller modification module, configured to determine the modified memory cgroup as the target controller in response to a modification of the memory cgroup currently belonging to the target process; a target subsystem controller modification module, configured to obtain the modified blkcg_css as the target subsystem controller in response to a modification of the blkcg_css belonging to the target process; and a second correspondence re-establishment module, configured to determine the modified memory cgroup as the target controller and the modified blkcg_css as the target subsystem controller, and re-establish the second correspondence.
[0085] In some embodiments of this application, the data read / write rate limiting device 300 further includes: a first correspondence recording module, used to perform memory accounting on the target page memory when the target process generates the target page memory during cache read / write, so as to record the correspondence between the target process and the target controller as the first correspondence.
[0086] In some embodiments of this application, the target subsystem determination module 320 includes: a target subsystem controller determination unit, configured to determine the target subsystem controller corresponding to the target controller based on the second correspondence; and a target subsystem determination unit, configured to determine the target subsystem corresponding to the target controller according to the correspondence between the target subsystem controller and the target subsystem.
[0087] In some embodiments of this application, the data read / write rate limiting device 300 further includes: an index node information acquisition module, used to acquire index node information of the target index node corresponding to the target process; a write-back restriction enabling module, used to determine that the target process has enabled cache read / write write-back restriction when the index node information indicates that the target index node has enabled the control group write-back function; the target controller determination module 310 further includes: a target controller determination unit, used to determine the target controller corresponding to the target page memory based on the first correspondence relationship when writing back the target page memory generated by the target process in the first version of control group Cgroup v1 if it is determined that the target process has enabled cache read / write write-back restriction.
[0088] In some embodiments of this application, the inode information acquisition module includes: a dirty page count information acquisition unit for the target memory; a rate limiting module for reading and writing image evaluation data; and a module for acquiring dirty page count information of the target memory in the target inode without determining whether the memorycgroup and blkio cgroup of the Cgroup v1 are enabled; a control group write-back information acquisition unit for the target memory; a control group write-back information acquisition unit for the file system; and an inode information determination unit for determining the inode information based on the dirty page count information of the target memory, the control group write-back information of the target memory, and the control group write-back information of the file system.
[0089] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device and module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0090] In the several embodiments provided in this application, the coupling between modules can be electrical, mechanical, or other forms of coupling.
[0091] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0092] This application provides a structural block diagram of an electronic device. Please refer to... Figure 9 This document illustrates a structural block diagram of an electronic device according to an embodiment of this application. The electronic device 100 can be a computer, server, or other electronic device capable of running applications. The electronic device 100 in this application may include one or more of the following components: a processor 101, a memory 102, and one or more applications, wherein the one or more applications can be stored in the memory 102 and configured to be executed by one or more processors 101, and the one or more applications are configured to perform the methods described in the foregoing method embodiments.
[0093] Processor 101 may include one or more processing cores. Processor 101 connects to various parts within the electronic device 100 using various interfaces and lines, and performs various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets, or instruction sets stored in memory 102, and by calling data stored in memory 102. Optionally, processor 101 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 101 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into processor 101 and may be implemented separately using a communication chip.
[0094] The memory 102 may include random access memory (RAM) or read-only memory (ROM). The memory 102 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 102 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the electronic device 100 during use (such as phonebook data, audio and video data, chat log data, etc.).
[0095] Please refer to Figure 10 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable storage medium 200 stores program code that can be invoked by a processor to execute the methods described in the above method embodiments.
[0096] The computer-readable storage medium 200 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 200 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 200 has storage space for program code 210 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 210 may be compressed, for example, in a suitable form.
[0097] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for limiting the rate of data read and write, characterized in that, The method includes: When writing back the target page memory generated by the target process in the first version of control group Cgroup v1, the target controller corresponding to the target page memory is determined based on the first correspondence. The target page memory is generated when the target process performs cache read and write. The Cgroup v1 is pre-configured and cache read and write write-back restrictions are enabled. The first correspondence is determined according to the controller memory cgroup of the control group to which the target process belongs. Based on the second correspondence, the target subsystem corresponding to the target controller is determined. The second correspondence is determined when the target page memory is generated based on the subsystem controller blkcg_css of the control group to which the target process belongs. The target subsystem is the subsystem blkio cgroup corresponding to blkcg_css. Based on the target subsystem, the write-back speed of data written back from the target page memory to the target memory is limited.
2. The method according to claim 1, characterized in that, Before determining the target controller corresponding to the target page memory based on the first correspondence when writing back the target page memory generated by the target process in the first version of control group Cgroupv1, the method further includes: When the target process performs cache read / write, the target page memory is generated, and the target control group to which the target process currently belongs is determined. Based on the control group identifier corresponding to the target control group, determine the memorycgroup to which the target process currently belongs and the blkcg_css to which the target process currently belongs; The memory cgroup to which the target process currently belongs is determined as the target controller, and the blkcg_css to which the target process currently belongs is determined as the target subsystem controller. A correspondence between the target controller and the target subsystem controller is established as the second correspondence.
3. The method according to claim 2, characterized in that, After determining the memorycgroup currently belonging to the target process as the target controller, and determining the blkcg_css currently belonging to the target process as the target subsystem controller, and establishing a correspondence between the target controller and the target subsystem controller as the second correspondence, the method further includes: In response to a modification of the memory cgroup to which the target process currently belongs, the modified memory cgroup is determined as the target controller; In response to a modification to the blkcg_css of the target process, the modified blkcg_css is obtained and used as the target subsystem controller; The modified memory cgroup is identified as the target controller, and the modified blkcg_css is identified as the target subsystem controller, and the second correspondence is re-established.
4. The method according to claim 1, characterized in that, Before determining the target controller corresponding to the target page memory based on the first correspondence, the process includes: When the target process performs cache read / write operations, the target page memory is generated. The target page memory is then used for memory accounting to record the correspondence between the target process and the target controller, which serves as the first correspondence.
5. The method according to claim 1, characterized in that, The step of determining the target subsystem corresponding to the target controller based on the second correspondence includes: Based on the second correspondence, the target subsystem controller corresponding to the target controller is determined; Based on the correspondence between the target subsystem controller and the target subsystem, the target subsystem corresponding to the target controller is determined.
6. The method according to any one of claims 1-5, characterized in that, Before determining the target controller corresponding to the target page memory based on the first correspondence when writing back the target page memory generated by the target process in the first version of control group Cgroup v1, the method further includes: Obtain the index node information of the target index node corresponding to the target process; If the index node information indicates that the target index node has enabled the control group write-back function, it is determined that the target process has enabled cache read / write write-back restrictions; When writing back the target page memory generated by the target process in the first version of control group Cgroup v1, determining the target controller corresponding to the target page memory based on the first correspondence includes: If it is determined that the target process has enabled write-back restrictions for cache read / write, then when writing back the target page memory generated by the target process in the first version of control group Cgroup v1, the target controller corresponding to the target page memory is determined based on the first correspondence.
7. The method according to claim 6, characterized in that, The step of obtaining the inode information of the target inode corresponding to the target process includes: Without determining whether the memory cgroup and blkio cgroup of the Cgroup v1 are enabled, obtain the dirty page count information of the target memory in the target inode; Obtain the control group write-back information of the target memory; Obtain the control group write-back information corresponding to the file system in the target inode; The inode information is determined based on the dirty page count information of the target memory, the control group write-back information of the target memory, and the control group write-back information corresponding to the file system.
8. A data read / write rate limiting device, characterized in that, The device includes: The target controller determination module is used to determine the target controller corresponding to the target page memory based on a first correspondence when writing back the target page memory generated by the target process in the first version of the control group Cgroup v1. The target page memory is generated when the target process performs cache read and write. The Cgroup v1 is pre-configured and cache read and write write-back restrictions are enabled. The first correspondence is determined according to the controller memory cgroup of the control group to which the target process belongs. The target subsystem determination module is used to determine the target subsystem corresponding to the target controller based on a second correspondence relationship. The second correspondence relationship is determined when the target page memory is generated based on the subsystem controller blkcg_css of the control group to which the target process belongs. The target subsystem is the subsystem blkcg_css corresponding to blkcg_css. The speed limiting module is used to limit the write-back speed of data written back from the target page memory to the target memory based on the target subsystem.
9. An electronic device, characterized in that, The electronic device includes: One or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more applications being configured to perform the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1-7.
Citation Information
Patent Citations
Data reading / writing method, system and device, and computer readable storage medium
CN108509288A
Memory management method and device
CN114327245A