A SLUB memory application monitoring method and system based on LINUX operating system
By adding system files and registering read and write functions in the Linux operating system, the call stack information of SLUB memory application is obtained, and the problem of system restarting is solved when the kernel state memory leak is located, improving the efficiency of problem positioning.
Patent Information
- Application Number
- CN202210036634.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-13
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2042-01-13
AI Technical Summary
When locating kernel-state memory leaks in Linux operating systems, the existing technology requires a system restart, resulting in a large business impact and the recurrence of problems is not conducive to analysis and positioning.
The system file /proc/sys/vm/slab/slabname/enable_trace is added through the procfs file system, enabling the call stack information of the SLUB memory application, and register the read and write functions. By setting the slub_debug parameter to enable or turn off the call stack switch to avoid system restart.
It realizes the call stack information of SLUB memory application without system restart, which significantly improves the efficiency of users to analyze and locate kernel-state memory leakage problems and reduces business impact.
Smart Images

Figure CN114356583B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of PCB, and in particular to a SLUB memory application monitoring method and system based on a LINUX operating system. Background Art
[0002] At present, it is often necessary to monitor the usage of system memory during system operation. Among them, memory leakage is the most common and also very difficult to locate problem. The Linux operating system kernel allocates memory to each kernel module through the SLUB memory allocator. For kernel-state memory leakage, it is necessary to obtain the call stack information of the SLUB memory application in order to locate and analyze the cause of the memory leakage.
[0003] However, in the process of locating kernel-mode memory leaks in the current kernel, it is necessary to recompile the kernel by configuring compilation options and replace the kernel to obtain the call stack information of the SLUB memory request. Since replacing the kernel requires restarting the system, restarting the system in a production environment will have a great impact on the business and the scenario where the problem occurs after the system restart will also be destroyed, which is not conducive to the reproduction and location of the problem. Therefore, this method is not friendly for problem location.
[0004] Therefore, how to avoid the business impact caused by system restart and improve the efficiency of users in analyzing and locating kernel memory leak problems is one of the technical difficulties in this field. Summary of the invention
[0005] The purpose of the present invention is to provide a SLUB memory application monitoring method and system based on the LINUX operating system, which avoids the business impact caused by system restart and greatly improves the efficiency of user analysis and positioning of kernel state memory leakage problems.
[0006] In order to solve the above technical problems, an embodiment of the present invention provides a SLUB memory application monitoring method of a LINUX operating system, comprising:
[0007] S1, add a new system file / proc / sys / vm / slab / slabname / enable_trace through the procfs file system to enable obtaining the call stack information of SLUB memory application;
[0008] S2, registering the read and write functions of the system file;
[0009] S3, determine whether enable_trace in the current write function is 1;
[0010] If so, S4, set slub_debug = DEBUG_DEFAULT_FLAGS to turn on the switch for obtaining the call stack, and call the init_tracking() function to initialize the data structure related to the acquisition of the call stack; otherwise, S5, set slub_debug = 0 to turn off the switch for obtaining the call stack.
[0011] Among them, it also includes:
[0012] Displays the current status of the get call stack switch.
[0013] Wherein, the S3 further includes:
[0014] S31, determine whether enable_trace in the current write function is 1 or 0;
[0015] If so, S32, the enable_trace input in the current write function is valid, otherwise, S33, the enable_trace input in the current write function is invalid.
[0016] Wherein, after S33, the method further includes:
[0017] The information that the enable_trace input in the write function is invalid is fed back to the front end.
[0018] In addition, the embodiment of the present application further provides a SLUB memory application monitoring system based on the LINUX operating system, including:
[0019] The system file creation module is used to add a new system file / proc / sys / vm / slab / slabname / enable_trace through the procfs file system to enable obtaining the call stack information of SLUB memory application;
[0020] A read-write function registration module, used for registering the read-write functions of the system file;
[0021] The enable_trace judgment module in the write function is used to judge whether the enable_trace in the current write function is 1 and output the judgment result;
[0022] The call stack acquisition switch execution module is used to set slub_debug=DEBUG_DEFAULT_FLAGS to turn on the call stack acquisition switch according to the judgment result after enable_trace is 1, and call the init_tracking() function to initialize the data structure related to the call stack acquisition, otherwise, set slub_debug=0 to turn off the call stack acquisition switch.
[0023] Wherein, it also includes a display module connected to the acquisition call stack switch execution module, which is used to display the current state of the acquisition call stack switch.
[0024] Among them, it also includes an input legality judgment module connected to the enable_trace judgment module in the write function, which is used to determine that the enable_trace input in the current write function is valid after enable_trace in the current write function is 1 or 0, otherwise, it determines that the enable_trace input in the current write function is invalid.
[0025] Among them, it also includes an input invalid feedback module connected to the input legality judgment module, which is used to feedback the invalid information of enable_trace input in the write function to the front end after the enable_trace input in the write function is invalid.
[0026] The SLUB memory application monitoring method and system based on the LINUX operating system provided by the embodiment of the present invention has the following advantages compared with the prior art:
[0027] The SLUB memory application monitoring method and system based on the LINUX operating system provided by the embodiment of the present invention, adds a new system file / proc / sys / vm / slab / slabname / enable_trace through the procfs file system to enable the acquisition of the call stack information of the SLUB memory application; then registers the read and write functions of the system file; by judging the enable_trace status in the external input write function, judges whether the enable_trace in the current write function is 1; if so, sets slub_debug=DEBUG_DEFAULT_FLAGS to turn on the acquisition call stack switch, and calls the init_tracking() function to initialize the acquisition call stack related data structure, otherwise, S5, sets slub_debug=0 to turn off the acquisition call stack switch. Acquiring the call stack information of the SLUB memory application by setting system parameters avoids the problem of system restart, avoids the business impact caused by the system restart, and greatly improves the efficiency of users in analyzing and locating kernel state memory leak problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 A schematic diagram of a specific implementation of a method for monitoring SLUB memory application of a LINUX operating system provided by an embodiment of the present invention;
[0030] Figure 2 A write function legality judgment step flow of a SLUB memory application monitoring method for a LINUX operating system provided by an embodiment of the present invention;
[0031] Figure 3 A structural diagram of a specific implementation of a SLUB memory application monitoring system for a LINUX operating system provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0032] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0033] Please refer to Figure 1-3 , Figure 1 A schematic diagram of a specific implementation of a method for monitoring SLUB memory application of a LINUX operating system provided by an embodiment of the present invention; Figure 2 A write function legality judgment step flow of a SLUB memory application monitoring method for a LINUX operating system provided by an embodiment of the present invention; Figure 3 A structural diagram of a specific implementation of a SLUB memory application monitoring system for a LINUX operating system provided by an embodiment of the present invention.
[0034] In a specific implementation, the SLUB memory application monitoring method of the LINUX operating system includes:
[0035] S1, add a new system file / proc / sys / vm / slab / slabname / enable_trace through the procfs file system to enable obtaining the call stack information of SLUB memory application;
[0036] S2, registering the read and write functions of the system file;
[0037] S3, determine whether enable_trace in the current write function is 1;
[0038] If so, S4, set slub_debug = DEBUG_DEFAULT_FLAGS to turn on the switch for obtaining the call stack, and call the init_tracking() function to initialize the data structure related to the acquisition of the call stack; otherwise, S5, set slub_debug = 0 to turn off the switch for obtaining the call stack.
[0039] A new system file / proc / sys / vm / slab / slabname / enable_trace is added through the procfs file system to enable the acquisition of the call stack information of the SLUB memory application; then the read and write functions of the system file are registered; by judging the enable_trace status in the external input write function, it is judged whether the enable_trace in the current write function is 1; if so, slub_debug=DEBUG_DEFAULT_FLAGS is set to turn on the acquisition call stack switch, and the init_tracking() function is called to initialize the data structure related to the acquisition call stack, otherwise, S5, slub_debug=0 is set to turn off the acquisition call stack switch. Acquiring the call stack information of the SLUB memory application by setting system parameters avoids the problem of system restart and the business impact caused by system restart, which greatly improves the efficiency of users in analyzing and locating kernel memory leak problems.
[0040] In order to enable the user or staff to intuitively obtain the call stack switch information and thus perform subsequent operations, in one embodiment, the SLUB memory application monitoring method of the LINUX operating system further includes:
[0041] Displays the current status of the get call stack switch.
[0042] By displaying the current status of the acquisition call stack switch, subsequent operations can be performed directly. This application does not limit the display method. It can be directly entering the page or program after the acquisition call stack switch is turned on, and the page does not change, or directly displaying its status as on or status, or other display methods. This application does not limit this.
[0043] Since different writing modes or operation errors may occur during the writing process of the write function, in order to make the write function operate in a specified operation mode, in one embodiment, S3 further includes:
[0044] S31, determine whether enable_trace in the current write function is 1 or 0;
[0045] If so, S32, the enable_trace input in the current write function is valid, otherwise, S33, the enable_trace input in the current write function is invalid.
[0046] By judging whether the input is valid, the judgment is made directly by the data type, that is, first judging whether it is valid, and then judging whether the status needs to be changed, thereby improving management efficiency. In this application, there is no limitation on the operations after whether the input is valid.
[0047] In order to further improve the user's convenience of operation, for example, after the user writes data, the user may not be able to open it. In order to improve the user's convenience of use, after S33, the following steps are further included:
[0048] The information that the enable_trace input in the write function is invalid is fed back to the front end.
[0049] By feeding back invalid input to the front end, or even issuing a prompt, such as a legal input type, or a corresponding input selection method, such as direct selection, etc., this application does not limit the content and method of the feedback.
[0050] In addition, the embodiment of the present application further provides a SLUB memory application monitoring system based on the LINUX operating system, including:
[0051] A system file creation module 10 is used to add a new system file / proc / sys / vm / slab / slabname / enable_trace through the procfs file system, so as to enable obtaining the call stack information of the SLUB memory application;
[0052] A read-write function registration module 20, used for registering the read-write functions of the system file;
[0053] The enable_trace judgment module 30 in the write function is used to judge whether the enable_trace in the current write function is 1, and output the judgment result;
[0054] The call stack acquisition switch execution module 40 is used to set slub_debug=DEBUG_DEFAULT_FLAGS to turn on the call stack acquisition switch according to the judgment result after enable_trace is 1, and call the init_tracking() function to initialize the data structure related to the call stack acquisition; otherwise, set slub_debug=0 to turn off the call stack acquisition switch.
[0055] Since the SLUB memory application monitoring system based on the LINUX operating system is a system corresponding to the SLUB memory application monitoring method based on the LINUX operating system and has the same beneficial effects, this application will not elaborate on this.
[0056] In order to further improve the convenience of operation, in one embodiment, the SLUB memory application monitoring system based on the LINUX operating system also includes a display module connected to the acquisition call stack switch execution module, which is used to display the current state of the acquisition call stack switch.
[0057] By displaying the current status of the acquisition call stack switch, the user or staff can intuitively obtain the acquisition call stack switch information, and thus perform subsequent operations. Subsequent operations can be performed directly. This application does not limit the display method. It can be directly entering the page or program after the acquisition call stack switch is turned on, the page does not change, or directly displaying its status as on or status, or other display methods, which are not limited in this application.
[0058] Since different writing modes or operating errors may occur during the writing process of the write function, in order to make the write function operate in a specified operating mode, in one embodiment, the SLUB memory application monitoring system based on the LINUX operating system also includes an input legality judgment module connected to the enable_trace judgment module in the write function, which is used to determine that the enable_trace input in the current write function is valid after enable_trace in the current write function is 1 or 0, otherwise, determine that the enable_trace input in the current write function is invalid.
[0059] By making a legal judgment on the input, the enable_trace in the write function is first judged to be legal, and then the status is judged, which improves the judgment efficiency. In this application, it can be directly filtered, or other judgment methods can be used. By judging whether the input is valid, it is directly judged by the data type, that is, first judge whether it is valid, and then judge whether the status needs to be changed, which improves the management efficiency. In this application, there is no limitation on the operation after the input is valid.
[0060] In order to further improve the user's operating convenience, for example, after the user writes data, the user may not be able to open it. In order to improve the user's convenience, in one embodiment, the SLUB memory application monitoring system based on the LINUX operating system also includes an input invalid feedback module connected to the input legality judgment module, which is used to feedback the invalid enable_trace input information in the write function to the front end after the enable_trace input in the write function is invalid.
[0061] By feeding back invalid input to the front end, or even issuing a prompt, such as a legal input type, or a corresponding input selection method, such as direct selection, etc., this application does not limit the content and method of the feedback.
[0062] In this application, other prompts can also be provided, such as voice,
[0063] In summary, the SLUB memory application monitoring method and system based on the LINUX operating system provided by the embodiment of the present invention adds a new system file / proc / sys / vm / slab / slabname / enable_trace through the procfs file system to enable the acquisition of the call stack information of the SLUB memory application; then registers the read and write functions of the system file; by judging the enable_trace status in the external input write function, judge whether the enable_trace in the current write function is 1; if so, set slub_debug=DEBUG_DEFAULT_FLAGS to turn on the acquisition call stack switch, and call the init_tracking() function to initialize the acquisition call stack related data structure, otherwise, S5, set slub_debug=0 to turn off the acquisition call stack switch. Acquiring the call stack information of the SLUB memory application by setting system parameters avoids the problem of system restart, avoids the business impact caused by system restart, and greatly improves the efficiency of users in analyzing and locating kernel state memory leak problems.
[0064] The above is a detailed introduction to the SLUB memory application monitoring method and system based on the LINUX operating system provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, the present invention can also be improved and modified, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.
Claims
1. A SLUB memory application monitoring method for a LINUX operating system, characterized in that: include: S1, add a new system file / proc / sys / vm / slab / slabname / enable_trace through the procfs file system to enable obtaining the call stack information of SLUB memory application; S2, registering the read and write functions of the system file; S3, determine whether enable_trace is 1 in the current write function; If so, S4, set slub_debug = DEBUG_DEFAULT_FLAGS to turn on the switch for obtaining the call stack, and call the init_tracking() function to initialize the data structure related to the acquisition of the call stack; otherwise, S5, set slub_debug = 0 to turn off the switch for obtaining the call stack.
2. The SLUB memory application monitoring method of the LINUX operating system as claimed in claim 1, characterized in that: Also includes: Displays the current status of the get call stack switch.
3. The SLUB memory application monitoring method of the LINUX operating system as claimed in claim 2, characterized in that: The S3 further includes: S31, determine whether enable_trace in the current write function is 1 or 0; If so, S32, the enable_trace input in the current write function is valid, otherwise, S33, the enable_trace input in the current write function is invalid.
4. The SLUB memory application monitoring method of the LINUX operating system as claimed in claim 3, characterized in that: After S33, the method further includes: The information that the enable_trace input in the write function is invalid is fed back to the front end.
5. A SLUB memory application monitoring system based on LINUX operating system, characterized in that: include: The system file creation module is used to add a new system file / proc / sys / vm / slab / slabname / enable_trace through the procfs file system to enable obtaining the call stack information of SLUB memory application; A read-write function registration module, used for registering the read-write functions of the system file; The enable_trace judgment module in the write function is used to judge whether the enable_trace in the current write function is 1 and output the judgment result; The call stack acquisition switch execution module is used to set slub_debug=DEBUG_DEFAULT_FLAGS to turn on the call stack acquisition switch according to the judgment result after enable_trace is 1, and call the init_tracking() function to initialize the data structure related to the call stack acquisition, otherwise, set slub_debug=0 to turn off the call stack acquisition switch.
6. The SLUB memory application monitoring system of the LINUX operating system as claimed in claim 5, characterized in that: It also includes a display module connected to the acquisition call stack switch execution module, which is used to display the current state of the acquisition call stack switch.
7. The SLUB memory application monitoring system of the LINUX operating system as claimed in claim 6, characterized in that: It also includes an input legality judgment module connected to the enable_trace judgment module in the write function, which is used to determine that the enable_trace input in the current write function is valid after enable_trace in the current write function is 1 or 0, otherwise, determine that the enable_trace input in the current write function is invalid.
8. The SLUB memory application monitoring system of the LINUX operating system as claimed in claim 7, characterized in that: It also includes an invalid input feedback module connected to the input legality judgment module, which is used to feed back invalid enable_trace input information in the write function to the front end after the enable_trace input in the write function is invalid.
Citation Information
Patent Citations
Memory leak detection method, device and system and storage medium
CN110781075A
Method and system for positioning slub memory leakage of linux kernel
CN112631941A