File system inode maintenance method and electronic device

By monitoring file system creation events in the operating system kernel-mode program and automatically cleaning up inodes, the system failures and data loss caused by inode exhaustion are resolved, and automated management and real-time maintenance of inodes are achieved.

CN122633643APending Publication Date: 2026-08-25INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611125496.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-28
Publication Date
2026-08-25

AI Technical Summary

Technical Problem

In existing technologies, the exhaustion of inode resources in Linux/Unix-like operating systems can prevent the system from creating files or directories, leading to application failures and data loss. Furthermore, existing solutions lack real-time performance and efficiency, and complex operations pose high risks.

Method used

By pre-loading packet filter functions in the operating system kernel program, the system monitors file or directory creation to obtain the target device number, queries the inode usage and threshold, calculates the node growth rate, and sends context information to the user-space program for automatic cleanup when the threshold is exceeded, thus achieving automated management of inodes.

Benefits of technology

It achieves automated utilization awareness and release of index nodes, saving manpower and time costs, reducing system resource consumption, and has real-time management capabilities without requiring an operating system restart.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122633643A_ABST
    Figure CN122633643A_ABST
Patent Text Reader

Abstract

The application discloses an inode maintenance method of a file system and an electronic device, and relates to the technical field of computers, and comprises the following steps: when it is monitored that a file or a directory is created, triggering a packet filter function pre-mounted in a kernel state program to obtain a target device number corresponding to a target file system; taking the target device number as a key, querying a current inode usage, an alarm threshold and a growth rate threshold from a packet filter mapping table; if the current inode usage is less than the alarm threshold, calculating a node growth rate according to the current inode usage and a historical inode usage; when the node growth rate exceeds a preset growth rate threshold, sending context information when the packet filter function is triggered to a user state program, so as to clean up the inode according to a preset node cleaning strategy and the context information. The application can improve the efficiency of inode release and reduce the consumption of system resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method for maintaining inodes in a file system and an electronic device. Background Technology

[0002] In the file system of Linux / Unix-like operating systems, there exists an inode (i.e., index node). An inode is a pre-allocated, non-dynamically expandable system resource used to store metadata (such as file type, permissions, owner, size, timestamp, data block pointers, and other attribute information) of file system objects (such as files and directories). Once the inode is exhausted, the system will be unable to create new files, directories, and other objects, resulting in application failures, service interruptions, and data loss.

[0003] Currently, inode usage is typically monitored and cleaned up manually or through pre-written scripts by administrators. These methods are reactive, addressing situations where inode exhaustion has already occurred. Business operations may suffer irreversible consequences such as interruptions or data loss due to inode depletion, and these methods lack real-time capability and consume significant system resources. Pre-allocating more inodes or using a dynamically allocated file system typically requires complex operations such as data backup, reformatting, and data recovery, which carries a high risk of data loss, is complex, and results in long downtime, thus lacking universal applicability. Summary of the Invention

[0004] In view of this, the purpose of this application is to provide a method and electronic device for maintaining inodes in a file system, which can realize automated inode usage awareness and automatic release, saving labor and time costs, and improving the efficiency of inode release. Furthermore, this application does not require restarting the operating system, thereby reducing the consumption of system resources, while also meeting the requirements for real-time management of inodes. The specific solution is as follows: In a first aspect, this application discloses a method for maintaining inodes in a file system, applied to an operating system, including: When a file or directory is detected to be created, a packet filter function pre-mounted in the kernel-mode program of the operating system is triggered to obtain the target device number corresponding to the target file system associated with the created file or directory. Using the target device number as the key, query the target file system's current inode usage, usage alarm threshold, and preset growth rate threshold from the kernel-mode program's packet filter mapping table; If the current index node utilization rate is less than the utilization rate alarm threshold, then the node growth rate of the index node within the historical preset time period is calculated based on the current index node utilization rate and the historical index node utilization rate of the target file system. When the node growth rate exceeds the preset growth rate threshold, the context information triggered by the packet filter function is sent to the user-space program to clean up the inodes in the target file system according to the node release priority in the preset node cleanup strategy; the context information includes the target device number.

[0005] Secondly, this application discloses an electronic device, including a processor and a memory; wherein, when the processor executes a computer program stored in the memory, it implements the aforementioned file system inode maintenance method.

[0006] As can be seen, this application is applied to an operating system. When the creation of a file or directory is detected, a packet filter function pre-mounted in the kernel-mode program of the operating system is first triggered to obtain the target device number corresponding to the target file system associated with the created file or directory. Then, using the target device number as the key, the current inode usage rate, usage rate alarm threshold, and preset growth rate threshold of the target file system are queried from the packet filter mapping table of the kernel-mode program. If the current inode usage rate is less than the usage rate alarm threshold, the node growth rate of the inodes within a preset historical period is calculated based on the current inode usage rate and the historical inode usage rate of the target file system. When the node growth rate exceeds the preset growth rate threshold, the context information of the packet filter function is sent to the user-mode program to clean up the inodes in the target file system according to the node release priority in the preset node cleanup policy and based on the context information. The context information includes the target device number.

[0007] When this application detects the creation of a file or directory, it triggers a packet filter function (such as an eBPF function) pre-mounted in the kernel-mode program. This function first obtains the device number of the relevant file system, and then uses this device number as a key to retrieve the data from the packet filter mapping table of the kernel-mode program (such as eBPF). The system queries the current file system's index node utilization rate, utilization alarm threshold, and preset growth rate threshold in the `map` function. If the index node utilization rate is less than the utilization alarm threshold, the system further calculates the growth rate of the index nodes within a preset historical time period based on the current and historical index node utilization rates. When the node growth rate exceeds the preset growth rate threshold, the context information triggered by the filter function is sent to the user-space program. This allows the user-space program to clean up the index nodes according to the node release priority in the preset node cleanup strategy and based on the context information. Through this method, automated index node utilization awareness and automatic release are achieved, saving manpower and time costs. Furthermore, this application uses a packet filter function to enable kernel-space and user-space programs to collaboratively achieve index node utilization awareness and release. The complex process of obtaining the index node utilization rate, threshold judgment, and node growth rate calculation is implemented by the kernel-space program, while the index node cleanup / release operation is implemented by the user-space program. This improves the efficiency of index node release. In addition, this application does not require restarting the operating system, reduces the consumption of system resources, and does not require setting a preset period, thus meeting the requirements for real-time management of index nodes. Attached Figure Description

[0008] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0009] Figure 1 This is a flowchart of a file system inode maintenance method disclosed in this application; Figure 2 This is a flowchart of a specific file system inode maintenance method disclosed in this application. Detailed Implementation

[0010] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.

[0011] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0012] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0013] This application discloses a method for maintaining inodes in a file system, applied to an operating system. See [link to relevant documentation]. Figure 1 As shown, the method includes: Step S11: When a file or directory is detected to be created, trigger the packet filter function in the kernel-mode program pre-mounted in the operating system to obtain the target device number corresponding to the target file system associated with the created file or directory.

[0014] It should be noted that the file system inode maintenance scheme proposed in this application is specifically applied to Linux / Unix-like operating systems, and a packet filter function, such as the eBPF (extended Berkeley Packet Filter, a technology for running sandbox programs in the Linux kernel) function, is pre-mounted in the kernel-mode program of the operating system. In addition, a packet filter mapping table (such as eBPF map) is also pre-created in the kernel-mode program.

[0015] In this embodiment, when the creation of a file or directory (such as the log directory, tmp directory, etc.) is detected, a packet filter function (such as the eBPF function) pre-mounted in the kernel-mode program of the operating system is first triggered to obtain the device number of the target file system associated with the currently created file or directory, thus obtaining the target device number. Among them, the detected files include, but are not limited to, log files (files used to record business processing procedures, running information, etc. during business operation) and temporary files (some intermediate process files generated during business operation, characterized by large quantity and short timeliness). The directories include, but are not limited to, the log directory (the business log file directory), the tmp directory (the business temporary file directory), and the core directories of the operating system (such as / usr / bin, / usr / sbin), the business binary directory, etc.

[0016] Specifically, the mounting process of packet filter functions can include: mounting the packet filter function to the target function of the kernel-mode program using kernel probes; the target function is the kernel function called when creating or deleting an inode. For example, using probes such as kprobe, uprobe, and tracepoint, the eBPF function is mounted to the entry point of the kernel function called by the kernel-mode program when creating or deleting an inode (such as the function called when creating a file or directory). Kernel functions include, but are not limited to, vfs_create (creating a regular file), vfs_mkdir (creating a directory), vfs_open, vfs_symlink (creating a symbolic link), vfs_link (creating a hard link), and vfs_rmdir (deleting a directory). These functions are used by the kernel-mode program when creating files / directories. When the kernel-mode program calls these functions, it simultaneously creates inodes. Each time a file or directory is created, an inode is generated synchronously, thereby increasing the number of inodes used. By pre-loading packet filter functions into the kernel functions of kernel-mode programs, it is possible to automatically listen for file or directory creation events, which facilitates the automated maintenance of file system inodes, thereby saving manpower and time costs.

[0017] Step S12: Using the target device number as the key, query the current inode usage, usage alarm threshold, and preset growth rate threshold of the target file system from the packet filter mapping table of the kernel program.

[0018] In this embodiment, after obtaining the target device number corresponding to the target file system associated with the currently created file or directory, the target device number can be used as a key to query the current inode usage rate (which refers to the ratio of the number of inodes already used in the current target file system to the total number of inodes), usage alarm threshold, and preset growth rate threshold corresponding to the target file system from the packet filter mapping table (such as eBPF map) of the kernel program.

[0019] Specifically, the formula for calculating inode utilization is: Inode Utilization = (Number of Inodes Used / Total Number of Inodes) 100%. The number of used inodes and the total number of inodes can be obtained from the / proc filesystem (e.g., / proc / fs / ). Read from stats.

[0020] In this embodiment, before maintaining the inodes of the file system, the method further includes: obtaining the number of inodes currently used in different file systems and the number of inodes pre-allocated to each file system to obtain the current number of used nodes and the current total number of pre-allocated nodes; calculating the ratio of the current number of used nodes to the current total number of pre-allocated nodes to obtain the current inode utilization rate of each file system; using the device number corresponding to each file system as the key and the current inode utilization rate as the value to bind the current inode utilization rate and the device number, and saving the bound current inode utilization rate and device number to the packet filter mapping table of the kernel program. In this embodiment, the number of currently used index nodes in each file system requiring index node maintenance is first collected to obtain the current number of currently used nodes for each file system. The number of index nodes pre-allocated to each file system is also obtained to obtain the total number of currently pre-allocated nodes for each file system. Then, the ratio of the current number of currently used nodes to the total number of currently pre-allocated nodes for each file system is calculated to obtain the current index node utilization rate for each file system. The device number corresponding to each file system is used as the key, and the current index node utilization rate is used as the value, thus binding the current index node utilization rate and the device number in a key-value pair manner. The bound current index node utilization rate and device number (i.e., key-value pair) are then saved to the first mapping table (denoted as usage_map) located in the packet filter mapping table. By binding and storing the current index node utilization rate and device number of each file system in a key-value pair manner, the usage status of index nodes for any file system can be quickly queried in real time, thereby improving the overall efficiency of index node maintenance.

[0021] In addition, before maintaining the inodes of the file system, the process specifically includes: collecting the number of created inodes, deleted inodes, used inodes, and pre-allocated inodes for different file systems over multiple historical time periods according to a preset collection frequency, to obtain the number of created nodes, deleted nodes, historically used nodes, and historically pre-allocated nodes for each file system in different historical time periods; calculating the ratio of historically used nodes to historically pre-allocated nodes and the difference between the number of created nodes and deleted nodes in each historical time period to obtain the historical node utilization rate and the net increase in historical nodes; according to... A preset sliding time window aggregates the net increment of historical nodes within each historical time period to obtain the growth rate of multiple historical nodes corresponding to each historical time period. The average growth rate of multiple historical nodes corresponding to a single historical time period is calculated to obtain the average node growth rate. The maximum value among the utilization rates of multiple historical nodes corresponding to a single file system is determined to obtain the maximum node utilization rate. Based on the maximum node utilization rate and the average node growth rate, the utilization alarm threshold and the preset growth rate threshold corresponding to each historical time period are determined. The device number corresponding to each file system is used as the key, and the utilization alarm threshold and the preset growth rate threshold are used as the value to obtain key-value pairs. The key-value pairs are then saved to the packet filter mapping table of the kernel program. In this embodiment, the number of created index nodes, deleted index nodes, used index nodes, and pre-allocated index nodes in each file system to be maintained within multiple historical time periods (e.g., 6:01-8:00, 8:01-11:30, 11:31-13:30, 13:31-17:30, 17:31-24:00, 00:00-06:00) can be collected at a preset collection frequency (e.g., once per minute). This yields the number of created nodes, deleted nodes, historically used nodes, and the total number of historically pre-allocated nodes for each file system in different historical time periods. It should be noted that the number of historical time periods and the division rules can be determined according to actual business needs and application scenarios. See Table 1 for details. Table 1. Business characteristics and index node usage for different time periods.

[0022] It is evident that the inode usage of a file system varies across different time periods (T1, T2, T3, T4, T5, T6) due to the varying quantity and type of business processes handled. This results in different inode usage and demand across different time periods (Tn). Therefore, different inode usage thresholds need to be set for different business systems. By analyzing the inode usage patterns across different time periods, we can determine the patterns in inode usage. For example, government services experience peak inode usage from 8:00 AM to 4:30 PM, while nighttime is a low-demand period; web services experience peak inode usage from 9:00 AM to 11:00 AM every Monday; and e-commerce services experience peak inode usage after 7:00 PM every night. By analyzing these patterns, we can divide different business processes into different time periods and set corresponding inode usage thresholds for each period.

[0023] Furthermore, the number of historically used nodes collected at a preset collection frequency (e.g., once every minute) within each historical time period (i.e., Tn) is calculated separately. , representing the number of inodes used by a file system within minute t and the total number of historically pre-allocated nodes ( The ratio of the total number of inodes pre-allocated in a file system to the historical node utilization rate is used to obtain the historical node utilization rate. (This represents the inode usage rate of a certain file system within minute t). The specific calculation formula is as follows: Subsequently, the difference between the number of created nodes (denoted as Icreate(t), representing the total number of inodes created in a file system within minute t) and the number of deleted nodes (Idelete(t), representing the total number of inodes deleted in a file system within minute t) collected at a preset collection frequency (e.g., once every minute) is calculated to obtain the net increase in historical nodes ΔIt (representing the net increase in inodes of a file system within minute t). The specific calculation formula is: ΔIt = Icreate(t) - Idelete(t).

[0024] Next, the net increment of historical nodes within each historical time period (Tn) is aggregated according to a preset sliding time window (e.g., a sliding time window of 3 minutes, i.e., 00:00-00:03, 00:03-00:06, 00:06-00:09, and so on). This yields the growth rate of multiple historical nodes corresponding to each historical time period (Tn). The specific calculation formula is as follows: ; In the formula, This represents the inode growth rate (%) within a 3-minute sliding time window ending at minute t. This represents the total net increase in inodes within 3 minutes.

[0025] Furthermore, calculate the growth rate of multiple historical nodes corresponding to a single historical time period (i.e., Tn). The average value is used to obtain the average node growth rate. Then determine the utilization rate of multiple historical nodes corresponding to a single file system. The maximum value in the range is used to obtain the maximum node utilization. Then based on the maximum node utilization rate Average node growth rate The usage alarm threshold and preset growth rate threshold corresponding to each historical time period (Tn) are determined. Finally, the device number corresponding to each file system and the historical time period (Tn) are used as the key, and the usage alarm threshold and preset growth rate threshold are used as the value. This binds the device number and the corresponding threshold information into a key-value pair, which is then saved to the second mapping table (denoted as threshold_map) of the packet filter map (eBPF map) in the kernel program. By binding the device number and corresponding threshold information of each file system to key-value pairs and storing the bound information in the packet filter map of the kernel program, orderly management of threshold information for different file systems is achieved. This makes the maintenance of index nodes for different file systems more convenient and accurate, reducing the probability of errors (bugs). Furthermore, historical data related to index nodes is collected based on factors such as preset collection frequency and multiple historical time periods. The collected historical data is analyzed and processed to derive threshold information corresponding to different services and time periods. Compared to manually preset thresholds, this method better reflects actual application needs, thus achieving effective maintenance of index nodes.

[0026] In addition, in calculating the average node growth rate Previously, it was also possible to first analyze the abnormal historical node growth rate. The identification and filtering process is as follows: Step 1: Calculate an original average value for each time period (Tn). The specific calculation formula is: ; In the formula, k is the total number of 3-minute sliding time windows in the current time period (Tn) (e.g., T3=8:01-11:30, a total of 209 minutes → 69 windows). This represents the node growth rate of the j-th 3-minute sliding time window; Step 2: Calculate the raw standard deviation using the sample standard deviation calculation method. The specific calculation formula is as follows: Step 3: Analyze the node growth rate based on the original standard deviation. Filtering, or removing outlier data, specifically, can be used to identify data that meets the following criteria: node growth rate. The difference between the value and the original mean is greater than twice the standard deviation: Step 4: Calculate the average value of the filtered m non-abnormal values ​​and use it as the average node growth rate for that time period (Tn). The specific calculation formula is as follows: ; In the formula, This represents the node growth rate for the j-th 3-minute sliding time window after filtering.

[0027] By filtering and screening abnormal data (i.e., historical node growth rate), the accuracy of usage alarm threshold and preset growth rate threshold settings can be improved, thereby maintaining the index nodes in the file system more effectively and accurately, which is more in line with actual application needs.

[0028] In addition, to facilitate manual viewing and adjustment, various configuration interfaces (such as RESTful API, an application programming interface based on the REST architecture specification) can be provided to facilitate administrators to view / modify / adjust, and to define more granular policies for different file systems (such as different levels of usage alarm thresholds, whitelists, cleanup permissions, the amount of data to be cleaned each time, and priority, etc.).

[0029] Specifically, determining the usage alarm threshold and preset growth rate threshold for each historical time period based on the maximum node utilization rate and average node growth rate can include: generating a growth rate correction coefficient based on the maximum node utilization rate and average node growth rate; and determining the usage alarm threshold and preset growth rate threshold for each historical time period based on the relationship between the growth rate correction coefficient and the initial usage rate threshold and initial growth rate threshold. In this embodiment, the maximum node utilization rate can be used as the basis for determining the usage alarm threshold and preset growth rate threshold. and average node growth rate Generate a growth rate correction factor K, the specific calculation formula is as follows: Next, based on the relationship between the growth rate correction coefficient K and the initial utilization rate threshold (e.g., 85%) and the initial growth rate threshold (e.g., 90%), the utilization rate alarm threshold corresponding to each historical time period is determined. and preset growth rate threshold For example, through formula and Obtain the usage rate alarm threshold and the preset growth rate threshold respectively. Here, B can be the usage rate for any historical node. For example, after collecting data (including historical node usage rates) for multiple historical time periods over 14 days at a preset collection frequency (1 value per minute), a total of 20,160 values ​​are obtained over 14 days. Then, effective usage rate data (19,800 values) are filtered out from the 20,160 values, and the 9,900th number after filtering (i.e., the median) is denoted as B.

[0030] It should be noted that the average node growth rate is based on different time periods. Different types of business systems can also be classified, as shown in Table 2: Table 2 Different business scenarios and corresponding classification criteria

[0031] It can be seen that the average node growth rate is based on different time periods. By understanding the relationships between index nodes, we can determine their usage and use this information as a basis for classifying different business systems.

[0032] Specifically, using the target device number as the key, querying the target file system's current inode usage, usage alarm threshold, and preset growth rate threshold from the kernel program's packet filter map table can include: obtaining the timestamp when the current file or directory was created, obtaining the current timestamp, and determining the target time period corresponding to the current timestamp; using the target device number as the key, querying the target file system's current inode usage, as well as the usage alarm threshold and preset growth rate threshold corresponding to the target time period from the kernel program's packet filter map table. In this embodiment, firstly, the current timestamp when the current file or directory was created is obtained, then the target time period (e.g., T2) corresponding to the current timestamp is determined, then the target device number corresponding to the current file system is used as the key to query the corresponding value (i.e., Value) from the first mapping table (usage_map) of the packet filter map (eBPF map) in the kernel program to obtain the current inode usage of the target file system, and querying the usage alarm threshold and preset growth rate threshold corresponding to the target time period (e.g., T2) from the second mapping table (threshold_map) of the packet filter map (eBPF map).

[0033] Step S13: If the current index node utilization rate is less than the utilization rate alarm threshold, calculate the node growth rate of the index node within the historical preset time period based on the current index node utilization rate and the historical index node utilization rate of the target file system.

[0034] In this embodiment, after querying the current index node utilization rate, utilization rate alarm threshold, and preset growth rate threshold corresponding to the current target file system, it is determined whether the current index node utilization rate is less than the utilization rate alarm threshold. If it is less, the node growth rate of the index node within the historical preset time period is further calculated based on the current index node utilization rate and the historical index node utilization rate of the target file system.

[0035] Specifically, calculating the node growth rate of index nodes within a preset historical time period based on the current index node utilization rate and the historical index node utilization rate of the target file system can include: obtaining the index node utilization rates of the target file system within multiple different preset historical time periods to obtain multiple historical index node utilization rates; and calculating the difference between the current index node utilization rate and each historical index node utilization rate to obtain the node growth rate for each preset historical time period. In this embodiment, the index node utilization rates of the target file system within multiple different preset historical time periods (such as within 10 minutes, 20 minutes, and 30 minutes before the current time) are obtained to obtain multiple historical index node utilization rates. Then, the difference between the current index node utilization rate and each historical index node utilization rate (representing the net increase in index nodes per unit time) is calculated to obtain the node growth rate for each preset historical time period.

[0036] Step S14: When the node growth rate exceeds the preset growth rate threshold, the context information triggered by the packet filter function is sent to the user-space program to clean up the inodes in the target file system according to the node release priority in the preset node cleanup strategy; the context information includes the target device number.

[0037] In this embodiment, it is determined whether the node growth rate exceeds a preset growth rate threshold. If it exceeds the preset growth rate threshold, it indicates that the inodes may be exhausted in the short term. At this time, the context information of the packet filter function (eBPF function) when it is triggered, such as the target device number, timestamp, triggering process PID (process identifier), etc., can be sent to the user-space program. After the user-space program receives the above context information, it can use the rule engine and follow the node release priority in the preset node cleanup strategy. At the same time, it can clean up / delete the inodes in the target file system based on the content of the context information, thereby avoiding business interruption caused by untimely inode cleanup.

[0038] It should be noted that, in order to avoid accidental deletion, the list of files / directories corresponding to the inode to be deleted can be sent to the corresponding management terminal first, and the deletion action can be performed after the administrator / user confirms it.

[0039] Specifically, when the node growth rate exceeds a preset growth rate threshold, the context information triggered by the packet filter function is sent to the user-space program. This can include: sequentially judging whether the growth rate of each node is greater than the corresponding preset growth rate threshold according to the historical preset duration from shortest to longest; wherein, there is a positive correlation between the historical preset duration and the corresponding preset growth rate threshold; if there is a node growth rate greater than the corresponding preset growth rate threshold, the context information triggered by the packet filter function is sent to the user-space program; the context information also includes the current timestamp. In this embodiment, the growth rate of each node is first determined sequentially according to historical preset durations from shortest to longest (e.g., the last 10 minutes, last 20 minutes, and last 30 minutes) to see if it exceeds the corresponding preset growth rate threshold (which is positively correlated with the corresponding preset growth rate threshold). If the increase in the last 10 minutes exceeds 5%, the increase in the last 20 minutes exceeds 7%, and the increase in the last 30 minutes exceeds 10%, it indicates that the inodes may be exhausted in the short term. At this time, an over-threshold event can be generated based on the context information (such as the target device number, current timestamp, triggering process PID, etc.) when the packet filter function is triggered, and this event is sent to the rule engine in the user-space program to clean up and release the index nodes as soon as possible, avoiding the impact on the current business and system. This embodiment analyzes the node growth rate of multiple historical preset durations and determines its relationship with the corresponding preset growth rate threshold. When the utilization alarm threshold is reached, it can further determine whether there is a situation where the inodes are exhausted in the short term, which can prevent the rapid exhaustion of inodes, making the system more stable, thereby avoiding the interruption of user services and improving the user experience.

[0040] Furthermore, after querying the target file system's current inode usage, usage alarm threshold, and preset growth rate threshold from the kernel-mode program's packet filter mapping table, the process may further include: if the current inode usage is not less than the usage alarm threshold, then triggering the step of sending the context information of the packet filter function to the user-mode program; after cleaning up the inodes in the target file system, obtaining the current number of inodes in the target file system; calculating the ratio of the current number of inodes to the total number of currently pre-allocated nodes to obtain the new node usage rate, and updating the current inode usage rate in the packet filter mapping table using the new node usage rate. In this embodiment, if the current index node utilization rate is not less than the utilization rate alarm threshold, it indicates that the current index node utilization is high and has reached the alarm line. Immediate cleanup and release of the index nodes are required to avoid service failures and business interruptions caused by index node exhaustion. In this case, the context information triggered by the packet filter function (eBPF function) can be directly sent to the user-space program to clean up the index nodes in the target file system. After cleanup, the number of index nodes in the target file system is obtained, and the ratio of the current number of index nodes to the total number of pre-allocated nodes is calculated to obtain the new node utilization rate. Finally, the new node utilization rate is used to update the current index node utilization rate in the packet filter map (eBPF map) in a timely manner. Through the above update operation, it can be ensured that the node utilization rate obtained when maintaining the file system's index nodes next time is up-to-date, ensuring the accuracy of the real-time obtained node utilization rate and thus ensuring the effectiveness of index node maintenance.

[0041] As can be seen, in this embodiment of the application, when a file or directory is detected to be created, a packet filter function (such as an eBPF function) pre-mounted in the kernel-mode program is triggered. This function first obtains the device number of the relevant file system, and then uses this device number as a key to retrieve the data from the packet filter mapping table of the kernel-mode program (such as eBPF). The system queries the current file system's index node utilization rate, utilization alarm threshold, and preset growth rate threshold in the `map` function. If the index node utilization rate is less than the utilization alarm threshold, the system further calculates the growth rate of the index nodes within a preset historical time period based on the current and historical index node utilization rates. When the node growth rate exceeds the preset growth rate threshold, the context information triggered by the filter function is sent to the user-space program. This allows the user-space program to clean up the index nodes according to the node release priority in the preset node cleanup strategy and based on the context information. Through this method, automated index node utilization awareness and automatic release are achieved, saving manpower and time costs. Furthermore, this embodiment uses a packet filter function to enable kernel-space and user-space programs to collaboratively achieve index node utilization awareness and release. The complex calculation process of obtaining index node utilization, threshold judgment, and node growth rate is implemented by the kernel-space program, while the cleanup / release operation of index nodes is implemented by the user-space program. This improves the efficiency of index node release. In addition, this embodiment does not require restarting the operating system, reduces the consumption of system resources, and does not require setting a preset period, thus meeting the requirements for real-time management of index nodes.

[0042] This application discloses a specific method for maintaining inodes in a file system, applied to an operating system. See [link to relevant documentation]. Figure 2 As shown, the method includes: Step S21: When a file or directory is detected to be created, trigger the packet filter function in the kernel-mode program pre-mounted in the operating system to obtain the target device number corresponding to the target file system associated with the created file or directory.

[0043] Step S22: Using the target device number as the key, query the current inode usage, usage alarm threshold, and preset growth rate threshold of the target file system from the packet filter mapping table of the kernel program.

[0044] Step S23: If the current index node utilization rate is less than the utilization rate alarm threshold, calculate the node growth rate of the index node within the historical preset time period based on the current index node utilization rate and the historical index node utilization rate of the target file system.

[0045] Step S24: When the node growth rate exceeds the preset growth rate threshold, the context information triggered by the packet filter function is sent to the user-space program to clean up temporary files in the target file system that exceed the first creation time according to the first node release priority in the preset node cleanup strategy, based on the target device number in the context information; the context information includes the target device number.

[0046] In this embodiment, if the node growth rate exceeds a preset growth rate threshold, the inodes may be exhausted in a short period. At this time, the context information triggered by the packet filter function (such as the target device number, current timestamp, triggering process PID, etc.) can be sent to the rule engine in the user-space program. This rule engine then cleans up files older than 7 days in the / tmp / directory of the target file system according to the first node release priority in the preset node cleanup strategy and the target device number and current timestamp in the context information. That is, the first node release priority is to release temporary files (tmp files) older than 7 days.

[0047] The node cleanup strategy can be located on the local disk or in a configuration database. It can include multiple cleanup rules with different priorities (e.g., clean up temporary files first, then cache files, and finally old log files). Each cleanup rule can include the target directory and file matching pattern (e.g., / var / ). .log, / etc / nginx / This includes information such as the .log format, conditions (e.g., file creation / modification time, file size), and actions performed (deletion, compression). Specifically, / var / The .log pattern matches files in the / var directory that end with .log, which can be operating system audit logs, / etc / nginx / , etc. The .log pattern matches files in the / etc / nginx directory that begin with the .log extension. Files ending in .log are log files generated after the nginx service starts.

[0048] Furthermore, the node cleanup policy allows for the setting of a whitelist (containing directories / files that are prohibited from being cleaned up), and it pre-checks the node cleanup policy for syntax and security. Once the checks pass, parameters (such as thresholds) can be dynamically written to the corresponding eBPF mapping table. Thresholds can be added, modified, or deleted at any time without requiring a system restart. Additionally, for each cleanup rule, after performing a deletion operation, a precise search and deletion operation can be initiated by releasing the executor (e.g., using `find / var / log -type f -name '...')`. The command `.log' -mtime +7 -delete` searches for files in the ` / var / log` directory that end with `.log` and were last modified more than 7 days ago, and then deletes them, thus achieving precise deletion and avoiding the accidental deletion of valid files.

[0049] Step S25: Count the number of inodes in the cleaned target file system to obtain the number of nodes after cleanup.

[0050] In this embodiment, after the first node release priority index node cleanup is completed, the number of index nodes in the target file system after cleanup is immediately recounted to obtain the number of cleaned nodes.

[0051] Step S26: Calculate the ratio of the number of cleaned nodes to the total number of pre-allocated nodes to obtain the node utilization rate after cleanup, and determine whether the node utilization rate after cleanup is greater than or equal to the utilization rate alarm threshold.

[0052] In this embodiment, the inode usage rate is recalculated by calculating the ratio of the number of cleaned nodes to the total number of pre-allocated nodes in the current target file system, and the cleaned node usage rate is obtained. Then, it is determined again whether the cleaned node usage rate is greater than or equal to the usage rate alarm threshold.

[0053] Step S27: If the node usage rate after cleanup is greater than or equal to the usage rate alarm threshold, then clean up the log files in the target file system that exceed the second creation time according to the second node release priority in the preset node cleanup strategy.

[0054] In this embodiment, if the node utilization rate after cleanup is greater than or equal to the utilization rate alarm threshold, it indicates that the current index node utilization rate is still high and needs to be cleaned up. At this time, the log files in the target file system that have exceeded the second creation time can be cleaned up according to the second node release priority in the preset node cleanup strategy, such as cleaning up old log files under the / var / log directory.

[0055] Step S28: If the node utilization rate is less than the utilization rate alarm threshold after cleanup, then stop the cleanup operation.

[0056] In this embodiment, if the node utilization rate is less than the utilization rate alarm threshold after cleaning, it indicates that the utilization rate of the current index node has dropped below the threshold, and the cleaning / deletion operation can be stopped.

[0057] For more detailed processing procedures of steps S21 to S23, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.

[0058] As can be seen, in this embodiment, inodes are cleaned up sequentially according to different node release priorities in the preset node cleanup strategy, and the inode usage rate is recalculated immediately after each cleanup. For example, the priority 1 rule is executed first: clean up files older than 7 days in the / tmp / directory. After execution, the inode usage rate is recalculated immediately. If the usage rate has dropped below the threshold, subsequent operations are stopped. If it has not dropped below the threshold, the priority 2 rule is executed: clean up old log files in the / var / log directory. In this way, the inode cleanup operation is executed in descending order of priority. After the cleanup action of one priority is completed, the current inode usage rate is queried again. If the usage rate has fallen below the threshold, subsequent operations are stopped. In this way, over-cleanup can be avoided. If it is still above the threshold, the rule of the next priority is executed. In addition, this embodiment places the threshold judgment process in the eBPF function of the kernel program, and places the logically complex and high-risk file search and deletion operations in the user-space program. The eBPF function ensures the monitoring performance and avoids global scanning, thereby ensuring the overall security and stability of the system.

[0059] Accordingly, this application also discloses a file system inode maintenance device, applied to an operating system, the device comprising: The triggering module is used to detect when a file or directory is created and trigger a packet filter function pre-mounted in the kernel-mode program of the operating system to obtain the target device number corresponding to the target file system associated with the created file or directory. The query module is used to query the current inode usage, usage alarm threshold, and preset growth rate threshold of the target file system from the packet filter mapping table of the kernel program, using the target device number as the key. The calculation module is used to calculate the node growth rate of the index node within a preset historical period based on the current index node utilization rate and the historical index node utilization rate of the target file system if the current index node utilization rate is less than the utilization rate alarm threshold. The sending module is used to send the context information triggered by the packet filter function to the user-space program when the node growth rate exceeds the preset growth rate threshold, so as to clean up the inodes in the target file system according to the node release priority in the preset node cleanup strategy and based on the context information; the context information includes the target device number.

[0060] The specific workflow of each of the above modules can be found in the relevant content disclosed in the foregoing embodiments, and will not be repeated here.

[0061] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any of the above-described embodiments of the inode maintenance method for a file system.

[0062] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in the embodiments of the inode maintenance method of any of the above-described file systems when it is run.

[0063] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0064] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described embodiments of the file system inode maintenance method.

[0065] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described embodiments of the inode maintenance method for a file system.

[0066] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0067] The foregoing has provided a detailed description of a file system inode maintenance method and electronic device provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of this application.

Claims

1. A method for maintaining inodes in a file system, characterized in that, Applied to operating systems, including: When a file or directory is detected to be created, a packet filter function pre-mounted in the kernel-mode program of the operating system is triggered to obtain the target device number corresponding to the target file system associated with the created file or directory. Using the target device number as the key, query the packet filter mapping table of the kernel program to find the current inode usage, usage alarm threshold and preset growth rate threshold of the target file system; If the current index node utilization rate is less than the utilization rate alarm threshold, then the node growth rate of the index node within a preset historical time period is calculated based on the current index node utilization rate and the historical index node utilization rate of the target file system. When the node growth rate exceeds the preset growth rate threshold, the context information triggered by the packet filter function is sent to the user-space program to clean up the inodes in the target file system according to the node release priority in the preset node cleanup strategy; the context information includes the target device number.

2. The file system inode maintenance method according to claim 1, characterized in that, Also includes: Get the number of inodes currently in use in different file systems and the number of inodes pre-allocated to each file system, and get the current number of inodes currently in use and the current total number of pre-allocated inodes; Calculate the ratio of the number of currently used nodes to the total number of currently pre-allocated nodes to obtain the current index node utilization rate of each file system; The device number corresponding to each file system is used as the key, and the current inode usage rate is used as the value to bind the current inode usage rate and the device number. The bound current inode usage rate and the device number are then saved to the packet filter mapping table of the kernel program.

3. The file system inode maintenance method according to claim 2, characterized in that, Also includes: Collect the number of created index nodes, deleted index nodes, used index nodes, and pre-allocated index nodes for each file system in different historical time periods according to a preset collection frequency, and obtain the number of created nodes, deleted nodes, historical used nodes, and historical pre-allocated nodes for each file system in different historical time periods. Calculate the ratio of the number of historically used nodes to the total number of historically pre-allocated nodes in each of the historical time periods, and the difference between the number of created nodes and the number of deleted nodes, to obtain the historical node utilization rate and the net increase in historical nodes. The net increment of the historical nodes within each historical time period is aggregated according to a preset sliding time window to obtain the growth rate of multiple historical nodes corresponding to each historical time period. Calculate the average growth rate of multiple historical nodes corresponding to a single historical time period to obtain the average node growth rate, and determine the maximum value among the multiple historical node utilization rates corresponding to a single file system to obtain the maximum node utilization rate; Based on the maximum node utilization rate and the average node growth rate, determine the utilization rate alarm threshold and the preset growth rate threshold for each of the historical time periods; The device number corresponding to each file system is used as the key, and the usage alarm threshold and the preset growth rate threshold are used as the values ​​to obtain key-value pairs. The key-value pairs are then saved to the packet filter mapping table of the kernel program.

4. The file system inode maintenance method according to claim 3, characterized in that, The process of determining the usage alarm threshold and preset growth rate threshold for each of the historical time periods based on the maximum node utilization rate and the average node growth rate includes: A growth rate correction coefficient is generated based on the maximum node utilization rate and the average node growth rate. Based on the relationship between the growth rate correction coefficient and the initial utilization rate threshold and the initial growth rate threshold, the utilization rate alarm threshold and the preset growth rate threshold corresponding to each of the historical time periods are determined.

5. The file system inode maintenance method according to claim 4, characterized in that, The step of using the target device number as a key to query the current inode usage, usage alarm threshold, and preset growth rate threshold of the target file system from the packet filter mapping table of the kernel program includes: Get the timestamp when the current file or directory was created, obtain the current timestamp, and determine the target time period corresponding to the current timestamp; Using the target device number as the key, query the current inode usage rate of the target file system, as well as the usage rate alarm threshold and preset growth rate threshold corresponding to the target time period from the packet filter mapping table of the kernel program.

6. The file system inode maintenance method according to claim 5, characterized in that, The step of calculating the node growth rate of index nodes within a historical preset time period based on the current index node utilization rate and the historical index node utilization rate of the target file system includes: Obtain the index node utilization rate of the target file system within multiple different historical preset time periods to obtain multiple historical index node utilization rates; Calculate the difference between the current index node utilization rate and the utilization rate of each historical index node to obtain the node growth rate for each historical preset duration; Accordingly, when the node growth rate exceeds the preset growth rate threshold, sending the context information triggered by the packet filter function to the user-space program includes: The growth rate of each node is determined sequentially in ascending order of the historical preset duration to determine whether it is greater than the corresponding preset growth rate threshold; wherein, there is a positive correlation between the historical preset duration and the corresponding preset growth rate threshold. If the node growth rate exceeds the corresponding preset growth rate threshold, the context information triggered by the packet filter function is sent to the user-space program; the context information also includes the current timestamp.

7. The file system inode maintenance method according to claim 6, characterized in that, The step of cleaning up the inodes in the target file system according to the node release priority in the preset node cleanup strategy and based on the context information includes: According to the first node release priority in the preset node cleanup strategy, and based on the target device number in the context information, the temporary files in the target file system that exceed the first creation time are cleaned up; The number of inodes in the cleaned target file system is counted to obtain the number of nodes after cleanup. Calculate the ratio of the number of cleaned-up nodes to the total number of currently pre-allocated nodes to obtain the cleaned-up node utilization rate, and determine whether the cleaned-up node utilization rate is greater than or equal to the utilization rate alarm threshold; If the node usage rate after cleanup is greater than or equal to the usage rate alarm threshold, then log files in the target file system that exceed the second creation time are cleaned up according to the second node release priority in the preset node cleanup strategy. If the node utilization rate after cleanup is less than the utilization rate alarm threshold, then the cleanup operation is stopped.

8. The file system inode maintenance method according to claim 2, characterized in that, After querying the target file system's current inode usage, usage alarm threshold, and preset growth rate threshold from the kernel-mode program's packet filter mapping table, the process further includes: If the current index node utilization rate is not less than the utilization rate alarm threshold, then the step of sending the context information of the packet filter function to the user-space program is triggered. After cleaning up the inodes in the target file system, the current number of inodes in the target file system is obtained to get the current number of inodes; Calculate the ratio of the current number of index nodes to the total number of currently pre-allocated nodes to obtain the new node utilization rate, and use the new node utilization rate to update the current index node utilization rate in the packet filter mapping table.

9. The inode maintenance method for a file system according to any one of claims 1 to 8, characterized in that, Also includes: The packet filtering function is attached to the target function of the kernel-mode program using a kernel probe. The target function is a kernel function that is called when an inode is created or deleted.

10. An electronic device, characterized in that, It includes a processor and a memory; wherein, when the processor executes a computer program stored in the memory, it implements the inode maintenance method of the file system as described in any one of claims 1 to 9.