Page table configuration method and device
By initializing the page table size at the start of the operating system and dynamically adjusting the page table parameters according to the CPU and/or process identification during the system operation, the problem of inflexible page table configuration in the existing technology is solved, and the implementation of the incompatibility of page table configuration in different scenarios Using different page table sizes improves memory processing efficiency and performance.
Patent Information
- Application Number
- CN202411464479.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-02-18
AI Technical Summary
The method of configuring page tables in the prior art is not flexible enough to dynamically adjust the page table size during the system operation, and it is necessary to recompile the kernel or restart the machine to take effect.
When the operating system starts, initializes the memory according to the first page table parameters, selects the page table size, and creates the process based on the second page table parameters identified by the CPU and/or the process according to the preconfigured correspondence when creating the kernel process, so as to achieve the following: Adjustment of page table size during system operation.
Improves flexibility in page table configuration, allowing different page table sizes to be used in different scenarios, without recompiling the kernel or restarting the machine, improving the memory processing efficiency and performance of applications in the operating system.
Smart Images

Figure CN119473937A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a page table configuration method and device. Background Art
[0002] The page table in the Linux system kernel is a data structure used to manage the mapping relationship between virtual memory and physical memory. Currently, it is usually necessary to determine the page table size (such as 4K) when compiling the kernel, or use a large page mechanism to configure the page table.
[0003] However, if the page table size needs to be changed during the operation of the Linux system, the kernel needs to be recompiled if the kernel is compiled; and the large page mechanism also requires the machine to be restarted to take effect. It can be seen that the page table configuration method in the related art is not flexible enough. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a page table configuration method and device, which initializes the memory according to the first page table parameter when the operating system starts, that is, selects the page table size when the operating system starts, without having to compile the kernel again or restart the machine, thereby improving the flexibility of the page table configuration. In addition, in the process of creating a kernel process, a process can be created based on the second page table parameter corresponding to the CPU and / or process identifier according to the pre-configured correspondence, thereby achieving the adjustment of the page table size during the operation of the system, so that different page table sizes can be used in different scenarios, and there is no need to recompile the kernel or restart the machine, thereby improving the flexibility of the page table configuration. In addition, different CPU masks and process identifiers can be configured with different second page table parameters respectively, so that the second page table parameters match the actual data processing volume, which is also conducive to improving the memory processing efficiency of applications in the operating system, thereby improving the performance of the application.
[0005] To achieve the above object, according to one aspect of an embodiment of the present invention, a page table configuration method is provided. The page table configuration method of the embodiment of the present invention comprises: in response to the startup of an operating system, obtaining a first page table parameter; the first page table parameter is obtained by configuring a page table configuration variable in a kernel;
[0006] Initializing the memory according to the first page table parameter to configure the page table for kernel operation according to the first page table parameter;
[0007] In response to process creation in the kernel, second page table parameters corresponding to the process to be created are determined according to a preconfigured correspondence relationship, so as to create the process according to the second page table parameters; the correspondence relationship indicates the second page table parameters corresponding to the CPU mask and / or process identifier.
[0008] Optionally, the method further comprises: writing corresponding relationships between the plurality of process identifiers and the second page table parameters into a memory storage list through the first kernel interface;
[0009] According to the preconfigured corresponding relationship, the second page table parameters corresponding to the process to be created are determined, including: searching the memory storage list according to the target process identifier of the process to be created, determining the second page table parameters corresponding to the target process identifier from the memory storage list, and using the determined second page table parameters as the second page table parameters corresponding to the process to be created.
[0010] Optionally, the method further includes: storing the corresponding relationship between the plurality of CPU masks and the second page table parameters respectively in a register through a second kernel interface;
[0011] Determine the second page table parameter corresponding to the process to be created according to the preconfigured corresponding relationship, including: obtaining the CPU mask corresponding to the process to be created through the process descriptor; and determine the second page table parameter corresponding to the CPU mask corresponding to the process to be created according to the corresponding relationship in the register.
[0012] Optionally, after creating the process, the method also includes: in response to a switching instruction, switching the CPU core corresponding to the process; determining whether the second page table parameters corresponding to the CPU cores before and after the switching are the same based on the corresponding relationship in the register; if not, processing the process according to the second page table parameters corresponding to the CPU core before the switching.
[0013] Optionally, the method further includes: binding the process to multiple CPU cores, wherein the bound multiple CPU cores correspond to the same second page table parameter;
[0014] Switching a CPU core corresponding to a process includes: determining a target CPU core to be switched from a plurality of bound CPU cores, so that the target CPU core runs the process.
[0015] Optionally, the method also includes: obtaining a virtual address to be converted; parsing a target page table parameter from the virtual address; the target page table parameter is configured according to a page table configuration variable in the kernel, a CPU mask and / or a process identifier; obtaining a page table according to the target page table parameter, and determining a physical address corresponding to the virtual address according to the obtained page table.
[0016] Optionally, the method further includes: determining a virtual address space corresponding to the process, and a code segment, a data segment, and a stack segment included in the virtual address space; and verifying the code segment, the data segment, and the stack segment respectively;
[0017] When it is determined according to the verification result that there is no memory overflow, the page table is obtained.
[0018] To achieve the above object, according to another aspect of an embodiment of the present invention, a page table configuration device is provided. A page table configuration device of an embodiment of the present invention comprises: a parameter acquisition module, a first configuration module and a second configuration module; wherein:
[0019] The parameter acquisition module is configured to: in response to the operating system starting, acquire a first page table parameter; the first page table parameter is obtained by configuring a page table configuration variable in the kernel;
[0020] The first configuration module is configured to: initialize the memory according to the first page table parameter to configure the page table of the kernel operation according to the first page table parameter;
[0021] The second configuration module is configured to: in response to process creation in the kernel, determine the second page table parameters corresponding to the process to be created according to a preconfigured correspondence relationship, so as to create the process according to the second page table parameters; the correspondence relationship indicates the second page table parameters corresponding to the CPU mask and / or process identifier.
[0022] To achieve the above purpose, according to another aspect of an embodiment of the present invention, an electronic device for configuring a page table is provided. An electronic device for configuring a page table according to an embodiment of the present invention comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a method for configuring a page table according to an embodiment of the present invention.
[0023] To achieve the above object, according to another aspect of an embodiment of the present invention, a computer readable storage medium is provided. A computer readable storage medium according to an embodiment of the present invention stores a computer program, which, when executed by a processor, implements a method for configuring a page table according to an embodiment of the present invention.
[0024] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, which, when executed by a processor, implements a method for configuring a page table according to an embodiment of the present invention.
[0025] An embodiment of the above invention has the following advantages or beneficial effects: by initializing the memory according to the first page table parameter when the operating system starts, that is, selecting the page table size when the operating system starts, without having to compile the kernel again or restart the machine, the flexibility of the page table configuration is improved. In addition, in the process of creating a kernel process, a process can be created based on the second page table parameter corresponding to the CPU and / or process identifier according to the pre-configured correspondence, thereby achieving the adjustment of the page table size during system operation, so that different page table sizes can be used in different scenarios, and there is no need to recompile the kernel or restart the machine, thereby improving the flexibility of the page table configuration. In addition, different CPU masks and process identifiers can be configured with different second page table parameters respectively, so that the second page table parameters match the actual data processing volume, which is also conducive to improving the memory processing efficiency of applications in the operating system, thereby improving the performance of the application.
[0026] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0028] Figure 1 is a schematic diagram of main steps of a page table configuration method according to an embodiment of the present invention;
[0029] Figure 2 is a schematic diagram of main steps of a method for configuring a page table during an operating system startup process according to an embodiment of the present invention;
[0030] Figure 3 1 is a schematic diagram of main steps of a method for configuring a page table for a process according to an embodiment of the present invention;
[0031] Figure 4 1 is a schematic diagram of main steps of a method for configuring a page table for a CPU according to an embodiment of the present invention;
[0032] Figure 5 is a schematic diagram of main modules of a page table configuration device according to an embodiment of the present invention;
[0033] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0034] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0035] It should be pointed out that the embodiments of the present invention and the technical features therein may be combined with each other without conflict.
[0036] Figure 1 A page table configuration method according to an embodiment of the present invention can be applied to a Linux system. The method mainly includes the following steps S101-S103:
[0037] Step S101: in response to the startup of the operating system, a first page table parameter is obtained; the first page table parameter is obtained by configuring a page table configuration variable in the kernel.
[0038] In the process of configuring the first page table parameter, the macro definition related to the page table configuration in the kernel can be converted into a variable first, and then the first page table parameter can be configured by configuring the value of the variable, such as configuring the first page table parameter to 4K, 16K or 64K, etc. After configuring the first page table parameter, during the startup of the operating system, the first page table parameter can be obtained through cmdline to configure the page table of the kernel operation according to the first page table parameter. In addition, the default value of the first page table parameter can also be configured, such as 4K. During the startup of the operating system, if the kernel page table is not specially selected, the default value of the first page table parameter can be used to configure the page table of the kernel operation, that is, use the 4K page table. That is to say, in this step, the first page table parameter can be configured by configuring the default value of the page table configuration variable, or by modifying the default value of the page table configuration variable. Among them, cmdline refers to command line parameters, which can guide the kernel startup; these parameters are input through the command line interface when the operating system or application is executed, which can be used to configure the operating environment of the system or specify certain specific operations.
[0039] Step S102: Initializing the memory according to the first page table parameter, so as to configure the page table for kernel operation according to the first page table parameter.
[0040] In order to facilitate the acquisition of the first page table parameter, the cmdline can be parsed in advance in parse_early_param() during the startup of the operating system. Among them, parse_early_param() is a function used to parse and process early parameters during the startup of the Linux kernel. Specifically, the parse_early_param() function is called during the initialization phase of the kernel, which traverses a series of predefined options including the first page table parameter and checks whether the passed parameters match. The function ensures that the kernel can correctly process the parameters passed in the early stage, thereby preparing for the initialization and configuration of the subsequent operating system. After obtaining the first page table parameter, the memory can be initialized according to the configured first page table parameter during memory initialization, so that the operating system is started according to the configured first page table parameter. The page table size corresponding to the first page table parameter is the page table size used when the kernel is running, thereby realizing the configuration of the page table size during the startup of the operating system without compiling the kernel again, improving the flexibility of the page table configuration, and facilitating the configuration of the page table size according to actual needs, which is also conducive to avoiding resource waste and improving application performance.
[0041] Step S103: In response to the process creation in the kernel, determine the second page table parameters corresponding to the process to be created according to the preconfigured correspondence relationship, so as to create the process according to the second page table parameters; the correspondence relationship indicates the second page table parameters corresponding to the CPU mask and / or process identifier.
[0042] Among them, the first page table parameter and the second page table parameter may be the same or different. That is to say, the page table size selected when the operating system is started, the page table size selected on different CPU cores, and the page table size selected on different processes may be the same or different. Exemplarily, if when creating a process after the operating system is started, it is determined that the second page table parameter corresponding to the CPU mask and the process identifier is not configured, that is, the page table size of the operation is not configured at the CPU level and the process level, then the same page table size as the kernel parameter can be used, in which case the first page table parameter is the same as the second page table parameter. For another example, the second page table parameter corresponding to the CPU mask and the process identifier can be configured to the same value as the first page table parameter, such as 64K, in which case the first page table parameter is also the same as the second page table parameter. Alternatively, the second page table parameter corresponding to the CPU mask and the process identifier can be configured to be different from the first page table parameter, such as the second page table parameter corresponding to the CPU mask is 16K, the second page table parameter corresponding to the process identifier is 16K, and the first page table parameter selected when the operating system is started is 4K, in which case the first page table parameter is different from the second page table parameter.
[0043] In one embodiment of the present invention, for the process-level page table configuration, the correspondence between multiple process identifiers and second page table parameters can be written into the memory storage list through the first kernel interface. Therefore, in the process of determining the second page table parameters corresponding to the process to be created, the memory storage list can be searched according to the target process identifier of the process to be created, and the second page table parameters corresponding to the target process identifier can be determined from the memory storage list, and the determined second page table parameters are used as the second page table parameters corresponding to the process to be created.
[0044] Among them, the first kernel interface is a newly added kernel interface in the embodiment of the present invention, through which the keyword of the process name and the required page table size (second page table parameter) can be written into the memory storage list. Therefore, when creating a process, a fuzzy search can be performed based on the keyword to match the page table size corresponding to the process to be created. After the match is successful, the process can be created according to the corresponding page table size. It is worth mentioning that when writing the process name and the required page table size into the memory storage list, different page table sizes can be written correspondingly for different processes, thereby enabling different page table sizes to be selected when creating different processes, and there is no need to determine the page table size during kernel compilation, thereby not only improving the flexibility of page table configuration, but also helping to reduce resource waste and improve application performance.
[0045] In addition, in one embodiment of the present invention, for the CPU-level page table configuration, the correspondence between multiple CPU masks and the second page table parameters can be stored in the register through the second kernel interface; thus, in the process of determining the second page table parameters corresponding to the process to be created, the CPU mask corresponding to the process to be created can be obtained through the process descriptor, and then the second page table parameters corresponding to the CPU mask corresponding to the process to be created can be determined according to the correspondence in the register.
[0046] Among them, the second kernel interface is a kernel interface newly added in the embodiment of the present invention, and the CPU mask and the corresponding page table size (second page table parameter) can be associated and configured in the register through the newly added kernel interface. When creating a process in the kernel, the corresponding page table size can be configured according to the CPU core running the process, so as to configure the page table size at the CPU level. Exemplarily, when the fork() function is called to create a process, the corresponding CPU mask can be obtained through the process descriptor task_struct. If the second page table parameter corresponding to the CPU core is configured in the register, the process is created according to the page table size corresponding to the second page table parameter. Among them, the fork() function can create a new process by copying an existing process, and the created process is stored in a bidirectional circular linked list, which can string together the process descriptors task_struct of multiple processes. The process descriptor task_struct is the only entity that perceives the existence of the process in the Linux system, which includes all the information of the process, so the CPU mask corresponding to the process can be obtained through task_struct. In the process of running the process, according to the address information in the memory descriptor mm_struct corresponding to the process, the corresponding page table size of the process can be analyzed accordingly to find the real physical memory. It should be understood that different second page table parameters can be configured for processes on different CPU cores, so that different CPU cores use page table sizes corresponding to the second page table parameters when running processes. Among them, mm_struct describes all information for managing process address space in the Linux system.
[0047] It is worth mentioning that in the embodiment of the present invention, no matter the first page table parameter and the second page table parameter are configured to 4K or a larger value (such as 16K or 64K), the slab memory allocator and the partner allocator of the Linux system are still configured to manage the process memory in units of 4K page tables. When a larger page table is needed (such as a 16K page table or a 64K page table), memory allocation can be performed based on the ratio of the large page table to the 4K page table. Taking the 16K page table as an example, the memory allocation can be performed in the manner of 16K=4K×22. 64K and other larger page tables can also be used in this manner, which is conducive to reducing memory fragmentation and thus improving memory utilization.
[0048] In addition, CPU scheduling is performed in the Linux system, that is, switching the CPU between processes, so that the operating system runs more efficiently. In one embodiment of the present invention, after the CPU core corresponding to the process is switched in response to the switching instruction, the second page table parameters corresponding to the CPU cores before and after the switch can be determined according to the corresponding relationship between the CPU mask stored in the register and the second page table parameters. If they are not the same, the process is continued to be processed according to the second page table parameters corresponding to the CPU core before the switch. That is to say, after the process is created, even if other CPU cores take over the processing of this process, the page table size used when the process was created is still used. This avoids physical address parsing errors caused by switching page table sizes and ensures the normal operation of the process. For example, according to the corresponding relationship in the register, the second page table parameter corresponding to CPU core 1 is determined to be 4K according to CPU mask 1, and the second page table parameter corresponding to CPU core 2 is determined to be 16K according to CPU mask 2. After the process is switched from CPU core 1 to CPU core 2 for processing, the process is still processed according to the 4K page table size. That is to say, if a 4K page table is allocated according to the second page table parameter corresponding to CPU core 1 when a process is created, then even if CPU core 2 is configured with a 16K page table size, it will still use the 4K page table for parsing when taking over this process, instead of using the page table size (16K) configured for CPU core 2, to avoid address parsing errors caused by switching the page table size during process running.
[0049] Furthermore, in an embodiment of the present invention, a CPU affinity scheme is configured to avoid errors caused by process switching page table sizes. Specifically, a process is bound to multiple CPU cores, and multiple CPU cores bound to the same process correspond to the same second page table parameters. In the process of switching the CPU core corresponding to the process, the target CPU core to be switched can be determined from the multiple CPU cores bound to the process, so that the process is run through the target CPU core after the switch. As a result, the page table size corresponding to the CPU core does not change before and after the switch, and there will be no address resolution errors caused by changes in the page table size, thereby ensuring the normal operation of the process.
[0050] According to the above embodiment, it is possible to select different page table sizes when the operating system starts, select different page table sizes on different CPU cores, and select different page table sizes on different processes. Regardless of the page table size configured when the operating system starts, the page table configuration at the CPU level or the process level, after configuration, several bits in the virtual address can be used as a judgment mark for the page table size. For example, two bits of the 64-bit address are used as judgment marks for different page table sizes such as 4K, 16K or 64K. Therefore, when parsing the virtual address, after obtaining the virtual address to be converted, the target page table parameters can be parsed from the virtual address, and the target page table parameters are the page table size configured based on the page table configuration variables in the kernel, the CPU mask and / or the process identifier in the method provided by the above embodiment; then the page table is obtained according to the target page table parameters to determine the physical address corresponding to the virtual address according to the obtained page table.
[0051] Exemplarily, different page table flags are used to divide the number of bits of a 64-bit virtual address differently. For example, when a 4K page table is determined, the page table is divided into four levels: PGD (Page Global Directory), PUD (Page Upper Directory), PMD (Page Middle Directory) and PTE (Page Table), and the number of bits corresponding to PGD, PUD, PMD and PTE can be determined respectively, so that the virtual address is parsed through PGD, PUD, PMD and PTE to find the physical address corresponding to the virtual address.
[0052] In addition, after the process is created, the process has its own virtual address space, which includes code segments, data segments, and stack segments. In an embodiment of the present invention, in order to avoid the crash of the operating system due to the memory flying situation, the code segment, data segment, and stack segment included in the virtual address space can be determined when the page table is obtained, and the code segment, data segment, and stack segment are checked. When it is determined according to the check result that there is no memory flying situation, it means that the metadata in the memory has not been modified by irrelevant code, then the page table can be obtained and the corresponding physical address can be determined according to the page table. Exemplarily, it can be detected whether each segment has the memory flying situation by means of incremental checksum. For another example, since the code segment is read-only, the code will not be rewritten generally. The data segment and the heap generally store data, do not involve instructions, and generally do not have the memory flying situation. The stack area stores both data and code, which is more prone to memory flying situation than the code segment, data segment, and heap. Therefore, it can be mainly verified by checking the stack area data, such as checking the end address of the stack area to determine whether there is a memory flying situation, thereby avoiding the operating system crash caused by the metadata being modified by irrelevant code, and improving the stability of the operating system.
[0053] Reference below Figure 2 , the method for configuring the page table size when the operating system is started according to an embodiment of the present invention is described. Figure 2 As shown, the method comprises the following steps:
[0054] Step S201: converting macro definitions related to page table configuration in the kernel into variables, and configuring the first page table parameters by configuring the values of the variables.
[0055] Step S202: during the operating system startup process, the command line parameters are parsed by using the parse_early_param() function to obtain the first page table parameters.
[0056] Step S203: Initialize the memory according to the first page table parameter to configure the page table for kernel operation according to the first page table parameter.
[0057] Reference below Figure 3 , the method of configuring different page table sizes on different processes according to the embodiment of the present invention is described. Figure 3 As shown, the method comprises the following steps:
[0058] Step S301: writing the correspondence between a plurality of process identifiers and the second page table parameters into a memory storage list through the first kernel interface.
[0059] Step S302: In response to the process creation, the memory storage list is searched according to the target process identifier of the process to be created, so as to determine the second page table parameter corresponding to the target process identifier from the memory storage list.
[0060] Step S303: Create a process according to the second page table parameter corresponding to the target process identifier.
[0061] Reference below Figure 4 , the method of configuring different page table sizes on different CPUs according to the embodiment of the present invention is described. Figure 4 As shown, the method comprises the following steps:
[0062] Step S401: storing the corresponding relationship between the CPU mask and the second page table parameter in the register through the second kernel interface.
[0063] Step S402: In response to the process creation in the kernel, a CPU mask corresponding to the process to be created is obtained through the process descriptor, and a second page table parameter corresponding to the CPU mask is determined according to the corresponding relationship in the register.
[0064] Step S403: Create a process according to the second page table parameters.
[0065] Step S404: Bind the process to multiple CPU cores, where the multiple CPU cores bound to the process correspond to the same second page table parameters.
[0066] Step S405: In response to the switch instruction, determine a target CPU core to be switched from the bound multiple CPU cores, so that the target CPU core runs a process.
[0067] According to a page table configuration method of an embodiment of the present invention, it can be seen that by initializing the memory according to the first page table parameter when the operating system starts, that is, selecting the page table size when the operating system starts, there is no need to compile the kernel again or restart the machine, thereby improving the flexibility of the page table configuration. In addition, in the process of creating a kernel process, a process can be created based on the second page table parameter corresponding to the CPU and / or process identifier according to the pre-configured correspondence, thereby achieving the adjustment of the page table size during the system operation, so that different page table sizes can be used in different scenarios, and there is no need to recompile the kernel or restart the machine, thereby improving the flexibility of the page table configuration. In addition, different CPU masks and process identifiers can be configured with different second page table parameters respectively, so that the second page table parameters match the actual data processing amount, which is also conducive to improving the memory processing efficiency of applications in the operating system, thereby improving the performance of the application. In addition, the above-mentioned performance improvement belongs to the improvement at the operating system level, and the performance can be optimized without modifying the application code.
[0068] Based on the same inventive concept as the above embodiments, the embodiment of the present invention also provides a page table configuration device, such as Figure 5 As shown, the page table configuration device 500 includes: a parameter acquisition module 501, a first configuration module 502 and a second configuration module 503; wherein,
[0069] The parameter acquisition module 501 is configured to: in response to the operating system starting, acquire a first page table parameter, the first page table parameter being obtained by configuring a page table configuration variable in the kernel;
[0070] The first configuration module 502 is configured to: initialize the memory according to the first page table parameter to configure the page table of the kernel operation according to the first page table parameter;
[0071] The second configuration module 503 is configured to: in response to the process creation in the kernel, determine the second page table parameters corresponding to the process to be created according to the preconfigured correspondence relationship, so as to create the process according to the second page table parameters; the correspondence relationship indicates the second page table parameters corresponding to the CPU mask and / or process identifier.
[0072] In an embodiment of the present invention, the second configuration module 503 is further configured to: write the correspondence between multiple process identifiers and the second page table parameters into a memory storage list through the first kernel interface; search the memory storage list according to the target process identifier of the process to be created, determine the second page table parameters corresponding to the target process identifier from the memory storage list, and use the determined second page table parameters as the second page table parameters corresponding to the process to be created.
[0073] In one embodiment of the present invention, the second configuration module 503 is configured as follows: storing the correspondence between multiple CPU masks and the second page table parameters in a register through a second kernel interface; obtaining the CPU mask corresponding to the process to be created through a process descriptor; and determining the second page table parameters corresponding to the CPU mask corresponding to the process to be created based on the correspondence in the register.
[0074] In one embodiment of the present invention, the page table configuration device 500 also includes a switching module 504, which is configured to: respond to a switching instruction, switch the CPU core corresponding to the process; determine whether the second page table parameters corresponding to the CPU cores before and after the switching are the same based on the corresponding relationship in the register; if not, process the process according to the second page table parameters corresponding to the CPU core before the switching.
[0075] In one embodiment of the present invention, the switching module 504 is configured to: bind the process to multiple CPU cores, the bound multiple CPU cores correspond to the same second page table parameters; determine the target CPU core to be switched from the bound multiple CPU cores, so that the target CPU core runs the process.
[0076] In one embodiment of the present invention, the page table configuration device 500 also includes a conversion module 505, which is configured to: obtain a virtual address to be converted, parse target page table parameters from the virtual address, and the target page table parameters are configured according to the page table configuration variables, CPU mask and / or process identifier in the kernel; obtain a page table according to the target page table parameters, and determine the physical address corresponding to the virtual address according to the obtained page table.
[0077] In one embodiment of the present invention, the conversion module 505 is further configured to: determine the virtual address space corresponding to the process, and the code segment, data segment and stack segment included in the virtual address space; verify the code segment, data segment and stack segment; and obtain the page table when it is determined according to the verification result that there is no memory overflow.
[0078] According to a page table configuration device provided by the above embodiment, it can be seen that by initializing the memory according to the first page table parameter when the operating system starts, that is, selecting the page table size when the operating system starts, there is no need to compile the kernel again or restart the machine, thereby improving the flexibility of the page table configuration. In addition, in the process of creating a kernel process, a process can be created based on the second page table parameter corresponding to the CPU and / or process identifier according to the pre-configured correspondence, thereby achieving the adjustment of the page table size during the system operation, so that different page table sizes can be used in different scenarios, and there is no need to recompile the kernel or restart the machine, thereby improving the flexibility of the page table configuration. In addition, different CPU masks and process identifiers can be configured with different second page table parameters respectively, so that the second page table parameters match the actual data processing volume, which is also conducive to improving the memory processing efficiency of applications in the operating system, thereby improving the performance of the application. In addition, the above performance improvement belongs to the improvement at the operating system level, and the performance can be optimized without modifying the application code.
[0079] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0080] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0081] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0082] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.
[0083] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0084] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0085] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The described system may also be set in a processor, for example, it may be described as: a processor includes a parameter acquisition module, a first configuration module, and a second configuration module. The names of these modules do not constitute a limitation on the system itself in some cases, for example, the parameter acquisition module may also be described as a "module for acquiring page table parameters".
[0086] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: in response to the start of the operating system, obtaining a first page table parameter; the first page table parameter is obtained by configuring the page table configuration variable in the kernel; initializing the memory according to the first page table parameter to configure the page table of the kernel operation according to the first page table parameter; in response to the process creation in the kernel, determining the second page table parameter corresponding to the process to be created according to the preconfigured correspondence relationship, so as to create the process according to the second page table parameter; the correspondence relationship indicates the second page table parameter corresponding to the CPU mask and / or process identifier.
[0087] According to the technical solution of the embodiment of the present invention, by initializing the memory according to the first page table parameter when the operating system starts, that is, selecting the page table size when the operating system starts, there is no need to compile the kernel again or restart the machine, thereby improving the flexibility of the page table configuration. In addition, in the process of creating a kernel process, a process can be created based on the second page table parameter corresponding to the CPU and / or process identifier according to the pre-configured correspondence, thereby achieving the adjustment of the page table size during the operation of the system, so that different page table sizes can be used in different scenarios, and there is no need to recompile the kernel or restart the machine, thereby improving the flexibility of the page table configuration. In addition, different CPU masks and process identifiers can be configured with different second page table parameters respectively, so that the second page table parameters match the actual data processing volume, which is also conducive to improving the memory processing efficiency of applications in the operating system, thereby improving the performance of the application. In addition, the above-mentioned performance improvement belongs to the improvement at the operating system level, and the performance can be optimized without modifying the application code.
[0088] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A page table configuration method, characterized in that: include: In response to the operating system starting, obtaining a first page table parameter; The first page table parameter is obtained by configuring the page table configuration variable in the kernel; Initializing the memory according to the first page table parameter to configure the page table of the kernel operation according to the first page table parameter; In response to process creation in the kernel, second page table parameters corresponding to the process to be created are determined according to a preconfigured correspondence relationship, so as to create the process according to the second page table parameters; the correspondence relationship indicates the second page table parameters corresponding to the CPU mask and / or process identifier.
2. The method according to claim 1, characterized in that The method further comprises: writing the corresponding relationship between the plurality of process identifiers and the second page table parameters into a memory storage list through the first kernel interface; Determining the second page table parameter corresponding to the process to be created according to the preconfigured corresponding relationship includes: The memory storage list is searched according to the target process identifier of the process to be created, a second page table parameter corresponding to the target process identifier is determined from the memory storage list, and the determined second page table parameter is used as the second page table parameter corresponding to the process to be created.
3. The method according to claim 1, characterized in that: The method further comprises: storing the corresponding relationship between the plurality of CPU masks and the second page table parameters respectively in a register through a second kernel interface; Determining the second page table parameter corresponding to the process to be created according to the preconfigured corresponding relationship includes: Get the CPU mask corresponding to the process to be created through the process descriptor; According to the corresponding relationship in the register, a second page table parameter corresponding to the CPU mask corresponding to the process to be created is determined.
4. The method according to claim 3, characterized in that After creating the process, it also includes: In response to the switching instruction, switching the CPU core corresponding to the process; Determining whether the second page table parameters corresponding to the CPU cores before and after the switching are the same according to the corresponding relationship in the register; If not, the process is processed according to the second page table parameter corresponding to the CPU core before the switch.
5. The method according to claim 4, characterized in that The method further includes: binding the process to a plurality of CPU cores, wherein the bound plurality of CPU cores correspond to the same second page table parameter; The switching of the CPU core corresponding to the process includes: determining a target CPU core to be switched from the bound multiple CPU cores, so that the target CPU core runs the process.
6. The method according to any one of claims 1 to 5, characterized in that: Also includes: Get the virtual address to be converted; Parsing target page table parameters from the virtual address; The target page table parameters are configured according to page table configuration variables, CPU masks and / or process identifiers in the kernel; A page table is obtained according to the target page table parameter, so as to determine the physical address corresponding to the virtual address according to the obtained page table.
7. The method according to claim 6, characterized in that Also includes: Determine a virtual address space corresponding to the process, and a code segment, a data segment, and a stack segment included in the virtual address space; Verifying the code segment, data segment and stack segment; When it is determined according to the verification result that there is no memory overflow, the page table is obtained.
8. A page table configuration device, characterized in that: include: parameter acquisition module, a first configuration module and a second configuration module; wherein, The parameter acquisition module is configured to: in response to the operating system starting, acquire a first page table parameter; the first page table parameter is obtained by configuring a page table configuration variable in the kernel; The first configuration module is configured to: initialize the memory according to the first page table parameter to configure the page table of the kernel operation according to the first page table parameter; The second configuration module is configured to: in response to process creation in the kernel, determine the second page table parameters corresponding to the process to be created according to a preconfigured correspondence relationship, so as to create the process according to the second page table parameters; the correspondence relationship indicates the second page table parameters corresponding to the CPU mask and / or process identifier.
9. An electronic device for configuring a page table, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the page table configuration method as described in any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the page table configuration method according to any one of claims 1 to 7 is implemented.