A method and device for realizing dynamic and refined memory merging management of operating system

By designing kernel modules and user-mode daemons in the operating system to dynamically manage memory merging, the problem of insufficient memory resource utilization in KSM technology is solved, and memory merging efficiency and system performance are improved.

CN118672791BActive Publication Date: 2024-10-29SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411156483.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-22
Publication Date
2024-10-29
Estimated Expiration
2044-08-22

AI Technical Summary

Technical Problem

The existing KSM memory merging technology has problems of complex operation and low efficiency in terms of flexible and convenient use and dynamic and fine-grained management of memory, resulting in insufficient utilization of memory resources.

Method used

Design the kernel module and user-mode daemon process to implement process-level memory merger management through the proc file system, dynamically adjust the overall system and process-level memory merger parameters and status, automatically start or shut down the memory merger mechanism based on the memory load threshold, and based on the free memory situation Adjust the scan range and waiting time between cycles.

Benefits of technology

It improves memory utilization and system performance, reduces the overall system overhead, and achieves more efficient and convenient memory consolidation management. It is suitable for Xinchuang operating system environment based on Linux.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118672791B_ABST
    Figure CN118672791B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for realizing dynamic and refined memory merging management of an operating system, and relates to the field of memory management technology. In view of the problems of complex operation and low efficiency in the existing KSM memory merging technology, the following scheme is adopted: a kernel module is designed to create and monitor files under the proc file system, and the functions of adding, deleting, modifying and checking process-level memory merging are realized by reading and writing the files; a user-mode daemon is designed to dynamically adjust the overall memory merging parameters of the system and the process-level memory merging state. By realizing a new kernel module and a corresponding user-mode daemon, the present invention can more efficiently, conveniently, dynamically and finely manage the memory merging mechanism of the operating system, thereby improving memory utilization and system performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of memory management, and in particular to a method and a device for realizing dynamic and refined memory merging management of an operating system. Background Art

[0002] In modern operating systems, multiple processes run simultaneously, and each process needs to allocate a certain amount of memory space to store its code and data. However, many processes may use the same or similar data, which leads to a waste of memory resources. This problem is more prominent in a virtualized environment. Multiple virtual machines may usually run the same operating system and the same basic applications, resulting in a large number of duplicate memory pages. Merging these memory pages and using Copy On Write to manage the merged memory when modifying the page can save a lot of memory resources.

[0003] In recent years, some kernel-based memory merging technologies, such as Kernel SamepageMerging (KSM) in the Linux kernel, have solved this problem by scanning and merging identical memory pages. However, KSM memory merging technology has problems such as complex operation and low efficiency in terms of flexibility and convenience in use and dynamic and fine management of memory. Summary of the invention

[0004] The existing KSM memory merging technology relies on the user-mode daemon to actively call the madvise or prctl system call to inform the kernel which memory can be scanned and attempted to be merged. This method requires developers to perform additional coding work in the application and may result in missing some memory areas and fail to fully utilize memory resources. Based on this, the present invention proposes a method and device for realizing dynamic and refined operating system memory merging management to efficiently, conveniently, dynamically and finely manage the operating system memory merging mechanism, thereby improving memory utilization and system performance.

[0005] In a first aspect, the present invention provides a method for implementing dynamic and refined operating system memory merging management. The technical solution adopted to solve the above technical problem is as follows:

[0006] A method for implementing dynamic and refined operating system memory merging management comprises the following steps:

[0007] Design a kernel module to create and monitor files under the proc file system, and implement the add, delete, modify and query functions of process-level memory merging by reading and writing the files;

[0008] Design a user-mode daemon to dynamically adjust the system's overall memory merging parameters and process-level memory merging status.

[0009] Optionally, the specific process of designing a kernel module is as follows:

[0010] In the initialization function of the kernel module, create a ksm_proc folder under the proc file system, and create ksm_process_pid_control file and ksm_process_run file in the ksm_proc folder for communication between the user-mode daemon and the kernel module;

[0011] Register the read and write functions of the corresponding file in the kernel module. The registered functions are called when the user writes or reads the file. At the same time, use the copy_from_user and copy_to_user functions to transfer data between user space and kernel space.

[0012] In the function corresponding to the file writing operation, the detection and processing of whether the input content identifies the process id is legal and whether it is a reentry operation are implemented. If the input pid is a positive integer, the function of enabling the corresponding process memory merging is implemented. If the input pid is a negative integer, the function of disabling the corresponding process memory merging is implemented.

[0013] In the function corresponding to the file reading operation, the function of processing and returning the process ID list is implemented according to the process list with enabled memory merging saved in the current kernel space and the current existence status of the process.

[0014] Optionally, dynamically adjust the overall system memory merging parameters through the user-mode daemon. The specific implementation process is as follows:

[0015] Start the user-mode daemon to periodically scan and record the overall system memory load;

[0016] Based on the preset threshold of memory load, determine whether to start the operating system memory merging mechanism:

[0017] a1) When the memory load does not exceed the preset threshold M, the operating system memory merging mechanism is not started;

[0018] a2) When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started;

[0019] After the operating system memory merging mechanism is started, the user-mode daemon continues to monitor the amount of free memory:

[0020] b1) If the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened.

[0021] b2) If the free memory is continuously higher than the preset threshold value N, the scanning range of each cycle is reduced and the waiting time between cycles is extended.

[0022] Preferably, after the operating system memory merging mechanism is started, when the amount of free memory continues to be monitored through the user-mode daemon process, the historical data of the memory merging status of the process within the time window is recorded, wherein the scope of the scanned process is all user-mode daemons of the system or specified by preset keywords.

[0023] Optionally, the process-level memory merging state can be dynamically adjusted through a user-mode daemon. The specific implementation process is as follows:

[0024] Start the user-mode daemon process to periodically scan and record the overall system memory load and the memory usage of each process;

[0025] The user-mode daemon obtains the system's memory usage data by reading the proc file system or calling the corresponding API;

[0026] When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started to dynamically adjust the memory merging parameters:

[0027] When the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened. At the same time, the memory merging efficiency within the time window of each scanned process is calculated, and all scanned processes with merging efficiency higher than the preset threshold value P are added to the memory merging of the operating system, where the memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process;

[0028] When the free memory continues to be higher than the preset threshold N, the scanning range of each cycle is reduced and the waiting time between cycles is extended. At the same time, the memory merging efficiency within the time window of each scanned process is calculated. If it is higher than the preset threshold P and lower than the preset threshold Q, the process is temporarily removed from the operating system's memory merging mechanism. The memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process.

[0029] In a second aspect, the present invention provides a device for implementing dynamic and refined operating system memory merging management. The technical solution adopted to solve the above technical problem is as follows:

[0030] A device for implementing dynamic and refined operating system memory merging management includes a kernel design part and a process design part, wherein:

[0031] A kernel module is designed through the kernel design part, and the kernel module is used to create and monitor files under the proc file system, and the functions of adding, deleting, modifying and checking the process-level memory merge are realized by reading and writing the files;

[0032] A user-mode daemon is designed through the process design part, and the user-mode daemon is used to dynamically adjust the system's overall memory merging parameters and process-level memory merging status.

[0033] Optionally, the specific process of designing a kernel module through the kernel design part is as follows:

[0034] In the initialization function of the kernel module, create a ksm_proc folder under the proc file system, and create ksm_process_pid_control file and ksm_process_run file in the ksm_proc folder for communication between the user-mode daemon and the kernel module;

[0035] Register the read and write functions of the corresponding file in the kernel module. The registered functions are called when the user writes or reads the file. At the same time, use the copy_from_user and copy_to_user functions to transfer data between user space and kernel space.

[0036] In the function corresponding to the file writing operation, the detection and processing of whether the input content identifies the process id is legal and whether it is a reentry operation are implemented. If the input pid is a positive integer, the function of enabling the corresponding process memory merging is implemented. If the input pid is a negative integer, the function of disabling the corresponding process memory merging is implemented.

[0037] In the function corresponding to the file reading operation, the function of processing and returning the process ID list is implemented according to the process list with enabled memory merging saved in the current kernel space and the current existence status of the process.

[0038] Optionally, a user-mode daemon is designed through the process design part, and the user-mode daemon is used to dynamically adjust the overall memory merging parameters of the system. The specific implementation process is as follows:

[0039] Start the user-mode daemon to periodically scan and record the overall system memory load;

[0040] Based on the preset threshold of memory load, determine whether to start the operating system memory merging mechanism:

[0041] a1) When the memory load does not exceed the preset threshold M, the operating system memory merging mechanism is not started;

[0042] a2) When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started;

[0043] After the operating system memory merging mechanism is started, the user-mode daemon continues to monitor the amount of free memory:

[0044] b1) If the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened.

[0045] b2) If the free memory is continuously higher than the preset threshold value N, the scanning range of each cycle is reduced and the waiting time between cycles is extended.

[0046] Preferably, after the operating system memory merging mechanism is started, when the amount of free memory continues to be monitored through the user-mode daemon process, the historical data of the memory merging status of the process within the time window is recorded, wherein the scope of the scanned process is all user-mode daemons of the system or specified by preset keywords.

[0047] Optionally, a user-mode daemon is designed through the process design part, and the user-mode daemon is used to dynamically adjust the process-level memory merging state. The specific implementation process is as follows:

[0048] Start the user-mode daemon process to periodically scan and record the overall system memory load and the memory usage of each process;

[0049] The user-mode daemon obtains the system's memory usage data by reading the proc file system or calling the corresponding API;

[0050] When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started to dynamically adjust the memory merging parameters:

[0051] When the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened. At the same time, the memory merging efficiency within the time window of each scanned process is calculated, and all scanned processes with merging efficiency higher than the preset threshold value P are added to the memory merging of the operating system, where the memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process;

[0052] When the free memory continues to be higher than the preset threshold N, the scanning range of each cycle is reduced and the waiting time between cycles is extended. At the same time, the memory merging efficiency within the time window of each scanned process is calculated. If it is higher than the preset threshold P and lower than the preset threshold Q, the process is temporarily removed from the operating system's memory merging mechanism. The memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process.

[0053] Compared with the prior art, the method and device for implementing dynamic and refined operating system memory merging management of the present invention have the following beneficial effects:

[0054] By implementing a new kernel module and a corresponding user-mode daemon process, the present invention can more efficiently, conveniently, dynamically and finely manage the memory merging mechanism of the operating system, improve memory utilization and system performance, and reduce the overall overhead of the system. It is particularly suitable for a Linux-based trusted computing operating system environment. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] Attached Figure 1 It is a flow chart of the method of embodiment 1 of the present invention. DETAILED DESCRIPTION

[0056] In order to make the technical solution, the technical problem solved and the technical effect of the present invention more clearly understood, the technical solution of the present invention is clearly and completely described below in conjunction with specific embodiments.

[0057] Embodiment 1: Combining with the attached Figure 1 This embodiment proposes a method for implementing dynamic and refined operating system memory merging management, which includes the following steps:

[0058] (I) Design a kernel module to create and monitor files under the proc file system, and implement the add, delete, modify and query functions of process-level memory merging by reading and writing the files.

[0059] The specific process of designing a kernel module is as follows:

[0060] In the initialization function of the kernel module, create a ksm_proc folder under the proc file system, and create ksm_process_pid_control file and ksm_process_run file in the ksm_proc folder for communication between the user-mode daemon and the kernel module;

[0061] Register the read and write functions of the corresponding file in the kernel module. The registered functions are called when the user writes or reads the file. At the same time, use the copy_from_user and copy_to_user functions to transfer data between user space and kernel space.

[0062] In the function corresponding to the file writing operation, the detection and processing of whether the input content identifies the process id is legal and whether it is a reentry operation are implemented. If the input pid is a positive integer, the function of enabling the corresponding process memory merging is implemented. If the input pid is a negative integer, the function of disabling the corresponding process memory merging is implemented.

[0063] In the function corresponding to the file reading operation, the function of processing and returning the process ID list is implemented according to the process list with enabled memory merging saved in the current kernel space and the current existence status of the process.

[0064] (ii) Design a user-mode daemon to dynamically adjust the system's overall memory merging parameters and process-level memory merging status.

[0065] I) Dynamically adjust the overall memory merging parameters of the system through the user-mode daemon. The specific implementation process is as follows:

[0066] Start the user-mode daemon to periodically scan and record the overall system memory load;

[0067] Based on the preset threshold of memory load, determine whether to start the operating system memory merging mechanism:

[0068] a1) When the memory load does not exceed the preset threshold M, the operating system memory merging mechanism is not started;

[0069] a2) When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started;

[0070] After the operating system memory merging mechanism is started, the amount of free memory is continuously monitored through the user-mode daemon process. At the same time, the historical data of the memory merging status of the process within the time window is recorded. The scope of the scanned process is all user-mode daemons of the system or specified by preset keywords.

[0071] b1) If the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened.

[0072] b2) If the free memory is continuously higher than the preset threshold value N, the scanning range of each cycle is reduced and the waiting time between cycles is extended.

[0073] It should be added that the user-mode daemon also records detailed log information during the process of adjusting memory merging parameters, including memory load changes and parameter adjustments. At the same time, an exception handling mechanism is designed so that timely measures can be taken when errors or abnormal situations occur.

[0074] II) Dynamically adjust the process-level memory merging state through the user-mode daemon. The specific implementation process is as follows:

[0075] Start the user-mode daemon process to periodically scan and record the overall system memory load and the memory usage of each process;

[0076] The user-mode daemon obtains the system's memory usage data by reading the proc file system or calling the corresponding API;

[0077] When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started to dynamically adjust the memory merging parameters:

[0078] When the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened. At the same time, the memory merging efficiency within the time window of each scanned process is calculated, and all scanned processes with merging efficiency higher than the preset threshold value P are added to the memory merging of the operating system, where the memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process;

[0079] When the free memory continues to be higher than the preset threshold N, the scanning range of each cycle is reduced and the waiting time between cycles is extended. At the same time, the memory merging efficiency within the time window of each scanned process is calculated. If it is higher than the preset threshold P and lower than the preset threshold Q, the process is temporarily removed from the operating system's memory merging mechanism. The memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process.

[0080] Embodiment 2: Refer to the attached Figure 1 This embodiment proposes a device for implementing dynamic and refined operating system memory merging management, which includes a kernel design part and a process design part, wherein:

[0081] A kernel module is designed through the kernel design part, and the kernel module is used to create and monitor files under the proc file system, and the functions of adding, deleting, modifying and checking the process-level memory merge are realized by reading and writing the files;

[0082] A user-mode daemon is designed through the process design part, and the user-mode daemon is used to dynamically adjust the system's overall memory merging parameters and process-level memory merging status.

[0083] In this embodiment, the specific process of designing the kernel module through the kernel design part is as follows:

[0084] In the initialization function of the kernel module, create a ksm_proc folder under the proc file system, and create ksm_process_pid_control file and ksm_process_run file in the ksm_proc folder for communication between the user-mode daemon and the kernel module;

[0085] Register the read and write functions of the corresponding file in the kernel module. The registered functions are called when the user writes or reads the file. At the same time, use the copy_from_user and copy_to_user functions to transfer data between user space and kernel space.

[0086] In the function corresponding to the file writing operation, the detection and processing of whether the input content identifies the process id is legal and whether it is a reentry operation are implemented. If the input pid is a positive integer, the function of enabling the corresponding process memory merging is implemented. If the input pid is a negative integer, the function of disabling the corresponding process memory merging is implemented.

[0087] In the function corresponding to the file reading operation, the function of processing and returning the process ID list is implemented according to the process list with enabled memory merging saved in the current kernel space and the current existence status of the process.

[0088] In this embodiment, a user-mode daemon is designed through the process design part, and the user-mode daemon is used to dynamically adjust the overall memory merging parameters of the system. The specific implementation process is as follows:

[0089] Start the user-mode daemon to periodically scan and record the overall system memory load;

[0090] Based on the preset threshold of memory load, determine whether to start the operating system memory merging mechanism:

[0091] a1) When the memory load does not exceed the preset threshold M, the operating system memory merging mechanism is not started;

[0092] a2) When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started;

[0093] After the operating system memory merging mechanism is started, the amount of free memory is continuously monitored through the user-mode daemon process. At the same time, the historical data of the memory merging status of the process within the time window is recorded. The scope of the scanned process is all user-mode daemons of the system or specified by preset keywords.

[0094] b1) If the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened.

[0095] b2) If the free memory is continuously higher than the preset threshold value N, the scanning range of each cycle is reduced and the waiting time between cycles is extended.

[0096] It should be added that the user-mode daemon also records detailed log information during the process of adjusting memory merging parameters, including memory load changes and parameter adjustments. At the same time, an exception handling mechanism is designed so that timely measures can be taken when errors or abnormal situations occur.

[0097] In this embodiment, a user-mode daemon is designed through the process design part, and the user-mode daemon is used to dynamically adjust the process-level memory merging state. The specific implementation process is as follows:

[0098] Start the user-mode daemon process to periodically scan and record the overall system memory load and the memory usage of each process;

[0099] The user-mode daemon obtains the system's memory usage data by reading the proc file system or calling the corresponding API;

[0100] When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started to dynamically adjust the memory merging parameters:

[0101] When the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened. At the same time, the memory merging efficiency within the time window of each scanned process is calculated, and all scanned processes with merging efficiency higher than the preset threshold value P are added to the memory merging of the operating system, where the memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process;

[0102] When the free memory continues to be higher than the preset threshold N, the scanning range of each cycle is reduced and the waiting time between cycles is extended. At the same time, the memory merging efficiency within the time window of each scanned process is calculated. If it is higher than the preset threshold P and lower than the preset threshold Q, the process is temporarily removed from the operating system's memory merging mechanism. The memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process.

[0103] In summary, the method and device for implementing dynamic and refined operating system memory merging management of the present invention, by implementing a new kernel module and a corresponding user-mode daemon process, can more efficiently, conveniently, dynamically and finely manage the operating system memory merging mechanism, improve memory utilization and system performance, and reduce the overall system overhead, and is particularly suitable for Linux-based trusted operating system environments.

[0104] The above specific examples are used to explain the principles and implementation methods of the present invention in detail. These examples are only used to help understand the core technical content of the present invention. Based on the above specific embodiments of the present invention, any improvements and modifications made by technicians in this technical field without departing from the principles of the present invention should fall within the scope of patent protection of the present invention.

Claims

1. A method for implementing dynamic and refined operating system memory merging management, characterized in that: The steps include: Design a kernel module to create and monitor files under the proc file system, and implement the add, delete, modify and query functions of process-level memory merging by reading and writing the files; Design a user-mode daemon to dynamically adjust the system's overall memory merging parameters and process-level memory merging status; The specific process of designing the kernel module is as follows: In the initialization function of the kernel module, create a ksm_proc folder under the proc file system, and create ksm_process_pid_control file and ksm_process_run file in the ksm_proc folder for communication between the user-mode daemon and the kernel module; Register the read and write functions of the corresponding file in the kernel module. The registered functions are called when the user writes or reads the file. At the same time, use the copy_from_user and copy_to_user functions to transfer data between user space and kernel space. In the function corresponding to the file writing operation, the detection and processing of whether the input content identifies the process id is legal and whether it is a reentry operation are implemented. If the input pid is a positive integer, the function of enabling the corresponding process memory merging is implemented. If the input pid is a negative integer, the function of disabling the corresponding process memory merging is implemented. In the function corresponding to the file reading operation, the function of processing and returning the process ID list is implemented according to the process list with enabled memory merging saved in the current kernel space and the current existence status of the process.

2. A method for implementing dynamic and refined operating system memory merging management according to claim 1, characterized in that: The overall memory merging parameters of the system are dynamically adjusted through the user-mode daemon. The specific implementation process is as follows: Start the user-mode daemon to periodically scan and record the overall system memory load; Based on the preset threshold of memory load, determine whether to start the operating system memory merging mechanism: a1) When the memory load does not exceed the preset threshold M, the operating system memory merging mechanism is not started; a2) When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started; After the operating system memory merging mechanism is started, the user-mode daemon continues to monitor the amount of free memory: b1) If the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened. b2) If the free memory is continuously higher than the preset threshold value N, the scanning range of each cycle is reduced and the waiting time between cycles is extended.

3. The method for implementing dynamic and refined operating system memory merging management according to claim 2, characterized in that: After the operating system memory merging mechanism is started, when the amount of free memory continues to be monitored through the user-mode daemon process, the historical data of the memory merging status of the process within the time window is recorded, where the scope of the scanned process is all user-mode daemons of the system or specified by preset keywords.

4. The method for implementing dynamic and refined operating system memory merging management according to claim 2, characterized in that: The process-level memory merging state is dynamically adjusted through the user-mode daemon. The specific implementation process is as follows: Start the user-mode daemon process to periodically scan and record the overall system memory load and the memory usage of each process; The user-mode daemon obtains the system's memory usage data by reading the proc file system or calling the corresponding API; When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started to dynamically adjust the memory merging parameters: When the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened. At the same time, the memory merging efficiency within the time window of each scanned process is calculated, and all scanned processes with merging efficiency higher than the preset threshold value P are added to the memory merging of the operating system, where the memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process; When the free memory continues to be higher than the preset threshold N, the scanning range of each cycle is reduced and the waiting time between cycles is extended. At the same time, the memory merging efficiency within the time window of each scanned process is calculated. If it is higher than the preset threshold P and lower than the preset threshold Q, the process is temporarily removed from the operating system's memory merging mechanism. The memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process.

5. A device for implementing dynamic and refined operating system memory merging management, characterized in that: It includes kernel design part and process design part, among which: A kernel module is designed through the kernel design part, and the kernel module is used to create and monitor files under the proc file system, and the functions of adding, deleting, modifying and checking the process-level memory merge are realized by reading and writing the files; Design a user-mode daemon through the process design part, and use the user-mode daemon to dynamically adjust the system's overall memory merging parameters and process-level memory merging status; Among them, the specific process of designing the kernel module through the kernel design part is as follows: In the initialization function of the kernel module, create a ksm_proc folder under the proc file system, and create ksm_process_pid_control file and ksm_process_run file in the ksm_proc folder for communication between the user-mode daemon and the kernel module; Register the read and write functions of the corresponding file in the kernel module. The registered functions are called when the user writes or reads the file. At the same time, use the copy_from_user and copy_to_user functions to transfer data between user space and kernel space. In the function corresponding to the file writing operation, the detection and processing of whether the input content identifies the process id is legal and whether it is a reentry operation are implemented. If the input pid is a positive integer, the function of enabling the corresponding process memory merging is implemented. If the input pid is a negative integer, the function of disabling the corresponding process memory merging is implemented. In the function corresponding to the file reading operation, the function of processing and returning the process ID list is implemented according to the process list with enabled memory merging saved in the current kernel space and the current existence status of the process.

6. The device for implementing dynamic and refined operating system memory merging management according to claim 5, characterized in that: The user-mode daemon is designed through the process design part, and the user-mode daemon is used to dynamically adjust the overall memory merging parameters of the system. The specific implementation process is as follows: Start the user-mode daemon to periodically scan and record the overall system memory load; Based on the preset threshold of memory load, determine whether to start the operating system memory merging mechanism: a1) When the memory load does not exceed the preset threshold M, the operating system memory merging mechanism is not started; a2) When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started; After the operating system memory merging mechanism is started, the user-mode daemon continues to monitor the amount of free memory: b1) If the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened. b2) If the free memory is continuously higher than the preset threshold value N, the scanning range of each cycle is reduced and the waiting time between cycles is extended.

7. The device for implementing dynamic and refined operating system memory merging management according to claim 6, characterized in that: After the operating system memory merging mechanism is started, when the amount of free memory continues to be monitored through the user-mode daemon process, the historical data of the memory merging status of the process within the time window is recorded, where the scope of the scanned process is all user-mode daemons of the system or specified by preset keywords.

8. The device for implementing dynamic and refined operating system memory merging management according to claim 6, characterized in that: The user-state daemon is designed through the process design part, and the user-state daemon is used to dynamically adjust the process-level memory merging state. The specific implementation process is as follows: Start the user-mode daemon process to periodically scan and record the overall system memory load and the memory usage of each process; The user-mode daemon obtains the system's memory usage data by reading the proc file system or calling the corresponding API; When the memory load exceeds the preset threshold M, the operating system memory merging mechanism is started to dynamically adjust the memory merging parameters: When the free memory is continuously lower than the preset threshold value N, the scanning range of each cycle is expanded and the waiting time between cycles is shortened. At the same time, the memory merging efficiency within the time window of each scanned process is calculated, and all scanned processes with merging efficiency higher than the preset threshold value P are added to the memory merging of the operating system, where the memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process; When the free memory continues to be higher than the preset threshold N, the scanning range of each cycle is reduced and the waiting time between cycles is extended. At the same time, the memory merging efficiency within the time window of each scanned process is calculated. If it is higher than the preset threshold P and lower than the preset threshold Q, the process is temporarily removed from the operating system's memory merging mechanism. The memory merging efficiency is calculated by the number of memory pages merged by the process and the number of all memory pages used by the process.

Citation Information

Patent Citations

  • File system of distributed type file system client side

    CN102541984A

  • Persistent memory unified management method fusing Linux virtual memory system and file system

    CN113254198A