A method and device for integrating file pages in memory
By automatically integrating file pages of executable binary files in memory, the problem of low page integration efficiency in the prior art is solved, and more efficient memory utilization and addressing performance is achieved.
Patent Information
- Application Number
- CN202111572189.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2041-12-21
AI Technical Summary
In the prior art, page integration of file pages of executable binary files requires technicians to be very familiar with the page integration method of operating system, and it is necessary to add page integration instructions to the executable binary files of the application, which is inefficient.
Provides a page integration method for file pages in memory. By reading executable binary files from disk into memory when receiving instructions to execute applications, and mapping physical addresses to virtual addresses, determining the virtual address range and read and write flag bits of file pages. When writing is prohibited, consolidate the file pages with the virtual address contiguous file pages into larger file pages and build a new page table.
It realizes file page integration without the need for technicians to actively call methods, lowers the technical threshold, and reduces addressing time without increasing in-page fragmentation, improves memory utilization and system performance.
Smart Images

Figure CN114385552B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of operating system technology, and more particularly, to a method and device for integrating file pages in a memory. Background Art
[0002] When the operating system manages memory, it usually manages it in units of 4KB, that is, 4KB is one page. As applications grow larger, 8KB, 16KB, 32KB, 64KB, 256KB, 2MB, 1GB, etc. are used as management units, that is, 8KB, 16KB, 32KB, 64KB, 256KB, 2MB, 1GB, etc. are used as one page.
[0003] When the operating system performs addressing, it does so based on the page table, which records the physical address corresponding to each page virtual address. A page size that is too small will result in larger page table entries, increasing the search speed and additional overhead during addressing, but will also reduce memory fragmentation in the program and improve memory utilization. A page size that is too large will waste memory space, cause memory fragmentation, and reduce memory utilization, but it can reduce the addressing time of page table entries and the Translation Lookaside Buffer (TLB) in the process.
[0004] In order to strike a balance between larger pages and smaller pages, the related art generally still uses 4KB as the management unit. However, for multiple 4KB pages with consecutive virtual addresses, page integration can be performed to obtain larger pages. In this way, the memory will not be wasted too much and the addressing time can be reduced.
[0005] In the related art, page integration of file pages of executable binary files is still achieved by manually changing the application code. This page integration method of file pages requires technicians to be very familiar with the page integration method of the operating system, and requires technicians to have instructions for applying for page integration in the executable binary file corresponding to the application. This has high requirements for technicians and low efficiency. Summary of the invention
[0006] In view of this, one or more embodiments of the present specification provide a page integration method for file pages in a memory.
[0007] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0008] According to a first aspect of one or more embodiments of the present specification, a page integration method for file pages in memory is proposed, which is used to integrate file pages of size x with continuous virtual addresses in an executable binary file into file pages of size X, where X and x are positive integer powers of 2, X>x, and X=2 n *x, n are positive integers; the method comprises:
[0009] When receiving an instruction to execute an application program, reading an executable binary file corresponding to the application program from a disk into a memory, and mapping a physical address of the executable binary file in the memory into a virtual address;
[0010] Determine the virtual address range and read / write flag of the file page of the executable binary file;
[0011] When the read / write flag is set to prohibit writing, the virtual address range of the file page of the executable binary file is set to n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
[0012] According to a second aspect of one or more embodiments of the present specification, a page integration device is provided for integrating file pages of size x with continuous virtual addresses in an executable binary file into file pages of size X, where X>x, X=2 n *x, n are positive integers; the device comprises:
[0013] A reading module, configured to read an executable binary file corresponding to the application from a disk into a memory upon receiving an instruction to execute the application, and map a physical address of the executable binary file in the memory to a virtual address;
[0014] A determination module, used to determine the virtual address range and read / write flag of the file page of the executable binary file;
[0015] The integration module is used to, when the read-write flag is set to prohibit writing, convert the virtual address range of the file page of the executable binary file into a binary file every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
[0016] According to a third aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0017] processor;
[0018] a memory for storing processor-executable instructions;
[0019] The processor implements the page integration method of file pages in the memory as described above by running the executable instructions.
[0020] According to a fourth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the page integration method of file pages in the memory as described above are implemented.
[0021] One or more embodiments of the present specification provide a method for integrating file pages in memory, for integrating file pages of size x with continuous virtual addresses in an executable binary file into file pages of size X, wherein X and x are positive integer powers of 2, X>x, and X=2 n *x, n are positive integers. When receiving the instruction to execute the application, read the executable binary file corresponding to the application from the disk into the memory, and map the physical address of the executable binary file in the memory to the virtual address. Determine the virtual address range and read-write flag of the file page of the executable binary file. When the read-write flag is set to prohibit writing, the virtual address range of the executable binary file page is mapped to 0 for every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and the page table corresponding to the application is constructed according to the integration result.
[0022] Through one or more embodiments of this specification, for each application in the system, the virtual address range of the executable binary file page corresponding to the application is allocated every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, so that as many file pages in the memory as possible are integrated into larger pages, reducing the addressing time without increasing the fragmentation within the page. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a flowchart of a madvise calling method provided by an exemplary embodiment.
[0024] Figure 2 The present invention is a flowchart of a method for integrating file pages in a memory provided by an exemplary embodiment.
[0025] Figure 3 The present invention is a flowchart of a method for integrating file pages in a memory according to a specific embodiment.
[0026] Figure 4 It is a flowchart of another method for integrating file pages in memory according to a specific embodiment.
[0027] Figure 5 It is a schematic diagram of a framework of a page integration device for file pages in a memory provided by an exemplary embodiment.
[0028] Figure 6 It is a structural schematic diagram of a device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0029] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0030] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0031] After the application is installed and deployed on the device, the device will save the executable binary file of the application on the disk. When the application needs to be executed, the CPU will read the executable binary file corresponding to the application from the disk to the memory, and then execute the relevant steps.
[0032] An executable binary file includes a code segment and a data segment. The data segment is the variable required when executing the executable binary file, and the code segment is the code when executing the executable binary file.
[0033] After the executable binary file of the application is read into the memory, the code segment of the executable binary file will be used as the file page. When the code segment is changed in the memory, that is, when the content of the file page is changed, it needs to be written back to the disk; the data segment of the executable binary file will be used as an anonymous page. When the data segment is changed in the memory, that is, when the content of the anonymous page is changed, it does not need to be written back to the disk.
[0034] Among them, for the file page of an executable binary file of an application, it includes two parts, one part is the code itself, and the other part is the dynamic link library that the code depends on when executing, which is also a binary file.
[0035] Since the content of anonymous pages does not need to be written back to disk when it changes, the system can directly perform page integration, while the content of file pages needs to be written back to disk when it changes. The current system does not support page integration of file pages. In the related art, the Linux system generally calls the madvise method, and madvise can mark different memory areas. After determining that the executable binary file corresponding to the application is large, the technician added a page integration instruction to the executable binary file, that is, applying to the system to call the madvise method to mark the memory area of the executable binary file, so that the system can integrate the 4KB file page corresponding to the executable binary file into a 2048KB (2MB) file page.
[0036] This page integration method for file pages requires the technician to be very familiar with the page integration method of the operating system, and requires the technician to have instructions for applying for page integration in the executable binary file corresponding to the application program, which has high requirements for the technician and low efficiency.
[0037] like Figure 1 As shown in the figure, this specification shows a structural diagram of the madvise method of the Linux system. In the related technology, it is necessary to set transparent huge pages (THP) to madvise, where THP can be set to never, madvise, and always. When set to never, page integration will not be performed on file pages or anonymous pages in the memory; when set to madvise or always, the technician can actively call madvise to perform page integration on the specified file pages; when set to always, page integration will be dynamically performed on anonymous pages in the memory.
[0038] After setting THP to madvise or always, if the technician needs to integrate the file pages of an application's executable binary file into larger pages during execution, an instruction to call madvise must exist in the application's executable binary file, that is, the executable binary file itself must contain an instruction to apply for page integration. After that, the system will add the virtual address range of the file pages of the executable binary file to the scanning queue of khugepaged, so that the khugepaged process can integrate the file pages of the executable binary file.
[0039] This method of calling madvise requires explicit modification and submission of a larger application code if you want to add the function of page integration for file pages, and call the madvise system call for different code segment areas in turn to integrate the file pages of the application into larger pages. This method requires human participation and requires recompiling and deploying applications, which is not convenient for use in cloud scenarios. In addition, this manual modification method has high requirements for technical personnel, who need to be very familiar with this page integration method and be able to accurately add corresponding instructions to the executable binary file corresponding to the application, and has low efficiency.
[0040] Based on this, this specification provides a page integration method for file pages in memory, which is used to integrate file pages of size x with continuous virtual addresses in an executable binary file into file pages of size X, where X and x are positive integer powers of 2, X>x, and X=2 n *x, n are positive integers. When receiving the instruction to execute the application, read the executable binary file corresponding to the application from the disk into the memory, and map the physical address of the executable binary file in the memory to the virtual address. Determine the virtual address range and read-write flag of the file page of the executable binary file. When the read-write flag is set to prohibit writing, the virtual address range of the executable binary file page is mapped to 0 for every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and the page table corresponding to the application is constructed according to the integration result.
[0041] According to the method of this specification, for each application in the system, the virtual address range of the executable binary file page corresponding to the application is set every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, so that the file pages in the memory are integrated into larger pages as much as possible, reducing the addressing time without increasing the fragmentation within the page.
[0042] This specification provides a page integration method for file pages in a memory, and a corresponding page integration device, equipment, and computer-readable storage medium.
[0043] First, the page integration method of the file page in the memory provided by this specification is described in detail. The page integration method of the file page in the memory provided by this specification is used to integrate the file pages of size x with continuous virtual addresses in the executable binary file into the file page of size X, where X and x are positive integer powers of 2, X>x, and X=2 n *x, n are positive integers. For example, x = 4KB, X = 2048KB (that is, 2MB), then 2 n =512, n=9; for example, x=4KB, X=256KB, then 2n =64, n=6; for example, x=8KB, X=512KB, then 2 n =64, n=6.
[0044] It should be noted that x and X are the same unit, which can be KB, MB, GB, TB, etc.
[0045] The function implemented by the method of this description is to add a function to the existing system, so that the relevant data in the memory can be accessed and changed.
[0046] like Figure 2 FIG. 1 is a flow chart of a method for integrating file pages in a memory shown in this specification, comprising the following steps:
[0047] Step 201: When an instruction to execute an application is received, an executable binary file corresponding to the application is read from a disk into a memory, and a physical address of the executable binary file in the memory is mapped to a virtual address.
[0048] A device will deploy many applications. When these applications are not executed, the corresponding executable binary files will generally be stored on the disk. When an application needs to be executed, that is, when an instruction to execute an application is received, the corresponding executable binary file will be read from the disk into the memory to execute the relevant steps.
[0049] For example, the instruction to execute the application may be a detected double-click of the application icon by the left button of the mouse. In another example, the instruction to execute the application may be a corresponding instruction input in a command terminal, and so on.
[0050] After the executable binary file is read into the memory, the physical address of the executable binary file is mapped to a virtual address. The mapping of the physical address to the virtual address is explained in detail in the related art, and this specification does not repeat the information here.
[0051] Step 203: Determine the virtual address range and read / write flag bits of the file page of the executable binary file.
[0052] Executable binary files include data segments and code segments. The data segment will be treated as an anonymous page. The reason why it is called an anonymous page is that when the content of the data segment changes (that is, when the content of the anonymous page changes), it does not need to be written back to the disk. The code segment will be treated as a file page, and when the content of the file page changes, it needs to be written back to the disk.
[0053] It should be noted that anonymous pages and file pages are divided based on virtual addresses. A 4KB page refers to a 4KB space with continuous virtual addresses, and the same applies to pages of other sizes.
[0054] Step 205: When the read / write flag is set to "prohibit write", the virtual address range of the file page of the executable binary file is set to 2. n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and the page table corresponding to the application is constructed according to the integration result.
[0055] Each file will have read and write flags, such as read permission, write permission, execute permission, etc., as well as the number of readers and writers, indicating the number of processes reading or writing the file.
[0056] As mentioned above, when the content of a file page changes in memory, it needs to be written back to the disk to ensure the consistency between the content on the disk and the content in memory, but larger pages will have problems when writing back. Therefore, for file pages whose read / write flag is write-prohibited, their content will not change, so smaller pages whose read / write flag is write-prohibited can be directly integrated into larger pages. For file pages without a write-prohibited flag, such as the file page where the code segment of a dynamic link library is located, they can be integrated into larger pages when the number of writers is zero, and the larger pages can be split into smaller file pages when the number of writers is greater than zero.
[0057] The larger page mentioned in this specification refers to the page of size X, and the smaller page refers to the page of size x. The larger page and the smaller page are only for the convenience of readers to understand and writers to write.
[0058] Among them, the page table is used to query the physical address according to the virtual address, taking one page as the unit. Originally, the page size is x, and the number of entries in the page table will be large. After page integration, it will be integrated into a page of size M. The content of the page table will change and the number of entries will also decrease. Therefore, it is necessary to rebuild the page table corresponding to the page of size M after page integration.
[0059] In actual applications, different devices use different units as the minimum management unit, for example, 4KB, 8KB, 16KB, 32KB, 64KB, 128KB, 256KB, etc. As mentioned above, too small a page will increase the search speed during addressing and bring additional overhead, but it will also reduce memory fragmentation in the program and improve memory utilization. Too large a page will waste memory, cause memory fragmentation, and reduce memory utilization, but it can reduce addressing time.
[0060] Where x and X are both positive integer powers of 2, x>X, X=2 n *x, n are positive integers.
[0061] Depending on the actual application, the values of x, X, and n may change, but this does not affect the page integration method for file pages in the memory shown in this specification.
[0062] In practical applications, Linux systems are widely used. In Linux systems, the page integration of the file pages of executable binary files is still integrated manually. When the technicians determine that the file pages of the executable binary files corresponding to the application will occupy a large space, they will add the page integration instructions of the application file pages to the corresponding position in the executable binary files. After receiving the instructions, the system will add the virtual address range of the file pages of the executable binary files corresponding to the application to the scanning queue of the khugepaged process. The khugepaged process performs page integration on the address range of the scanning queue, that is, every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X.
[0063] Therefore, in one or more embodiments of the present specification, when the operating system is a Linux system, step 205 is, when the read-write flag is set to prohibit writing, adding the virtual address range of the file page of the executable binary file to the scanning queue of the khugepaged process, so that the khugepaged process adds the virtual address range of the file page of the executable binary file to the scanning queue of the khugepaged process every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and the page table corresponding to the application is constructed according to the integration result.
[0064] In this way, the khugepaged process of the Linux system can be used to complete the page integration process, thereby reducing the development cost of implementing the page integration method for file pages in the memory shown in this specification under the Linux system.
[0065] Furthermore, in order to enable the user to control whether to enable page integration for the document page, a page integration switch for the document page may be set in advance.
[0066] Before performing page integration, determine whether the page integration switch is turned on. If it is turned on, it is determined that the user wants to integrate the file pages in the memory into larger pages as much as possible, and the virtual address range of the code segment of the executable binary file is increased every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
[0067] If it is not enabled, it is determined that the user does not want to enable the function implemented by the method shown in this description, and page integration is not performed.
[0068] As mentioned above, in order to balance the impact of larger pages and smaller pages, virtual addresses are allocated with smaller pages to avoid excessive page fragmentation and waste of space. After the allocation is completed, the pages with continuous virtual addresses are integrated into larger pages as much as possible to reduce the time of addressing and increase the speed of accessing and reading the actual content stored in the physical address in the memory.
[0069] When performing page integration, the virtual address range of the file page of the executable binary file is divided into two parts every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X. The pages of size x with discontinuous virtual addresses cannot be integrated into one page. In addition, in order to integrate as many pages of size x as possible, when mapping the physical addresses of the code segments of the executable binary files and dynamic link libraries to virtual addresses, the starting physical addresses of the code segments are preferentially mapped to the starting virtual addresses aligned with size X. For the description of alignment, please refer to the description in the related art, which will not be described in detail here.
[0070] At present, the operating system still manages memory in units of 4KB. When allocating memory, it is generally allocated in a range of 4KB. The integrated large page is generally a page of 2MB in size. Therefore, in the following, this manual takes x as 4KB and X as 2048KB (i.e. 2MB) as an example for detailed description. Figure 3 shown.
[0071] Step 301: When an instruction to execute an application is received, the executable binary file corresponding to the application is read from the disk into the memory, and the physical address of the executable binary file in the memory is mapped to a virtual address.
[0072] Step 303: Determine the virtual address range and read / write flag bits of the file page of the executable binary file.
[0073] Step 305: When the read / write flag is set to prohibit writing, in the virtual address range of the file page of the executable binary system, every 512 consecutive virtual addresses of 4KB file pages are integrated into a file page of 2048KB, and based on the integration result, a page table corresponding to the application is constructed.
[0074] The above is a detailed description of the page integration method for file pages in memory. Through the above-mentioned page integration method for file pages in memory, there is no need for technical personnel to actively call related methods, which lowers the technical threshold. Moreover, since the method of this specification can be used for each application, the coverage of larger pages is expanded, and the addressing process (i.e., the process of obtaining the physical address by querying the page table based on the virtual address) is accelerated without increasing the fragmentation within the page.
[0075] like Figure 4 As shown in the figure, a specific embodiment of the present specification is shown. The page integration switch of the file page is pre-set in the Linux system. When the page integration switch is turned on, the code segment of the executable binary file of the application is aligned as much as possible with a size of X. After the mapping is completed, the virtual address range of the file page of the executable binary file is added to the scanning queue of khugepaged, so that the khugepaged process integrates the 4KB file pages with every 512 consecutive virtual addresses in the virtual address range of the file page of the executable binary file into a 2MB file page.
[0076] In addition, the inventors conducted tests on arm physical machines and x84 physical machines in actual applications. Table 1 shows the results of the inventors testing various methods on arm physical machines:
[0077] TPS(times) QPS(times) RT (milliseconds) 4K Pages 725.4 14508.9 1.38 THP 723.1 14461.9 1.38 The method shown in this manual 787.5 15750.1 1.27 Average performance improvement percentage 8.6% 8.5% 8.7%
[0078] As shown in Table 2, the inventors tested various methods in the X86 physical set.
[0079] TPS(times) QPS(times) RT (milliseconds) 4K Pages 767.3 15346.3 1.3 THP 772.3 15445.4 1.3 The method shown in this manual 800.5 16010.2 1.25 Average performance improvement percentage 4% 3.7% 4%
[0080] Among them, 4K pages refer to the situation where smaller pages are not integrated into larger pages, that is, there are only 4KB pages in the memory. THP refers to the above-mentioned manual method, in which technicians add active call instructions in the corresponding executable binary file in some applications. The method of this specification refers to the page integration method shown above.
[0081] TPS (Transactions Per Second) is the number of transactions processed per second. The T in TPS includes the three steps of "message reception", "message processing (for example: database operation)", and "response", which is a complete transaction.
[0082] QPS (Query Per Second), translated into Chinese as "query rate per second", is a measure of the amount of traffic processed by a specific query server within a specified time.
[0083] RT (Response Time) refers to the time from when a transaction is requested to when the system completes processing and returns the result, that is, the response time.
[0084] Among them, arm physical machine and X86 physical machine are two types of physical machines that are more commonly used in practical applications. Therefore, the inventors conducted tests on arm physical machine and X86 physical machine respectively.
[0085] It can be found that the method of this specification has better effects on arm physical machines and X86 physical machines. The page integration method of file pages in memory provided by this specification can effectively improve the overall performance of the physical machine.
[0086] Next, the page integration device corresponding to the page integration method of the file pages in the memory is described in detail.
[0087] This specification provides a page integration device, such as Figure 5 As shown, it is a schematic diagram of the structure of the page integration device shown in this specification, which is used to integrate the file pages of size x with continuous virtual addresses in the executable binary file into the file pages of size X, wherein X, x are positive integer powers of 2, X>x, X=2 n *x, n are positive integers; the device comprises:
[0088] The reading module 501 is used to read the executable binary file corresponding to the application from the disk into the memory when receiving the instruction to execute the application, and map the physical address of the executable binary file in the memory to the virtual address;
[0089] A determination module 503 is used to determine a virtual address range and a read / write flag of a file page of the executable binary file;
[0090] The integration module 505 is used to, when the read-write flag is set to prohibit writing, convert the virtual address range of the file page of the executable binary file into a binary file every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
[0091] Wherein, this is the page integration switch of the file page in advance, and at this time, the integration module 505 can also be used to: determine whether the page integration switch is turned on;
[0092] When the read / write flag is set to prohibit writing and the page integration switch is turned on, the virtual address range of the code segment of the executable binary file is changed every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
[0093] In addition, the device may further include:
[0094] A mapping module (not shown in the figure) is used to preferentially map the physical address of the code segment of the executable binary file to a continuous virtual address of size X when mapping the physical address of the code segment of the executable binary file to a virtual address.
[0095] In addition, when the operating system is a Linux system, the integration module can be specifically used for:
[0096] The virtual address range of the file page of the executable binary file is added to the scanning queue of the khugepaged process, so that the khugepaged process adds the virtual address range of the file page of the executable binary file ... n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
[0097] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0098] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0099] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0100] This specification also provides an electronic device, including:
[0101] processor;
[0102] a memory for storing processor-executable instructions;
[0103] The processor executes the executable instructions to implement any of the above-mentioned methods for integrating file pages in the memory.
[0104] Figure 6 A more specific schematic diagram of the hardware structure of an electronic device provided in an embodiment of this specification is shown, and the device may include: a processor 610, a memory 620, an input / output interface 630, a communication interface 640, and a bus 650. The processor 610, the memory 620, the input / output interface 630, and the communication interface 640 are connected to each other in communication within the device through the bus 650.
[0105] The processor 610 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0106] The memory 620 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 620 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 620 and called and executed by the processor 610.
[0107] The input / output interface 630 is used to connect the input / output module to realize information input and output. The input / output module can be configured as a component in the device (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0108] The communication interface 640 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).
[0109] The bus 650 comprises a pathway for transmitting information between the various components of the device (eg, the processor 610, the memory 620, the input / output interface 630, and the communication interface 640).
[0110] It should be noted that, although the above device only shows the processor 610, the memory 620, the input / output interface 630, the communication interface 640 and the bus 650, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.
[0111] The present specification also provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of any of the above-mentioned methods for integrating file pages in a memory.
[0112] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0113] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0114] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0115] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0116] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0117] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A method for integrating file pages in memory, for integrating file pages of size x with continuous virtual addresses in an executable binary file into file pages of size X, wherein: X, x is a positive integer power of 2, X>x, X=2 n *x, n are positive integers; the method comprises: When receiving an instruction to execute an application program, reading an executable binary file corresponding to the application program from a disk into a memory, and mapping a physical address of the executable binary file in the memory into a virtual address; Determine the virtual address range and read / write flag of the file page of the executable binary file; When the read / write flag is set to prohibit writing, the virtual address range of the file page of the executable binary file is set to n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
2. The method according to claim 1, presetting a page integration switch of a file page, wherein the virtual address range of the code segment of the executable binary file is set to n The x consecutive pages of virtual addresses are converted into one X page, and according to the integration result, a page table corresponding to the application is constructed, including: Determine whether the page integration switch is turned on; When the page consolidation switch is turned on, the virtual address range of the code segment of the executable binary file is n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
3. The method according to claim 1, further comprising: When mapping the physical address of the code segment of the executable binary file to the virtual address, the starting physical address of the code segment of the executable binary file is preferentially mapped to the starting virtual address aligned with a size of X.
4. The method according to claim 1, in the case where the operating system is a Linux system, the virtual address range of the code segment of the executable binary file is n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and according to the integration result, a page table corresponding to the application is constructed, including: The virtual address range of the file page of the executable binary file is added to the scanning queue of the khugepaged process, so that the khugepaged process adds the virtual address range of the file page of the executable binary file ... n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
5. A page integration device for file pages in memory, used to integrate file pages of size x with continuous virtual addresses in an executable binary file into file pages of size X, wherein: X, x is a positive integer power of 2, X>x, X=2 n *x, n are positive integers; the device comprises: A reading module, configured to read an executable binary file corresponding to the application from a disk into a memory upon receiving an instruction to execute the application, and map a physical address of the executable binary file in the memory to a virtual address; A determination module, used to determine the virtual address range and read / write flag of the file page of the executable binary file; The integration module is used to, when the read-write flag is set to prohibit writing, convert the virtual address range of the file page of the executable binary file into a binary file every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
6. The device according to claim 5, wherein a page integration switch of the file page is pre-set, and the integration module is specifically used for: Determine whether the page integration switch is turned on; When the read / write flag is set to prohibit writing and the page integration switch is turned on, the virtual address range of the code segment of the executable binary file is changed every 2 n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
7. The apparatus of claim 5, further comprising: The mapping module is used for preferentially mapping the starting physical address of the code segment of the executable binary file to the starting virtual address aligned with size X when mapping the physical address of the code segment of the executable binary file to the virtual address.
8. The device according to claim 5, wherein when the operating system is a Linux system, the integration module is specifically used for: When the read / write flag is set to prohibit writing, the virtual address range of the file page of the executable binary file is added to the scanning queue of the khugepaged process, so that the khugepaged process adds the virtual address range of the file page of the executable binary file ... and adds the virtual address range of the file page of the executable binary file n The file pages of size x with consecutive virtual addresses are integrated into a file page of size X, and a page table corresponding to the application is constructed according to the integration result.
9. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the page integration method for file pages in the memory as described in any one of claims 1-4 by running the executable instructions.
10. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the page integration method for file pages in a memory as claimed in any one of claims 1 to 4.
Citation Information
Patent Citations
Page table entry merging method and device and electronic equipment
CN111949572A