Logging method and apparatus, electronic device, and storage medium

By creating a tree model and logging code in the storage system, recording the call relationship of memory operation functions and generating logs, the problem that the storage system cannot locate memory errors is solved, and high-accurate memory error positioning is achieved.

WO2025129878A1PCT designated stage expired Publication Date: 2025-06-26INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

Application Number
PCT/CN2024/089178
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-12-20
Filing Date
2024-04-22
Publication Date
2025-06-26

AI Technical Summary

Technical Problem

The prior art cannot effectively realize logging of the storage system, resulting in the inability to locate the memory error of the storage system.

Method used

Create a tree model to describe the call relationship of memory operation functions, and add logging code in each node, logging key fields to generate memory logs. When a memory page error is detected, the record's key fields are retrieved from memory to locate the error.

Benefits of technology

It realizes logging and memory error positioning of the storage system, improving the accuracy of memory error positioning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024089178_26062025_PF_FP_ABST
    Figure CN2024089178_26062025_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computers, and discloses a logging method and apparatus, an electronic device, and a non-volatile readable storage medium, applied to a storage system. The method comprises: creating a tree model on the basis of memory operation function calling relationships, the memory operation function calling relationships comprising a calling relationship between multiple levels of service functions, a calling relationship between the service functions and buffer interface functions, and a calling relationship between the buffer interface functions and memory page interface functions; adding a logging code in each node of the tree model; when the logging code runs, writing into a memory a key field of a function corresponding to the node, so as to generate a log in the memory; and upon detecting a memory page error, acquiring the recorded key field from the memory, so as to acquire the memory operation function calling relationships and operation information to locate the error. The present application implements logging of a storage system and locating of memory errors.
Need to check novelty before this filing date? Find Prior Art

Description

Log recording method, device, electronic device and storage medium

[0001] CROSS-REFERENCE TO RELATED APPLICATIONS

[0002] This application claims priority to the Chinese patent application filed with the China Patent Office on December 20, 2023, with application number 202311756821.3, and application name “A logging method, device, electronic device and storage medium”, all contents of which are incorporated by reference into this application. Technical Field

[0003] The present application relates to the field of computer technology, and more specifically, to a log recording method, device, electronic device, and non-volatile readable storage medium. Background Art

[0004] In related art, logging tools for locating memory errors use a logging system to manage both the application's memory allocator and memory pool, effectively recording the operating system's memory resources. However, because storage systems manage memory pages using their own memory pools, they only locate errors in memory pages within those pools. Therefore, these logging tools are not applicable to locating memory errors in storage products.

[0005] Therefore, how to implement log recording in a storage system is a technical problem that needs to be solved by those skilled in the art.

[0006] Summary of the Invention

[0007] The purpose of this application is to provide a log recording method, device, electronic device and non-volatile readable storage medium to implement log recording of a storage system.

[0008] To achieve the above objectives, the present application provides a logging method, which is applied to a storage system and includes:

[0009] Create a tree model based on the memory operation function call relationship; wherein the memory operation function call relationship includes the call relationship between multi-level business functions, the call relationship between business functions and cache interface functions, and the call relationship between cache interface functions and memory page interface functions. Each node in the tree model corresponds to a function.

[0010] Add logging code to each node in the tree model; the logging code is used to record the key fields of the function corresponding to the node, and the key fields are used to describe the structure of the tree model and record operation information;

[0011] When the logging code is run, the key fields of the function corresponding to the node are written to the memory to generate logs in the memory;

[0012] When a memory page fault is detected, the key fields of the record are obtained from the memory to obtain the memory operation function call relationship and operation information and locate the fault.

[0013] Before writing the key fields of the function corresponding to the node into memory, the following steps are also included:

[0014] Apply for memory space in the memory, which is used to record key fields.

[0015] After applying for memory space in the memory, it also includes:

[0016] Create a circular queue in the memory space, which is used to record key fields.

[0017] Among them, creating a circular queue in the memory space includes:

[0018] A corresponding circular queue is created for each thread in the memory space. The circular queue is used to record the key fields of the function called by the thread.

[0019] Among them, the key fields of the function corresponding to the node are written into the memory, including:

[0020] Determine the thread corresponding to the function corresponding to the node, and write the key field of the function into the circular queue corresponding to the thread.

[0021] Among them, the key fields of the function are written into the circular queue corresponding to the thread, including:

[0022] Determine whether the circular queue corresponding to the thread is full;

[0023] If the circular queue corresponding to the thread is not full, the key field of the function is written to the first non-empty position in the circular queue.

[0024] After determining whether the circular queue corresponding to the thread is full, the following steps are further included:

[0025] When the circular queue corresponding to the thread is full, the key field of the function is written to the position where the data is written earliest in the circular queue.

[0026] The process of determining whether the circular queue corresponding to the thread is full includes:

[0027] Determine whether the circular queue corresponding to the thread meets the preset conditions; if the circular queue corresponding to the thread meets the preset conditions, determine that the circular queue is full; wherein the preset conditions are: (rear+1)%maxSize=front, front is the position of the first element in the circular queue, rear is the position after the last element in the circular queue, maxSize is the total number of positions in the circular queue, and % is a remainder operation.

[0028] Among them, the key fields of the record are obtained from the memory to obtain the memory operation function call relationship and operation information and locate the error, including:

[0029] Get the key fields of each thread record from the memory to obtain the memory operation function call relationship and operation information of each thread and locate the error.

[0030] Among them, the key fields include any one or a combination of the current function name, function position, parent function name, access start address, access length, and access type. The current function name, function position, and parent function name are used to describe the structure of the tree model, and the access start address, access length, and access type are used to record operation information.

[0031] After the log is generated in memory, it also includes:

[0032] Add the code of the binary structured browsing tool to the log code. The code of the binary structured browsing tool is used to structure the browsing data in binary form.

[0033] Among them, the key fields of the record are obtained from the memory to obtain the memory operation function call relationship and operation information and locate the dislocation, including:

[0034] Get the key fields of each thread record from the memory to obtain the memory operation function call relationship and operation information of each thread;

[0035] Based on the binary structure browsing tool, the memory operation function call relationship and operation information of each thread are browsed and errors are located.

[0036] When a memory page error is detected, key fields of the record are obtained from the memory, including:

[0037] When an exception signal or interrupt signal is received from the operating system, it is determined that a memory page error has occurred and the key fields of the record are obtained from the memory.

[0038] When an operation of accessing an illegal memory area is detected, the operating system sends an exception signal or an interrupt signal.

[0039] When an operation of accessing a released memory area is detected, the operating system sends an exception signal or an interrupt signal.

[0040] When a memory page error is detected, key fields of the record are obtained from the memory to obtain the memory operation function call relationship and operation information and locate the error, including:

[0041] When a memory page fault is detected, key fields of the record are obtained from the memory to generate a dump file;

[0042] Determine the memory operation function call relationship and operation information based on the dump file and locate the error.

[0043] Among them, obtaining the memory operation function call relationship and operation information and locating errors include:

[0044] Obtain the memory operation function call relationship and operation information, locate the error function according to the memory operation function call relationship and operation information, and determine the error operation or error transfer parameter in the error function.

[0045] To achieve the above objectives, the present application provides a log recording device, which is applied to a storage system and includes:

[0046] A first creation module is configured to create a tree model based on a memory operation function call relationship; wherein the memory operation function call relationship includes a call relationship between multi-level business functions, a call relationship between a business function and a cache interface function, and a call relationship between a cache interface function and a memory page interface function, and each node in the tree model corresponds to a function;

[0047] A first adding module is configured to add a logging code to each node in the tree model; wherein the logging code is used to record the key fields of the function corresponding to the node, and the key fields are used to describe the structure of the tree model and record operation information;

[0048] The writing module is configured to write the key fields of the function corresponding to the node into the memory when the logging code is run, so as to generate logs in the memory;

[0049] The acquisition module is configured to obtain key fields of the record from the memory when a memory page error is detected, so as to obtain the memory operation function call relationship and operation information and locate the error.

[0050] Among them, also include:

[0051] The application module is configured to apply for memory space in the memory, and the memory space is used to record key fields.

[0052] Among them, also include:

[0053] The second creation module is configured to create a circular queue in the memory space, and the circular queue is used to record the key fields.

[0054] The second creation module is configured to: create a corresponding circular queue for each thread in the memory space, and the circular queue is used to record the key fields of the function called by the thread.

[0055] The writing module is configured to: determine the thread corresponding to the function corresponding to the node, and write the key fields of the function into the circular queue corresponding to the thread.

[0056] The writing module includes:

[0057] A determination unit configured to determine whether a circular queue corresponding to a thread is full;

[0058] The first writing unit is configured to write the key field of the function into the first non-empty position in the circular queue when the circular queue corresponding to the thread is not full;

[0059] The second writing unit is configured to write the key field of the function into the earliest written data position in the circular queue when the circular queue corresponding to the thread is full.

[0060] Among them, the judgment unit is configured to: judge whether the circular queue corresponding to the thread meets the preset conditions; if the circular queue corresponding to the thread meets the preset conditions, then determine that the circular queue is full; wherein the preset conditions are: (rear+1)%maxSize=front, front is the position of the first element in the circular queue, rear is the position after the last element in the circular queue, maxSize is the total number of positions in the circular queue, and % is a remainder operation.

[0061] The acquisition module is configured to obtain key fields of each thread record from the memory to obtain the memory operation function call relationship and operation information of each thread and locate errors.

[0062] Among them, the key fields include any one or a combination of the current function name, function position, parent function name, access start address, access length, and access type. The current function name, function position, and parent function name are used to describe the structure of the tree model, and the access start address, access length, and access type are used to record operation information.

[0063] Among them, also include:

[0064] The second adding module is configured to add the code of the binary structured browsing tool to the code of the log, where the code of the binary structured browsing tool is used to structure the browsing data in binary form.

[0065] Among them, the acquisition module is configured to: obtain the key fields of each thread record from the memory to obtain the memory operation function call relationship and operation information of each thread; browse the memory operation function call relationship and operation information of each thread based on the binary structured browsing tool and locate errors.

[0066] The acquisition module is configured to: when receiving an abnormal signal or an interrupt signal sent by the operating system, determine that a memory page error occurs, and acquire key fields of the record from the memory.

[0067] When an operation of accessing an illegal memory area is detected, the operating system sends an exception signal or an interrupt signal.

[0068] When an operation of accessing a released memory area is detected, the operating system sends an exception signal or an interrupt signal.

[0069] The acquisition module is configured to: when a memory page error is detected, obtain key fields of the record from the memory to generate a dump file; determine the memory operation function call relationship and operation information based on the dump file and locate the error.

[0070] The acquisition module is configured to: acquire the memory operation function call relationship and operation information, locate the error function according to the memory operation function call relationship and operation information, and determine the error operation or error transfer parameter in the error function.

[0071] To achieve the above objectives, the present application provides an electronic device, comprising:

[0072] a memory configured to store a computer program;

[0073] The processor is configured to implement the steps of the above-mentioned logging method when executing the computer program.

[0074] To achieve the above objectives, the present application provides a computer non-volatile readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned logging method are implemented.

[0075] It can be seen from the above scheme that a logging method provided by the present application is applied to a storage system, and the method includes: creating a tree model based on the memory operation function call relationship; wherein the memory operation function call relationship includes the call relationship between multi-level business functions, the call relationship between the business function and the cache interface function, and the call relationship between the cache interface function and the memory page interface function, and each node in the tree model corresponds to a function; adding logging code to each node in the tree model; wherein, the logging code is used to record the key fields of the function corresponding to the node, and the key fields are used to describe the structure of the tree model and record operation information; when the logging code is run, the key fields of the function corresponding to the node are written into the memory to generate a log in the memory; when a memory page error is detected, the recorded key fields are obtained from the memory to obtain the memory operation function call relationship and operation information and locate the error.

[0076] The logging method provided by the present application creates a tree model based on the memory operation function call relationship, adds logging code to each node in the tree model, and when the logging code is run, the key fields of the corresponding function are written into the memory to generate a log. When a memory page error is detected, the key fields of the record can be obtained from the memory, and the error can be located based on the memory operation function call relationship and operation information. It can be seen that the present application realizes the logging and memory error location of the storage system. At the same time, the memory error location is performed using the memory operation function call relationship, which improves the accuracy of memory error location. The present application also discloses a logging device, an electronic device, and a computer non-volatile readable storage medium, which can also achieve the above-mentioned technical effects.

[0077] It should be understood that the foregoing general description and the following detailed description are merely illustrative and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0078] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the drawings required for the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. The drawings are used to provide a further understanding of the present disclosure and constitute part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure, but do not constitute a limitation of the present disclosure. In the drawings:

[0079] FIG1 is a flow chart showing a log recording method according to an exemplary embodiment;

[0080] FIG2 is a schematic diagram of a tree model according to an exemplary embodiment;

[0081] FIG3 is a schematic diagram of a circular queue according to an exemplary embodiment;

[0082] FIG4 is a flow chart showing another logging method according to an exemplary embodiment;

[0083] FIG5 is a schematic diagram showing a circular queue in a memory space according to an exemplary embodiment;

[0084] FIG6 is a structural diagram of a log recording device according to an exemplary embodiment;

[0085] Fig. 7 is a structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0086] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application. In addition, in the embodiments of the present application, "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0087] The embodiment of the present application discloses a log recording method, which implements log recording of a storage system.

[0088] Referring to FIG1 , a flow chart of a logging method according to an exemplary embodiment is shown. As shown in FIG1 , the method includes:

[0089] S101: Creating a tree model based on the memory operation function call relationship; wherein the memory operation function call relationship includes the call relationship between multi-level business functions, the call relationship between business functions and cache interface functions, and the call relationship between cache interface functions and memory page interface functions, and each node in the tree model corresponds to a function;

[0090] This embodiment is applied to a storage system, and aims to log user-defined memory pages in a self-built memory pool of the storage system.

[0091] It is understandable that since memory calls belong to the underlying general functions, the upper-level functions will cross-call them, and the upper-level functions of the upper-level layers will call the upper-level functions, thus forming a complex calling relationship. Therefore, in this step, a tree model is created based on the memory operation function calling relationship, and each node in the tree model corresponds to a function. The memory operation function calling relationship includes the calling relationship between multi-level business functions, the calling relationship between business functions and cache interface functions, and the calling relationship between cache interface functions and memory page interface functions. The created tree model is shown in Figure 2.

[0092] The tree model can be used to describe the entire process of memory operations. For example, which business function calls which cache interface function, and which cache interface function calls which memory page interface function.

[0093] S102: Adding logging code to each node in the tree model; wherein the logging code is used to record key fields of the function corresponding to the node, and the key fields are used to describe the structure of the tree model and record operation information;

[0094] In this step, according to the tree relationship of function calls, logging code is added to each node in the tree model to record the key fields of the corresponding function. The key fields are used to describe the structure of the tree model and record operation information.

[0095] Key fields include the current function name, function location, parent function name, access start address, access length, and access type. The current function name, function location, and parent function name describe the tree model structure, while the access start address, access length, and access type record operation information. The current function name is a fixed-length string that records the name of the current function. If it exceeds the specified length, it will be truncated. The function location is an integer field that is used to distinguish code lines when calling multiple child functions within a function. The parent function name is a fixed-length string that records the name of the parent function. If it exceeds the specified length, it will be truncated. The access start address is an integer field with different meanings at different levels and can represent memory page numbers, buffer unit numbers, cache data block addresses, etc. The access length is an integer field with different meanings at different levels and can represent the number of sectors, memory pages, cache data blocks, etc. The access type is an integer field and can include allocate, release, read, write, and copy.

[0096] S103: When the logging code is executed, the key fields of the function corresponding to the node are written into the memory to generate a log in the memory;

[0097] As a feasible implementation, before writing the key fields of the function corresponding to the node into the memory, the method further includes: applying for memory space in the memory, the memory space being used to record the key fields. In an optional embodiment, applying for a large block of continuous memory space is used to store log data.

[0098] As an optional implementation, after applying for memory space in the memory, the method further includes: creating a circular queue in the memory space, the circular queue being used to record key fields. In an optional embodiment, a circular queue based on a structure array can be created in the applied memory space, as shown in FIG3 , for recording key fields of the function.

[0099] When the program reaches the logging code, the key fields of the corresponding function are written to memory. This information forms a log in memory, which can be used to record important events and operations during program execution. Adding logging does not affect normal business performance or the reproduction of problems.

[0100] S104: When a memory page error is detected, key fields of the record are obtained from the memory to obtain a memory operation function call relationship and operation information and locate the error.

[0101] In an optional embodiment, when a memory page fault is detected, key fields of the record can be obtained from the memory, which include the memory operation function call relationship and operation information. Using this information, the location and cause of the fault can be located.

[0102] As a feasible implementation method, when a memory page error is detected, the key fields of the record are obtained from the memory, including: when an exception signal or interrupt signal sent by the operating system is received, it is determined that a memory page error has occurred, and the key fields of the record are obtained from the memory.

[0103] As a feasible implementation, when an operation of accessing an illegal memory area is detected, the operating system sends an exception signal or an interrupt signal. As another feasible implementation, when an operation of accessing a released memory area is detected, the operating system sends an exception signal or an interrupt signal.

[0104] As you can understand, memory page faults are typically caused by accessing an illegal memory area or a freed memory area. If a memory page fault occurs during program execution, the operating system sends an exception signal or interrupt signal to the program, notifying it of the error. Upon receiving this signal, the program calls the corresponding error or exception handling function to handle the error. During this process, the logging code can be called to retrieve key fields from the error, including function call details and operation information.

[0105] As a feasible implementation, when a memory page fault is detected, key fields of the record are retrieved from memory to obtain the memory operation function call relationship and operation information and locate the fault, including: when a memory page fault is detected, key fields of the record are retrieved from memory to generate a dump file; and based on the dump file, the memory operation function call relationship and operation information are determined and the fault is located. In an optional embodiment, when the program detects a memory page fault, an assertion is explicitly triggered, causing the program to crash and generate a dump file. The error can be located by analyzing the dump file.

[0106] As a feasible implementation method, obtaining memory operation function call relationships and operation information and locating errors includes: obtaining memory operation function call relationships and operation information, locating the erroneous function based on the memory operation function call relationships and operation information, and determining the erroneous operation or incorrectly passed parameters in the erroneous function. In an optional embodiment, the memory operation function call relationships and operation information can be used to understand which function the error occurred in and which other functions this function called during execution. In addition, information such as function parameters, execution results, and execution time can also be obtained, which can help better understand the function's execution process and behavior. Using information from these key fields, the location and cause of the error can be quickly located. For example, if an error is found to occur in a specific function, the function's code can be carefully examined to determine which operations caused the memory page error. If it is found that this function called an incorrect function or passed incorrect parameters during execution, then this is the cause of the error.

[0107] As an optional implementation, after the log is generated in the memory, the method further includes: adding a binary structured browsing tool code to the log code, where the binary structured browsing tool code is used to structure browsing data in binary form.

[0108] In an optional embodiment, code for a binary structured browsing tool is added to the log queue code to browse data in a structured binary format. This tool helps developers visualize and analyze the program execution process. By presenting the memory operation function call relationship and operation information of each thread in a graphical interface, developers can more intuitively understand the program execution process and behavior. This helps developers quickly locate the location and cause of errors. When a memory page fault is detected, the key fields of the record are retrieved from memory, and the binary structured browsing tool is used to browse the memory operation function call relationship and operation information to locate the fault.

[0109] The logging method provided by the embodiment of the present application creates a tree model based on the memory operation function call relationship, adds logging code to each node in the tree model, and when the logging code is executed, writes the key fields of the corresponding function to the memory to generate a log. When a memory page error is detected, the key fields of the record can be obtained from the memory, and the error can be located based on the memory operation function call relationship and operation information. As can be seen from this, the embodiment of the present application implements logging and memory error location of the storage system. At the same time, the memory operation function call relationship is used to locate the memory error, thereby improving the accuracy of memory error location.

[0110] The embodiment of this application discloses a log recording method. Compared with the previous embodiment, this embodiment further explains the technical solution. Optional:

[0111] Referring to FIG4 , a flow chart of another logging method according to an exemplary embodiment is shown. As shown in FIG4 , the method includes:

[0112] S201: Apply for memory space in the memory, and create a corresponding circular queue for each thread in the memory space. The circular queue is used to record key fields of the function called by the thread.

[0113] In this embodiment, a circular queue is created for each thread in the allocated memory space, storing the key fields of all functions called by that thread, as shown in Figure 5. Memory space is the area used to store data during program execution. Allocating space in memory provides the necessary memory space for creating a circular queue for each thread. A circular queue is a data structure that implements queue operations within a fixed-size array. In this scenario, the circular queue is used to record the key fields of the functions called by each thread. Each thread has its own corresponding circular queue, which is used to store key field information for functions called during the thread's execution. When a thread calls a function, the key field information for that function is added to the corresponding circular queue. By creating a corresponding circular queue for each thread in memory, the thread's execution process can be easily tracked and recorded. This allows the cause and location of the error to be analyzed by viewing the information in the circular queue when a program error occurs.

[0114] In a circular queue, front points to the first element in the queue, that is, arr[front] is the first element in the queue. The initial value of front is 0, and rear points to the position after the last element in the queue. Because we want to leave a space as a convention, the initial value of rear is 0. The queue is full when (rear+1)%maxSize == front, and the queue is empty when rear == front.

[0115] It can be seen that this embodiment can use a circular queue method to record logs in the memory according to the thread that calls the function, which is different from the prior art that records logs on the disk according to the timeline method.

[0116] S202: Creating a tree model based on the memory operation function call relationship; wherein the memory operation function call relationship includes the call relationship between multi-level business functions, the call relationship between business functions and cache interface functions, and the call relationship between cache interface functions and memory page interface functions, and each node in the tree model corresponds to a function;

[0117] S203: Adding logging code to each node in the tree model; wherein the logging code is used to record the key fields of the function corresponding to the node, and the key fields are used to describe the structure of the tree model and record operation information;

[0118] This embodiment can fully record the function call relationships for each thread's memory operations during the logging process. Existing technologies only record individual functions and fail to capture the function call relationships. Memory functions are low-level, general-purpose functions that are frequently and extensively called by different business modules. When a memory error occurs, fully recording the function call relationships for each thread's memory operations allows pinpointing the actual cause of the error.

[0119] S204: When the logging code is executed, the thread corresponding to the function corresponding to the node is determined, and the key fields of the function are written into the circular queue corresponding to the thread to generate a log;

[0120] In an optional embodiment, when the program runs to the logging code in a function, it first obtains the current thread sequence number of the function, obtains the corresponding circular queue based on the thread sequence number, and writes the key fields of the function into the circular queue.

[0121] As a feasible implementation method, the key field of the function is written into the circular queue corresponding to the thread, including: determining whether the circular queue corresponding to the thread is full; if the circular queue corresponding to the thread is not full, writing the key field of the function into the first non-empty position in the circular queue; if the circular queue corresponding to the thread is full, writing the key field of the function into the position where data is written earliest in the circular queue.

[0122] In an optional embodiment, it is determined whether the circular queue corresponding to the thread meets the preset conditions; if the circular queue corresponding to the thread meets the preset conditions, it is determined that the circular queue is full; wherein the preset conditions are: (rear+1)%maxSize=front, front is the position of the first element in the circular queue, rear is the position after the last element in the circular queue, maxSize is the total number of positions in the circular queue, and % is a remainder operation.

[0123] During logging, the first node of the circular queue is obtained and the function's key fields are written to the first node. The name of the parent function is obtained using the backtrace function. If the number of logs exceeds the queue length, the new log overwrites the old one.

[0124] S205: When a memory page fault is detected, the key fields of each thread record are obtained from the memory to obtain the memory operation function call relationship and operation information of each thread and locate the fault;

[0125] S206: Browse the memory operation function call relationship and operation information of each thread based on the binary structure browsing tool and locate errors.

[0126] In an optional embodiment, when the program detects a memory page error, an assert is triggered explicitly, causing the program to crash and generate a dump. Based on a binary structured browsing tool, the memory operation function call relationship of each thread is browsed, and the root cause of the memory error is located based on information such as the type, starting address, and length of the memory operation.

[0127] The following introduces a log recording device provided in an embodiment of the present application. The log recording device described below and the log recording method described above can be referenced to each other.

[0128] 6 , which is a structural diagram of a logging device according to an exemplary embodiment, includes:

[0129] A first creation module 100 is configured to create a tree model based on a memory operation function call relationship; wherein the memory operation function call relationship includes a call relationship between multi-level business functions, a call relationship between a business function and a cache interface function, and a call relationship between a cache interface function and a memory page interface function, and each node in the tree model corresponds to a function;

[0130] This embodiment is applied to a storage system, and aims to log user-defined memory pages in a self-built memory pool of the storage system.

[0131] It is understandable that, since memory calls belong to bottom-level general functions, upper-level functions will cross-call them, and the upper-level functions of the upper-level layers will call the upper-level functions, thus forming a complex calling relationship. Therefore, in this step, a tree model is created based on the memory operation function calling relationship, and each node in the tree model corresponds to a function. The memory operation function calling relationship includes the calling relationship between multi-level business functions, the calling relationship between business functions and cache interface functions, and the calling relationship between cache interface functions and memory page interface functions. The entire process of memory operations can be described through the tree model. For example, which business function calls which cache interface function, and which cache interface function calls which memory page interface function.

[0132] The first adding module 200 is configured to add a logging code to each node in the tree model; wherein the logging code is used to record the key fields of the function corresponding to the node, and the key fields are used to describe the structure of the tree model and record operation information;

[0133] In this step, according to the tree relationship of function calls, logging code is added to each node in the tree model to record the key fields of the corresponding function. The key fields are used to describe the structure of the tree model and record operation information.

[0134] Key fields include the current function name, function location, parent function name, access start address, access length, and access type. The current function name, function location, and parent function name describe the tree model structure, while the access start address, access length, and access type record operation information. The current function name is a fixed-length string that records the name of the current function. If it exceeds the specified length, it will be truncated. The function location is an integer field that is used to distinguish code lines when calling multiple child functions within a function. The parent function name is a fixed-length string that records the name of the parent function. If it exceeds the specified length, it will be truncated. The access start address is an integer field with different meanings at different levels and can represent memory page numbers, buffer unit numbers, cache data block addresses, etc. The access length is an integer field with different meanings at different levels and can represent the number of sectors, memory pages, cache data blocks, etc. The access type is an integer field and can include allocate, release, read, write, and copy.

[0135] The writing module 300 is configured to write the key fields of the function corresponding to the node into the memory when the logging code is executed, so as to generate a log in the memory;

[0136] In an alternative embodiment, when the program reaches logging code, the key fields of the corresponding function are written to memory. This information forms a log in memory, which can be used to record important events and operations during program execution. Adding logging does not affect normal business performance or the reproduction of problems.

[0137] The acquisition module 400 is configured to acquire key fields of the record from the memory when a memory page error is detected, so as to obtain the memory operation function call relationship and operation information and locate the error.

[0138] In an alternative embodiment, when a memory page fault is detected, key fields recorded in the memory can be retrieved. These key fields include the memory operation function call relationship and operation information. This information can be used to locate the location and cause of the error. Memory page faults are typically caused by accessing an illegal memory area or a released memory area. During program execution, if a memory page fault occurs, the operating system sends an exception signal or interrupt signal to the program, notifying it of the error. Upon receiving this signal, the program calls the corresponding error handling function or exception handling function to handle the error. During this processing, the logging code can be called to retrieve the key fields at the time of the error. These fields include the function call relationship and operation information. This information can be used to determine which function the error occurred in and which other functions were called during execution. Furthermore, information such as function parameters, execution results, and execution time can be obtained, which can help better understand the function's execution process and behavior. Using this information, the location and cause of the error can be quickly located. For example, if the error is found to occur in a specific function, the code of that function can be carefully examined to determine which operations caused the memory page fault. If you find that this function calls an incorrect function or passes incorrect parameters when it is executed, then this is the cause of the error.

[0139] The logging device provided by the embodiment of the present application creates a tree model based on the memory operation function call relationship, adds logging code to each node in the tree model, and when the logging code is executed, writes the key fields of the corresponding function to the memory to generate a log. When a memory page error is detected, the key fields of the record can be obtained from the memory, and the error can be located based on the memory operation function call relationship and operation information. It can be seen that the embodiment of the present application realizes the logging and memory error location of the storage system. At the same time, the memory operation function call relationship is used to locate the memory error, thereby improving the accuracy of memory error location.

[0140] As an optional implementation, it also includes:

[0141] The application module is configured to apply for memory space in the memory, and the memory space is used to record key fields.

[0142] In an optional embodiment, a large block of continuous memory space is applied for storing log data.

[0143] As an optional implementation, it also includes:

[0144] The second creation module is configured to create a circular queue in the memory space, and the circular queue is used to record the key fields.

[0145] In an optional embodiment, a circular queue based on a structure array may be created in the applied memory space to record key fields of the function.

[0146] As an optional implementation, the second creation module is configured to: create a corresponding circular queue for each thread in the memory space, where the circular queue is used to record key fields of the function called by the thread.

[0147] A circular queue is created for each thread in the allocated memory space. This queue stores the key fields of all functions called by the thread. Memory space is used to store data during program execution. Allocating memory space provides the necessary memory for creating a circular queue for each thread. A circular queue is a data structure that implements queue operations within a fixed-size array. In this scenario, it is used to record the key fields of functions called by each thread. Each thread has its own circular queue, which stores key field information for functions called during execution. When a thread calls a function, the key field information is added to the thread's corresponding circular queue. Creating a circular queue for each thread in memory makes it easy to track and record the thread's execution process. This allows you to analyze the cause and location of program errors by reviewing the information in the circular queue.

[0148] In a circular queue, front points to the first element in the queue, that is, arr[front] is the first element in the queue. The initial value of front is 0, and rear points to the position after the last element in the queue. Because we want to leave a space as a convention, the initial value of rear is 0. The queue is full when (rear+1)%maxSize == front, and the queue is empty when rear == front.

[0149] It can be seen that this embodiment can use a circular queue method to record logs in the memory according to the thread that calls the function, which is different from the prior art that records logs on the disk according to the timeline method.

[0150] As an optional implementation, the writing module 300 is configured to: determine a thread corresponding to a function corresponding to a node, and write key fields of the function into a circular queue corresponding to the thread.

[0151] In an optional embodiment, when the program runs to the logging code in a function, it first obtains the current thread sequence number of the function, obtains the corresponding circular queue based on the thread sequence number, and writes the key fields of the function into the circular queue.

[0152] As an optional implementation, the writing module 300 includes:

[0153] A determination unit configured to determine whether a circular queue corresponding to a thread is full;

[0154] The first writing unit is configured to write the key field of the function into the first non-empty position in the circular queue when the circular queue corresponding to the thread is not full;

[0155] The second writing unit is configured to write the key field of the function into the earliest written data position in the circular queue when the circular queue corresponding to the thread is full.

[0156] As an optional implementation, the judgment unit is configured to: judge whether the circular queue corresponding to the thread meets the preset conditions; if the circular queue corresponding to the thread meets the preset conditions, determine that the circular queue is full; wherein the preset conditions are: (rear+1)%maxSize=front, front is the position of the first element in the circular queue, rear is the position after the last element in the circular queue, maxSize is the total number of positions in the circular queue, and % is a remainder operation.

[0157] As an optional implementation, the acquisition module 400 is configured to: acquire key fields of each thread record from the memory to obtain the memory operation function call relationship and operation information of each thread and locate errors.

[0158] As an optional implementation, it also includes:

[0159] The second adding module is configured to add the code of the binary structured browsing tool to the code of the log, where the code of the binary structured browsing tool is used to structure the browsing data in binary form.

[0160] In an optional embodiment, when the program detects a memory page error, an assert is triggered explicitly, causing the program to crash and generate a dump. Based on a binary structured browsing tool, the memory operation function call relationship of each thread is browsed, and the root cause of the memory error is located based on information such as the type, starting address, and length of the memory operation.

[0161] As an optional implementation, the acquisition module 400 is configured to: obtain the key fields of each thread record from the memory to obtain the memory operation function call relationship and operation information of each thread; browse the memory operation function call relationship and operation information of each thread based on a binary structured browsing tool and locate errors.

[0162] As an optional implementation, the acquisition module 400 is configured to: when receiving an exception signal or an interrupt signal sent by the operating system, determine that a memory page error occurs, and acquire key fields of the record from the memory.

[0163] As an optional implementation, when an operation of accessing an illegal memory area is detected, the operating system sends an exception signal or an interrupt signal.

[0164] As an optional implementation, when an operation of accessing a released memory area is detected, the operating system sends an exception signal or an interrupt signal.

[0165] As an optional implementation, the acquisition module 400 is configured to: when a memory page error is detected, obtain key fields of the record from the memory to generate a dump file; determine the memory operation function call relationship and operation information based on the dump file and locate the error.

[0166] As an optional implementation, the acquisition module 400 is configured to: obtain the memory operation function call relationship and operation information, locate the error function based on the memory operation function call relationship and operation information, and determine the error operation or error transfer parameter in the error function.

[0167] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0168] Based on the hardware implementation of the above program modules, and in order to implement the method of the embodiment of the present application, the embodiment of the present application further provides an electronic device. FIG7 is a structural diagram of an electronic device according to an exemplary embodiment. As shown in FIG7 , the electronic device includes:

[0169] Communication interface 1, capable of exchanging information with other devices such as network devices;

[0170] The processor 2 is connected to the communication interface 1 to implement information exchange with other devices and is configured to execute the logging method provided by one or more of the above technical solutions when running a computer program. The computer program is stored in the memory 3.

[0171] Of course, in actual applications, the various components in the electronic device are coupled together via bus system 4. It will be appreciated that bus system 4 is configured to enable communication between these components. In addition to a data bus, bus system 4 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in FIG7 , all of these buses are labeled as bus system 4.

[0172] The memory 3 in the embodiment of the present application is configured to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program for operating on the electronic device.

[0173] It is understood that the memory 3 can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a magnetic disk memory or a magnetic tape memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus random access memory (DRRAM).The memory 3 described in the embodiments of the present application is intended to include but is not limited to these and any other suitable types of memories.

[0174] The methods disclosed in the above embodiments of the present application can be applied to processor 2 or implemented by processor 2. Processor 2 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in processor 2 or instructions in software form. The above processor 2 may be a general-purpose processor, a DSP (Digital Signal Processor), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Processor 2 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the methods disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a non-volatile readable storage medium, which is located in memory 3. Processor 2 reads the program in memory 3 and completes the steps of the above method in combination with its hardware.

[0175] When the processor 2 executes the program, the corresponding processes in each method of the embodiment of the present application are implemented. For the sake of brevity, they are not repeated here.

[0176] In an exemplary embodiment, the present application also provides a non-volatile readable storage medium, namely, a computer non-volatile readable storage medium, for example, including a memory 3 storing a computer program. The computer program can be executed by a processor 2 to perform the aforementioned method steps. The computer non-volatile readable storage medium can be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface storage, optical disk, CD-ROM, etc.

[0177] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer non-volatile readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned non-volatile readable storage medium includes: various non-volatile readable storage media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.

[0178] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer non-volatile readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a non-volatile readable storage medium and includes a number of instructions for enabling an electronic device (which can be a personal computer, server, network device, etc.) to execute all or part of the methods of each embodiment of the present application. The aforementioned non-volatile readable storage medium includes: various non-volatile readable storage media that can store program code, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.

[0179] The above are only specific embodiments of the present application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

Claims

1. A log recording method, characterized in that: Applied to a storage system, the method comprises: A tree model is created according to the calling relationship of the memory operation function; wherein the calling relationship of the memory operation function includes the calling relationship between multi-level business functions, the calling relationship between the business function and the cache interface function, and the calling relationship between the cache interface function and the memory page interface function, and each node in the tree model corresponds to a function; Adding a logging code in each node in the tree model; wherein the logging code is used to record a key field of a function corresponding to the node, and the key field is used to describe the structure of the tree model and record operation information; When the logging code is executed, the key fields of the function corresponding to the node are written into the memory to generate a log in the memory; When a memory page error is detected, key fields of the record are obtained from the memory to obtain the memory operation function call relationship and operation information and locate the error.

2. The log recording method according to claim 1, characterized in that: Before writing the key fields of the function corresponding to the node into the memory, the method further includes: Apply for memory space in the memory, where the memory space is used to record the key field.

3. The log recording method according to claim 2, characterized in that: After applying for memory space in the memory, the method further includes: A circular queue is created in the memory space, where the circular queue is used to record the key field.

4. The log recording method according to claim 3, characterized in that: Creating a circular queue in the memory space, including: A corresponding circular queue is created for each thread in the memory space, and the circular queue is used to record key fields of the function called by the thread.

5. The log recording method according to claim 4, characterized in that: Write the key fields of the function corresponding to the node into the memory, including: A thread corresponding to the function corresponding to the node is determined, and a key field of the function is written into a circular queue corresponding to the thread.

6. The log recording method according to claim 5, characterized in that: Writing the key fields of the function into the circular queue corresponding to the thread includes: Determine whether the circular queue corresponding to the thread is full; If the circular queue corresponding to the thread is not full, the key field of the function is written into the first non-empty position in the circular queue.

7. The log recording method according to claim 6, characterized in that: After determining whether the circular queue corresponding to the thread is full, the method further includes: When the circular queue corresponding to the thread is full, the key field of the function is written into the earliest position of data written in the circular queue.

8. The log recording method according to claim 6, characterized in that: The determining whether the circular queue corresponding to the thread is full includes: Determine whether the circular queue corresponding to the thread meets the preset conditions; if the circular queue corresponding to the thread If the circular queue meets the preset conditions, it is determined that the circular queue is full; wherein the preset conditions are: (rear+1)%maxSize=front, front is the position of the first element in the circular queue, rear is the position after the last element in the circular queue, maxSize is the total number of positions in the circular queue, and % is the remainder operation.

9. The log recording method according to claim 4, characterized in that: Obtain key fields of the record from the memory to obtain the memory operation function call relationship and operation information and locate errors, including: The key fields of each thread record are obtained from the memory to obtain the memory operation function call relationship and operation information of each thread and locate the error.

10. The log recording method according to claim 1, characterized in that: The key fields include any one or a combination of the current function name, function position, parent function name, access start address, access length, and access type. The current function name, the function position, and the parent function name are used to describe the structure of the tree model, and the access start address, the access length, and the access type are used to record operation information.

11. The log recording method according to claim 4, characterized in that: After the log is generated in the memory, it also includes: The code of the binary structured browsing tool is added to the code of the log, and the code of the binary structured browsing tool is used to structure the browsing data in binary form.

12. The log recording method according to claim 11, characterized in that: Obtaining key fields of the record from the memory to obtain the memory operation function call relationship and operation information and locate the misalignment, including: Acquire key fields of each thread record from the memory to acquire memory operation function call relationship and operation information of each thread; Based on the binary structure browsing tool, the memory operation function call relationship and operation information of each thread are browsed and errors are located.

13. The log recording method according to claim 1, characterized in that: When a memory page error is detected, obtaining key fields of the record from the memory includes: When an abnormal signal or an interrupt signal sent by the operating system is received, it is determined that a memory page error occurs, and a key field of the record is obtained from the memory.

14. The log recording method according to claim 13, characterized in that: When an operation of accessing an illegal memory area is detected, the operating system sends the exception signal or the interrupt signal.

15. The log recording method according to claim 13, characterized in that: When an operation of accessing a released memory area is detected, the operating system sends the exception signal or the interrupt signal.

16. The log recording method according to claim 1, characterized in that: When a memory page error is detected, the key fields of the record are obtained from the memory to obtain the memory operation function call relationship and operation information and locate the error, including: When a memory page error is detected, obtaining key fields of the record from the memory to generate a dump file; Based on the dump file, the memory operation function call relationship and operation information are determined and the error is located.

17. The log recording method according to claim 1, characterized in that: The obtaining of memory operation function call relationship and operation information and locating errors includes: Acquire the memory operation function calling relationship and operation information, locate the error function according to the memory operation function calling relationship and the operation information, and determine the error operation or error transfer parameter in the error function.

18. A log recording device, characterized in that: Applied to a storage system, the device comprises: A first creation module is configured to create a tree model according to a memory operation function call relationship; wherein the memory operation function call relationship includes a call relationship between multi-level business functions, a call relationship between a business function and a cache interface function, and a call relationship between a cache interface function and a memory page interface function, and each node in the tree model corresponds to a function; A first adding module is configured to add a logging code in each node in the tree model; wherein the logging code is used to record a key field of a function corresponding to the node, and the key field is used to describe the structure of the tree model and record operation information; A writing module, configured to write key fields of the function corresponding to the node into a memory when the logging code is run, so as to generate a log in the memory; The acquisition module is configured to acquire key fields of the record from the memory when a memory page error is detected, so as to acquire the memory operation function call relationship and operation information and locate the error.

19. An electronic device, characterized in that: include: a memory configured to store a computer program; A processor, configured to implement the steps of the logging method according to any one of claims 1 to 17 when executing the computer program.

20. A computer non-volatile readable storage medium, characterized in that: The computer non-volatile readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the logging method according to any one of claims 1 to 17 are implemented.

Citation Information

Patent Citations

  • Method for prolonging service life of nonvolatile storage with reconfigurable file system directory tree

    CN103744961A

  • Log stack information analysis method and apparatus, computer device, and storage medium

    CN109522209A

  • Log recording method and device, electronic equipment and storage medium

    CN117435385A

  • Automatic Creation of Structured Error Logs from Unstructured Error Logs

    US20230131162A1

Cited By

  • Kernel module log redirection method, electronic equipment, storage medium and product

    CN121412073A