A method for processing a virtual memory space of a file, a computing device

CN115576864BActive Publication Date: 2026-10-20UNIONTECH SOFTWARE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211212377.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-28
Publication Date
2026-10-20
Estimated Expiration
2042-09-28

AI Technical Summary

Technical Problem

[0005]显然,基于目前一个文件的所有VMA(映射此文件的所有VMA)通过一个区间树管理的方法,即使在同一时刻对区间树的不同区段进行VMA操作处理,也无法实现,降低了进程的多并发性能

Benefits of technology

[0019]根据本发明的文件的虚拟内存空间的处理方法,文件的地址空间中存储由用于管理文件的所有VMA的多个区间树所组成的区间树数组、区间树数组的读锁和写锁、以及区间树数组中各区间树的读锁和写锁。基于此,在接收到对文件的地址空间执行VMA操作处理的目标请求后获取所要处理的待处理区间树。如果目标请求为写请求,则获取区间树数组的读锁和待处理区间树的写锁,并对待处理区间树执行写处理。如果目标请求为读请求,则获取区间树数组的读锁和待处理区间树的读锁,并对待处理区间树执行读处理。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115576864B_ABST
    Figure CN115576864B_ABST
Patent Text Reader

Abstract

The application discloses a kind of processing method of the virtual memory space of file, computing device, it is related to computer field.The address space of file stores interval tree array consisting of multiple interval trees for managing all VMA of file, read lock and write lock of interval tree array, the read lock and write lock of each interval tree.The above-mentioned method includes: receiving target request for executing VMA operation processing to the address space of file;Based on target request, obtain the interval tree to be processed to be processed interval tree.If target request is write request, obtain the read lock of interval tree array and the write lock of interval tree to be processed, and execute write processing to interval tree to be processed.If target request is read request, obtain the read lock of interval tree array and the read lock of interval tree to be processed, and execute read processing to interval tree to be processed.The interval tree and interval tree lock of the VMA of the file managed by the present application are detailed, so multiple interval trees of the VMA of the file managed can be processed at the same time, and the performance of process multi-concurrent is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computers, and more particularly to a method for processing the virtual memory space of a file and a computing device. Background Technology

[0002] To allow multiple processes to access physical memory simultaneously, the operating system introduces a new abstraction between applications and physical memory: virtual memory. Each process has its own unified and contiguous virtual address space, and can only access its own virtual address space during runtime. When a process accesses its virtual memory, the Memory Management Unit (MMU) translates the virtual address into a physical address, and the operating system sets the mapping between virtual and physical addresses, allowing multiple processes to share a single block of physical memory. Furthermore, the operating system only maps the virtual addresses actually used by a process to physical addresses, improving the utilization of physical memory.

[0003] As can be seen, after adding virtual memory between the application and physical memory, when a process reads or writes a file, it maps the file in memory to the virtual address space it actually uses. Specifically, a process manages its own virtual address space through a virtual memory area (VMA). A VMA refers to a contiguous segment of virtual space (i.e., a process's virtual address space includes multiple VMAs). Therefore, when a process reads or writes a file, it is essentially mapping the portion of the file it is reading or writing into its own VMA.

[0004] In other words, whenever a file is read or written by a process, a mapping relationship is established between that file and the process's Virtual MA (VMA). Currently, the mapping relationship between a file and each process's VMA is managed through the file's address space, specifically through a range tree within the address space. Furthermore, the file's address space stores read-write locks to maintain mutual exclusion access to this range tree, ensuring that only one process can perform write operations on this range tree at any given time, such as deleting or adding VMAs.

[0005] Clearly, the current method of managing all VMAs (mapped to all VMAs of a file) through a range tree cannot achieve the desired performance even if VMA operations are performed on different segments of the range tree at the same time, thus reducing the multi-concurrency performance of the process. Summary of the Invention

[0006] To address this, the present invention provides a method for processing the virtual memory space of a file, a computing device, and a readable storage medium, in an attempt to solve or at least alleviate the problems mentioned above.

[0007] According to one aspect of the present invention, a method for processing the virtual memory space of a file is provided. The address space of the file stores an array of interval trees, read locks and write locks on the interval tree array, and read locks and write locks on each interval tree in the interval tree array. The interval tree array consists of multiple interval trees used to manage all virtual memory spaces (VMA) of the file. The method includes: receiving a target request to perform VMA operation processing on the address space of the file, the target request including a read request or a write request; based on the target request, obtaining the interval tree to be processed; if the target request is a write request, acquiring the read lock on the interval tree array and the write lock on the interval tree to be processed, and performing write processing on the interval tree to be processed; if the target request is a read request, acquiring the read lock on the interval tree array and the read lock on the interval tree to be processed, and performing read processing on the interval tree to be processed.

[0008] Optionally, the method for processing the virtual memory space of a file according to the present invention further includes: determining the two endpoint values ​​of each interval tree in the interval tree array; and storing the two endpoint values ​​of each interval tree into the address space of the file.

[0009] Optionally, in the method for processing the virtual memory space of a file according to the present invention, determining the two endpoint values ​​of each interval tree in the interval tree array includes: determining the size of the file portion managed by an interval tree based on the file size and the number of interval trees in the interval tree array; determining the first endpoint value and the second endpoint value of each interval tree based on the determined size of the file portion managed by an interval tree, wherein the first endpoint value of each interval tree is the offset of the starting position of the file portion managed by the interval tree relative to the starting position of the file, and the second endpoint value of each interval tree is the offset of the ending position of the file portion managed by the interval tree relative to the starting position of the file.

[0010] Optionally, in the method for processing the virtual memory space of a file according to the present invention, determining the size of the file portion managed by an interval tree based on the file size and the number of interval trees in the interval tree array includes: calculating the size of the file portion that an interval tree can manage based on the file size and the number of interval trees in the interval tree array; determining whether the calculated size of the file portion that an interval tree can manage is greater than or equal to a preset size; if so, determining the calculated size of the file portion that an interval tree can manage as the size of the file portion managed by an interval tree.

[0011] Optionally, in the method for processing the virtual memory space of a file according to the present invention, wherein: when the target request is a request to add or delete a VMA in the address space of the file, the target request is determined to be a write request; when the target request is a request to search for a VMA in the address space of the file, the target request is determined to be a read request.

[0012] Optionally, in the method for processing the virtual memory space of a file according to the present invention, each interval tree corresponds to an index value. Obtaining the interval tree to be processed includes: when the target request is a request to add or delete a VMA in the address space of the file, obtaining the first index value of the interval tree to be processed based on the minimum offset of the file portion mapped by the VMA to be added or deleted; and using the interval tree corresponding to the first index value as the interval tree to be processed.

[0013] Optionally, in the method for processing the virtual memory space of a file according to the present invention, performing write processing on the interval tree to be processed includes: when the target request is a request to add a Virtual Memory Access (VMA) to the address space of the file, adding the VMA to be added as a node to the interval tree to be processed, and detecting whether the maximum offset of the file portion mapped by the added VMA is greater than the second endpoint value of the interval tree to be processed; if so, updating the second endpoint value of the interval tree to be processed to the maximum offset of the file portion mapped by the added VMA.

[0014] Optionally, in the method for processing the virtual memory space of a file according to the present invention, performing write processing on the interval tree to be processed includes: when the target request is a request to delete a Virtual Memory Access (VMA) in the address space of the file, removing the VMA to be deleted from the interval tree to be processed.

[0015] Optionally, in the method for processing the virtual memory space of a file according to the present invention, obtaining the interval tree to be processed includes: when the target request is a request to perform a search for a Virtual Memory Access (VMA) in the address space of the file, obtaining a second index value of the interval tree to be processed based on the searched offset; and taking the interval tree corresponding to the second index value and the candidate interval trees whose second endpoint values ​​are greater than the searched offset as the interval trees to be processed, wherein the candidate interval trees are the interval trees corresponding to each index value less than the second index value.

[0016] Optionally, in the method for processing the virtual memory space of a file according to the present invention, performing read processing on the interval tree to be processed includes: searching for the VMA including the searched offset in the interval tree.

[0017] According to another aspect of the present invention, a computing device is provided, comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, the program instructions including instructions for performing a processing method for a virtual memory space of a document according to the present invention.

[0018] According to another aspect of the present invention, a readable storage medium storing program instructions is provided, which, when read and executed by a computing device, causes the computing device to perform a method for processing the virtual memory space of a file according to the present invention.

[0019] According to the method for processing the virtual memory space of a file of the present invention, the address space of the file stores an array of interval trees consisting of multiple interval trees used to manage all VMAs of the file, read locks and write locks on the interval tree array, and read locks and write locks on each interval tree in the interval tree array. Based on this, upon receiving a target request to perform VMA operation processing on the address space of the file, the interval tree to be processed is obtained. If the target request is a write request, the read locks on the interval tree array and the write locks on the interval tree to be processed are acquired, and write processing is performed on the interval tree to be processed. If the target request is a read request, the read locks on the interval tree array and the read locks on the interval tree to be processed are acquired, and read processing is performed on the interval tree to be processed.

[0020] As can be seen, this invention refines the interval tree and interval tree lock of the VMA of managed files. Thus, when performing VMA processing on the address space of a file, it is only necessary to acquire the lock of the interval tree to which the VMA to be operated belongs. In this way, multiple interval trees of the VMA of managed files can be processed at the same time, thereby improving the performance of multiple concurrent processes. Attached Figure Description

[0021] To achieve the foregoing and related objectives, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings. These aspects indicate various ways in which the principles disclosed herein may be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. The foregoing and other objectives, features, and advantages of this disclosure will become more apparent from the following detailed description, taken in conjunction with the accompanying drawings. Throughout this disclosure, the same reference numerals generally refer to the same parts or elements.

[0022] Figure 1 A structural block diagram of a computing device 100 according to an embodiment of the present invention is shown;

[0023] Figure 2 A flowchart of a method 200 for processing the virtual memory space of a file according to an embodiment of the present invention is shown. Detailed Implementation

[0024] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.

[0025] This invention provides a method for processing the virtual memory space of files executed in computing devices. This method refines the granularity of the interval tree managing the file's Virtual Memory Access (VMA) and employs fine-grained interval tree locks accordingly. This allows for simultaneous operations on the VMA of different file segments, thereby improving the performance of concurrent processes.

[0026] Figure 1 A block diagram of the physical components (i.e., hardware) of a computing device 100 is shown. In a basic configuration, the computing device 100 includes at least one processing unit 102 and a system memory 104. According to one aspect, depending on the configuration and type of the computing device, the processing unit 102 may be implemented as a processor. The system memory 104 includes, but is not limited to, volatile memory (e.g., random access memory), non-volatile memory (e.g., read-only memory), flash memory, or any combination of such memory. According to one aspect, the system memory 104 includes an operating system 105 and a program module 106, the program module 106 including a virtual memory space processing module 120 configured to execute a virtual memory space processing method 200 of the present invention.

[0027] According to one aspect, operating system 105 is, for example, suitable for controlling the operation of computing device 100. Furthermore, examples are practiced in conjunction with graphics libraries, other operating systems, or any other applications, and are not limited to any particular application or system. Figure 1 The basic configuration is illustrated by the components within the dashed lines 108. According to one aspect, the computing device 100 has additional features or functions. For example, according to one aspect, the computing device 100 includes additional data storage devices (removable and / or non-removable), such as disks, optical discs, or magnetic tapes. This additional storage... Figure 1 The middle part is shown by removable storage device 109 and non-removable storage device 110.

[0028] As stated above, according to one aspect, a program module is stored in system memory 104. According to one aspect, the program module may include one or more applications. The present invention does not limit the type of application; for example, applications may include: email and contact applications, word processing applications, spreadsheet applications, database applications, slideshow applications, drawing or computer-aided applications, web browser applications, etc.

[0029] According to one aspect, examples can be practiced on circuits including discrete electronic components, packaged or integrated electronic chips containing logic gates, circuits utilizing microprocessors, or on a single chip containing electronic components or a microprocessor. For example, it can be practiced via wherein... Figure 1Each or many of the components shown can be implemented as an example by integrating a System-on-a-Chip (SOC) on a single integrated circuit. According to one aspect, such an SOC device may include one or more processing units, graphics units, communication units, system virtualization units, and various application functions, all integrated (or “burned in”) as a single integrated circuit onto a chip substrate. When operating via the SOC, the functions described herein can be operated via dedicated logic integrated on a single integrated circuit (chip) with other components of the computing device 100. Embodiments of the invention can also be implemented using other techniques capable of performing logical operations (e.g., AND, OR, and NOT), including but not limited to mechanical, optical, fluid, and quantum technologies. Additionally, embodiments of the invention can be implemented within a general-purpose computer or in any other circuit or system.

[0030] According to one aspect, computing device 100 may also have one or more input devices 112, such as a keyboard, mouse, pen, voice input device, touch input device, etc. It may also include output devices 114, such as a display, speaker, printer, etc. The foregoing devices are examples and other devices may also be used. Computing device 100 may include one or more communication connections 116 that allow communication with other computing devices 118. Examples of suitable communication connections 116 include, but are not limited to: RF transmitter, receiver and / or transceiver circuitry; Universal Serial Bus (USB), parallel and / or serial ports.

[0031] As used herein, the term computer-readable medium includes computer storage medium. Computer storage medium can include volatile and non-volatile, removable and non-removable media implemented using any method or technology for storing information (e.g., computer-readable instructions, data structures, or program modules). System memory 104, removable storage device 109, and non-removable storage device 110 are examples of computer storage media (i.e., memory storage). Computer storage media can include random access memory (RAM), read-only memory (ROM), electrically erasable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape, magnetic tape, disk storage or other magnetic storage devices, or any other article of manufacture that can be used to store information and is accessible by computer device 100. According to one aspect, any such computer storage medium can be part of computing device 100. Computer storage media does not include carrier waves or other transmitted data signals.

[0032] According to one aspect, a communication medium is implemented by computer-readable instructions, data structures, program modules, or other data in a modulated data signal (e.g., a carrier wave or other transmission mechanism), and includes any information transmission medium. According to one aspect, the term "modulated data signal" describes a signal having one or more sets of characteristics or altered in a manner that encodes information in the signal. By way of example and not limitation, a communication medium includes wired media such as wired networks or direct wired connections, and wireless media such as acoustic, radio frequency (RF), infrared, and other wireless media.

[0033] Figure 2 A flowchart of a method 200 for processing the virtual memory space of a file according to an embodiment of the present invention is shown. Method 200 is adapted for use on a computing device (e.g., Figure 1 The operation is performed in the computing device 100 shown. The operating system of the computing device can be Linux or other operating systems such as Unix, Windows, etc., and the present invention does not specifically limit it.

[0034] This invention refines the interval tree for managing the VMAs of a file, employing multiple interval trees to manage all VMAs of the file. In other words, it utilizes an array of interval trees to manage all VMAs of the file. Based on this, the invention stores in the file's address space an array of interval trees consisting of multiple interval trees used to manage all VMAs of the file, read locks and write locks on the interval tree array, and read locks and write locks on each interval tree within the interval tree array.

[0035] Specifically, according to one embodiment of the present invention, a range tree array i_mmap_array is added to the address_space of the file. The range tree array i_mmap_array includes AS_MMAP_ARRAY_SIZE range tree as_mmap_rb members, where each range tree as_mmap_rb member manages a preset size (i.e., range) of the file portion, which is mmap_tree_size. Furthermore, the range tree array i_mmap_array stores read and write locks, such as the read-write lock i_mmap_rwsem, to protect the range tree array. Each range tree as_mmap_rb member stores the read and write locks, such as the read-write lock as_mmap_rwsem, to protect the range tree. In some embodiments, the range tree as_mmap_rb members also store their root node mmap_rb_root.

[0036] The interval tree array `i_mmap_array` is typically initialized when a process loads an executable file using the `exec` family of functions, when a dynamic library loader maps a shared library file into the process's virtual address space, or when the process maps a file into its virtual address space using `mmap`. Essentially, this initialization determines the range of the file portion managed by each interval tree. Specifically, it determines the two endpoint values ​​of each interval tree in the array and stores these endpoint values ​​in the file's address space. Preferably, the two endpoint values ​​of each interval tree are stored in the corresponding interval tree member.

[0037] According to one embodiment of the present invention, the two endpoint values ​​of each interval tree in the interval tree array can be determined in the following manner.

[0038] First, the size of the file portion managed by one interval tree is determined based on the file size and the number of interval trees in the interval tree array. Specifically, the size of the file portion that one interval tree can manage is calculated based on the file size and the number of interval trees in the interval tree array. Further, the ratio tmp_tree_size of the file size and the number of interval trees (AS_MMAP_ARRAY_SIZE) is calculated, and this ratio tmp_tree_size is used as the size of the file portion that one interval tree can manage. In some embodiments, to prevent the interval trees from being too small, after calculating the size tmp_tree_size of the file portion that one interval tree can manage, it is compared with a preset size mmap_tree_size; in other words, it is determined whether tmp_tree_size is greater than or equal to the preset size mmap_tree_size. If it is, the calculated size tmp_tree_size of the file portion that one interval tree can manage is determined as the size of the file portion managed by one interval tree; otherwise, the preset size mmap_tree_size is determined as the size of the file portion managed by one interval tree.

[0039] Then, based on the size of the file portion managed by the determined interval tree, the first and second endpoint values ​​of each interval tree are determined. The first endpoint value of each interval tree is the offset of the starting position of the file portion managed by that interval tree relative to the starting position of the file, and the second endpoint value is the offset of the ending position of the file portion managed by that interval tree relative to the starting position of the file. That is, the first endpoint value of an interval tree is the offset of the starting data of the (corresponding) portion of the file content managed by that interval tree relative to the starting data of the entire file, min_offset, and the second endpoint value is the offset of the ending data of the portion of the file content managed by that interval tree relative to the starting data of the entire file, max_offset. It should be noted that the interval tree array in the file's address space remains fixed after initialization and is generally only modified when the address space is destroyed. If the file size increases beyond the range that the array can represent, the last interval tree in the interval tree array can be used to manage all pages exceeding the range.

[0040] Next, when all VMAs of a file are managed by multiple interval trees, the method for handling the file's virtual memory space will be explained in detail. For example... Figure 2 As shown, the method 200 for processing the virtual memory space of a file according to the present invention begins at 210. In 210, a target request to perform VMA operation processing on the address space of a file is received.

[0041] The target request can be a read request or a write request. Specifically, the target request can be a request to add a Virtual Address Module (VMA) to the file's address space, a request to delete a VMA from the file's address space, or a request to search for VMAs in the file's address space. For example, if part or all of the content of file 1 is mapped into the virtual address space of process A, then when process A exits or calls the exec function family to load a new executable file, it is necessary to unmap the mapping of file 1 in process A's virtual address space. This requires deleting process A's VMA from the range tree managing all VMAs of file 1. At this point, a request to delete process A's VMA from the address space of file 1 will be received. Examples of business scenarios requiring adding or searching for VMAs in the file's address space will not be provided here.

[0042] Upon receiving the target request, proceed to step 220. Based on the target request, obtain the pending range tree to be processed. Specifically, if the target request is to add or delete a VMA in the file's address space, the target request is determined to be a write request. If the target request is to search for a VMA in the file's address space, the target request is determined to be a read request.

[0043] Furthermore, according to one embodiment of the present invention, an index value can be assigned to each interval tree in the interval tree array, so that each interval tree corresponds to an index value. Thus, in some embodiments, the interval tree to be processed can be obtained through the index value corresponding to each interval tree.

[0044] Specifically, when the target request is a request to add a VMA to the address space of a file or a request to delete a VMA from the address space of a file, the pending interval tree to be processed can be obtained in the following way.

[0045] First, based on the minimum offset of the file portion mapped by the VMA to be added or deleted (i.e., the offset of the starting position of the file portion mapped by the VMA to be added or deleted relative to the starting position of the entire file), the first index value of the interval tree to be processed is obtained. More specifically, based on the minimum offset of the file portion mapped by the VMA to be added or deleted and the size of the file portion managed by the interval tree, the first index value of the interval tree to be processed is obtained. Specifically, in some embodiments, the floor value of the quotient of the minimum offset of the file portion mapped by the VMA to be added or deleted and the size of the file portion managed by the interval tree can be used as the first index value of the interval tree to be processed. Of course, the first index value can also be obtained in other ways, and this invention is not limited thereto. Then, the interval tree corresponding to the first index value is used as the interval tree to be processed.

[0046] For ease of understanding, an example is given below. The interval tree array `i_mmap_array` includes three interval tree members `as_mmap_rb`. The index of the first interval tree member `as_mmap_rb` is 1, the index of the second interval tree member `as_mmap_rb` is 2, and the index of the third interval tree member `as_mmap_rb` is 3. The size of the file portion managed by one interval tree is 10, and the minimum offset of the file portion to be added to the VMA mapping is 13. Obviously, the floor value of the quotient of the minimum offset of the file portion to be added to the VMA mapping (13) and the size of the file portion managed by one interval tree (10) is 2. Therefore, the interval tree to be processed is the second interval tree. It should be noted that this is only an example, and the interval tree to be processed can be obtained in other ways, which are not limited in this invention.

[0047] When the target request is to search for a VMA in the address space of a file, the processing interval tree can be obtained in the following way.

[0048] First, based on the searched offset, the second index value of the interval tree to be processed is obtained. The searched offset is the offset of the file data to be searched relative to the starting data of the entire file. More specifically, based on the searched offset and the size of the file portion managed by the interval tree, the second index value of the interval tree to be processed is obtained. Alternatively, the floor value of the quotient of the searched offset and the size of the file portion managed by the interval tree can be used as the second index value of the interval tree to be processed. Then, the interval tree corresponding to the second index value and the candidate interval trees whose second endpoint values ​​are greater than the searched offset are taken as the interval trees to be processed. The candidate interval trees are the interval trees corresponding to each index value less than the second index value.

[0049] To clarify, when adding a VMA to a certain interval tree, there might be a situation where the second endpoint value of that interval tree is greater than its initial second endpoint value (this will be discussed in detail later), meaning the maximum offset of the added VMA exceeds the range managed by this interval tree. Therefore, in this embodiment, when the target request is a VMA search request, in addition to using the interval tree corresponding to the second index value as the interval tree to be processed, the interval trees corresponding to index values ​​smaller than the second index value whose second endpoint values ​​are greater than the searched offset are also used as interval trees to be processed. In other words, this invention performs special boundary checking processing when processing VMA search requests, which makes it more accurate.

[0050] At this point, we have obtained the interval tree to be processed. The next step is to process the interval tree as follows.

[0051] If the target request is a write request, after acquiring the interval tree to be processed, enter step 230 to acquire the read lock on the interval tree array and the write lock on the interval tree to be processed, and then perform write processing on the interval tree to be processed. Acquiring the read lock on the interval tree array is to prevent the file's address space from being destroyed during the write processing of the interval tree to be processed (the read lock on the interval tree array can be held by multiple threads simultaneously). Acquiring the write lock on the interval tree to be processed ensures that only one thread can perform write processing on the interval tree to be processed at any given time, i.e., maintaining mutual exclusion access to the interval tree.

[0052] The following describes the write processing process performed on the range tree to be processed. When the target request is to delete a Virtual MA in the address space of a file, the VMA to be deleted is removed from the range tree to be processed.

[0053] When the target request is to add a Virtual Machine (VMA) to the address space of a file, the VMA to be added is added as a node to the processing interval tree. It is then checked whether the maximum offset of the file portion mapped by the added VMA (i.e., the offset of the end position of the file portion mapped by the added VMA relative to the start position of the entire file) is greater than the second endpoint value of the processing interval tree. If so, the second endpoint value of the processing interval tree is updated to the maximum offset of the file portion mapped by the added VMA. Otherwise, the second endpoint value of the processing interval tree remains unchanged; that is, no processing is performed on the endpoint of the processing interval tree.

[0054] After the write operation on the interval tree to be processed is completed, according to an embodiment of the present invention, the write lock on the interval tree to be processed and the read lock on the interval tree array are released. That is, when a VMA is added to or removed from the interval tree to be processed, the write lock on the interval tree to be processed and the read lock on the interval tree array are also released.

[0055] If the target request is a read request, after obtaining the interval tree to be processed, proceed to step 240 to acquire read locks on the interval tree array and the interval tree to be processed, and perform read processing on the interval tree to be processed. Specifically, when the target request is to search for a VMA in the interval tree to be processed, the VMA including the searched offset is searched in the interval tree to be processed. According to one embodiment of the present invention, after the search (i.e., the search) is completed in any interval tree to be processed, the read lock of this interval tree is released. In some embodiments, after a VMA is found in a certain interval tree to be processed, it is also necessary to delete it from that interval tree. In this case, a write lock of that interval tree can be acquired, the found VMA can be directly deleted from the interval tree, and finally the write lock in this interval tree can be released. In addition, after all the obtained interval trees to be processed have been processed, the read lock on the interval tree array can be released.

[0056] As can be seen, this invention refines the range tree and range tree lock of the VMAs managed in the file. Thus, when adding or deleting VMAs in the file's address space, only a write lock on the range tree to which the VMA to be operated belongs needs to be acquired. This allows for simultaneous addition or deletion of VMAs across multiple range trees of the managed file's VMAs, thereby improving the performance of multi-process concurrency. Furthermore, when searching for VMAs in the file's address space, this invention only needs to search within the acquired range trees to be processed, which obviously reduces the search range and thus improves search speed.

[0057] The above embodiments refine the interval tree of the VMA that manages the file based on the file offset. In some embodiments, each process may have a red-black tree of the VMA of the file, or a radix tree may be used with free lock technology. By linking all VMAs that are mapped to a physical page together, all VMAs that share the same physical page can be found.

[0058] According to the method for processing the virtual memory space of a file of the present invention, the address space of the file stores an array of interval trees consisting of multiple interval trees used to manage all VMAs of the file, read locks and write locks of the interval tree array, and read locks and write locks of each interval tree in the interval tree array. Based on this, upon receiving a target request to perform VMA operation processing on the address space of the file, the interval tree to be processed is obtained. If the target request is a write request, the read lock of the interval tree array and the write lock of the interval tree to be processed are obtained, and write processing is performed on the interval tree to be processed. If the target request is a read request, the read lock of the interval tree array and the read lock of the interval tree to be processed are obtained, and read processing is performed on the interval tree to be processed.

[0059] As can be seen, this invention refines the range trees and range tree locks for all VMAs of the managed file. Thus, when performing VMA processing on the file's address space, only the lock of the range tree to which the operated VMA belongs needs to be acquired. This allows VMA processing to be performed on different range trees of the managed file simultaneously, thereby improving the performance of multiple concurrent processes. Furthermore, this invention reduces the file range protected by a single lock, thus reducing the lock waiting time for each process even when multiple processes need to operate on a particular range tree simultaneously.

[0060] The various techniques described herein can be implemented in combination with hardware or software, or a combination thereof. Thus, the methods and apparatus of the present invention, or certain aspects or portions thereof, can take the form of program code (i.e., instructions) embedded in a tangible medium, such as a removable hard disk, USB flash drive, floppy disk, CD-ROM, or any other machine-readable storage medium, wherein when the program is loaded into and executed by a machine such as a computer, the machine becomes an apparatus for practicing the present invention.

[0061] When the program code is executed on a programmable computer, the computing device generally includes a processor, a processor-readable storage medium (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store program code; the processor is configured to execute a method for processing the virtual memory space of the document according to instructions in the program code stored in the memory.

[0062] By way of example, and not limitation, readable media include readable storage media and communication media. Readable storage media stores information such as computer-readable instructions, data structures, program modules, or other data. Communication media generally embodies computer-readable instructions, data structures, program modules, or other data in the form of modulated data signals such as carrier waves or other transmission mechanisms, and includes any information delivery medium. Any combination of the above is also included within the scope of readable media.

[0063] In the specification provided herein, the algorithms and displays are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used with the examples of this invention. The required structure for constructing such systems is apparent from the above description. Furthermore, this invention is not directed to any particular programming language. It should be understood that the contents of the invention described herein can be implemented using various programming languages, and the above description of specific languages ​​is for the purpose of disclosing the best mode of implementation of the invention.

[0064] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.

[0065] It should be understood that, in order to simplify this disclosure and aid in understanding one or more aspects of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof in the above description of exemplary embodiments of the invention. However, this method of disclosure should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim.

[0066] Those skilled in the art will understand that modules, units, or components of the devices disclosed in the examples herein can be arranged in the devices described in this embodiment, or alternatively, can be located in one or more devices different from the devices in this example. The modules in the foregoing examples can be combined into a single module or, in addition, can be divided into multiple sub-modules.

[0067] Those skilled in the art will understand that modules in the device of the embodiments can be adaptively changed and placed in one or more devices different from that embodiment. Modules, units, or components in the embodiments can be combined into a single module, unit, or component, and further, they can be divided into multiple sub-modules, sub-units, or sub-components. Except where at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or device so disclosed. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature that serves the same, equivalent, or similar purpose.

[0068] Furthermore, those skilled in the art will understand that although some embodiments described herein include certain features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the invention and form different embodiments.

[0069] Furthermore, some of the embodiments described herein are methods or combinations of method elements that can be implemented by a processor of a computer system or by other means of performing the functions. Therefore, a processor having the necessary instructions for implementing the methods or method elements forms means for implementing the methods or method elements. Furthermore, the elements described herein in the apparatus embodiments are examples of means for implementing the functions performed by elements for the purposes of carrying out the invention.

[0070] As used herein, unless otherwise specified, the use of ordinal numbers such as “first,” “second,” “third,” etc., to describe ordinary objects merely indicates different instances of similar objects and is not intended to imply that the objects being described must have a given order in time, space, ordering, or any other manner.

[0071] Although the invention has been described with reference to a limited number of embodiments, those skilled in the art will understand from the foregoing description that other embodiments are conceivable within the scope of the invention described herein. Furthermore, it should be noted that the language used in this specification has been chosen primarily for readability and instructional purposes, and not for the purpose of interpreting or limiting the subject matter of the invention. Therefore, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the invention is illustrative and not restrictive, and the scope of the invention is defined by the appended claims.

Claims

1. A method for processing the virtual memory space of a file, wherein the address space of the file stores a range tree array, read locks and write locks of the range tree array, and read locks and write locks of each range tree in the range tree array, the range tree array being composed of multiple range trees for managing all virtual memory spaces (VMAs) of the file, the method comprising: The system receives a target request to perform a Virtual Machine Action (VMA) operation on the address space of the file. The target request includes a read request or a write request. When the target request is to add or delete a VMA on the address space of the file, the target request is determined to be a write request. When the target request is to search for a VMA on the address space of the file, the target request is determined to be a read request. Based on the target request, obtain the tree of the intervals to be processed; If the target request is a write request, then acquire the read lock of the interval tree array and the write lock of the interval tree to be processed, and perform write processing on the interval tree to be processed; If the target request is a read request, then acquire the read lock of the interval tree array and the read lock of the interval tree to be processed, and perform read processing on the interval tree to be processed; The method further includes: Determining the two endpoint values ​​of each interval tree in the interval tree array includes: determining the size of the file portion managed by an interval tree based on the file size and the number of interval trees in the interval tree array; and determining the first endpoint value and the second endpoint value of each interval tree based on the determined size of the file portion managed by an interval tree, wherein the first endpoint value of each interval tree is the offset of the starting position of the file portion managed by the interval tree relative to the starting position of the file, and the second endpoint value of each interval tree is the offset of the ending position of the file portion managed by the interval tree relative to the starting position of the file. Store the two endpoint values ​​of each interval tree into the address space of the file; Each interval tree corresponds to an index value. Obtaining the interval tree to be processed includes: when the target request is to add or delete a VMA in the address space of the file, obtaining the first index value of the interval tree to be processed based on the minimum offset of the file portion mapped by the VMA to be added or deleted; and using the interval tree corresponding to the first index value as the interval tree to be processed. Perform write processing on the interval tree to be processed, including: when the target request is to add a VMA to the address space of the file, add the VMA to be added as a node to the interval tree to be processed, and detect whether the maximum offset of the file portion mapped by the added VMA is greater than the second endpoint value of the interval tree to be processed; if so, update the second endpoint value of the interval tree to be processed to the maximum offset of the file portion mapped by the added VMA. The method of obtaining the interval tree to be processed further includes: when the target request is a request to perform a VMA search on the address space of the file, obtaining a second index value of the interval tree to be processed based on the searched offset; and taking the interval tree corresponding to the second index value and the candidate interval trees whose second endpoint value is greater than the searched offset as the interval tree to be processed, wherein the candidate interval trees are the interval trees corresponding to each index value less than the second index value.

2. The method as described in claim 1, wherein, The step of determining the size of the portion of the file managed by a given interval tree based on the file size and the number of interval trees in the interval tree array includes: Based on the size of the file and the number of interval trees in the interval tree array, calculate the size of the portion of the file that an interval tree can manage. Determine whether the size of the file portion that a calculated interval tree can manage is greater than or equal to a preset size; If so, the size of the file portion that a calculated interval tree can manage is determined as the size of the file portion managed by the interval tree.

3. The method as described in claim 1 or 2, wherein, Perform write processing on the interval tree to be processed, including: When the target request is to delete a VMA in the address space of the file, the VMA to be deleted is removed from the pending range tree.

4. The method as described in claim 1 or 2, wherein, Perform read processing on the interval tree to be processed, including: Search for the VMA containing the offset being searched in the interval tree to be processed.

5. A computing device, comprising: At least one processor; as well as A memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, the program instructions including instructions for performing the method as described in any one of claims 1-4.

6. A readable storage medium storing program instructions that, when read and executed by a computing device, cause the computing device to perform the method as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Memory space management method and apparatus

    CN108628753A