Memory optimization system, method, device and storage medium based on memory sampling

By using memory sampling technology in the operating system to record and optimize pages with low access frequency, the problem of memory optimization delay in the existing technology is solved, memory management is implemented during normal operation, and system load and the risk of insufficient memory are reduced.

CN115061944BActive Publication Date: 2024-10-15INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210726716.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-24
Publication Date
2024-10-15
Estimated Expiration
2042-06-24

AI Technical Summary

Technical Problem

When managing memory, existing operating systems need to wait until the remaining memory reaches a critical value before optimizing. As a result, memory optimization may be too delayed during high load periods and increase system pressure.

Method used

A system based on memory sampling is used to record the memory access operations of user-mode processes through the physical memory sampling module. Pages with low access frequency are screened out for optimization according to the configured sampling parameters to avoid waiting for critical values ​​before memory recycling.

Benefits of technology

Memory optimization can be performed when the operating system is running normally, slowing down the frequency of traditional memory recycling optimization, preventing the system from frequently entering a state of insufficient memory, and reducing system load.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115061944B_ABST
    Figure CN115061944B_ABST
Patent Text Reader

Abstract

The present invention proposes a memory optimization system, method, device and storage medium based on memory sampling, the system comprising: a physical memory sampling module, used to record the access operation of the user state process to the memory and add the description structure of the memory page that meets the sampling parameter requirements to a linked list; a memory file system module, used to use the memory file system under / sys / kernel to interact with the user state and feedback and record data; a parameter configuration module, used to configure the sampling parameters after the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file; a memory processing module, used to regularly access the linked list, filter out pages with low access frequency, and optimize them; a log module, used to record the operation logs of the physical memory sampling module and the memory processing module. The present invention can reduce the probability of entering the memory recovery optimization of the traditional operating system and avoid the operating system from frequently entering the state of insufficient memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and more particularly to a memory optimization system, method, device and storage medium based on memory sampling. Background Art

[0002] The operating system is the basic platform of modern computer technology. Countless application scenarios and countless hardware types are linked and interacted through the operating system. The operating system is software running on the hardware platform. It is responsible for interacting with applications and users. It provides a unified interface for applications and users. It shields the differences between different underlying hardware. Finally, it can realize the efficient operation of user processes without the user's perception. Due to the limited physical memory space, in order to protect the physical memory of the operating system from being arbitrarily accessed by any user-state process. Therefore, the Linux operating system proposes the concept of virtual memory. User-state processes access virtual memory space. The kernel state maps physical memory to virtual space by mapping. Because the user process space is relatively large. The actual physical space may change. Therefore, when the kernel manages memory, in order to save the use of physical memory. It is necessary to manage the memory space to a certain extent. If the physical memory space is full, the operating system cannot work properly. It will bring disastrous consequences. Therefore, efficient and orderly management of memory is an important technical research scope of the operating system.

[0003] At present, when the operating system kernel manages memory, it uses the critical value judgment method. When the critical value is not reached, the operating system will not optimize the memory. However, when the remaining memory enters different critical value intervals, in order to ensure that the operating system always has remaining memory, different mechanisms will be started to organize and optimize the memory. For example: a server with 4G memory has 3G remaining memory when the system starts, and the critical value is 128MB. As more and more processes run on the operating system, the remaining memory of the operating system will become less and less. Until the critical value is reached, the operating system will start a kswapd process. After startup, according to certain rules, check whether the processes corresponding to each physical memory can be recycled. If it can be recycled, recycle the memory page. Save the memory content to the hard disk (file system). Thus, the memory page is released. More memory is available. Until the remaining memory is higher than the critical value.

[0004] However, the critical value judgment method requires waiting for the remaining memory of the operating system to reach the critical value before optimizing the memory. If the kernel triggers the process to recycle after the critical value is reached, the operating system will often be highly loaded at that moment. This is because the operating system is already in a high-load state when it reaches the critical value. If memory optimization is performed at the same time, the intervention time may be relatively late, further increasing the pressure on the operating system. Summary of the invention

[0005] In view of the above problems, the purpose of the present invention is to provide a memory optimization system, method, device and storage medium based on memory sampling, which does not need to wait until the remaining memory reaches a critical value before starting the memory sorting and recycling work. Instead, the memory of the operating system is sampled when the operating system is running normally. According to the sampling results and configuration, the memory of the operating system is sorted, recycled and optimized.

[0006] To achieve the above-mentioned purpose, the present invention is implemented through the following technical solutions: a memory optimization system based on memory sampling, comprising: a physical memory sampling module, a memory file system module, a parameter configuration module, a memory processing module and a log module; the physical memory sampling module is used to record the access operation of the user state process to the memory, collect data according to the sampling parameters configured by the parameter configuration module, and add the description structure of the memory page that meets the sampling parameter requirements to a linked list; the memory file system module is used to use the memory file system under / sys / kernel to establish directories and files in the memory, interact with the user state and feedback and record data; the parameter configuration module is used to configure the sampling parameters after the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file; the sampling parameters include the sampled memory space range, sampling step and sampling threshold; the memory processing module is used to regularly access the linked list, filter out pages with low access frequency, and optimize them; the log module is used to record the operation logs of the physical memory sampling module and the memory processing module.

[0007] Further, the recording of the access operation of the user state process to the memory includes:

[0008] When performing memory conversion during memory access, the corresponding memory block is atomically incremented;

[0009] The access operation includes a read and write operation of the memory.

[0010] Further, the files created in the memory include:

[0011] The first record file is used to record the physical memory space of the sample;

[0012] The second record file is used to record the sampling results;

[0013] The third recording file is used to record the sampling step length;

[0014] The fourth record file is used to record the memory optimization threshold;

[0015] The fifth record file is used to record the amount of optimized memory;

[0016] The memory file system module completes the interaction between kernel state and user state through the above five files;

[0017] The first record file, the third record file and the fourth record file are all readable and writable files, and the second record file and the fifth record file are read-only files.

[0018] Furthermore, the unit of the sampled physical memory space is memory page, and the configuration is performed in memory page unit; the sampling result is in step size unit, and the sampling result is displayed; the sampling result is counted based on the access frequency; the sampling step size is the number of pages, and the sampling is performed in 16 pages by default; the memory optimization threshold defaults to 0, and the optimization work is started when the memory page is 0 after startup; the optimized memory amount is in page unit, and the optimized memory amount is recorded.

[0019] Furthermore, the format of the sampled memory space range is two digital integers separated by a dash; if the parameters written by the user do not conform to the format, the configuration will not be successful, and the log will be output to the log module; if the starting number of the sampled memory space range is less than 0, or the number is greater than the maximum physical memory, the sampled memory space range is automatically adjusted to the actual range of the current memory space.

[0020] Furthermore, the sampling step unit is the number of pages, and the value range is 1-64; the sampling threshold is N, that is, the collection and recycling work will be started only when the number of occupied pages of the system is greater than N, and the default value of the sampling threshold is 0.

[0021] Furthermore, the timed access linked list screens out pages with low access frequency and optimizes them, including: after the timed access to the linked list, traverse each page in the linked list for secondary confirmation to confirm the pages with low access frequency, and perform memory optimization operations on the confirmed pages; when performing the memory optimization operation, first determine the type of the memory page, if the memory is also a kernel page, then do not optimize; if the memory page is a user state page, then determine the type of the user state page; if the user state page is a file page, then directly release it; if the user state page is an anonymous page, then check whether the current system has a swap partition, if there is a swap partition, then perform a swap operation.

[0022] Correspondingly, the present invention further discloses a memory optimization method based on memory sampling, which is applied to the memory optimization system based on memory sampling described in any one of the above items, and comprises the following steps:

[0023] S1: Use the memory file system under / sys / kernel to create directories and files in the memory, interact with the user state, and feedback and record data;

[0024] S2: records the memory access operations of the user-mode process;

[0025] S3: After the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file, the sampling parameters are configured;

[0026] S4: collect data according to the sampling parameters, and add the description structure of the memory page that meets the sampling parameter requirements to the linked list;

[0027] S5: Regularly access the linked list, filter out pages with low access frequency, and optimize them;

[0028] S6: Record the memory sampling, recycling, and swapping operations in the log.

[0029] Accordingly, the present invention discloses a memory optimization device based on memory sampling, comprising:

[0030] A memory, used for storing a memory optimization program based on memory sampling;

[0031] A processor is used to implement the steps of the memory optimization method based on memory sampling as described above when executing the memory optimization program based on memory sampling.

[0032] Correspondingly, the present invention discloses a readable storage medium, on which a memory optimization program based on memory sampling is stored. When the memory optimization program based on memory sampling is executed by a processor, the steps of the memory optimization method based on memory sampling as described above are implemented.

[0033] Compared with the prior art, the present invention has the following beneficial effects:

[0034] 1. The present invention realizes that there is no need to wait for the critical value, and memory optimization can be accessed when the operating system is running normally. Because if the critical value is reached and the kernel starts the process for recycling, the operating system will often be highly loaded at that moment. Because the operating system is already in a high-load state when it touches the critical value. If memory optimization is performed at the same time, the intervention time point may be relatively late, further increasing the pressure on the operating system. Therefore, the present invention samples and records the memory access of the operating system during normal operation. And optimizes the memory used by each process. There is no need to wait until the memory is insufficient before intervening.

[0035] 2. The sampling mechanism used in the present invention does not conflict with the traditional operating system memory recovery optimization mechanism. Because even if the present invention is adopted, when the operating system load is high, the traditional operating system memory recovery optimization mechanism and scheme will still be entered. The present invention can reduce the probability of entering the traditional operating system memory recovery optimization and avoid the operating system frequently entering the state of insufficient memory.

[0036] It can be seen that compared with the prior art, the present invention has outstanding substantive features and significant progress, and the beneficial effects of its implementation are also obvious. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0038] Attached Figure 1 It is a system structure diagram of a specific implementation mode of the present invention.

[0039] Attached Figure 2 It is a method flow chart of a specific implementation mode of the present invention.

[0040] In the figure, 1 is the physical memory sampling module; 2 is the memory file system module; 3 is the parameter configuration module; 4 is the memory processing module; and 5 is the log module. DETAILED DESCRIPTION

[0041] The core of the present invention is to provide a memory optimization system based on memory sampling. In the prior art, the critical value judgment method needs to wait for the remaining memory of the operating system to reach the critical value before the memory can be optimized. If the kernel triggers the process to recycle after the critical value is reached, the operating system will often be highly loaded at that moment. Because the operating system is already in a high-load state when it touches the critical value. If memory optimization is performed at the same time, the intervention time point may be relatively late, further increasing the pressure on the operating system.

[0042] The memory optimization system based on memory sampling provided by the present invention includes: a physical memory sampling module, a memory file system module, a parameter configuration module, a memory processing module and a log module; the physical memory sampling module is used to record the access operation of the user state process to the memory, collect data according to the sampling parameters configured by the parameter configuration module, and add the description structure of the memory page that meets the sampling parameter requirements to the linked list; the memory file system module is used to use the memory file system under / sys / kernel to establish directories and files in the memory, interact with the user state and feedback data and record data; the parameter configuration module is used to configure the sampling parameters after the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file; the sampling parameters include the memory space range, sampling step and sampling threshold of the sampling; the memory processing module is used to access the linked list regularly, filter out pages with low access frequency, and optimize them; the log module is used to record the operation logs of the physical memory sampling module and the memory processing module. It can be seen that the present invention does not need to wait until the remaining memory reaches the critical value before starting the memory sorting and recycling work. Instead, the memory of the operating system is sampled when the operating system is running normally. According to the sampling results and configuration, the memory of the operating system is sorted, recycled, and optimized.

[0043] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0044] Embodiment 1:

[0045] like Figure 1 As shown, this embodiment provides a memory optimization system based on memory sampling, including: a physical memory sampling module 1, a memory file system module 2, a parameter configuration module 3, a memory processing module 4 and a log module 5.

[0046] The physical memory sampling module 1 is used to record the access operations of the user-state process to the memory, collect data according to the sampling parameters configured by the parameter configuration module, and add the description structure of the memory page that meets the sampling parameter requirements to the linked list. Among them, the access operation includes the read and write operations of the memory. The access operations of the user-state process to the memory are recorded, and the corresponding memory block is atomically incremented when the memory access is performed for memory conversion.

[0047] The memory file system module 2 is used to use the memory file system under / sys / kernel to create directories and files in the memory, interact with the user state, and feedback and record data.

[0048] Among them, the files established in the memory include: a first record file for recording the sampled physical memory space; a second record file for recording the sampling results; a third record file for recording the sampling step size; a fourth record file for recording the memory optimization threshold; and a fifth record file for recording the amount of optimized memory. The memory file system module completes the interaction between the kernel state and the user state through the above five files. Specifically, the first record file, the third record file, and the fourth record file are all readable and writable files, and the second record file and the fifth record file are read-only files.

[0049] In the data recorded in the above five files, the unit of sampled physical memory space is memory page, and the configuration is performed in memory page unit; the sampling result is in step size, and the sampling result is displayed; the sampling result is counted based on the access frequency; the sampling step size is the number of pages, and the default sampling is 16 pages; the default threshold of memory optimization is 0, and the optimization work starts when the memory page is 0 after startup; the number of optimized memory is in page unit, and the number of optimized memory is recorded.

[0050] Parameter configuration module 3 is used to configure sampling parameters after the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file. The sampling parameters include the sampled memory space range, sampling step and sampling threshold. Among them, the format of the sampled memory space range is two digital integers separated by a horizontal bar; if the parameters written by the user do not conform to this format, the configuration will not be successful, and the log will be output to the log module; if the starting number of the sampled memory space range is less than 0, or the number is greater than the maximum physical memory, the sampled memory space range will be automatically adjusted to the actual range of the current memory space. The sampling step unit is the number of pages, and the value range is 1-64; the sampling threshold is N, that is, the system will start collecting and recycling only when the number of occupied pages is greater than N. The default value of the sampling threshold is 0.

[0051] The memory processing module 4 is used to regularly access the linked list, filter out pages with low access frequency, and optimize them. The memory processing module 4 is specifically used to: after regularly accessing the linked list, traverse each page in the linked list for secondary confirmation to confirm the pages with low access frequency, and perform memory optimization operations on the confirmed pages; when performing memory optimization operations, first determine the type of memory page, if the memory is also a kernel page, then do not optimize; if the memory page is a user state page, then determine the type of the user state page; if the user state page is a file page, then directly release it; if the user state page is an anonymous page, then check whether the current system has a swap partition, if there is a swap partition, then perform a swap operation.

[0052] The log module 5 is used to record the operation logs of the physical memory sampling module and the memory processing module.

[0053] Embodiment 2:

[0054] Based on the embodiment, this embodiment also discloses a memory optimization system based on memory sampling, including: a physical memory sampling module, a memory file system module, a parameter configuration module, a memory processing module and a log module. These five sub-modules all run in the Linux kernel. These five sub-modules are a kernel module in the specific implementation process. These five modules are managed by a kernel module ko. The modules can be installed or uninstalled at the same time. The five modules can only be installed and uninstalled at the same time, and cannot be installed or uninstalled separately.

[0055] The design idea of ​​this system is: first, after the operating system kernel module loads the ko of this module, it is not enabled by default. By default, it does not affect the original functions of the kernel. If you need to enable this system. You need to mount the memory file system module of this system first. The mounting method is mount-t debugfs none / sys / kernel / mm / mons. After the mounting is completed, you can see that / sys / debug / mons has been mounted under the kernel's memory file system. After being mounted, this system will officially start working in the kernel. At the same time, on the contrary, if the file system is umounted, the system will be uninstalled. After the Umount command is executed, this system is uninstalled in the kernel module. It is no longer working. Similarly, the five modules will be uninstalled together and stop working. These five modules cooperate with each other to complete the work of operating system memory optimization.

[0056] Based on the above design ideas, the specific functions of the five modules used in this system are as follows:

[0057] Physical memory sampling module. This module is the entrance to the system. Every time a user-mode process accesses memory, it will be recorded by the physical memory sampling module. The access here includes read and write operations. Since the address space is a continuous address. As long as the accessed physical address belongs to a certain memory page, it is an access to that segment of memory. Since the operating system's memory page access is very frequent, the work of this module is very simple, that is, the corresponding memory block is atomically incremented during the memory conversion of the memory access. Try to minimize the impact on the operating system.

[0058] Memory file system module. The file system is a basic concept of the Linux system. This solution uses the memory file system under / sys / kernel. Create a directory in the memory. Create a file. Used to interact with the user state and feedback data. Record data. In the memory file system module. Record five files, namely: File 1, used to record the sampled physical memory space; File 2, used to record the sampling results; File 3, used to record the sampling step; File 4, used to record the memory optimization threshold; File 5, used to record the amount of optimized memory. Among them, files 1, 3, and 4 are all readable and writable files. Files 2 and 5 are read-only files. The interaction between the kernel state and the user state is completed through these five files. Writing to the first four files is to configure this system. Among them, the unit of the sampled physical memory space is memory page. Configure in memory page units. For example, there are 65536 memory pages in a system. The default configuration of this file is 0-65536, that is, all memory pages will be sampled. The reason for the design of memory pages is that all subsequent memory recovery, swapping and other operations are in pages. The sampling results are displayed in steps. The sampling results are counted based on the access frequency. There are ten frequency levels from 0 to 9. The sampling step is the number of pages, and the default sampling is 16 pages. The default threshold for memory optimization is 0, which means the number of used memory pages reaches a certain value to start working. The default is to start working at startup. The number of optimized memory in the last file is in pages, and the number of optimized memory is recorded. It is 0 at startup and is used to monitor the working status of this system.

[0059] Parameter configuration module. As can be seen from the above, this system needs to receive the user's parameter writing work. After the user writes to the corresponding memory file. It will trigger the write operation of the kernel virtual file system (VFS). After the write operation. Configure the parameters of this system. The parameters that can be configured are the sampled memory space range, sampling step and sampling threshold. The format of the sampled memory space is two digital integers separated by a dash (-). If the parameters written by the user do not conform to this format, the configuration will not succeed, and a log will be output to the kernel log. If the starting number is less than 0, or the number is greater than the maximum physical memory, the data will be automatically changed to a reasonable value (less than 0 is set to 0, and greater than the maximum value is set to the maximum value). After the configuration is completed, it will be notified to the physical memory sampling module, and the physical memory sampling module will collect according to the latest data, and the memory part that does not fall into it will not be collected. The sampling step is the number of pages, and the value range is 1-64. Values ​​greater than 1 or less than 64 will be set to a reasonable range. Similarly, after the configuration is completed, the physical memory sampling module will be notified, and the physical memory sampling module will collect data based on the latest data. The sampling threshold defaults to 0, and it starts working by default. If you want to wait until the operating system starts the mechanism after a certain period of time, you can modify the value. For example, if it is modified to 50000, the system will start collecting and recycling only when the number of occupied pages is greater than 5000.

[0060] Memory processing module. The memory processing module is expressed as a kernel thread (kthread). The kernel thread will optimize according to a linked list of memory pages to be optimized maintained by the kernel sampling module. When the kernel sampling module collects data, it will add the description structure (struct page) of the memory page that meets the requirements to the linked list. The memory processing module will access the linked list regularly. After accessing the linked list, it is necessary to traverse each page in the linked list for secondary confirmation to confirm whether it is still a page with low access frequency. If it is still, memory optimization operations will be performed. There are two types of memory optimization operations. Since memory pages are divided into two types: kernel pages and user-mode pages. Kernel-mode pages will not be optimized. User-mode pages are also divided into two types: file pages and anonymous pages. File pages will be released directly, and anonymous pages will check whether the current system has a swap partition. If there is a swap partition, the swap operation will be performed.

[0061] Log module. This system will record logs during the collection, recycling, and exchange processes. Each operation will record debug logs. Therefore, the physical memory sampling module and the memory processing module record logs through this module.

[0062] Embodiment three:

[0063] Based on the above embodiments, Figure 2 As shown, the present invention also discloses a memory optimization method based on memory sampling, comprising the following steps:

[0064] S1: Use the memory file system under / sys / kernel to create directories and files in the memory, interact with the user state, and feedback and record data.

[0065] S2: Records the memory access operations of user-mode processes.

[0066] S3: After the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file, the sampling parameters are configured.

[0067] S4: Collect data according to the sampling parameters, and add the description structure of the memory page that meets the sampling parameter requirements to the linked list.

[0068] S5: Regularly access the linked list, filter out pages with low access frequency, and optimize them.

[0069] S6: Record the memory sampling, recycling, and swapping operations in the log.

[0070] This embodiment provides a memory optimization method based on memory sampling, which can sample the memory of the operating system when the operating system is running normally, and organize, recycle, and optimize the memory of the operating system according to the sampling results and configuration. It can reduce the probability of entering the memory recycling optimization of the traditional operating system and avoid the operating system frequently entering the state of insufficient memory.

[0071] Embodiment 4:

[0072] This embodiment discloses a memory optimization device based on memory sampling, including a processor and a memory; wherein the processor implements the following steps when executing a memory optimization program based on memory sampling stored in the memory:

[0073] 1. Use the memory file system under / sys / kernel to create directories and files in the memory, interact with the user state, and feedback and record data.

[0074] 2. Record the memory access operations of user-mode processes.

[0075] 3. After the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file, configure the sampling parameters.

[0076] 4. Collect data according to the sampling parameters, and add the description structure of the memory page that meets the sampling parameter requirements to the linked list.

[0077] 5. Regularly access the linked list, filter out pages with low access frequency, and optimize them.

[0078] 6. Record the memory sampling, recycling and swapping operations in the log.

[0079] Furthermore, the memory optimization device based on memory sampling in this embodiment may also include:

[0080] The input interface is used to obtain the memory optimization program based on memory sampling imported from the outside, and save the obtained memory optimization program based on memory sampling to the memory, and can also be used to obtain various instructions and parameters transmitted by the external terminal device, and transmit them to the processor, so that the processor can use the above various instructions and parameters to carry out corresponding processing. In this embodiment, the input interface can specifically include but is not limited to a USB interface, a serial interface, a voice input interface, a fingerprint input interface, a hard disk reading interface, etc.

[0081] The output interface is used to output various data generated by the processor to the terminal device connected thereto, so that other terminal devices connected to the output interface can obtain various data generated by the processor. In this embodiment, the output interface may specifically include but is not limited to a USB interface, a serial interface, etc.

[0082] The communication unit is used to establish a remote communication connection between the memory optimization device based on memory sampling and the external server, so that the memory optimization device based on memory sampling can mount the image file to the external server. In this embodiment, the communication unit may specifically include but is not limited to a remote communication unit based on wireless communication technology or wired communication technology.

[0083] The keyboard is used to obtain various parameter data or instructions input by the user by tapping the keycaps in real time.

[0084] The display is used to display the relevant information of the server power supply line short circuit locating process in real time.

[0085] The mouse can be used to assist users in inputting data and simplify user operations.

[0086] Embodiment five:

[0087] This embodiment also discloses a readable storage medium, and the readable storage medium mentioned here includes random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, register, hard disk, removable hard disk, CD-ROM or any other form of storage medium known in the technical field. The readable storage medium stores a memory optimization program based on memory sampling, and the memory optimization program based on memory sampling implements the following steps when executed by the processor:

[0088] 1. Use the memory file system under / sys / kernel to create directories and files in the memory, interact with the user state, and feedback and record data.

[0089] 2. Record the memory access operations of user-mode processes.

[0090] 3. After the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file, configure the sampling parameters.

[0091] 4. Collect data according to the sampling parameters, and add the description structure of the memory page that meets the sampling parameter requirements to the linked list.

[0092] 5. Regularly access the linked list, filter out pages with low access frequency, and optimize them.

[0093] 6. Record the memory sampling, recycling and swapping operations in the log.

[0094] In summary, the present invention can reduce the probability of entering the memory recovery optimization of the traditional operating system and avoid the operating system frequently entering the state of insufficient memory.

[0095] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. As for the method disclosed in the embodiment, since it corresponds to the system disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0096] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0097] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or units, which can be electrical, mechanical or other forms.

[0098] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0099] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, or each module may exist physically separately, or two or more modules may be integrated into one unit.

[0100] Similarly, each processing unit in each embodiment of the present invention may be integrated into one functional module, or each processing unit may exist physically, or two or more processing units may be integrated into one functional module.

[0101] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0102] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used 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 "include", "comprise" 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 sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0103] The memory optimization method, system, device and readable storage medium based on memory sampling provided by the present invention are introduced in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.

Claims

1. A memory optimization system based on memory sampling, characterized in that: include: Physical memory sampling module, memory file system module, parameter configuration module, memory processing module and log module; The physical memory sampling module is used to record the access operation of the user state process to the memory, collect data according to the sampling parameters configured by the parameter configuration module, and add the description structure of the memory page that meets the sampling parameter requirements to the linked list; The memory file system module is used to use the memory file system under / sys / kernel to create directories and files in the memory, interact with the user state and feedback and record data; The parameter configuration module is used to configure sampling parameters after the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file; the sampling parameters include the memory space range of the sampling, the sampling step and the sampling threshold; The memory processing module is used to regularly access the linked list, filter out pages with low access frequency, and optimize them; The log module is used to record the operation logs of the physical memory sampling module and the memory processing module.

2. The memory optimization system based on memory sampling according to claim 1, characterized in that: The recording of the access operation of the user state process to the memory includes: When performing memory conversion during memory access, the corresponding memory block is atomically incremented; The access operation includes a read and write operation of the memory.

3. The memory optimization system based on memory sampling according to claim 1, characterized in that: The files created in the memory include: The first record file is used to record the physical memory space of the sample; The second record file is used to record the sampling results; The third recording file is used to record the sampling step length; The fourth record file is used to record the memory optimization threshold; The fifth record file is used to record the amount of optimized memory; The memory file system module completes the interaction between kernel state and user state through the above five files; The first record file, the third record file and the fourth record file are all readable and writable files, and the second record file and the fifth record file are read-only files.

4. The memory optimization system based on memory sampling according to claim 3, characterized in that: The unit of the sampled physical memory space is a memory page, and configuration is performed in units of a memory page; The sampling results are displayed in units of step length; the sampling results are counted based on the access frequency; The sampling step is the number of pages, and the sampling is performed in units of 16 pages by default; The default threshold of the memory optimization is 0, and the optimization work is started when the memory page is 0 after startup; The optimized memory quantity is recorded in pages.

5. The memory optimization system based on memory sampling according to claim 1, characterized in that: The format of the sampled memory space range is two digital integers separated by a dash; if the parameters written by the user do not conform to this format, the configuration will not succeed and a log will be output to the log module; If the starting number of the sampled memory space range is less than 0, or the number is greater than the maximum physical memory, the sampled memory space range is automatically adjusted to the actual range of the current memory space.

6. The memory optimization system based on memory sampling according to claim 1, characterized in that: The sampling step unit is page number, and the value range is 1-64; The sampling threshold is N, that is, the collection and recovery work will not start until the number of occupied pages of the system is greater than N. The default value of the sampling threshold is 0.

7. The memory optimization system based on memory sampling according to claim 1, characterized in that: The timed access linked list screens out pages with low access frequency and optimizes them, including: After regularly accessing the linked list, traverse each page in the linked list for secondary confirmation to confirm pages with low access frequency, and perform memory optimization operations on the confirmed pages; When performing memory optimization operations, first determine the type of memory page. If the memory is also a kernel page, no optimization is performed. If the memory page is a user state page, determine the type of the user state page. If the user state page is a file page, it is directly released; if the user state page is an anonymous page, check whether the current system has a swap partition. If so, perform the swap operation.

8. A memory optimization method based on memory sampling, characterized in that: The method is applied to the memory optimization system based on memory sampling as claimed in any one of claims 1 to 7, comprising the following steps: S1: Use the memory file system under / sys / kernel to create directories and files in the memory, interact with the user state, and feedback and record data; S2: records the memory access operations of the user-mode process; S3: After the user triggers the write operation of the kernel virtual file system when writing to the corresponding memory file, the sampling parameters are configured; S4: collect data according to the sampling parameters, and add the description structure of the memory page that meets the sampling parameter requirements to the linked list; S5: Regularly access the linked list, filter out pages with low access frequency, and optimize them; S6: Record the memory sampling, recycling, and swapping operations in the log.

9. A memory optimization device based on memory sampling, characterized in that: include: A memory, used for storing a memory optimization program based on memory sampling; A processor is used to implement the steps of the memory optimization method based on memory sampling as claimed in claim 8 when executing the memory optimization program based on memory sampling.

10. A readable storage medium, characterized in that: The readable storage medium stores a memory optimization program based on memory sampling, and when the memory optimization program based on memory sampling is executed by a processor, the steps of the memory optimization method based on memory sampling as described in claim 8 are implemented.