Embedded device cache management system, method, device and medium
Through the cache management system that interacts with user-state and kernel-state modules, threshold values and release priority are set, which solves the memory application failure and performance degradation of cache management in embedded devices, and achieves efficient file cache release and read-write performance improvements.
Patent Information
- Application Number
- CN202510333572.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-20
- Publication Date
- 2025-07-11
AI Technical Summary
In the prior art, embedded devices directly clear caches in high-performance and low-latency business scenarios lead to a degradation of disk read and write performance, and the kernel passive memory recovery risk of memory failure.
A cache management system that interacts with user-state and kernel-state modules is adopted. By setting threshold values and file cache release priority, file cache is accurately released, avoiding memory application failures and improving read and write performance.
It realizes the avoidance of memory application failure in high-performance and low-latency business scenarios, accurately release file cache, and improve the overall read and write performance of embedded devices.
Smart Images

Figure CN120295981A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of embedded technology, and particularly to an embedded device cache management system, method, device, and medium. Background Art
[0002] Embedded devices generally refer to embedded devices based on the Linux operating system. In high-specification business scenarios, such embedded devices will frequently perform a large number of file read and write operations. After running for a period of time, the device memory will be occupied by a large number of file caches. When a large number of file caches occupy the memory, there are generally two processing methods: First, use the relevant commands of the operating system to directly clear the cache, release the clean file caches, and thus free up memory space; Second, passively wait for a memory application. When the Linux kernel detects that the number of free pages in the system memory is lower than the low watermark, it triggers the kernel to recycle the file caches, thereby freeing up memory space.
[0003] However, the above two processing methods have the following problems:
[0004] The operation of directly clearing the cache will release the non-dirty page file caches of all files. In high-performance and low-latency business scenarios, this will cause the disk files to be read and written again, and the file caches and mappings will be performed again. Since the disk read and write operations are slow and the process is long, it will inevitably lead to a decline in business performance.
[0005] The kernel only triggers the recycling of a large number of file caches after passively detecting that the number of free pages in the system memory is lower than the low watermark. However, the kernel uses an asynchronous processing process for memory recycling. When applying for a large block of continuous memory, there is a risk of memory application failure. Summary of the Invention
[0006] To solve the above problems, an embedded device cache management system, method, device, and medium provided by this application can avoid the risk of failure when applying for a large block of continuous memory, can accurately release file caches, and can improve the overall read and write performance of embedded devices.
[0007] To achieve the above object, this application adopts the following technical solutions:
[0008] In a first aspect, the present invention provides an embedded device cache management system, including:
[0009] A user cache configuration module, configured to set a threshold value of the system file cache of the embedded device, and transmit the threshold value to the kernel cache monitoring module through a system call;
[0010] The kernel cache monitoring module is used to monitor the size of the system file cache of the embedded device by using a timed task. When the size of the system file cache reaches the threshold value, it notifies the kernel statistics module to collect file cache information in real time;
[0011] The kernel statistics module is used to traverse the file nodes under the superblock of the file system of the embedded device to statistically collect the file cache information corresponding to the file nodes in real time, and transfer the file cache information to the user cache release setting module;
[0012] The user cache release setting module is used to determine the file cache information to be released on the embedded device according to the received file cache information combined with the service scenario, and transfer the file cache information to be released to the user cache release module;
[0013] The user cache release module is used to transfer the received file cache information to be released to the kernel release module in the form of a linked list through a system call;
[0014] The kernel release module is used to release the physical pages in the memory area of the embedded device that match the file cache addresses in the file cache information to be released based on the release priority in the file cache information to be released.
[0015] Furthermore, the kernel cache monitoring module is specifically used for,
[0016] Start a timer task. In the timer task, query the memory size occupied by the shared file system of the embedded device, the file cache size occupied by non-active file pages, and the file cache size occupied by active file pages;
[0017] Determine the sum of the memory size occupied by the shared file system, the file cache size occupied by active file pages, and the file cache size occupied by active file pages as the system file cache size of the embedded device;
[0018] Compare the system file cache size of the embedded device with the threshold value. When the system file cache size reaches the threshold value, wake up the kernel statistics module to collect file cache information in real time.
[0019] Furthermore, the kernel release module is also used for,
[0020] Determine the default release priority for currently releasing file cache;
[0021] Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list;
[0022] Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
[0023] Further, the kernel release module is further configured to
[0024] After releasing each physical page, increment the count of the released pages by 1 to obtain the cumulative count of the released pages after traversing the physical page linked list of the memory area;
[0025] Determine whether the value obtained by multiplying the cumulative count of the released pages by the size of the physical page is less than the threshold of the system file cache. If it is less, decrement the default release priority of the currently released file cache by 1;
[0026] Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list;
[0027] Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
[0028] In a second aspect, the present invention further provides an embedded device cache management method, including:
[0029] The user cache configuration module sets the threshold of the system file cache of the embedded device and passes the threshold to the kernel cache monitoring module through a system call;
[0030] The kernel cache monitoring module monitors the size of the system file cache of the embedded device using a periodic task. When the size of the system file cache reaches the threshold, notify the kernel statistics module to collect file cache information in real time;
[0031] The kernel statistics module traverses the file nodes under the file system superblock of the embedded device to statistically collect the file cache information corresponding to the file nodes in real time, and passes the file cache information to the user cache release setting module;
[0032] The user cache release setting module determines the file cache information to be released of the embedded device according to the received file cache information in combination with the service scenario, and passes the file cache information to be released to the user cache release module;
[0033] The user cache release module passes the received file cache information to be released to the kernel release module in the form of a linked list through a system call;
[0034] The kernel release module releases the physical pages in the memory area of the embedded device that match the file cache address in the file information to be released based on the release priority in the file information to be released.
[0035] Further, the kernel cache monitoring module uses a timed task to monitor the size of the system file cache of the embedded device. When the size of the system file cache reaches the threshold value, it notifies the kernel statistics module to collect file cache information in real time, including:
[0036] Start a timer task. In the timer task, query the memory size occupied by the shared file system of the embedded device, the file cache size occupied by inactive file pages, and the file cache size occupied by active file pages;
[0037] Add the memory size occupied by the shared file system, the file cache size occupied by active file pages, and the file cache size occupied by active file pages, and determine it as the size of the system file cache of the embedded device;
[0038] Compare the size of the system file cache of the embedded device with the threshold value. When the size of the system file cache reaches the threshold value, wake up the kernel statistics module to collect file cache information in real time.
[0039] Further, the kernel release module releases the physical pages in the memory area of the embedded device that match the file cache address in the file information to be released based on the release priority in the file information to be released, including:
[0040] Determine the default release priority for the currently released file cache;
[0041] Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list;
[0042] Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
[0043] Further, it also includes
[0044] After releasing each physical page, increment the count of the number of released pages by 1 to obtain the cumulative count of released pages after traversing the physical page linked list of the memory area;
[0045] Judge whether the value obtained by multiplying the cumulative count of released pages by the size of the physical page is less than the threshold value of the system file cache. If it is less, decrement the default release priority of the currently released file cache by 1;
[0046] Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list;
[0047] Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
[0048] In a third aspect, the present invention further provides an electronic device, including: a processor and a memory;
[0049] The processor is coupled to the memory;
[0050] Wherein, the processor is configured to read and execute a program or instruction stored in the memory, so that the device executes the method as in the second aspect.
[0051] In a fourth aspect, the present invention further provides a computer-readable storage medium storing a computer program, and when the program is executed by a processor, the method as in the second aspect is implemented.
[0052] The technical solution provided by this application has at least the following technical effects or advantages:
[0053] The solution of this application is an embedded device file cache management system. Based on the characteristics of the user mode and kernel mode of the Linux operating system, through the interaction between multiple modules including the user cache configuration module, user cache release setting module, user cache release module in the user mode and the kernel cache monitoring module, kernel statistics module, kernel release module in the kernel mode, and considering the operating system cache threshold value and the release priority of the file cache in the file cache information to be released, the cache of the embedded device is managed. Considering the operating system cache threshold value can avoid the risk of memory application failure caused by the kernel asynchronously reclaiming memory when applying for a large block of continuous memory subsequently. Considering the release priority of the file cache can accurately release the file cache and ensure that the file cache strongly related to the service will not be released. The kernel statistics module obtains the file cache information by traversing the superblock of the file system, without the need to track file reads and writes, which can improve the overall read and write performance of the embedded device. In summary, the technical solution of this application can avoid the risk of failure when applying for a large block of continuous memory, can accurately release the file cache, and can improve the overall read and write performance of the embedded device.
[0054] Other features and advantages of this application will be described in the subsequent specification, and part of them will become obvious from the specification or will be understood by implementing this application. The objectives and other advantages of this application can be achieved and obtained through the structures pointed out in the specification, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of this application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0056] Figure 1 It is a schematic structural diagram of an embedded device file cache management system in an embodiment of the present application;
[0057] Figure 2 It is a schematic diagram of the file cache information counted in an embodiment of the present application;
[0058] Figure 3 It is a schematic diagram of the importance level corresponding to the file cache in an embodiment of the present application;
[0059] Figure 4 It is a schematic diagram of the interaction logic between the kernel cache monitoring module and the kernel statistics module in an embodiment of the present application;
[0060] Figure 5 It is a schematic diagram of releasing the file cache of the shared memory file system in an embodiment of the present application;
[0061] Figure 6 It is a schematic diagram of the information representation of the file cache to be released in an embodiment of the present application;
[0062] Figure 7 It is a schematic diagram of the logic for traversing the physical page linked list of the memory area to release physical pages in this example of the present application;
[0063] Figure 8 It is a schematic diagram of the logic for adjusting the release priority when releasing physical pages in this example of the present application;
[0064] Figure 9 It is a schematic diagram of the process of an embedded device file cache management method in an embodiment of the present application;
[0065] Figure 10 It is a schematic diagram of the process for the kernel cache monitoring module to wake up the kernel statistics module in an embodiment of the present application;
[0066] Figure 11 It is a schematic structural diagram of an electronic device provided in an embodiment of the present application. Detailed implementation manners
[0067] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0068] Figure 1 It is a schematic structural diagram of an embedded device file cache management system in an embodiment of the present application. As shown in the figure, the system includes:
[0069] A user cache configuration module, which is used to set the threshold value of the system file cache of the embedded device and pass the threshold value to the kernel cache monitoring module through system calls;
[0070] A kernel cache monitoring module, which is used to monitor the size of the system file cache of the embedded device by using a timing task. When the size of the system file cache reaches the threshold value, it notifies the kernel statistics module to collect file cache information in real time;
[0071] A kernel statistics module, which is used to traverse all file nodes of the embedded device, statistically collect the file cache information corresponding to each file node in real time, and pass the file cache information to the user cache release setting module;
[0072] A user cache release setting module, which is used to determine the file cache information to be released of the embedded device according to the received file cache information combined with the service scenario, and pass the file cache information to be released to the user cache release module;
[0073] A user cache release module, which is used to pass the received file cache information to be released to the kernel release module through system calls;
[0074] A kernel release module, which is used to release the physical pages in the memory area of the embedded device that match the file cache address in the file information to be released based on the release priority in the file information to be released.
[0075] It should be noted that for the sake of convenience of description, Figure 1 Exemplarily, only the main modules of the file cache management system structure of the embedded device are shown. In practical applications, the system may also include modules or components not shown in the figure; the system is not limited to the above module structure and may also be other module structures implementing the above method embodiments.
[0076] The solution of this application is an embedded device file cache management system. Based on the characteristics of the user space and kernel space of the Linux operating system, through the interaction between multiple modules including the user cache configuration module, user cache release setting module, user cache release module in the user space and the kernel cache monitoring module, kernel statistics module, kernel release module in the kernel space, and considering the operating system cache threshold and the release priority of file caches in the file caches to be released, the cache of the embedded device is managed. Considering the operating system cache threshold can avoid the risk of memory application failure caused by the kernel's asynchronous memory recycling when applying for a large continuous memory later. Considering the release priority of file caches can accurately release file caches and ensure that file caches strongly related to the business are not released. The kernel statistics module obtains file cache information by traversing the superblocks of the file system, without the need to track file reads and writes, which can improve the overall read and write performance of the embedded device. In summary, the technical solution of this application can avoid the risk of failure when applying for a large continuous memory, can accurately release file caches, and can improve the overall read and write performance of the embedded device.
[0077] The technical solution of this application is further described below:
[0078] The embedded device in this application refers to a communication device based on the Linux operating system. The running states of the Linux system include the user space and the kernel space. Modules in the user space cannot directly access hardware and perform privileged operations, but can request services from the kernel through system call interfaces. The kernel completes the corresponding operations and returns the results, that is, the user space requests services from the modules in the kernel space through system call interfaces, and the modules in the kernel space complete the corresponding operations and return the results to the modules in the user space. The kernel space is the running state with the highest privilege in the Linux system, with comprehensive hardware access rights and unrestricted memory access rights, capable of accessing the entire physical memory space and virtual memory space of the system, not only able to manage and allocate memory, but also directly access and modify data at any memory address. The kernel space runs in the kernel space and is isolated from the user space. Only through specific system calls and interfaces provided by the kernel space can the user space interact and cooperate. For the convenience of describing the technical solution of this application, the communication device based on the Linux operating system in this application can be directly referred to as an embedded device, and the cache management of the Linux operating system can also be regarded as the cache management of the embedded device. The user space and kernel space of the Linux system can also be referred to as the user space and kernel space of the embedded device.
[0079] In this application, the user space of the embedded device includes a user cache configuration module, a user cache release setting module, and a user cache release module, and the kernel space includes a kernel cache monitoring module, a kernel statistics module, and a kernel release module. Through the interaction between the modules in the user space and the kernel space, considering the operating system cache threshold and the release priority of the file cache in the file cache information to be released, the cache of the embedded device is managed.
[0080] The user cache configuration module sets the threshold value of the system file cache of the embedded device, denoted as over_size, according to the business characteristics of the embedded device (such as the business characteristics of communication devices such as routers and switches), and passes the threshold value to the kernel cache monitoring module through a system call.
[0081] The kernel cache monitoring module uses a timing task to monitor the size of the system file cache of the embedded device. When the size of the system file cache reaches the threshold value, it notifies the kernel statistics module to collect file cache information in real time; the kernel cache monitoring module starts a timer task to periodically query the occupancy of the system file cache of the embedded device and monitor the size of the system file cache. In the timer task, based on system instructions, query the size of the memory occupied by the shared file system of the embedded device, denoted as size1. The size of the memory occupied by the shared file system is taken from the shared memory count of the total physical pages used by the Linux system; based on system instructions, query the size of the file cache occupied by the inactive file pages of the embedded device, denoted as size2. The size of the file cache occupied by the inactive file pages is taken from the count of the inactive file pages of the total physical pages used by the system; based on system instructions, query the size of the file cache occupied by the active file pages of the embedded device, denoted as size3, which is taken from the count of the active file pages of the total physical pages used by the system; add the size of the memory occupied by the shared file system, the size of the file cache occupied by the active file pages, and the size of the file cache occupied by the active file pages (i.e., size1 + size2 + size3), and determine it as the size of the system file cache of the embedded device; compare the size of the system file cache of the embedded device with the threshold value passed by the received user cache configuration module. When the size of the system file cache reaches the threshold value, record the size of the system cache and notify the kernel statistics module to collect file cache information in real time, that is, wake up the real-time statistics sub-module of the kernel statistics module to collect file cache information in real time. When the size of the system file cache does not reach the threshold value, repeat the above steps in the timer task.
[0082] The real-time statistics sub-module of the kernel statistics module blocks after initializing the waiting event and waits to be woken up by the kernel cache monitoring module in the kernel state. After being woken up, the real-time statistics sub-module real-time statistics the important information of the current file cache of the embedded device. The important information includes the file cache size, file cache address corresponding to each file, the process ID of the file using process, user ID, etc. Figure 2 exemplarily lists the important information of the file cache. The importance level corresponding to the important information of the file cache is as Figure 3As shown, the larger the value of the importance level indicates a higher importance. Exemplarily, if the file cache information is not used by the current process, has a low usage frequency in historical statistics, and is not used by a critical business process, the importance level of the file cache information is determined to be 1; if the file cache information is not used by the current process and has a high usage frequency in historical statistics, the importance level of the file cache information is determined to be 2; if the file cache information is used by the current process and the current process is a non-critical business process, the importance level of the file cache information is determined to be 3; if the file cache information is used by the current process and the current process is a critical business process, the importance level of the file cache information is determined to be 4. The kernel statistics module further includes a timing statistics sub-module that collects important information of the file cache of the embedded device at regular intervals. Since the file cache of each file will not be actively released, the timing statistics sub-module can collect the important information of the file cache over a period of time, which can be used as a basis for judging the importance of the file cache. When collecting the importance information (historical data) of the file cache over a period of time, by restricting the number of entries or the size of the data, it is possible to prevent historical data from occupying too much memory, such as retaining the latest 50 polling data in a rolling manner. The process of the kernel statistics module for statistically collecting important information of the file cache is described as follows. The kernel of the Linux operating system will add all the file system superblocks of the embedded device to the superblock linked list. To statistically collect important information of the file cache, it is based on traversing all the file system superblocks of the embedded device and then traversing all the file nodes under the file system superblock. By traversing the file nodes under the file system superblock of the embedded device, the file cache size and file cache address corresponding to the file node can be obtained. The i_mapping pointer of the file node represents the file cache address, and i_mapping->nrpages represents the number of page frames occupied by the file cache corresponding to the file cache address of the file node. Multiplying this number of page frames by 4096 gives the file cache size corresponding to the file node. The i_mapping pointer is a structure member of the Linux kernel file node and represents the address containing the file data, that is, the file cache address. When traversing all the file system superblocks of the embedded device, if it is found that the magic number of the superblock is the shared memory file system, it is necessary to mark the file nodes under the shared memory file system superblock with the identifier belonging to the shared file system. For the file cache occupied by the file nodes with such shared file identifiers, if the file cache is not used by a process, when releasing the file cache, it is necessary to delete the file itself to further release the file cache. Based on this, the important information of the file cache also includes the marked identifier of the shared file system, and this identifier of the shared file system is used to identify the file cache with the identifier of the shared file system for specific cache release processing.After obtaining the file cache address corresponding to the file node, use the Linux kernel reverse mapping mechanism to traverse the virtual memory areas in the process space, find the virtual memory area to which the file cache address belongs, obtain the memory descriptor of the process through the virtual memory area, find the process descriptor according to the memory descriptor, and then obtain information such as the process ID and user ID corresponding to the file cache address according to the process descriptor. Figure 4 It is a schematic diagram of the interaction logic between the kernel cache monitoring module and the kernel statistics module in the embodiments of this application.
[0083] The kernel statistics module transfers the important information of the current file cache of the embedded device statistically in real time by the above real-time statistics sub-module, and the important information (historical data) of the file cache in the past period of time collected regularly by the timing statistics sub-module, to the user cache release setting module in the user space.
[0084] After receiving the historical and current important information of the file cache, the user cache release setting module determines the usage characteristics corresponding to the file cache according to the actual business scenario of the embedded device. For example, which file caches will be used next, which file caches will not be used next, and which file caches have a lower probability of being used next and other usage characteristics.
[0085] For the file caches that will not be used, release the file caches with high priority. For the file caches with a lower probability of being used, release the file caches with relatively high priority.
[0086] Among them, the file cache corresponding to the file of the shared memory file system that will not be used, that is, the file cache occupied by the file node marked with the shared file identifier, the file cache release logic is as Figure 5 follows. If the file cache belongs to the file cache corresponding to the file of the shared memory file system and the file cache is not used by any process, when releasing the file cache according to the business needs, it is necessary to delete the file of the shared memory file system corresponding to the file cache, and then release the file cache.
[0087] For the file cache corresponding to the file of the non-shared memory file system, determine the information table of the file caches to be released according to the priority. As Figure 6 shown, according to the needs of the business scenario, the information table of the file caches to be released determines the corresponding release priority based on the file cache address in the important information of each cached file. The larger the priority value, the more priority is given to the release. The user cache release setting module transfers the information table of the file caches to be released to the user cache release module.
[0088] The user cache release module organizes the data in the received information table of the file caches to be released in the form of a linked list and transfers it to the kernel release module in the kernel space through a system call.
[0089] After the kernel release module receives the linked list data of the file cache information to be released, based on the release priority in the file information to be released, it releases the physical pages in the embedded device memory area that match the file cache address in the file information to be released. Each file in the embedded device has a unique file cache address in the Linux kernel. Each file corresponds to a file cache, and the file cache uses physical page frames. A physical page frame refers to the smallest unit of cache in the system. When the Linux kernel allocates a free page to a file as a file cache, it records the file cache address of the physical page. The kernel release module realizes the release of the file cache based on the physical pages of the memory buddy system. When the Linux kernel manages memory, it divides the memory into memory areas, denoted as zone, including the DMA zone and the Normal zone. The DMA zone refers to the physical memory area specifically divided to support direct memory access (DMA) operations, which is used to meet the needs of hardware devices that can only access lower memory addresses for DMA transfers. The Normal zone refers to the regular memory area in the physical memory except for special areas such as the DMA zone. The memory in this area can be efficiently managed and used by the kernel, can be normally mapped to the linear address space of the kernel, and it is the most commonly used memory area, supporting various regular memory accesses and data processing operations to meet the normal operation needs of the system and applications. The memory area zone includes real physical pages, denoted as page, and the size of each physical page is 4k, which is managed by the physical page linked list page list. After the kernel release module receives the linked list data of the file cache information to be released, it determines the default release priority for the currently released file cache (for example, the default release priority is 4), traverses the physical page linked list page list of the memory area zone in sequence, and obtains the file cache address i_mapping of each physical page in the physical page linked list through the page_mapping interface (a function interface provided by the Linux kernel to obtain the file cache of the physical page). It compares the file cache address i_mapping of each physical page with the file cache address with the default release priority in the linked list data of the file cache information to be released. If they can match, it releases the physical page and increments the count of the released page number by 1. The process of traversing the physical page linked list page list of the memory area zone to release physical pages is as Figure 7 shown.
[0090] After traversing the physical page list of memory area zone to release physical pages, the cumulative released page data count is obtained, denoted as n. When the value of n multiplied by the size of a physical page, 4k (4096), is less than the set threshold over_size of the system file cache, it indicates that the size of the system file cache has not dropped below the threshold. At this time, the default release priority is decreased by 1 (for example, the default release priority is reduced to 3), and the physical page list pagelist of memory area zone is traversed again to release physical pages until the cumulative released page data count n multiplied by 4096 is greater than or equal to the set threshold over_size of the system file cache, at which point the kernel release module stops releasing the file cache. The adjustment logic of the release priority is as Figure 8 shown.
[0091] Based on the same technical concept as the above-mentioned embedded device file cache management system, Figure 9 is a flowchart of an embedded device file cache management method in an embodiment of the present application. The method includes:
[0092] S101. The user cache configuration module sets the threshold of the system file cache of the embedded device and passes the threshold to the kernel cache monitoring module through system calls;
[0093] S102. The kernel cache monitoring module uses a timed task to monitor the size of the system file cache of the embedded device. When the size of the system file cache reaches the threshold, it notifies the kernel statistics module to collect file cache information in real time;
[0094] S103. The kernel statistics module traverses the file nodes under the file system superblock of the embedded device to statistically collect the file cache information corresponding to the file nodes in real time and passes the file cache information to the user cache release setting module;
[0095] S104. The user cache release setting module determines the file cache information to be released of the embedded device according to the received file cache information in combination with the service scenario and passes the file cache information to be released to the user cache release module;
[0096] S105. The user cache release module passes the received file cache information to be released to the kernel release module in the form of a linked list through system calls;
[0097] S106. The kernel release module releases the physical pages in the memory area of the embedded device that match the file cache addresses in the file information to be released based on the release priority in the file information to be released.
[0098] Further, the kernel cache monitoring module monitors the size of the system file cache of the embedded device using a timed task. When the size of the system file cache reaches the threshold value, it notifies the kernel statistics module to collect file cache information in real time, such as Figure 10 shown, including:
[0099] S1021. Start a timer task. In the timer task, query the memory size occupied by the shared file system of the embedded device, the file cache size occupied by inactive file pages, and the file cache size occupied by active file pages;
[0100] S1022. Determine the sum of the memory size occupied by the shared file system, the file cache size occupied by active file pages, and the file cache size occupied by active file pages as the size of the system file cache of the embedded device;
[0101] S103. Compare the size of the system file cache of the embedded device with the threshold value. When the size of the system file cache reaches the threshold value, wake up the kernel statistics module to collect file cache information in real time.
[0102] Further, it also includes: The kernel statistics module transfers the file cache information collected regularly in the past period as historical data to the user cache release setting module in the user space.
[0103] Further, the kernel release module releases the physical pages in the memory area of the embedded device that match the file cache address in the file information to be released based on the release priority in the file information to be released, such as Figure 7 shown, including:
[0104] Determine the default release priority for the currently released file cache;
[0105] Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list;
[0106] Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
[0107] Further, it also includes,
[0108] After releasing each physical page, increment the count of the released page number by 1 to obtain the cumulative count of the released pages after traversing the physical page linked list of the memory area;
[0109] Judge whether the value obtained by multiplying the cumulative count of the released pages by the size of the physical page is less than the threshold value of the system file cache. If it is less, decrement the default release priority of the currently released file cache by 1;
[0110] Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list;
[0111] Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
[0112] Figure 11 This is a schematic structural diagram of an electronic device provided in an embodiment of the present application. As shown in the figure, the electronic device includes: a processor and a memory;
[0113] Among them, the processor is used to read and execute the programs and instructions stored in the memory, so that the electronic device executes the above method embodiments.
[0114] It should be noted that for the sake of convenience of description, Figure 11 Exemplarily, only the main components of the electronic device are shown. In actual applications, the electronic device may also include components or assemblies not shown in the figure.
[0115] The present application also provides a computer-readable storage medium storing programs or instructions. When the computer reads and executes the programs or instructions, the computer executes the above method embodiments.
[0116] Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. An embedded device cache management system, characterized in that, Comprising: A user cache configuration module, configured to set a threshold value for the system file cache of the embedded device, and transfer the threshold value to the kernel cache monitoring module through system calls; A kernel cache monitoring module, configured to monitor the size of the system file cache of the embedded device by using a timed task, and when the size of the system file cache reaches the threshold value, notify the kernel statistics module to collect file cache information in real time; A kernel statistics module, configured to traverse file nodes under the file system superblock of the embedded device to statistically collect file cache information corresponding to the file nodes in real time, and transfer the file cache information to the user cache release setting module; A user cache release setting module, configured to determine the file cache information to be released from the embedded device according to the received file cache information in combination with the service scenario, and transfer the file cache information to be released to the user cache release module; A user cache release module, configured to transfer the received file cache information to be released to the kernel release module in the form of a linked list through system calls; A kernel release module, configured to release physical pages in the memory area of the embedded device that match the file cache address in the file information to be released based on the release priority in the file information to be released.
2. The embedded device cache management system according to claim 1, wherein The kernel cache monitoring module is further configured to Start a timer task, in which the size of the memory occupied by the shared file system of the embedded device, the size of the file cache occupied by inactive file pages, and the size of the file cache occupied by active file pages are queried; Determine the sum of the size of the memory occupied by the shared file system, the size of the file cache occupied by the active file pages, and the size of the file cache occupied by the active file pages as the size of the system file cache of the embedded device; Compare the size of the system file cache of the embedded device with the threshold value, and when the size of the system file cache reaches the threshold value, wake up the kernel statistics module to collect file cache information in real time.
3. The embedded device cache management system according to any one of claims 1-2, characterized in that The kernel release module is further configured to Determine the default release priority for releasing the current file cache; Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list; Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
4. The embedded device cache management system according to claim 3, wherein The kernel release module is further configured to After releasing each physical page, increment the count of the number of released pages by 1 to obtain the cumulative count of released pages after traversing the physical page linked list of the memory area; Judge whether the value obtained by multiplying the cumulative count of released pages by the size of the physical page is less than the threshold value of the system file cache. If it is less, decrement the default release priority of the current file cache to be released by 1; Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list; Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
5. An embedded device cache management method, characterized in that, Comprising: The user cache configuration module sets the threshold value of the system file cache of the embedded device and passes the threshold value to the kernel cache monitoring module through system calls; The kernel cache monitoring module uses a timed task to monitor the size of the system file cache of the embedded device. When the size of the system file cache reaches the threshold value, it notifies the kernel statistics module to collect file cache information in real time; The kernel statistics module traverses the file nodes under the file system superblock of the embedded device to statistically collect the file cache information corresponding to the file nodes in real time and passes the file cache information to the user cache release setting module; The user cache release setting module determines the file cache information to be released of the embedded device according to the received file cache information in combination with the business scenario and passes the file cache information to be released to the user cache release module; The user cache release module passes the received file cache information to be released to the kernel release module in the form of a linked list through system calls; The kernel release module releases the physical pages in the memory area of the embedded device that match the file cache addresses in the file information to be released based on the release priority in the file information to be released.
6. The embedded device cache management method according to claim 5, characterized in that, The kernel cache monitoring module uses a timed task to monitor the size of the system file cache of the embedded device. When the size of the system file cache reaches the threshold value, it notifies the kernel statistics module to collect file cache information in real time, including: Starting a timer task. In the timer task, query the memory size occupied by the shared file system of the embedded device, the file cache size occupied by non-active file pages, and the file cache size occupied by active file pages; Determine the sum of the memory size occupied by the shared file system, the file cache size occupied by the active file pages, and the file cache size occupied by the active file pages as the size of the system file cache of the embedded device; Compare the size of the system file cache of the embedded device with the threshold value. When the size of the system file cache reaches the threshold value, wake up the kernel statistics module to collect file cache information in real time.
7. The cache management method for an embedded device according to any one of claims 5-6, characterized in that The kernel release module releases the physical pages in the memory area of the embedded device that match the file cache addresses in the file information to be released based on the release priority in the file information to be released, and also includes: Determine the default release priority for the current file cache to be released; Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list; Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If they can match, release the physical page.
8. The embedded device cache management method according to claim 7, wherein, It also includes, After releasing each physical page, increment the count of the number of released pages by 1 to obtain the cumulative count of released pages after traversing the physical page linked list of the memory area; Judge whether the value obtained by multiplying the cumulative count of released pages by the size of the physical page is less than the threshold value of the system file cache. If it is less, decrement the default release priority of the current file cache to be released by 1; Traverse the physical page linked list of the memory area in sequence to obtain the file cache address of each physical page in the physical page linked list; Compare the file cache address of each physical page with the file cache address with the default release priority in the file cache information to be released. If a match is found, release the physical page.
9. An electronic device, characterized in that, Including: A processor and a memory; The processor is coupled to the memory; Wherein, the processor is configured to read and execute the program or instruction stored in the memory, so that the device executes the method according to any one of claims 5-8.
10. A computer-readable storage medium, characterized in that, A computer program is stored, and when the program is executed by the processor, the method according to any one of claims 5-8 is implemented.