Optimization method and device for initializing resident memory of memory file system
The kernel thread of the page table hardware access bit records page association information, sorts out statistical information about the usage status of the classified file, and releases the memory occupied by unreached files, solving the problem of initramfs memory management and achieving efficient memory optimization and management.
Patent Information
- Application Number
- CN202311502646.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-10
- Publication Date
- 2025-05-13
AI Technical Summary
The existing technology lacks the effective management of the memory usage of the initialized memory file system initramfs during the startup process and system runtime, resulting in memory tightness and difficulty in optimization.
By creating a kernel thread for listening to page table hardware access bits, recording page association information, sorting out statistical information about the usage status of the classified file, and releasing the initramfs resident memory space that is not occupied by the accessed files based on this information.
It realizes efficient management of initramfs resident memory, reduces memory consumption, improves management accuracy and efficiency, and ensures system stability.
Smart Images

Figure CN119987985A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer memory management, and in particular to an optimization method for initializing a resident memory of a memory file system. Background Art
[0002] Initial RAM File System (initramfs) is a temporary root file system used to provide a temporary root file system during the computer system startup process. It contains some necessary files and tools, such as drivers, file system tools, network configuration, etc., so that the hardware and file system can be loaded correctly when the computer system starts, and can be booted to the normal root file system.
[0003] Take the startup of an embedded system as an example. In applications, embedded systems often hope to start up in the shortest possible time to improve user experience. In some applications, there are strict time requirements for the startup time, especially in industrial, medical equipment, smart devices and other application fields. In the fast startup solution, initramfs is often used to reduce the startup time, because the complete file system can be loaded into the memory in advance, so that when loading drivers or starting applications and other key processes, it is no longer necessary to load from flash, which can greatly speed up the startup speed of the embedded system. For the use of initramfs, one way to use it is to directly use initramfs as the final file system and put all the files needed for the complete startup of the embedded system in initramfs, including drivers, applications, shared object (SO) file libraries, etc. In this case, initramfs will be kept in the memory all the time, and the files needed after the embedded system starts can also be loaded directly from the memory, which further improves the running speed of the embedded system, but initramfs will always reside in the memory, especially for small memory solutions, it is easy to cause memory shortage. Therefore, the optimization of initramfs resident memory is an important part of the embedded system fast startup solution. However, the current embedded system does not provide a function to obtain the usage of initramfs during the startup process or subsequent system operation. Which files can be deleted after the system is started? Which files can be deleted at a certain stage after the system starts to release the corresponding memory? It depends on the developers to manually match the code and all files one by one and then delete them in a targeted manner. This requires a lot of manpower and is prone to errors. Summary of the invention
[0004] The present invention provides an optimization method for initializing a memory file system resident memory, so as to improve the management capability of the initializing memory file system resident memory.
[0005] The first aspect of the present application provides an optimization method for initializing a memory file system initramfs resident in memory, the optimization method comprising: on a system side that loads initramfs,
[0006] For each page of the initramfs resident memory, a data item is created for recording the associated information of the page, wherein the associated information at least includes: access information for indicating that the page has been accessed by the processor, and file name information corresponding to the page,
[0007] Call the pre-created kernel thread for monitoring the hardware access bit of the page table to monitor the hardware access bit of the page table.
[0008] According to the monitored hardware access bit, the accessed page is determined, and the access information is recorded in the data item of the accessed page.
[0009] Get the file name information corresponding to each page and record it in the data item.
[0010] Based on the access information and file name information in all data items, all data items are sorted and classified to obtain statistical information used to characterize the usage status of each file.
[0011] Based on the statistics, release the initramfs resident memory space occupied by unaccessed files.
[0012] Preferably, the arranging and classifying of all data items to obtain statistical information for characterizing the usage status of each file includes:
[0013] For each file name in all data items,
[0014] Based on the access information of all data items, determine the first usage information and the second usage information of the file corresponding to the file name,
[0015] in,
[0016] The first usage information is used to represent the overall usage level of the file corresponding to the file name.
[0017] The second usage information is used to indicate the usage status of the file content in the file corresponding to the file name.
[0018] The file name information corresponds to the first usage information and the second usage information one by one;
[0019] Preferably, releasing the initramfs resident memory space occupied by unaccessed files based on the statistical information includes:
[0020] According to the first usage information corresponding to each file name, an optimization strategy corresponding to the first usage information is determined,
[0021] According to the second usage information corresponding to each file name, the optimizable initramfs resident memory space is determined.
[0022] Preferably, the statistical information also includes: the total size of the files corresponding to each file name,
[0023] Preferably, the first usage information includes usage rate information, where the usage rate is: the proportion of the size of the accessed file in the file corresponding to the file name to the total size of the file corresponding to the file name;
[0024] Preferably, the second usage information includes: accessed mark information and non-accessed mark information of each page where the file corresponding to the file name is located;
[0025] Preferably, determining the optimization strategy corresponding to the first usage information according to the first usage information corresponding to each file name, and determining the optimizable initramfs resident memory space according to the second usage information corresponding to each file name, comprises:
[0026] For each file name in the statistics,
[0027] When the usage rate corresponding to the file name is less than or equal to the set lower usage rate threshold, check whether the file corresponding to the file name is needed. If not needed, directly remove it from the initramfs resident memory according to the second usage information corresponding to the file name.
[0028] If the usage rate of the file corresponding to the file name is greater than or equal to the set upper usage rate threshold, give up releasing the occupied initramfs resident memory space, or
[0029] When the usage rate corresponding to the file name is between the upper usage rate threshold and the lower usage rate threshold, the page where the part of the file content that has not been accessed is located is obtained according to the second usage information corresponding to the file name, and the initramfs resident memory space occupied by the part of the file content that has not been accessed is released.
[0030] The upper usage rate threshold is greater than the lower usage rate threshold.
[0031] Preferably, the acquiring, according to the second usage information corresponding to the file name, the page where the part of the file content that has not been accessed is located, and releasing the initramfs resident memory space occupied by the part of the file content that has not been accessed, comprises:
[0032] Determine the physical address offset corresponding to the unaccessed file content according to the second usage information,
[0033] Read the binary file of the unaccessed file content according to the physical address offset,
[0034] Decompile the read binary file to obtain the code corresponding to the binary file.
[0035] Determine the position of the code in the code file, trim the code, compile the code file retained after trimming to obtain an update binary file, and update the update binary file to the initramfs resident memory space.
[0036] Preferably, the optimization method is performed during the system startup process of loading initramfs, and further comprises:
[0037] Get initramfs at startup and store it in initramfs resident memory,
[0038] Creating the memory kernel thread;
[0039] Preferably, the calling of a pre-created kernel thread for monitoring a page table hardware access bit comprises:
[0040] During the startup process, the kernel thread is periodically called according to a set first time interval until the startup process ends.
[0041] Preferably, the optimization method is executed during the operation of the system loading initramfs, and further comprises: creating the memory kernel thread at any time during the operation,
[0042] The calling of a pre-created kernel thread for monitoring a page table hardware access bit includes:
[0043] During the running process, within the set statistical time, according to the set second time interval, the kernel thread is periodically called until the statistical time ends.
[0044] Preferably, the optimization method is performed during the system startup process and the operation process of loading initramfs, and further comprises:
[0045] Get initramfs at startup and store it in initramfs resident memory,
[0046] During the startup process, the memory kernel thread is created;
[0047] Preferably, the calling of a pre-created kernel thread for monitoring a page table hardware access bit comprises:
[0048] During the startup process, the kernel thread is periodically called according to the set first time interval until the startup process is completed.
[0049] During the running process, within the set statistical time, according to the set second time interval, the kernel thread created during the startup process is periodically called until the statistical time ends;
[0050] Preferably, releasing the initramfs resident memory space occupied by unaccessed files based on the statistical information includes:
[0051] Based on the statistical information obtained during the startup process and the statistical information obtained during the running process, determine the file usage status of the startup process and the running process files,
[0052] For files that are only used during the boot process but not during the running process, they are directly removed from the initramfs resident memory at any time after the boot process is completed.
[0053] For files that are not used during the startup process and files that are not used during the running process, memory optimization is performed during the current running process.
[0054] Preferably, the lower usage rate threshold is a first usage rate threshold during startup and a third usage rate threshold during operation.
[0055] The upper usage rate threshold is the second usage rate threshold during the startup process and the fourth usage rate threshold during the operation process;
[0056] The usage rate threshold is determined according to the ratio of the total size of the file corresponding to the file name to the file size of the entire initramfs and the usage rate critical point.
[0057] A second aspect of the present application provides an optimization device for initializing a memory file system initramfs resident memory, the device comprising:
[0058] The first creation module is used to create a data item for recording the associated information of each page of the initramfs resident memory, wherein the associated information at least includes: access information for indicating that the page has been accessed by the processor, and file name information corresponding to the page,
[0059] The second creation module is used to create a kernel thread for monitoring the hardware access bit of the page table.
[0060] The monitoring module is used to call the pre-created kernel thread for monitoring the hardware access bit of the page table, and monitor the hardware access bit of the page table.
[0061] The recording module is used to determine the visited pages according to the monitored hardware access bits, and record the access information in the data item of the visited pages, obtain the file name information corresponding to each page, and record it in the data item,
[0062] The statistics module is used to sort and classify all data items based on the access information and file name information in all data items to obtain statistical information used to characterize the usage status of each file.
[0063] An optimization module that is used to release the initramfs resident memory space occupied by unaccessed files based on statistical information.
[0064] A third aspect of the present application provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the methods for optimizing the initialization memory file system initramfs resident memory are implemented.
[0065] The embodiment of the present application provides an optimization method for initializing the resident memory of the memory file system, which monitors the access of the page through the kernel thread for monitoring the hardware access bit of the page table, and records the associated information of the resident memory page through the created data item, thereby providing an information source for the statistics of the usage status of each file in initramfs, and releasing the initramfs resident memory space occupied by the unaccessed files through the statistical information used to characterize the usage status of each file, which is conducive to reducing memory consumption and improving the accuracy of the resident memory management of the initialization memory file system. The optimization method of the present application has the characteristics of high flexibility and strong real-time performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 A flowchart of an optimization method for initializing a memory file system resident in memory according to an embodiment of the present application.
[0067] Figure 2 A flowchart of optimizing initramfs resident memory during the startup of an embedded system according to an embodiment of the present application.
[0068] Figure 3 A schematic diagram of the relationship between memory, pages, and data items.
[0069] Figure 4 A flowchart of optimizing initramfs resident memory during the operation of an embedded system.
[0070] Figure 5 A schematic diagram of an optimization device for initializing a memory file system resident in memory according to an embodiment of the present application.
[0071] Figure 6Another schematic diagram of an optimization device for initializing a memory file system resident in memory according to an embodiment of the present application. DETAILED DESCRIPTION
[0072] In order to make the objectives, technical means and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings.
[0073] The present application provides an optimization method for initializing the resident memory of a memory file system, which obtains the usage status of each file in initramfs by creating a kernel thread for monitoring the hardware access bit of the page table to monitor the pages accessed by the processor, and adopts different optimization strategies to optimize the resident memory of initramfs according to the usage status of each file.
[0074] See also Figure 1 As shown, Figure 1 A flowchart of an optimization method for initializing a memory file system resident in memory according to an embodiment of the present application is provided. The method includes: on the system side of loading initramfs, as an example, the system includes an embedded system, a computer system, such as an Android system supported by various terminals, etc.
[0075] Step 11, create a data item for recording the associated information of each page of the initramfs resident memory,
[0076] The associated information at least includes: access information used to indicate that the page has been accessed by the processor, and file name information corresponding to the page.
[0077] Step 12, calling a pre-created kernel thread for monitoring the hardware access bit of the page table, monitoring the hardware access bit of the page table,
[0078] As an example, a kernel thread may be created during system startup when initramfs is loaded, may be created during operation, or may be created during startup and used during operation.
[0079] As an example, for the call of the kernel thread, during the startup process, the kernel thread can be periodically called according to a set first time interval, such as a ms-level time interval, until the startup process ends; during the running process, the kernel thread can be periodically called according to a set second time interval within a set statistical time until the statistical time ends; during the startup process, the kernel thread can be periodically called according to a set first time interval until the startup process ends, and during the running process, the kernel thread created in the startup process can be periodically called according to a set second time interval, such as a ms-level time interval, within a set statistical time until the statistical time ends.
[0080] Step 13, according to the monitored hardware access bit, determine the accessed page, and record the access information into the data item of the accessed page,
[0081] Step 14, obtain the file name information corresponding to each page and record it in the data item.
[0082] As an example, the file name information corresponding to each page may be obtained at the end of each periodic monitoring process, or the file name information corresponding to each page may be obtained at the end of all periodic monitoring processes.
[0083] Step 15: sort and classify all data items based on the access information and file name information in all data items to obtain statistical information for characterizing the usage status of each file.
[0084] As an example, statistics can be obtained as follows:
[0085] For each file name in all data items,
[0086] Based on the access information of all data items, determine the first usage information and the second usage information of the file corresponding to the file name,
[0087] Furthermore, the total size of the file corresponding to the file name can also be determined.
[0088] in,
[0089] The first usage information is used to characterize the overall usage level of the file corresponding to the file name, for example, usage rate information used to represent the proportion of the size of the accessed file in the file corresponding to the file name to the total size of the file corresponding to the file name.
[0090] The second usage information is used to characterize the usage status of the file content in the file corresponding to the file name, for example, the access mark information and the non-access mark information of each page where the file corresponding to the file name is located.
[0091] The file name information corresponds one-to-one to the first usage information and the second usage information.
[0092] Step 16: Based on the statistical information, release the initramfs resident memory space occupied by the unaccessed files.
[0093] As an example, based on the first usage information corresponding to each file name, an optimization strategy corresponding to the first usage information is determined, and based on the second usage information corresponding to each file name, an optimizable initramfs resident memory space is determined.
[0094] The optimization strategy processes the file differently depending on the first usage information.
[0095] For example, for each file name in the statistics,
[0096] In the case where the usage rate of the file corresponding to the file name is less than or equal to the set lower usage rate threshold, manually check whether the file corresponding to the file name is needed, or, according to steps 12 to 15, check whether it is needed by monitoring the statistical information obtained by accessing the memory pages during the complete use of each function of each application installed in the system. If it is not needed, determine the memory page where the file corresponding to the file name is located based on the second usage information corresponding to the file name, that is, based on the unaccessed mark information in the second usage information, and directly remove the file in the memory page in the initramfs resident memory.
[0097] If the usage rate of the file corresponding to the file name is greater than or equal to the set upper usage rate threshold, the initramfs resident memory space occupied will be abandoned.
[0098] When the usage rate of the file corresponding to the file name is between the upper usage rate threshold and the lower usage rate threshold, the page where each unaccessed file content is located is obtained according to the second usage information corresponding to the file name, and the initramfs resident memory space occupied by each unaccessed file content is released.
[0099] Among them, the upper usage threshold is greater than the lower usage threshold. The usage threshold is determined according to the proportion of the total size of the file corresponding to the file name to the file size of the entire initramfs and the set usage critical point. For example, the usage critical point is set to 75%, and the usage critical point can be increased as the optimization space and usage increase.
[0100] As an example, for some unaccessed files, the memory space is released in the following way:
[0101] Determine the physical address offset corresponding to the unaccessed file content according to the second usage information,
[0102] Read the binary file of the unaccessed file content according to the physical address offset,
[0103] Decompile the read binary file to obtain the code corresponding to the binary file.
[0104] Determine the position of the code in the code file, trim the code, compile the code file retained after trimming to obtain an update binary file, and update the update binary file to the initramfs resident memory space.
[0105] The embodiment of the present application can obtain the usage status of each file in initramfs at any desired stage, which is conducive to improving the accuracy of memory optimization, improving the efficiency of optimization, and ensuring the stability of system startup and operation while freeing up memory space.
[0106] To facilitate understanding of the present application, an embedded system is used as an example for explanation. It should be understood that the present application is not limited to embedded systems, and any system that loads initramfs is applicable.
[0107] See also Figure 2 As shown, Figure 2 This is a flow chart of optimizing initramfs resident memory during the startup of an embedded system according to an embodiment of the present application. The method includes:
[0108] Step 21, when the embedded system starts to boot, it reads initramfs, decompresses initramfs and stores it in memory, and records the corresponding memory area address to obtain the initramfs resident memory area;
[0109] Step 22, recording each page in the initramfs resident memory area, and creating a data item for each page for recording the associated information of the page, wherein the associated information includes: access information for indicating that the page has been accessed by the CPU, and file name information corresponding to the page;
[0110] As an example, the size of a page is 4KB, and each data item has the same data structure.
[0111] Step 23, creating a kernel thread for monitoring the hardware access bit of the page table, and calling the kernel thread at every set first time interval to monitor the hardware access bit of the page table to determine whether the CPU has accessed the page corresponding to the access bit, that is, whether the page has been read and / or written. If the CPU has accessed the page, the data item corresponding to the page is recorded to indicate that the page has been accessed by the CPU.
[0112] For example, when creating a data item, the associated information in each data item is initialized, and when the page is accessed by the CPU, the access information in each data item is modified.
[0113] The first time interval may be set according to the degree of memory optimization required during the startup process. The smaller the first time interval is, the higher the monitoring frequency is, and the higher the degree of memory optimization is.
[0114] Step 24, when the embedded system is started, stop monitoring the access to the initramfs resident memory, use the file system (filesystem) related method to parse the file name information corresponding to each page in the initramfs resident memory area, and record the file name information in the data item.
[0115] See also Figure 3 As shown, Figure 3 A schematic diagram of the relationship between memory, pages, and data items.
[0116] Step 25, sorting and classifying the data item information corresponding to each page, the sorted and classified statistical information includes the file name, the total size of the file corresponding to the file name, the usage rate of the file corresponding to the file name (first usage information), and the usage information of each file content in the file corresponding to the file name (second usage information), and the information is saved in the designated file;
[0117] As an example, the usage rate of a file is represented by the percentage of the size of the file accessed corresponding to the file name to the total size of the file corresponding to the file name;
[0118] The usage information of each file content is described with pages as the smallest granularity. When a page is accessed, the page is recorded. For example, if the page corresponding to a certain file name is 0 to N, if page 0 has been accessed, then page 0 is marked as accessed. If page 1 has not been accessed, then page 1 is marked as not accessed. In this way, developers can clearly know which files have been used and which have not been used during the startup phase through the sorted and classified statistical information, and which content in the used files has been used and which content has not been used, so as to carry out targeted optimization;
[0119] As shown in Table 1, Table 1 is a schematic diagram of statistical information. In the table, + indicates that the corresponding page has been visited, and - indicates that the corresponding page has not been visited.
[0120] Table 1
[0121] file name File size Utilization Usage information of the file contents File0 XX XX +++++++++++++------+++++++++++++ File1 XX 0 ---------------------------------- File2 XX 100 ++++++++++ File3 XX XX +++++++-----+++++----+++++------- … … … … …
[0122] Step 26, based on the sorted and classified statistical information, according to different usage rates, an optimization strategy corresponding to the usage rate is adopted to optimize the initramfs resident memory.
[0123] As an example,
[0124] If the usage rate is equal to the first usage rate threshold, for example, the usage rate of File1 in the table is 0%, then check whether the file is used during the complete use of each application and each function installed by the system. If not, directly remove the file from the initramfs resident memory;
[0125] If the usage rate is equal to the second usage rate threshold, for example, the usage rate of File2 in the table is 100%, it means that all the contents of the file have been used and there is no room for optimization;
[0126] If the usage rate is between the first usage rate threshold and the second usage rate threshold, where the first usage rate threshold is the lower usage rate threshold and the second usage rate threshold is the upper usage rate threshold, for example, the usage rate of File3 in the table is between 0-100%, it means that part of the file is used. You can combine the code to determine whether there is room for optimization of the unused content.
[0127] Taking the support of Linux operating system as an example, since what is stored in the memory is an executable binary bin file, which is generated by calling the so file in the lib library, and for some file contents that have not been accessed, the physical address offset corresponding to the file contents that have not been accessed in the memory is determined according to the usage information of the file contents, the binary bin file of the file contents that have not been accessed is read according to the physical address offset, the read binary bin file is decompiled, and the position of the code in the code file is determined, that is, the specific number of lines of the code in the code file is determined, the code is trimmed based on the position of the code to remove the code, and the code file retained after trimming is recompiled to obtain an updated binary bin file, and the updated binary bin file is updated to the initramfs resident memory, so that the files that can be optimized can be found quickly, thereby reducing the memory consumption of the system.
[0128] As an example, to facilitate system reliability, the code file retained after trimming can be saved as the optimized file, and the code file before trimming can be saved at the same time as the pre-optimized file. The optimized file can be directly loaded at the next startup, and the pre-optimized file can be used as a backup when the application installed in the system or its function needs to use the pre-optimized file. For example, when the application itself or one of its functions is updated or upgraded, resulting in changes in the use of the file, the pre-optimized file needs to be used.
[0129] As an example, the usage threshold may be determined based on the proportion of the total size of the file corresponding to the file name in the entire initramfs file size and the usage critical point, so that different file names correspond to different usage thresholds.
[0130] See also Figure 4 As shown, Figure 4A flowchart of optimizing initramfs resident memory during the operation of an embedded system. The method includes:
[0131] Step 41, during the operation of the embedded system, within the set statistical time, at every set second time interval, the kernel thread for monitoring the page table hardware access bit is called to start the usage statistics of the files in the initfamfs resident memory. This step is the same as step 23.
[0132] Kernel threads can be created during the startup process or at any time during the running process.
[0133] The second time interval can be set according to the degree of memory optimization required during operation. The smaller the second time interval is, the higher the monitoring frequency is, and the higher the degree of memory optimization is.
[0134] Step 42, when the statistical time ends, stop monitoring the access to the initramfs resident memory, use the file system (filesystem) related method to parse the file name information corresponding to each page in the initramfs resident memory area, and record the file name information in the data item;
[0135] The data items may be created during the startup process or at any time during the running process.
[0136] Step 43, sorting and classifying the data item information corresponding to each page, the sorted and classified statistical information includes the file name, the total size of the file corresponding to the file name, the usage rate of the file corresponding to the file name, and the usage information of each file content in the file corresponding to the file name, and the information is saved in the designated file;
[0137] It should be understood that when both the startup process and the running process obtain statistical information, the statistical information is saved to different designated files. For example, the statistical information obtained by the startup process is saved to a first designated file, and the statistical information obtained by the running process is saved to a second designated file.
[0138] Step 44, based on the sorted and classified statistical information and according to different usage rates, an optimization strategy corresponding to the usage rate is adopted to optimize the initramfs resident memory.
[0139] As an example,
[0140] If the usage rate is less than or equal to the third usage rate threshold, check whether the file is used. If not, directly remove the file from the initramfs resident memory.
[0141] If the usage rate is greater than or equal to the fourth usage rate threshold, it means that the content of the file has been used and there is no room for optimization;
[0142] If the usage rate is between the third usage rate threshold and the fourth usage rate threshold, where the third usage rate threshold is used as the lower usage rate threshold and the fourth usage rate threshold is used as the upper usage rate threshold, it means that part of the content of the file is used, and it can be combined with the code to determine whether there is room for optimization of the unused part of the content. It should be understood that the third usage rate threshold can be the same as or different from the first usage rate threshold, and similarly, the fourth usage rate threshold can be the same as or different from the second usage rate threshold, which can be determined specifically according to the required degree of memory optimization.
[0143] As an example, according to the statistical information obtained during the startup process and the statistical information during the operation process, it can be found that some files are only used during the startup process, and will no longer be used during the operation process. Then, at any time after the completion of the startup process, the files in the memory page corresponding to the file names used only during the startup process can be dynamically deleted directly from the initramfs resident memory, thereby releasing memory space; if it is found that the files are not used during the startup process and the operation process, then the optimization is performed according to step 44 during the current operation process. In an application system, the embodiment of the present application successfully excavated 1.76MB of memory optimization space, and the total size of the initramfs resident memory of the application system was about 7MB, with an optimization rate of up to 25%.
[0144] See also Figure 5 As shown, Figure 5 A schematic diagram of an optimization device for initializing a memory file system resident in memory according to an embodiment of the present application. The device includes:
[0145] The first creation module is used to create a data item for recording the associated information of each page of the initramfs resident memory, wherein the associated information at least includes: access information for indicating that the page has been accessed by the processor, and file name information corresponding to the page,
[0146] The second creation module is used to create a kernel thread for monitoring the hardware access bit of the page table.
[0147] The monitoring module is used to call the pre-created kernel thread for monitoring the hardware access bit of the page table, and monitor the hardware access bit of the page table.
[0148] The recording module is used to determine the visited pages according to the monitored hardware access bits, and record the access information in the data item of the visited pages, obtain the file name information corresponding to each page, and record it in the data item,
[0149] The statistics module is used to sort and classify all data items based on the access information and file name information in all data items to obtain statistical information used to characterize the usage status of each file.
[0150] An optimization module that is used to release the initramfs resident memory space occupied by unaccessed files based on statistical information.
[0151] See also Figure 6 As shown, Figure 6 Another schematic diagram of an optimization device for initializing a memory file system resident in memory according to an embodiment of the present application. The device includes a memory and a processor, the memory stores a computer program, and the processor is configured to execute the computer program to implement the steps of the optimization method for initializing a memory file system resident in memory according to an embodiment of the present application.
[0152] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0153] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0154] An embodiment of the present invention further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the optimization method steps of initializing a memory file system resident in the memory are implemented.
[0155] As for the apparatus / network-side device / storage medium embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0156] In this article, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article 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, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0157] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for optimizing the initialization of the initramfs resident memory, characterized in that: The optimization method includes: on the system side of loading initramfs, For each page of the initramfs resident memory, a data item is created for recording the associated information of the page, wherein the associated information at least includes: access information for indicating that the page has been accessed by the processor, and file name information corresponding to the page, Call the pre-created kernel thread for monitoring the hardware access bit of the page table to monitor the hardware access bit of the page table. According to the monitored hardware access bit, the accessed page is determined, and the access information is recorded in the data item of the accessed page. Get the file name information corresponding to each page and record it in the data item. Based on the access information and file name information in all data items, all data items are sorted and classified to obtain statistical information used to characterize the usage status of each file. Based on the statistics, release the initramfs resident memory space occupied by unaccessed files.
2. The optimization method according to claim 1, characterized in that: The statistical information used to characterize the usage status of each file is obtained by arranging and classifying all data items, including: For each file name in all data items, Based on the access information of all data items, determine the first usage information and the second usage information of the file corresponding to the file name, in, The first usage information is used to represent the overall usage level of the file corresponding to the file name. The second usage information is used to indicate the usage status of the file content in the file corresponding to the file name. The file name information corresponds to the first usage information and the second usage information one by one; The releasing of the initramfs resident memory space occupied by the unaccessed files based on the statistical information includes: According to the first usage information corresponding to each file name, an optimization strategy corresponding to the first usage information is determined, According to the second usage information corresponding to each file name, the optimizable initramfs resident memory space is determined.
3. The optimization method according to claim 2, characterized in that: The statistical information also includes: the total size of the files corresponding to each file name, The first usage information includes usage rate information, where the usage rate is: the ratio of the size of the accessed file in the file corresponding to the file name to the total size of the file corresponding to the file name; The second usage information includes: accessed mark information and non-accessed mark information of each page where the file corresponding to the file name is located; The step of determining an optimization strategy corresponding to the first usage information according to the first usage information corresponding to each file name, and determining an optimizable initramfs resident memory space according to the second usage information corresponding to each file name, includes: For each file name in the statistics, When the usage rate corresponding to the file name is less than or equal to the set lower usage rate threshold, check whether the file corresponding to the file name is needed. If not needed, directly remove it from the initramfs resident memory according to the second usage information corresponding to the file name. If the usage rate of the file corresponding to the file name is greater than or equal to the set upper usage rate threshold, give up releasing the occupied initramfs resident memory space, or When the usage rate corresponding to the file name is between the upper usage rate threshold and the lower usage rate threshold, the page where the part of the file content that has not been accessed is located is obtained according to the second usage information corresponding to the file name, and the initramfs resident memory space occupied by the part of the file content that has not been accessed is released. The upper usage rate threshold is greater than the lower usage rate threshold.
4. The optimization method according to claim 3, characterized in that: The step of obtaining a page where a portion of the file content that has not been accessed is located according to the second usage information corresponding to the file name, and releasing the initramfs resident memory space occupied by the portion of the file content that has not been accessed includes: Determine the physical address offset corresponding to the unaccessed file content according to the second usage information, Read the binary file of the unaccessed file content according to the physical address offset, Decompile the read binary file to obtain the code corresponding to the binary file. Determine the position of the code in the code file, trim the code, compile the code file retained after trimming to obtain an update binary file, and update the update binary file to the initramfs resident memory space.
5. The optimization method according to claim 1, characterized in that: The optimization method is performed during the system startup process of loading initramfs, and further comprises: Get initramfs at startup and store it in initramfs resident memory, Creating the memory kernel thread; The calling of a pre-created kernel thread for monitoring a page table hardware access bit includes: During the startup process, the kernel thread is periodically called according to a set first time interval until the startup process ends.
6. The optimization method according to claim 1, characterized in that: The optimization method is executed during the operation of the system loading initramfs, and further comprises: creating the memory kernel thread at any time during the operation, The calling of a pre-created kernel thread for monitoring a page table hardware access bit includes: During the running process, within the set statistical time, according to the set second time interval, the kernel thread is periodically called until the statistical time ends.
7. The optimization method according to claim 1, characterized in that: The optimization method is performed during the system startup process and the operation process of loading initramfs, and further includes: Get initramfs at startup and store it in initramfs resident memory, During the startup process, the memory kernel thread is created; The calling of a pre-created kernel thread for monitoring a page table hardware access bit includes: During the startup process, the kernel thread is periodically called according to the set first time interval until the startup process is completed. During the running process, within the set statistical time, according to the set second time interval, the kernel thread created during the startup process is periodically called until the statistical time ends; The releasing of the initramfs resident memory space occupied by the unaccessed files based on the statistical information includes: Based on the statistical information obtained during the startup process and the statistical information obtained during the running process, determine the file usage status of the startup process and the running process files, For files that are only used during the boot process and not during the running process, remove them directly from the initramfs resident memory at any time after the boot process is completed, or For files that are not used during the startup process and files that are not used during the running process, memory optimization is performed during the current running process.
8. The optimization method according to claim 3, characterized in that: The lower usage rate threshold is the first usage rate threshold during the startup process and the third usage rate threshold during the operation process. The upper usage rate threshold is the second usage rate threshold during the startup process and the fourth usage rate threshold during the operation process; The usage rate threshold is determined according to the ratio of the total size of the file corresponding to the file name to the file size of the entire initramfs and the usage rate critical point.
9. An optimization device for initializing a memory file system initramfs resident memory, characterized in that: The device includes: The first creation module is used to create a data item for recording the associated information of each page of the initramfs resident memory, wherein the associated information at least includes: access information for indicating that the page has been accessed by the processor, and file name information corresponding to the page, The second creation module is used to create a kernel thread for monitoring the hardware access bit of the page table. The monitoring module is used to call the pre-created kernel thread for monitoring the hardware access bit of the page table, and monitor the hardware access bit of the page table. The recording module is used to determine the visited pages according to the monitored hardware access bits, and record the access information in the data item of the visited pages, obtain the file name information corresponding to each page, and record it in the data item, The statistics module is used to sort and classify all data items based on the access information and file name information in all data items to obtain statistical information used to characterize the usage status of each file. An optimization module that is used to release the initramfs resident memory space occupied by unaccessed files based on statistical information.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, which, when executed by a processor, implements the steps of the method for optimizing the resident memory of the initialized memory file system initramfs as claimed in any one of claims 1 to 8.