Method, device, computing device and readable storage medium for counting page cache

By traversing and matching the process management data structure, obtaining and accumulating the physical page frame data structure of the page cache management data structure of the target process, the problems of large and interference in the page cache in the prior art are solved, and the precise statistics of the target process page cache are achieved.

CN114490286BActive Publication Date: 2025-03-25UNIONTECH SOFTWARE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111634208.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-22
Publication Date
2025-03-25
Estimated Expiration
2041-12-22

AI Technical Summary

Technical Problem

In the prior art, when stating page cache of target processes, the error is large and susceptible to page cache of other processes, resulting in inaccurate statistical results.

Method used

By initializing the data structure, iterating through the management data structure of all processes, matching the PID of the target process, obtaining the page cache management data structure of the opened file, and traversing the physical page frame data structure in the tree data structure, and accumulating the page cache sum of the target process.

Benefits of technology

It realizes accurate statistics on the page cache of the target process, avoids the problems of page cache interference and loss of statistical data in other processes, and improves the accuracy of statistical results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114490286B_ABST
    Figure CN114490286B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for counting page cache, including: initializing a data for storing the page cache sum of a target process; traversing the management data structure of all processes, matching the management data structure of the target process according to the PID of the target process; obtaining the data structure of all opened files from the management data structure of the target process; obtaining the page cache management data structure of the file from the data structure of each file; obtaining a tree data structure from the page cache management data structure, traversing each physical page frame data structure in the tree data structure; and adding one to the page cache sum each time a physical page frame data structure is found. According to the technical solution of the present invention, the page cache of the target process can be accurately counted, avoiding the problems of interference with the page cache of other processes and loss of statistical data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of page reading and memory cache, and in particular to a method and device for counting page cache, a computing device and a readable storage medium. Background Art

[0002] When using a computing device to read files, disk reading is generally slow, so after the first read, it will be loaded into the memory and cached. It is necessary to count the number of file pages opened by the process cached in the memory. If the statistical result shows that the memory usage is too large, some memory can be released to avoid problems such as excessive pressure and insufficient space when the memory usage is too large.

[0003] There are currently two main methods used to conduct this statistics.

[0004] Existing solution 1: Count the cache of file pages opened by a process by counting the difference in the FilePages attribute value in the / sys / devices / system / node / nodeX / meminfo file over a period of time (nodeX in the path represents: node0, node1, ...).

[0005] The method to count the FilePages attribute value in / sys / devices / system / node / nodeX / meminfo is as follows: execute the target process and let the target process sleep before reading the file; execute: cat / sys / devices / system / node / nodeX / meminfo|grep FilePages to obtain the FilePages attribute value val1 before the target process reads the file; wake up the target process to read the file; the target process finishes reading the file; execute again: cat / sys / devices / system / node / nodeX / meminfo|grep FilePages to obtain the FilePages attribute value val2 after the target process reads the file; finally, calculate the page cache of the target process on NUMA node X as: val2-val1.

[0006] The disadvantage of this solution is that the statistical error is too large, and the target process is easily interfered by the page cache of other processes in the system during the statistical process. During the execution of the target process, there may be other processes in the system that perform page cache operations concurrently, which will result in the final statistical result including not only the page cache distribution of the target process, but also the distribution of the page cache of other processes. Therefore, this method actually counts the total page cache distribution of all processes in the system. Therefore, for scenarios where only the cache distribution of a single target process on each NUMA node needs to be obtained, the error of this statistical method cannot be estimated.

[0007] Existing solution 2: Tracking the allocation function of the kernel page cache through BPF dynamic tracing technology. The disadvantage of this solution is that since the allocation function of the page cache is executed too frequently, statistical data is easily lost during the dynamic tracing process, resulting in inaccurate statistical data and large errors. Summary of the invention

[0008] To this end, the present invention provides a method and apparatus for counting page caches, a computing device, and a readable storage medium, in an effort to solve or at least alleviate at least one of the above problems.

[0009] According to one aspect of the present invention, a method for counting page cache is provided, comprising: initializing data for storing the page cache sum of a target process; traversing the management data structures of all processes, and matching the management data structure of the target process according to the PID of the target process; obtaining the data structure of all opened files from the management data structure of the target process; obtaining the page cache management data structure of each file from the data structure of each file; obtaining a tree data structure from the page cache management data structure, and traversing each physical page frame data structure in the tree data structure; and adding one to the page cache sum each time a physical page frame data structure is found.

[0010] According to another aspect of the present invention, there is also provided a device for counting page cache, comprising: an initialization module for initializing data for storing the page cache sum of a target process; a target process matching module for traversing the management data structures of all processes and matching the management data structure of the target process according to the PID of the target process; a file structure acquisition module for acquiring the data structure of all opened files from the management data structure of the target process; a page cache management data structure acquisition module for acquiring the page cache management data structure of each file from its data structure; a physical page frame data structure traversal module for acquiring a tree data structure from the page cache management data structure and traversing each physical page frame data structure in the tree data structure; and an accumulation module for adding one to the page cache sum each time a physical page frame data structure is found.

[0011] According to another aspect of the present invention, there is provided a computing device, comprising: at least one processor and a memory storing program instructions; when the program instructions are read and executed by the processor, the computing device executes the above-mentioned method of counting page cache.

[0012] According to another aspect of the present invention, a readable storage medium storing program instructions is provided. When the program instructions are read and executed by a computing device, the computing device executes the above-mentioned method for counting page cache.

[0013] According to the technical solution of the present invention, the page cache of the target process can be accurately counted, avoiding the problems of cache interference and loss of statistical data of file pages opened by other processes. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] To achieve the above and related purposes, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings, which indicate various ways in which the principles disclosed herein can be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. The above and other purposes, features and advantages of the present disclosure will become more apparent by reading the following detailed description in conjunction with the accompanying drawings. Throughout the present disclosure, the same reference numerals generally refer to the same parts or elements.

[0015] Figure 1 A schematic diagram of a computing device 100 according to one embodiment of the present invention is shown;

[0016] Figure 2 The overall architecture of the statistical method according to the embodiment of the present invention is shown;

[0017] Figure 3 A flow chart of a method 300 for counting page caches according to an embodiment of the present invention is shown.

[0018] Figure 4 A schematic block diagram showing the implementation of the procfs file system for transferring process PIDs to a kernel module and exporting statistical results.

[0019] Figure 5 A schematic block diagram of an apparatus for counting page cache according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0020] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0021] In view of the problem that the existing page cache statistical method has large statistical errors, the present invention provides a method for statistical page cache, which can accurately count the page cache of the target process and avoid problems such as interference from other process page caches and loss of statistical data.

[0022] The method for counting page caches of the present invention is executed in a computing device. The computing device can be any device with storage and computing capabilities, which can be implemented as a server, a workstation, etc., or as a personal computer such as a desktop computer, a notebook computer, or as a terminal device such as a mobile phone, a tablet computer, a smart wearable device, an Internet of Things device, but is not limited thereto.

[0023] Figure 1 FIG. 1 is a schematic diagram of a computing device 100 according to an embodiment of the present invention. It should be noted that: Figure 1 The computing device 100 shown is only an example. In practice, the computing device used to implement the page cache statistics method of the present invention can be any type of device, and its hardware configuration can be different from the above. Figure 1 The computing device 100 shown is the same as Figure 1 The computing device 100 shown is different. In practice, the computing device used to implement the page cache statistics method of the present invention can be Figure 1 The hardware components of the computing device 100 shown are increased or deleted, and the present invention does not limit the specific hardware configuration of the computing device.

[0024] like Figure 1 As shown, in a basic configuration 102, computing device 100 typically includes system memory 106 and one or more processors 104. A memory bus 108 may be used for communication between processor 104 and system memory 106.

[0025] Depending on the desired configuration, the processor 104 can be any type of processor, including but not limited to: a microprocessor (μP), a microcontroller (μC), a digital information processor (DSP), or any combination thereof. The processor 104 can include one or more levels of cache such as a first-level cache 110 and a second-level cache 112, a processor core 114, and registers 116. An example processor core 114 can include an arithmetic logic unit (ALU), a floating point unit (FPU), a digital signal processing core (DSP core), or any combination thereof. An example memory controller 118 can be used with the processor 104, or in some implementations, the memory controller 118 can be an internal part of the processor 104.

[0026] Depending on the desired configuration, the system memory 106 can be any type of memory, including but not limited to: volatile memory (such as RAM), non-volatile memory (such as ROM, flash memory, etc.) or any combination thereof. The physical memory in the computing device generally refers to the volatile memory RAM, and the data in the disk needs to be loaded into the physical memory before it can be read by the processor 104. The system memory 106 may include an operating system 120, one or more applications 122, and program data 124. In some embodiments, the application 122 may be arranged to execute instructions on the operating system by one or more processors 104 using program data 124. The operating system 120 may be, for example, Linux, Windows, etc., which includes program instructions for processing basic system services and performing tasks that depend on hardware. The application 122 includes program instructions for implementing various user-desired functions, and the application 122 may be, for example, a browser, instant messaging software, a software development tool (such as an integrated development environment IDE, a compiler, etc.), etc., but is not limited thereto. When the application 122 is installed in the computing device 100, a driver module may be added to the operating system 120.

[0027] When the computing device 100 starts running, the processor 104 reads and executes the program instructions of the operating system 120 from the memory 106. The application 122 runs on the operating system 120 and uses the interfaces provided by the operating system 120 and the underlying hardware to implement various functions desired by the user. When the user starts the application 122, the application 122 is loaded into the memory 106, and the processor 104 reads and executes the program instructions of the application 122 from the memory 106.

[0028] Computing device 100 also includes a storage device 132 including a removable storage 136 and a non-removable storage 138 , both of which are connected to storage interface bus 134 .

[0029] The computing device 100 may also include an interface bus 140 that facilitates communication from various interface devices (e.g., output devices 142, peripheral interfaces 144, and communication devices 146) to the basic configuration 102 via the bus / interface controller 130. Example output devices 142 include a graphics processing unit 148 and an audio processing unit 150. They can be configured to facilitate communication with various external devices such as a display or speakers via one or more A / V ports 152. Example peripheral interfaces 144 may include a serial interface controller 154 and a parallel interface controller 156, which may be configured to facilitate communication with external devices such as input devices (e.g., keyboards, mice, pens, voice input devices, touch input devices) or other peripherals (e.g., printers, scanners, etc.) via one or more I / O ports 158. Example communication devices 146 may include a network controller 160, which may be arranged to facilitate communication with one or more other computing devices 162 via a network communication link via one or more communication ports 164.

[0030] A network communication link can be an example of a communication medium. Communication media can generally be embodied as computer-readable instructions, data structures, program modules in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium. A "modulated data signal" can be a signal in which one or more of its data sets or its changes can be carried out in a manner that encodes information in the signal. As a non-limiting example, communication media can include wired media such as a wired network or a dedicated line network, and various wireless media such as sound, radio frequency (RF), microwave, infrared (IR) or other wireless media. The term computer-readable medium used herein can include both storage media and communication media.

[0031] In the computing device 100 according to the present invention, the application 122 includes instructions for executing the method 300 for counting page caches of the present invention. The instructions may instruct the processor 104 to execute the method 300 for counting page caches of the present invention.

[0032] Figure 2 The overall architecture of the statistical method 300 is shown. As described above, when a computing device is used to read a file, disk reading is generally slow, so after the first read, it is loaded into the memory and cached. It is necessary to count the number of file pages opened by the process cached in the memory. If the statistical result shows that the memory usage is too large, part of the memory can be released to avoid problems such as too much pressure and insufficient space when the memory usage is too large.

[0033] It should be noted that, in the specific embodiment, the present invention specifically describes the page cache statistics method by taking the Linux operating system as an example. However, it should be understood that the page cache statistics method of the present invention is not limited to the specific type of operating system that executes the method, and those skilled in the art can understand that the method can also be implemented on other types of operating systems without creative labor. Any process of counting page caches by the method of the present invention implemented on other operating systems is within the protection scope of the present invention.

[0034] exist Figure 2 In the embodiment, the page cache number of all files opened by the target process (identified by PID) is counted by placing a program (page cache statistics module, also called kernel module) running in the Linux kernel, that is, the statistical method 300 is executed. The Linux kernel is an open source operating system kernel, a Unix-like operating system written in C language and compliant with the POSIX standard, and includes the core parts of the Linux system such as process management, memory management, and drivers. A process is a running activity of a program in a computer on a certain data set, and is the basic unit for resource allocation and scheduling of the system, and is the basis of the operating system structure.

[0035] Figure 2 The page cache statistics module shown in the figure counts the number of page caches of all files opened by the target process. In a NUMA environment, the page cache can also be counted separately according to the NUMA memory node to obtain the page cache size of the target process on each NUMA memory node. Among them, the NUMA environment refers to an architecture model for multi-processor access to memory, which is a non-uniform memory access (Non Uniform Memory Access) and is often used in some servers or large machines. In this multi-CPU, multi-memory computing environment, the independent memory unit of each CPU is called a NUMA memory node (such as Figure 2 NUMA0, NUMA1 shown).

[0036] Finally, the statistical results are exported to the user space through the procfs file system for users to view. The procfs file system is the abbreviation of the process file system, which is a pseudo file system (a file system dynamically generated at startup) used to export process information from the kernel to the user space.

[0037] Reference below Figure 3 The statistical method 300 according to the embodiment of the present invention is described in detail. Figure 3 As shown, the method 300 includes:

[0038] Step S310, initializing data for storing the page cache of the target process.

[0039] The target process refers to the process to be observed, such as a communication APP.

[0040] In a single CPU, single memory computing environment, this data only counts the page cache on a single memory and can be a numerical value. In a NUMA structure, the page cache on each NUMA memory node needs to be counted. At this time, the data initialized in step S310 can be an integer array, which is used to store the page cache sum corresponding to each NUMA node in a NUMA environment. For example, assuming there are four NUMA nodes, the array is initialized to {0,0,0,0}, corresponding to the initial page cache sum of the four NUMA nodes.

[0041] This step S310 is to apply for space from the memory for storing the statistical results. When allocating, the operating system will allocate space for storing data in a suitable place according to the environment needs.

[0042] S320, traverse the management data structures of all processes, and match the management data structure of the target process according to the PID of the target process.

[0043] In an operating system, there are usually multiple processes running at the same time, such as text editing tools, communication apps, etc. For example, if you want to observe a communication app, you need to find the process in the system first.

[0044] In the system, each process is described by a management data structure (process control block PCB) task_struct. Task_struct describes all the information of the process, including all the files opened by the process, etc. So we need to find the structure task_struct of the communication APP first.

[0045] The management data structure task_struct contains the PID of the process. It is determined whether the process PID in the management data structure task_struct is equal to the PID of the target process. If they are equal, the management data structure task_struct of the communication APP is found.

[0046] About the kernel module to know the PID of the target process: In the actual application scenario, write a program for the kernel module in advance, such as C language, and then compile it to get the binary result (named page_cache_tongji.ko), and install it into the kernel through the command insert page_cache_tongji.ko. By entering the command echo `pidof A`> / proc / pgcacheperprocess / pid_target in the user interface shell of the Linux system, the PID of the target process A can be imported into the Linux kernel module. In this way, the PID of the target process is written into the kernel module.

[0047] S330, obtaining the data structure (file) of all opened files from the management data structure of the target process.

[0048] When the communication APP is running, multiple files will be opened, such as files for mutual file transfer, required files, configuration files, etc. It is necessary to obtain the data structure of all files opened by the communication APP.

[0049] For example, a communication app opens a text file called 1.txt. When the file is opened, a data structure (file) is created to represent the file 1.txt in the operating system. File is a data structure that represents files in the Linux kernel. Among them, file operation permissions, file operation and other attributes will be placed in the data structure, and disk location, file size and other attributes will be indirectly placed in the data structure. 1.txt can be found through this data structure.

[0050] S340, obtaining the page cache management data structure address_space of each file from the data structure of each file.

[0051] Each data structure file contains a page cache management data structure address_space. Address_space is used to implement page cache management. For example, when a communication app opens some files, it needs to read the files into the memory and then cache them. When caching, address_space is used to manage the cached data.

[0052] This step is equivalent to jumping from the file data structure (file) to address_space. Because the page cache cannot be seen from the file, it is necessary to jump to the data structure address_space that actually manages the cache.

[0053] S350, obtaining a tree data structure from the page cache management data structure address_space, and traversing each physical page frame data structure in the tree data structure.

[0054] The tree data structure can be radix-tree or xarray, which is the attribute of the page cache management data structure address_space, and is used to store the mapping relationship between the page cache (i.e., the physical page frame data structure page) and the file data and the physical page frame. Page is a data structure representing a physical page frame in the Linux kernel, and a physical page frame is usually 4096 bytes in size.

[0055] For example, when the 1.txt file is opened, the relevant data will be loaded into the physical memory. 1.txt may contain many pages, and each page will be placed in a certain location in the physical memory. The physical page frame data structure and the mapping relationship between file data and physical page frames are stored through the tree data structure radix_tree / xarray. The physical page frame data structure page stores the physical memory location of these pages. In addition, page also stores other physical page attributes, such as physical page frame permissions, usage counts, etc., and page can also obtain the physical page frame base address.

[0056] For example, 1.txt has two pages, each of which is 4k. If you want to find the data of the second page, pass the offset 4k to the query function of the radix_tree data structure, so that the second 4k page can be found from radix_tree, and then the address of the page can be found through the data structure page, and then the file data stored in the page cache can be retrieved. Among them, the kernel module can call the relevant Linux mechanism to operate the data structure through the function interface provided by Linux, which belongs to the Linux internal system operation well known to technicians in this field, and will not be described in detail in this article.

[0057] radix-tree and xarray have the same function, which is to store page cache (i.e., physical page frame data structure page) and the mapping relationship between file data and physical page frames. The difference lies in the different kernel versions of Linux.

[0058] Each data structure file has a corresponding tree data structure radix_tree / xarray. In this step, the corresponding radix_tree / xarray in each file is traversed.

[0059] S360, each time a physical page frame data structure is found, the page cache sum is increased by one.

[0060] If it is in a NUMA environment, the NUMA memory node where the page cache is located is stored in the physical page frame data structure Page, and the NUMA memory node where the page cache is located can be obtained from Page, and the page cache sum of the NUMA node to which the page cache belongs in the array is increased by 1. Here, the function page_to_nid in the Linux kernel can be used to obtain the node where the page cache is located in page.

[0061] After updating the array and saving it, you can use the command cat / proc / pgcacheperprocess / pg_result to export the statistical results for users to view.

[0062] Figure 4A schematic block diagram showing the implementation of the procfs file system for transferring process PIDs to the Linux kernel module and exporting statistical results is shown. Figure 4 In the example, the PID of the target process is passed to the kernel module from / proc / pgcacheperprocess / pid_target. / proc / pgcacheperprocess / pg_result is a custom directory and a file path created by the Linux kernel module.

[0063] The statistical method according to the embodiment of the present invention is simple, convenient and easy to use. In addition, when it is necessary to count the distribution of a single process on each NUMA memory node, accurate statistics of the page cache distribution of the process on the NUMA memory node can be achieved. As mentioned above, when the user counts the page cache of the target process on a certain memory node, by counting the FilePages attribute value in the / sys / devices / system / node / nodeX / meminfo file or using the BPF dynamic tracking technology, the schemes all have errors, it is difficult to achieve accurate statistics, and it is not convenient to operate. The technical solution according to the embodiment of the present invention avoids this problem and can achieve accurate statistics.

[0064] The Linux system can also monitor the data created in step S310, and when the page cache in the data exceeds a predetermined value, a warning is issued to remind the user to release the page cache of the memory. In a NUMA environment, a warning can be issued when any value in the array exceeds a predetermined value. The predetermined value can be set according to the maximum runtime occupancy set by the user for (each) memory, etc. The warning issued can be in the form of text displayed on the screen, or prompting the machine to emit a prompt sound, etc.

[0065] The purpose of statistics can be used for page cache migration. For example, in a NUMA environment, a file is opened on CPU No. 0, and the page cache of the file may be distributed in a memory of one of the 10 NUMA nodes. Usually, a better solution is to place the page cache on a node that is closer to the CPU running the process. When there are more page caches on other more distant nodes, this problem can be optimized, such as migrating to a node that is closer to the CPU. In addition to page cache migration, statistics can also be used to view the reasons why there are more page caches on more distant nodes, so as to troubleshoot the problem as soon as possible.

[0066] The method can also be executed at predetermined intervals and monitored regularly to avoid excessive memory usage.

[0067] The method can also be executed at a predetermined time. To count the number of page caches loaded in a certain time period, such as one minute, the method can be executed at the time points one minute before and one minute after, respectively, to obtain the respective page cache sums, and then the two page cache sums are subtracted to obtain the number of page caches loaded in one minute. The time period can also be half an hour, one hour, etc., so that the memory usage in a certain time period can be understood.

[0068] In addition, the above method 300 can also be executed for multiple processes. The PIDs of the multiple processes to be monitored can be passed to the kernel module, and the kernel module initializes multiple arrays, each array representing the number of page caches of a process on each NUMA node. For multiple processes, the method can be executed in parallel or in sequence.

[0069] According to an embodiment of the present invention, a device for counting page cache is also provided. Figure 5 A schematic block diagram of the device for statistic page cache is shown. Figure 5 As shown, the device comprises:

[0070] Initialization module 510 is used to initialize a data for storing the page cache sum of the target process. The data may be a numerical value for storing the page cache sum of the target process in a single memory computing environment. In a NUMA environment, the data is an array of integer type for storing the page cache sum corresponding to each NUMA node in the NUMA environment, and the initialization module 510 initializes the integer type array according to the number of NUMA nodes, and the number of elements contained in the array is equal to the number of NUMA nodes.

[0071] The target process matching module 520 is used to traverse the management data structures of all processes and match the management data structure of the target process according to the PID of the target process;

[0072] The file structure acquisition module 530 is used to acquire the data structures of all opened files from the management data structure of the target process;

[0073] A page cache management data structure acquisition module 540, used to acquire a page cache management data structure of a file from a data structure of each file;

[0074] A physical page frame data structure traversal module 550 is used to obtain a tree data structure from a page cache management data structure and traverse each physical page frame data structure in the tree data structure;

[0075] The accumulation module 560 is used to add one to the page cache sum each time a physical page frame data structure is found. In a NUMA environment, the accumulation module 560 obtains the node where the page cache is located from the physical page frame data structure each time a physical page frame data structure is found, and adds one to the page cache sum of the NUMA node to which the page cache belongs in the array.

[0076] The device may also include: a timing module, used to start the device at a first predetermined time and a second predetermined time respectively, to obtain the page cache sum at the first predetermined time and the page cache sum at the second predetermined time; a subtraction module, used to subtract the page cache sum at the first predetermined time from the page cache sum at the second predetermined time, so as to obtain the number of page caches loaded in the time period between the second predetermined time and the first predetermined time.

[0077] The various techniques described herein may be implemented in combination with hardware or software, or a combination thereof. Thus, the method and apparatus of the present invention, or some aspects or parts of the method and apparatus of the present invention may be in the form of program codes (i.e., instructions) embedded in a tangible medium, such as a removable hard disk, a USB flash drive, a floppy disk, a CD-ROM, or any other machine-readable storage medium, wherein when the program is loaded into a machine such as a computer and executed by the machine, the machine becomes a device for practicing the present invention.

[0078] In the case where the program code is executed on a programmable computer, the computing device generally includes a processor, a storage medium readable by the processor (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store the program code; the processor is configured to execute the page cache statistics method of the present invention according to the instructions in the program code stored in the memory.

[0079] By way of example and not limitation, readable media include readable storage media and communication media. Readable storage media stores information such as computer readable instructions, data structures, program modules or other data. Communication media generally embody computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and include any information transfer medium. Any combination of the above is also included within the scope of readable media.

[0080] In the description provided herein, algorithms and displays are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with examples of the present invention. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages ​​can be utilized to implement the content of the present invention described herein, and the above description of specific languages ​​is for disclosing preferred embodiments of the present invention.

[0081] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0082] Similarly, it should be understood that in order to simplify the present disclosure and help understand one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following intention: the claimed invention requires more features than the features clearly stated in each claim. It should be understood by those skilled in the art that the modules or units or components of the devices in the examples disclosed herein can be arranged in the devices described in the embodiment, or alternatively can be located in one or more devices different from the devices in the example. The modules in the aforementioned examples can be combined into one module or can be divided into multiple submodules in addition.

[0083] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

[0084] In addition, it will be appreciated by those skilled in the art that although some of the embodiments described herein include certain features included in other embodiments rather than other features, the combination of features of different embodiments is meant to be within the scope of the present invention and to form different embodiments. In addition, some of the embodiments described herein are described as a combination of methods or method elements that can be implemented by a processor of a computer system or by other devices that perform the functions. Therefore, a processor with necessary instructions for implementing the method or method elements forms a device for implementing the method or method elements. In addition, the elements described herein of the device embodiments are examples of devices that are used to implement the functions performed by the elements for the purpose of implementing the invention.

[0085] As used herein, unless otherwise specified, the use of ordinal numbers "first," "second," "third," etc. to describe common objects merely indicates that different instances of similar objects are involved, and is not intended to imply that the objects so described must have a given order in time, space, order, or in any other manner.

[0086] Although the present invention has been described according to a limited number of embodiments, it will be apparent to those skilled in the art, with the benefit of the above description, that other embodiments may be envisioned within the scope of the invention thus described. In addition, it should be noted that the language used in this specification is primarily selected for readability and instructional purposes, rather than for the purpose of explaining or limiting the subject matter of the present invention.

Claims

1. A method for counting page caches, comprising: Initialize a data to store the page cache of the target process; Traverse the management data structure of all processes and match the management data structure of the target process according to the PID of the target process; Get the data structure of all opened files from the management data structure of the target process; Get the page cache management data structure of the file from the data structure of each file; Obtain a tree data structure from the page cache management data structure, and traverse each physical page frame data structure in the tree data structure; Each time a physical page frame data structure is found, the page cache sum is increased by one.

2. The method for counting page cache as described in claim 1, wherein the data is a numerical value used to store the page cache and of the target process in a single memory computing environment.

3. The method for counting page caches according to claim 1, wherein the data is an array of integer type, used to store the sum of page caches corresponding to each NUMA node in a NUMA environment, and the method comprises the steps of: Initializing the array of integer type according to the number of NUMA nodes, the number of elements contained in the array is equal to the number of NUMA nodes, and Whenever a physical page frame data structure is found, the NUMA node where the page cache is located is obtained from the physical page frame data structure, and the page cache sum of the NUMA node in the array is increased by one.

4. The method for counting page caches according to claim 1, further comprising: Execute the method at a first predetermined time and a second predetermined time respectively to obtain the page cache sum at the first predetermined time and the page cache sum at the second predetermined time; The page cache sum at the second predetermined time is subtracted from the page cache sum at the first predetermined time, thereby obtaining the number of page caches loaded within the time period between the second predetermined time and the first predetermined time.

5. A device for counting page cache, comprising: An initialization module, used to initialize data for storing the page cache of the target process; The target process matching module is used to traverse the management data structure of all processes and match the management data structure of the target process according to the PID of the target process; A file structure acquisition module is used to obtain the data structures of all opened files from the management data structure of the target process; A page cache management data structure acquisition module, used to acquire the page cache management data structure of each file from the data structure of each file; A physical page frame data structure traversal module is used to obtain a tree data structure from a page cache management data structure and traverse each physical page frame data structure in the tree data structure; The accumulation module is used for adding one to the page cache sum each time a physical page frame data structure is found.

6. The apparatus for counting page cache as claimed in claim 5, wherein the data is a numerical value used to store the page cache sum of the target process in a single memory computing environment.

7. The apparatus for counting page cache according to claim 5, wherein the data is an array of integer type, used to store the page cache corresponding to each NUMA node in a NUMA environment, and the initialization module initializes the array of integer type according to the number of NUMA nodes, and the number of elements contained in the array is equal to the number of NUMA nodes, and The accumulation module obtains the NUMA node where the page cache is located from the physical page frame data structure each time it finds a physical page frame data structure, and adds one to the page cache sum of the NUMA node in the array.

8. The apparatus for counting page cache according to claim 5, further comprising: A timing module, used to start the device at a first predetermined time and a second predetermined time respectively, to obtain the page cache sum at the first predetermined time and the page cache sum at the second predetermined time; The subtraction module is used to subtract the page cache sum at the first predetermined time from the page cache sum at the second predetermined time, so as to obtain the number of page caches loaded within the time period between the second predetermined time and the first predetermined time.

9. A computing device comprising: at least one processor and a memory storing program instructions; When the program instructions are read and executed by the processor, the computing device executes the method for counting page cache according to any one of claims 1 to 4.

10. A readable storage medium storing program instructions, when the program instructions are read and executed by a computing device, the computing device executes the method for counting page cache according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • System managing method and device

    CN104598166A

  • Page cache method for non-volatile storage

    CN107704400A