CN116627705A - Memory abnormality detection method, device, equipment and storage medium - Google Patents

Memory abnormality detection method, device, equipment and storage medium Download PDF

Info

Publication number
CN116627705A
CN116627705A CN202310673245.XA CN202310673245A CN116627705A CN 116627705 A CN116627705 A CN 116627705A CN 202310673245 A CN202310673245 A CN 202310673245A CN 116627705 A CN116627705 A CN 116627705A
Authority
CN
China
Prior art keywords
memory
released
called
calling
call
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310673245.XA
Other languages
Chinese (zh)
Inventor
王扬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
New H3C Cloud Technologies Co Ltd
Original Assignee
New H3C Cloud Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by New H3C Cloud Technologies Co Ltd filed Critical New H3C Cloud Technologies Co Ltd
Priority to CN202310673245.XA priority Critical patent/CN116627705A/en
Publication of CN116627705A publication Critical patent/CN116627705A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0706Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation the processing taking place on a specific hardware platform or in a specific software environment
    • G06F11/073Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation the processing taking place on a specific hardware platform or in a specific software environment in a memory management context, e.g. virtual memory or cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0751Error or fault detection not based on redundancy
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The disclosure provides a method, a device, equipment and a storage medium for detecting memory abnormality, wherein the method comprises the following steps: responding to a memory calling request, and detecting whether the state of the memory to be called is matched with a calling mode corresponding to the memory calling request; if the memory to be called is not matched, determining that the memory to be called is abnormal; if the state of the memory to be called is matched with the call mode corresponding to the memory call request and the memory to be called is the memory to be released, setting a delay condition for delaying the release of the memory to be released; if the delay condition is met, detecting whether the memory to be released is accessed repeatedly; and if the memory to be released is accessed repeatedly, determining that the memory to be released is abnormal. According to the method and the device, whether the memory abnormality occurs in the corresponding calling stage is detected by correspondingly detecting the matching degree of the actual state of the memory to be released in the corresponding stage and the calling mode in each stage of the memory to be released, so that the applicability is wide, and the detection is comprehensive.

Description

Memory abnormality detection method, device, equipment and storage medium
Technical Field
The disclosure belongs to the technical field of computers, and in particular relates to a memory abnormality detection method, a device, equipment and a storage medium.
Background
The memory management refers to the process of distributing memory resources according to the running requirement of an application program in the running process of the application program. In the running process of the application program, if the memory abnormality occurs, the running of the application program is crashed. Memory anomalies include, for example, memory out-of-range, pointer misalignment, repeated memory release, etc. In view of this, detecting whether a memory abnormality occurs or not and locating the problem of occurrence of the memory abnormality are one of the items for improving the performance in the memory management.
The conventional memory abnormality detection scheme is mainly used for detecting some preconfigured operation items, and the detection scope covered by the preconfigured detection items is smaller than the scope of abnormality occurrence in an actual scene, so that the applicability of the conventional memory abnormality detection scheme is poor.
Disclosure of Invention
The present disclosure provides a method, an apparatus, a device, and a storage medium for detecting a memory exception, where after a memory call request is received by presetting a state of a memory, whether the memory to be called is abnormal is determined according to whether a call mode corresponding to the memory call request matches with the state of the memory to be called. In the memory release stage, the memory to be released is released in a delayed manner, and then repeated access detection is performed under the condition that the delayed release condition is achieved, so that the method is wide in applicability and comprehensive in detection.
An embodiment of a first aspect of the present disclosure provides a method for detecting a memory exception, including:
responding to a memory calling request from an application program, detecting whether the state of a memory to be called is matched with a calling mode corresponding to the memory calling request, wherein the state of the memory to be called is used for identifying whether the memory to be called is occupied or not;
if the state of the memory to be called is not matched with the call mode corresponding to the memory call request, determining that the memory to be called is abnormal;
if the state of the memory to be called is matched with the call mode corresponding to the memory call request and the memory to be called is the memory to be released, setting a delay condition for delaying the release of the memory to be released;
if the delay condition is met, detecting whether the memory to be released is accessed repeatedly;
and if the memory to be released is repeatedly accessed, determining that the memory to be released is abnormal.
In an embodiment of the disclosure, the method further comprises:
if a memory exception positioning mode is started, responding to the memory call request, and storing call information corresponding to the memory call request into a preset storage area of the memory, wherein the memory call information comprises at least one of the following: and the application program calls the service identifier, the calling mode, the calling time and the calling stack of the memory to be called.
In the embodiment of the present disclosure, the state of the memory to be called is a use state or a release state, and if the state of the memory to be called is the release state, the memory to be called is the memory to be released, and the state of the memory to be called is not matched with a call mode corresponding to the memory call request, including:
the calling mode corresponding to the memory calling request is an application mode, and the state of the memory to be called is a use state; or the state of the memory to be released is a release state.
In an embodiment of the present disclosure, the setting a delay condition for delaying the release of the memory to be released includes:
adding the memory to be released into a preset queue to be released; or alternatively, the process may be performed,
and setting a countdown for delaying the release of the memory to be released according to a preset delay time.
In an embodiment of the present disclosure, before setting a delay condition for delaying the release of the memory to be released, the method further includes:
if the storage space of the memory to be released is larger than or equal to a preset threshold value, setting the access permission of the memory to be released as access prohibition;
if the storage space of the memory to be released is smaller than the preset threshold, setting an access identifier in the memory to be released, wherein the access identifier is used for indicating whether the memory to be released is accessed or not.
In an embodiment of the present disclosure, the detecting whether the memory to be released is accessed repeatedly includes:
if the storage space of the memory to be released is smaller than the preset threshold value, detecting whether the content of the access identifier is changed or not;
and if the content of the access identifier is changed, determining that the memory to be released is accessed repeatedly.
In an embodiment of the present disclosure, after determining that the memory to be invoked is abnormal, the method further includes:
acquiring a service identifier, a calling mode and a calling time corresponding to the abnormality;
and reading the program with the abnormality from the call stack determined by the service identifier, the call mode and the call time.
An embodiment of a second aspect of the present disclosure provides a memory exception detection apparatus, including:
the detection module is used for responding to a memory calling request from an application program, detecting whether the state of the memory to be called is matched with a calling mode corresponding to the memory calling request, wherein the state of the memory to be called is used for identifying whether the memory to be called is occupied or not;
the determining module is used for determining that the memory to be called is abnormal if the state of the memory to be called is not matched with the calling mode corresponding to the memory calling request;
The setting module is used for setting a delay condition for delaying the release of the memory to be released if the state of the memory to be called is matched with the calling mode corresponding to the memory calling request and the memory to be called is the memory to be released;
the detection module is further configured to detect whether the memory to be released is repeatedly accessed if the delay condition is satisfied;
and the determining module is further configured to determine that an exception occurs in the memory to be released if the memory to be released is repeatedly accessed.
In an embodiment of the disclosure, the apparatus further includes: the memory module is used for responding to the memory call request if the memory exception positioning mode is started, and storing call information corresponding to the memory call request into a preset memory area of the memory, wherein the memory call information comprises at least one of the following items: and the application program calls the service identifier, the calling mode, the calling time and the calling stack of the memory to be called.
In this embodiment of the present disclosure, the setting module is further configured to add the memory to be released to a preset queue to be released; and setting a countdown for delaying the release of the memory to be released according to a preset delay time.
In an embodiment of the disclosure, the apparatus further includes: an access right setting module and an access identification setting module, wherein,
the access right setting module is configured to set the access right of the memory to be released as access prohibition if the storage space of the memory to be released is greater than or equal to a preset threshold;
the access identifier setting module is configured to set an access identifier in the memory to be released if the storage space of the memory to be released is smaller than the preset threshold, where the access identifier is used to indicate whether the memory to be released is accessed.
In this embodiment of the present disclosure, the detection module is further configured to detect whether the content of the access identifier is changed if the storage space of the to-be-released memory is smaller than the preset threshold; and the determining module is further used for determining that the memory to be released is repeatedly accessed if the content of the access identifier is changed.
In an embodiment of the disclosure, the apparatus further includes: the acquisition module is used for acquiring the service identifier, the calling mode and the calling time corresponding to the abnormality; and reading the program with the abnormality from the call stack determined by the service identifier, the call mode and the call time.
Embodiments of the third aspect of the present disclosure provide an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor running the computer program to implement the method of the first aspect.
Embodiments of the fourth aspect of the present disclosure provide a computer-readable storage medium having stored thereon a computer program for execution by a processor to perform the method of the first aspect described above.
The technical scheme provided in the embodiment of the disclosure has at least the following technical effects or advantages:
the memory to be called related to the embodiment of the disclosure can set a state, and the state of the memory to be called is used for identifying whether the memory to be called is occupied or not. Thus, after receiving a memory call request from an application program, the embodiment of the disclosure can detect whether abnormal phenomena such as memory boundary crossing, pointer dislocation, repeated release and the like occur in the call of the memory to be called in different call stages according to whether the call mode corresponding to the memory call request is matched with the state of the memory to be called. Further, in the case that the call mode of the application program is a stage of releasing the memory and there is no repeated release of the memory to be released, the embodiment of the disclosure detects whether the memory to be released is repeatedly accessed or not before releasing by performing delayed release on the memory to be released. Therefore, by adopting the implementation manner of the embodiment of the disclosure, the memory abnormality detection item does not need to be preset, and the matching degree of the actual state and the calling mode of the memory to be called in the corresponding stage is correspondingly detected in each stage of the memory to be called in the application program, so that whether the memory abnormality occurs in the corresponding calling stage is detected, the scope to be detected corresponding to different implementation scenes does not need to be considered, the applicability is wide, the detection of the memory abnormality is more comprehensive, and the performance of the memory abnormality detection can be improved.
Additional aspects and advantages of the disclosure will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the disclosure.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the disclosure. Also, like reference numerals are used to designate like parts throughout the figures.
In the drawings:
fig. 1 is a flow chart illustrating a method for detecting a memory exception according to an embodiment of the disclosure;
FIG. 2 is a schematic diagram of a memory block deployment according to an embodiment of the present disclosure;
FIG. 3 is a schematic diagram illustrating another memory abnormality detection apparatus according to an embodiment of the disclosure;
FIG. 4 is a schematic diagram of an electronic device according to an embodiment of the disclosure;
fig. 5 shows a schematic diagram of a storage medium according to an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
It is noted that unless otherwise indicated, technical or scientific terms used in this disclosure should be given the ordinary meaning as understood by one of ordinary skill in the art to which this disclosure pertains.
The following describes an implementation scenario and related techniques related to embodiments of the present disclosure.
The embodiment of the disclosure relates to a memory management technology, in particular to a technology for monitoring, detecting, positioning and the like of memory anomalies.
The memory management includes a process of allocating memory for an application program (APP) or configuring memory released by the APP in response to a request of the APP by a memory management system in order to support the running of the APP. The memory management system and the APP may be deployed in an electronic device that may function as a terminal device, a server, or any server node of a distributed storage system.
In some implementations, the memory management system may obtain a memory area of the electronic device (hereinafter referred to as a "memory block"), for example, a memory block with a size of 8 megabytes (Mega Byte, MB or M), and then divide the memory block into a plurality of sub-areas (hereinafter, each sub-area is referred to as a "memory slice"), where the storage space of the plurality of memory slices may be 16 bytes (Byte, B), 32B, 64B, 128B, etc., respectively, and the storage space of the memory slice with the largest storage space may be 4M, for example, according to an exponential increase of 2. After receiving a request from an APP to apply for memory, the memory management system may allocate a memory slice with a matching memory space for the APP. Upon receiving a request from the APP to free memory, the memory management system may determine that the corresponding memory slice is unoccupied and may be reassigned.
The memory abnormality related to the embodiment of the disclosure includes stepping the memory, and stepping the memory includes memory out-of-range, pointer dislocation, repeated release, and the like. Because the generation of the anomalies is random, the anomalies are difficult to accurately and comprehensively monitor, and the positions and the processes of the anomalies are difficult to quickly locate, so that the memory management performance is poor.
The memory exception detection method provided by the embodiment of the disclosure can identify whether the memory to be called is occupied or not, and further, in each stage of calling the memory to be called by the application program, the matching degree of the actual state and the calling mode of the memory to be called in the corresponding stage is correspondingly detected to detect whether the memory exception occurs in the corresponding calling stage. And in the stage that the calling mode of the application program is to release the memory, the memory to be released is delayed to detect whether the memory to be released is repeatedly accessed before the memory to be released is released. Therefore, the scope to be detected corresponding to different realization scenes is not needed to be considered, the applicability is wide, the memory abnormality detection is comprehensive, and the memory management performance can be improved.
The following describes a method, apparatus, device and storage medium for detecting a memory exception according to an embodiment of the present disclosure with reference to the foregoing implementation scenario and the accompanying drawings.
As shown in fig. 1, an embodiment of the present disclosure provides a method for detecting a memory exception, which may be applied to the above-mentioned electronic device. The method comprises the following steps:
in step S11, in response to a memory call request from an application program, it is detected whether the state of the memory to be called matches a call pattern corresponding to the memory call request.
As can be seen from the foregoing description of the implementation scenario of the present disclosure, the call of the application program to the memory may include applying for allocating the memory and releasing the memory, and based on this, the memory call request may include two call modes, one is a call request for requesting allocation of the memory, and the other is a call request for requesting release of the memory, that is, in the embodiment of the present disclosure, the call modes corresponding to the memory call request may include an apply mode and a release mode.
The memory to be called may be a memory slice indicated by the memory call request. The state of the memory to be invoked may be used to identify whether the memory to be invoked is occupied. In some implementations, the state of the memory to be invoked may be a used state (used) or a released state (free). If the state of the memory to be called is used, marking that the memory to be called is occupied; if the state of the memory to be called is free, the memory to be called is marked as unoccupied.
For example, in the embodiment of the present disclosure, memory slice management information is provided, where the memory slice management information may include state information of a current memory slice, index information of a next free memory slice of the current memory slice, and the like. A metadata structure of the memory slice management information may be, for example, as follows:
struct sliceMng
{
nextIndex;
memStat;
wherein, nextIndex refers to index information of the next free memory chip; memStat refers to the state of the current memory slice, which may be used or free.
Further, detecting whether the state of the memory to be called matches with the call mode corresponding to the memory call request may be detecting whether the state of the memory to be called meets the requirement of the memory call request. For example, the call mode corresponding to the memory call request is an application mode, that is, the APP aims to apply for allocation of the memory to be called, and then the state of the memory to be called should be free, so as to meet the requirement of the memory call request. For another example, the call mode corresponding to the memory call request is a release mode, that is, the purpose of the APP is to release the occupied memory, and then the state of the memory to be called should be used to meet the requirement of the memory call request.
In step S12, if the state of the memory to be called does not match the call mode corresponding to the memory call request, it is determined that the memory to be called is abnormal.
The state of the memory to be called is not matched with the call mode corresponding to the memory call request, and the method can be implemented as follows: the calling mode corresponding to the memory calling request is an application mode, and the state of the memory to be called is a use state; or the calling mode of the memory calling request is a releasing mode, and the state of the memory to be called is a releasing state.
If the call mode corresponding to the memory call request is the application mode, the memory to be called should be an unoccupied memory slice, that is, the state of the memory to be called should be free, and if the state of the memory to be called is the use state, the electronic device can determine that the application program accesses the wrong memory address, and the problem of memory out-of-range or pointer dislocation occurs. Similarly, if the call mode of the memory call request is a release mode, the memory to be called should be the memory to be released, and the initial state of the memory to be released should be the occupied state, that is, the state of the memory to be released should be used, and if the state of the memory to be released is free, the electronic device may determine that the application program accesses the wrong memory address, and the problem of memory boundary crossing or pointer dislocation occurs. Based on the above, if the state of the memory to be called is not matched with the call mode corresponding to the memory call request, the electronic device can determine that the memory to be called is abnormal.
Therefore, by adopting the implementation manner, whether the memory to be called is occupied or not can be maintained, and in the stage of randomly calling the memory by the application program, whether the memory to be called is abnormal such as out-of-range memory, pointer dislocation or the like in the calling of the memory to be called in the corresponding calling stage is detected according to whether the calling mode corresponding to the memory calling request is matched with the state of the memory to be called or not.
In step S13, if the state of the memory to be called matches the call mode corresponding to the memory call request, and the memory to be called is the memory to be released, a delay condition for delaying the release of the memory to be released is set.
According to the foregoing description, matching the state of the memory to be called with the call mode corresponding to the memory call request may be implemented as: the calling mode corresponding to the memory calling request is an application mode, the state of the memory to be called is free, or the calling mode corresponding to the memory calling request is a release mode, and the state of the memory to be called is used, namely the memory to be called is the memory to be released. If the call mode corresponding to the memory call request is the release mode and the memory to be called is the memory to be released, it can be stated that no exception occurs in other call stages in the memory to be released. In the embodiment of the disclosure, whether the phase of releasing the memory is abnormal or not can be detected by delaying the release.
In some implementations, setting a delay condition for delaying the release of the memory to be released may be implemented as: and adding the memory to be released into a preset queue to be released. For example, the to-be-released queue may accommodate a preset number of to-be-released memory slices, and the preset number may be flexibly set, which is not limited herein. The preset number is 20000, for example.
In other implementations, setting a delay condition for delaying the release of the memory to be released may be implemented as: and setting a countdown for delaying the release of the memory to be released according to the preset delay time. The preset delay period may be flexibly set, and is not limited herein. The delay period may be set to, for example, 0.5 seconds(s).
In step S14, if the delay condition is satisfied, it is detected whether the memory to be released is repeatedly accessed.
As can be seen from the description of the delay condition in the above embodiment, if the memory to be released is added to the preset queue to be released, the delay condition can be achieved as follows: and when the memory to be released exits the queue according to the release sequence of the memory chips in the queue to be released. If the countdown of the delayed release is set for the memory to be released, the satisfaction of the delay condition can be achieved as follows: the countdown of the delayed release of the memory to be released reaches 0.
In order to facilitate detecting whether the memory to be released is repeatedly accessed and repeatedly released under the condition that the delay condition is met, in some implementations, before setting the delay condition of delaying the memory to be released, the electronic device may set the access permission of the memory to be released to be prohibited from accessing if the storage space of the memory to be released is greater than or equal to a preset threshold. If the storage space of the memory to be released is smaller than the preset threshold, the electronic device may set an access identifier in the memory to be released, where the access identifier may be used to indicate whether the memory to be released is accessed.
The preset threshold may be, for example, 4K.
For example, for a memory to be released that is greater than or equal to a preset threshold, the electronic device may call a system function mprotect, for example, to set an attribute of the memory to be released to be inaccessible. For the memory to be released which is smaller than the preset threshold, the electronic device may call a system function memset to set the content of the memory to be released as a magic word 'F', where the magic word 'F' is the access identifier.
Further, for the memory to be released which is greater than or equal to the preset threshold, if the memory to be released is repeatedly accessed, the electronic device can detect the information of the access error, so that the memory to be released can be detected to be repeatedly accessed. Aiming at the memory to be released which is smaller than a preset threshold, the electronic equipment can detect whether the content of the access identifier is changed, and if the content of the access identifier is changed, the memory to be released is determined to be repeatedly accessed; and if the content of the access identifier is not changed, determining that the memory to be released is not accessed repeatedly.
In step S15, if the memory to be released is repeatedly accessed, it is determined that the memory to be released is abnormal.
The memory to be released is repeatedly accessed, so that the memory to be released is released again, and the repeated access and the repeated release both belong to the abnormal category of stepping on the memory, so that the occurrence of the abnormality of the memory to be released can be determined.
Therefore, by adopting the implementation mode, the matching degree of the actual state and the calling mode of the memory to be called in the corresponding stage is correspondingly detected through each stage of calling the memory to be called in the application program, so that whether the memory abnormality occurs in the corresponding calling stage is detected, the scope to be detected corresponding to different implementation scenes is not required to be considered, the applicability is wide, the detection of the memory abnormality is comprehensive, and the performance of detecting the memory abnormality can be improved.
Further, in some implementations, the electronic device may also provide an anomaly locating function.
For example, in the embodiments of the present disclosure, the electronic device may deploy a memory exception positioning mechanism, which may also be referred to as a step-on memory detection mechanism. The memory abnormality locating mechanism can be realized as an optional function, and the electronic device can start a memory abnormality locating mode or close the memory abnormality locating mode through a configuration file.
Based on this, if the memory exception positioning mode is turned on, in response to the memory call request in step S11, the electronic device may further store call information corresponding to the memory call request in a preset storage area of the memory. The memory call information includes at least one of: the APP calls the service identification, the call mode, the call time and the call stack of the memory to be called. After determining that the memory to be called is abnormal, the electronic device can acquire the service identifier, the calling mode and the calling time corresponding to the abnormality, and further, reads the program with the abnormality from the calling stack determined by the service identifier, the calling mode and the calling time.
The service refers to a service of calling a memory executing process by the APP, for example, may include an alarm service, a cache service, an I/O processing service, and the like, and the service identifier may be implemented as a service ID, for example.
It should be noted that, if the memory exception positioning mode is turned on, the memory management system may record memory call information in a preset storage area in the applied memory block, where the call information not only includes the memory slice management information, but also includes information such as a memory slice log and a memory slice call stack.
As shown in fig. 2, a memory block provided in an embodiment of the present disclosure includes memory slices 1 to N, where N is an integer greater than or equal to 2, memory block management information, and each memory slice management information. The memory block management information, for example, maintains a configuration file for turning on or off the memory exception positioning mode. The state of the corresponding memory chip is maintained in each memory chip management information. If the memory abnormal positioning mode is in an on state, the log and the call stack of each memory slice can be stored in the memory block.
For example, each memory slice may allocate additional memory space to store a memory slice log for that memory slice and a call stack for that memory slice.
For any memory slice, the memory slice log comprises a call log in the process of calling the memory slice by the APP, and the call log can comprise information such as function names, call modes, service IDs, call storage space sizes, call time and the like of the operation memory of the service module. The metadata structure of the call log may be, for example, as follows:
wherein, funcName refers to the name of the business function; memOp refers to the call mode of the service to the memory; mid refers to the service ID; size refers to the size of the memory called; timestamp refers to the call time. Therefore, after the abnormal memory condition occurs, the electronic equipment can accurately position the specific service level of the APP, so that the positioning range is reduced.
For any memory slice, the memory slice call stack comprises a function call relation and a related program package used in the process of calling the memory slice by a service in the APP. The metadata structure of the memory slice call stack is, for example, as follows:
wherein stack [ ] refers to a function call stack array; timestamp refers to the call time.
It should be noted that the memory slice log and the memory slice call stack occupy the storage space of the memory slice, so that in order to reduce the occupation of the storage space of the memory slice as much as possible, the memory management system may control each memory slice to reserve the log and call stack of the service of the latest preset times, and the preset times may be 5 times, for example.
In addition, in some implementations, if it is determined that an exception occurs in a certain memory slice during the call process, the memory management system may store the log and the call stack in the memory slice in a coredump file, so as to locate and solve the problem of stepping on the memory.
In other implementations, if the memory exception location is not closed, the memory slice log and the memory slice call stack are not recorded in the memory block, and the partial storage space of each memory slice is not required to be occupied, so that the storage space can be saved.
In summary, the memory to be called according to the embodiments of the present disclosure may set a state, where the state of the memory to be called is used to identify whether the memory to be called is occupied. Thus, after receiving a memory call request from an application program, the embodiment of the disclosure can detect whether abnormal phenomena such as memory boundary crossing, pointer dislocation, repeated release and the like occur in the call of the memory to be called in different call stages according to whether the call mode corresponding to the memory call request is matched with the state of the memory to be called. Further, in the case that the call mode of the application program is a stage of releasing the memory and there is no repeated release of the memory to be released, the embodiment of the disclosure detects whether the memory to be released is repeatedly accessed or not before releasing by performing delayed release on the memory to be released. Therefore, by adopting the implementation manner of the embodiment of the disclosure, the memory abnormality detection item does not need to be preset, and the matching degree of the actual state and the calling mode of the memory to be called in the corresponding stage is correspondingly detected in each stage of the memory to be called in the application program, so that whether the memory abnormality occurs in the corresponding calling stage is detected, the scope to be detected corresponding to different implementation scenes does not need to be considered, the applicability is wide, the detection of the memory abnormality is more comprehensive, and the performance of the memory abnormality detection can be improved.
The embodiment of the present disclosure further provides a memory anomaly detection apparatus, which is configured to perform the operations of the memory anomaly detection method described in any one of the foregoing embodiments, as shown in fig. 3, where the apparatus includes:
the detecting module 301 is configured to detect, in response to a memory call request from an application program, whether a state of a memory to be called matches a call pattern corresponding to the memory call request, where the state of the memory to be called is used to identify whether the memory to be called is occupied;
a determining module 302, configured to determine that an exception occurs in the memory to be called if the state of the memory to be called is not matched with the call mode corresponding to the memory call request;
a setting module 303, configured to set a delay condition for delaying the release of the memory to be released if the state of the memory to be called matches with a call mode corresponding to the memory call request and the memory to be called is the memory to be released;
the detecting module 301 is further configured to detect whether the memory to be released is repeatedly accessed if the delay condition is satisfied;
the determining module 302 is further configured to determine that the memory to be released is abnormal if the memory to be released is repeatedly accessed.
The memory abnormality detection device further comprises a storage module, configured to, if a memory abnormality positioning mode is started, respond to the memory call request, store call information corresponding to the memory call request to a preset storage area of the memory, where the memory call information includes at least one of the following: and the application program calls the service identifier, the calling mode, the calling time and the calling stack of the memory to be called.
In the embodiment of the present disclosure, the state of the memory to be called is a use state or a release state, and if the state of the memory to be called is the release state, the memory to be called is the memory to be released, and the state of the memory to be called is not matched with a call mode corresponding to the memory call request, including:
the calling mode corresponding to the memory calling request is an application mode, and the state of the memory to be called is a use state; or the state of the memory to be released is a release state.
In the embodiment of the present disclosure, the setting module 303 is further configured to add the memory to be released to a preset queue to be released; and setting a countdown for delaying the release of the memory to be released according to a preset delay time.
In an embodiment of the disclosure, the apparatus further includes: the access permission setting module is used for setting the access permission of the memory to be released as access prohibition if the storage space of the memory to be released is larger than or equal to a preset threshold value; the access identifier setting module is configured to set an access identifier in the memory to be released if the storage space of the memory to be released is smaller than the preset threshold, where the access identifier is used to indicate whether the memory to be released is accessed. .
In this embodiment of the present disclosure, the detection module 301 is further configured to detect whether the content of the access identifier is changed if the storage space of the memory to be released is smaller than the preset threshold; and the determining module 302 determines that the memory to be released is repeatedly accessed if the content of the access identifier is changed.
In the embodiment of the disclosure, the memory abnormality detection device further includes an acquisition module, configured to acquire a service identifier, a call mode and a call time corresponding to the abnormality; and reading the program with the abnormality from the call stack determined by the service identifier, the call mode and the call time.
The memory abnormality detection device provided by the above-described embodiment of the present disclosure and the memory abnormality detection method provided by the embodiment of the present disclosure have the same beneficial effects as the method adopted, operated or implemented by the application program stored therein, because of the same inventive concept.
The embodiment of the disclosure also provides an electronic device for executing the memory abnormality detection method. Referring to fig. 4, a schematic diagram of an electronic device according to some embodiments of the present disclosure is shown. As shown in fig. 4, the electronic device 5 includes: a processor 500, a memory 501, a bus 502 and a communication interface 503, the processor 500, the communication interface 503 and the memory 501 being connected by the bus 502; the memory 501 stores a computer program that can be executed on the processor 500, and the processor 500 executes the memory abnormality detection method provided in any of the foregoing embodiments of the present disclosure when executing the computer program.
The memory 501 may include a high-speed random access memory (RAM: random Access Memory), and may further include a non-volatile memory (non-volatile memory), such as at least one magnetic disk memory. The communication connection between the system network element and at least one other network element is implemented via at least one communication interface 503 (which may be wired or wireless), the internet, a wide area network, a local network, a metropolitan area network, etc. may be used.
Bus 502 may be an ISA bus, a PCI bus, an EISA bus, or the like. The buses may be classified as address buses, data buses, control buses, etc. The memory 501 is configured to store a program, and the processor 500 executes the program after receiving an execution instruction, and the memory abnormality detection method disclosed in any of the foregoing embodiments of the disclosure may be applied to the processor 500 or implemented by the processor 500.
The processor 500 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuitry in hardware or instructions in software in the processor 500. The processor 500 may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; but may also be a Digital Signal Processor (DSP), application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The various methods, steps and logic blocks of the disclosure in the embodiments of the disclosure may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in connection with the embodiments of the present disclosure may be embodied directly in hardware, in a decoded processor, or in a combination of hardware and software modules in a decoded processor. The software modules may be located in a random access memory, flash memory, read only memory, programmable read only memory, or electrically erasable programmable memory, registers, etc. as well known in the art. The storage medium is located in the memory 501, and the processor 500 reads the information in the memory 501, and in combination with its hardware, performs the steps of the method described above.
The electronic device provided by the embodiment of the present disclosure and the memory abnormality detection method provided by the embodiment of the present disclosure are the same inventive concept, and have the same beneficial effects as the method adopted, operated or implemented by the electronic device.
Referring to fig. 5, the computer readable storage medium is shown as an optical disc 30, on which a computer program (i.e., a program product) is stored, which when executed by a processor, performs the memory abnormality detection method according to any of the foregoing embodiments.
It should be noted that examples of the computer readable storage medium may also include, but are not limited to, a phase change memory (PRAM), a Static Random Access Memory (SRAM), a Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a flash memory, or other optical or magnetic storage medium, which will not be described in detail herein.
The computer readable storage medium provided by the above embodiments of the present disclosure and the memory abnormality detection method provided by the embodiments of the present disclosure have the same advantageous effects as the method adopted, operated or implemented by the application program stored therein, because of the same inventive concept.
It should be noted that:
in the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the disclosure may be practiced without these specific details. In some instances, well-known structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the disclosure, various features of the disclosure are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be construed as reflecting the following schematic diagram: i.e., the claimed disclosure requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this disclosure.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features but not others included in other embodiments, combinations of features of different embodiments are meant to be within the scope of the disclosure and form different embodiments. For example, in the following claims, any of the claimed embodiments can be used in any combination.
While the invention has been described with respect to the preferred embodiments, it will be apparent to those skilled in the art that various changes and substitutions can be made herein without departing from the scope of the invention. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims (15)

1. The memory abnormality detection method is characterized by comprising the following steps:
responding to a memory calling request from an application program, detecting whether the state of a memory to be called is matched with a calling mode corresponding to the memory calling request, wherein the state of the memory to be called is used for identifying whether the memory to be called is occupied or not;
If the state of the memory to be called is not matched with the call mode corresponding to the memory call request, determining that the memory to be called is abnormal;
if the state of the memory to be called is matched with the call mode corresponding to the memory call request and the memory to be called is the memory to be released, setting a delay condition for delaying the release of the memory to be released;
if the delay condition is met, detecting whether the memory to be released is accessed repeatedly;
and if the memory to be released is repeatedly accessed, determining that the memory to be released is abnormal.
2. The method as recited in claim 1, further comprising:
if a memory exception positioning mode is started, responding to the memory call request, and storing call information corresponding to the memory call request into a preset storage area of the memory, wherein the memory call information comprises at least one of the following: and the application program calls the service identifier, the calling mode, the calling time and the calling stack of the memory to be called.
3. The method of claim 1, wherein the state of the memory to be called is a use state or a release state, and if the state of the memory to be called is the release state, the memory to be called is the memory to be released, and the state of the memory to be called is not matched with the call mode corresponding to the memory call request, including:
The calling mode corresponding to the memory calling request is an application mode, and the state of the memory to be called is a use state; or alternatively, the process may be performed,
the state of the memory to be released is a release state.
4. The method of claim 1, wherein setting a delay condition for delaying the release of the memory to be released comprises:
adding the memory to be released into a preset queue to be released; or alternatively, the process may be performed,
and setting a countdown for delaying the release of the memory to be released according to a preset delay time.
5. The method of claim 1, further comprising, prior to setting the delay condition for delaying the release of the memory to be released:
if the storage space of the memory to be released is larger than or equal to a preset threshold value, setting the access permission of the memory to be released as access prohibition;
if the storage space of the memory to be released is smaller than the preset threshold, setting an access identifier in the memory to be released, wherein the access identifier is used for indicating whether the memory to be released is accessed or not.
6. The method of claim 5, wherein the detecting whether the memory to be released is repeatedly accessed comprises:
If the storage space of the memory to be released is smaller than the preset threshold value, detecting whether the content of the access identifier is changed or not;
and if the content of the access identifier is changed, determining that the memory to be released is accessed repeatedly.
7. The method of claim 2, further comprising, after determining that the memory to be invoked is abnormal:
acquiring a service identifier, a calling mode and a calling time corresponding to the abnormality;
and reading the program with the abnormality from the call stack determined by the service identifier, the call mode and the call time.
8. A memory abnormality detection apparatus, comprising:
the detection module is used for responding to a memory calling request from an application program, detecting whether the state of the memory to be called is matched with a calling mode corresponding to the memory calling request, wherein the state of the memory to be called is used for identifying whether the memory to be called is occupied or not;
the determining module is used for determining that the memory to be called is abnormal if the state of the memory to be called is not matched with the calling mode corresponding to the memory calling request;
the setting module is used for setting a delay condition for delaying the release of the memory to be released if the state of the memory to be called is matched with the calling mode corresponding to the memory calling request and the memory to be called is the memory to be released;
The detection module is further configured to detect whether the memory to be released is repeatedly accessed if the delay condition is satisfied;
and the determining module is further configured to determine that an exception occurs in the memory to be released if the memory to be released is repeatedly accessed.
9. The apparatus of claim 8, wherein the apparatus further comprises:
the memory module is used for responding to the memory call request if the memory exception positioning mode is started, and storing call information corresponding to the memory call request into a preset memory area of the memory, wherein the memory call information comprises at least one of the following items: and the application program calls the service identifier, the calling mode, the calling time and the calling stack of the memory to be called.
10. The apparatus of claim 8, wherein the device comprises a plurality of sensors,
the setting module is further configured to add the memory to be released to a preset queue to be released, and set a countdown for delayed release of the memory to be released according to a preset delay duration.
11. The apparatus of claim 8, wherein the apparatus further comprises: an access right setting module and an access identification setting module, wherein,
The access right setting module is configured to set the access right of the memory to be released as access prohibition if the storage space of the memory to be released is greater than or equal to a preset threshold;
the access identifier setting module is configured to set an access identifier in the memory to be released if the storage space of the memory to be released is smaller than the preset threshold, where the access identifier is used to indicate whether the memory to be released is accessed.
12. The apparatus of claim 11, wherein the device comprises a plurality of sensors,
the detection module is further configured to detect whether the content of the access identifier is changed if the storage space of the memory to be released is smaller than the preset threshold;
and the determining module is further used for determining that the memory to be released is repeatedly accessed if the content of the access identifier is changed.
13. The apparatus of claim 9, wherein the apparatus further comprises:
the acquisition module is used for acquiring the service identifier, the calling mode and the calling time corresponding to the abnormality; and reading the program with the abnormality from the call stack determined by the service identifier, the call mode and the call time.
14. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor runs the computer program to implement the method of any one of claims 1-7.
15. A computer readable storage medium having stored thereon a computer program, wherein the program is executed by a processor to implement the method of any of claims 1-7.
CN202310673245.XA 2023-06-07 2023-06-07 Memory abnormality detection method, device, equipment and storage medium Pending CN116627705A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310673245.XA CN116627705A (en) 2023-06-07 2023-06-07 Memory abnormality detection method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310673245.XA CN116627705A (en) 2023-06-07 2023-06-07 Memory abnormality detection method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116627705A true CN116627705A (en) 2023-08-22

Family

ID=87636621

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310673245.XA Pending CN116627705A (en) 2023-06-07 2023-06-07 Memory abnormality detection method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116627705A (en)

Similar Documents

Publication Publication Date Title
CN108234630B (en) Data reading method and device based on distributed consistency protocol
US11157389B1 (en) Method for detecting memory leak based on linux kernel
US11822419B2 (en) Error information processing method and device, and storage medium
CN109992511B (en) Device and method for obtaining code test coverage rate
US11093361B2 (en) Bus monitoring system, method and apparatus
CN116627705A (en) Memory abnormality detection method, device, equipment and storage medium
CN110647463B (en) Method and device for restoring test breakpoint and electronic equipment
CN111857600A (en) Data reading and writing method and device
CN109558249B (en) Control method and device for concurrent operation
CN108388982B (en) Task running method and device and electronic equipment
CN113918371B (en) Memory processing method and device
CN114416442A (en) Hardware change detection method and device, electronic equipment and readable storage medium
CN110442467B (en) Data sharing method, terminal and computer readable storage medium
CN109800567B (en) Method and device for monitoring foreground application starting and terminal equipment
CN113535470A (en) Configuration backup method and device, electronic equipment and storage medium
CN117271141B (en) Resource updating system, device and network equipment
CN110569126A (en) Data packet processing method and device of target application and electronic equipment
CN111124814A (en) SOC memory access monitoring method and device and computer equipment
US11797373B2 (en) System and method for managing faults in integrated circuits
US11989572B2 (en) Computer system enabled with runtime software module tracking
CN112473128B (en) Method, apparatus, electronic device and storage medium for isolating game logic
CN116340030A (en) Fault processing method and device for service resources
CN114416540A (en) Memory leak detection method and device, electronic equipment and storage medium
CN113835982A (en) Memory leak test method, system, electronic device and medium
CN113157513A (en) Heap memory damage detection method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination