User mode memory monitoring method and device, electronic equipment and storage medium

By providing user-state memory monitoring methods and devices in the terminal system, monitoring user-state memory operation events and generating real-time monitoring results, the problem of difficult user programs in the terminal system to monitor and optimize the use of memory resources is solved, and the terminal performance and fluency is improved.

CN119847719APending Publication Date: 2025-04-18BEIJING XIAOMI MOBILE SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311346696.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-17
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

In terminal systems, how to effectively monitor and optimize the use of memory resources by user programs and improve terminal performance and fluency, especially when new functions are added and data processing tasks are increased complexity.

Method used

It provides a user-state memory monitoring method and device, including a memory management module and a memory tracking module. By monitoring user-state memory operation events (such as memory application and release events), memory monitoring results are generated and sent to user programs in real time, and memory operation events are managed using red and black tree data structures to generate monitoring results.

Benefits of technology

It can track memory usage in real time without relying on the operating system's proprietary interface in the user state, and provide targeted and optimized memory monitoring results, helping user programs to self-detection and self-repair, and improve the overall performance of the terminal.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847719A_ABST
    Figure CN119847719A_ABST
Patent Text Reader

Abstract

The invention relates to a user mode memory monitoring method and device, electronic equipment and a storage medium. Comprising a memory management module and a memory tracking module, wherein the memory tracking module is used for monitoring a memory operation event in a user mode, and sending the memory operation event to the memory management module; the memory operation event at least comprises an application event and a release event of a memory; and the memory management module is used for generating a memory monitoring result based on the received memory operation event and sending the memory monitoring result to a user program in real time. Through the device, memory tracking in a user mode can be realized without depending on a special interface provided by an operating system, and a memory monitoring result is sent to a user program in real time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer communications, and in particular to a user-mode memory monitoring method, device, electronic device, and storage medium. Background Art

[0002] With the rapid development of terminals, efficient memory usage can improve the fluency of terminal systems and the performance of mobile phone processing tasks. Therefore, the rational and efficient use of terminal memory is one of the major indicators reflecting terminal performance.

[0003] However, with the development of terminals, new functions are gradually added and the complexity of data processing tasks is gradually increasing, resulting in higher and higher requirements for terminal performance. Therefore, how to determine the usage of memory resources by user programs, use terminal memory reasonably, and optimize memory to improve the overall performance of the terminal is the key to the problem. Summary of the invention

[0004] In order to overcome the problems existing in the related art, the present disclosure provides a user-mode memory monitoring method, device, electronic device and storage medium.

[0005] According to a first aspect of an embodiment of the present disclosure, a user-mode memory monitoring device is provided, comprising: a memory management module and a memory tracking module; wherein:

[0006] The memory tracking module is used to monitor the memory operation events in the user state and send the memory operation events to the memory management module; the memory operation events at least include memory application events and release events;

[0007] The memory management module is used to generate a memory monitoring result based on the received memory operation event, and send the memory monitoring result to the user program in real time.

[0008] In some embodiments, the memory tracking module includes: a first tracking module and a second tracking module; wherein,

[0009] The first tracking module is used for monitoring the application event of the virtual memory and sending the application event of the virtual memory to the memory management module;

[0010] The second tracking module is used to monitor the release event of the virtual memory and the application event and release event of the physical memory, and send the release event of the virtual memory and the application event and release event of the physical memory to the memory management module.

[0011] In some embodiments, the first tracking module is specifically used to monitor the system call through a hook function to obtain the application event of the virtual memory.

[0012] In some embodiments, the second tracking module is specifically used to call a page fault file descriptor to obtain a release event of the virtual memory and an application event and a release event of the physical memory.

[0013] In some embodiments, the memory management module is specifically used to establish a red-black tree data structure, manage the nodes of the red-black tree based on the memory operation events, and generate memory monitoring results based on the nodes of the red-black tree.

[0014] In some embodiments, the memory management module is specifically used to establish a red-black tree data structure, add corresponding nodes in the red-black tree based on the virtual memory application event; delete corresponding nodes in the red-black tree based on the virtual memory release event; mark the corresponding nodes in the red-black tree based on the physical memory application event; delete the mark of the corresponding node in the red-black tree based on the physical memory release event; and generate memory monitoring results based on the nodes of the red-black tree.

[0015] In some embodiments, the apparatus further comprises:

[0016] A user program is used to perform memory self-detection and self-repair based on the received memory monitoring result.

[0017] According to a second aspect of an embodiment of the present disclosure, a user state memory monitoring method is provided, the method comprising:

[0018] Monitoring memory operation events of user-mode memory; the memory operation events at least include memory application events and memory release events;

[0019] A memory monitoring result is generated based on the memory operation event, and the memory monitoring result is sent to a user program in real time.

[0020] In some embodiments, monitoring the memory operation events of the user state memory includes:

[0021] The system call is monitored through the hook function to obtain the virtual memory application events.

[0022] In some embodiments, monitoring the memory operation events of the user state memory includes:

[0023] Call the page fault file descriptor to obtain the release event of virtual memory and the application event and release event of physical memory.

[0024] In some embodiments, generating a memory monitoring result based on the memory operation event includes:

[0025] A red-black tree data structure is established, nodes of the red-black tree are managed based on the memory operation events, and memory monitoring results are generated based on the nodes of the red-black tree.

[0026] In some embodiments, generating a memory monitoring result based on the memory operation event includes:

[0027] A red-black tree data structure is established, and corresponding nodes are added to the red-black tree based on the application event of the virtual memory; corresponding nodes are deleted from the red-black tree based on the release event of the virtual memory; corresponding nodes are marked in the red-black tree based on the application event of the physical memory; the mark of the corresponding node in the red-black tree is deleted based on the release event of the physical memory; and memory monitoring results are generated based on the nodes of the red-black tree.

[0028] In some embodiments, the method further comprises:

[0029] The user program performs memory self-detection and self-repair based on the received memory monitoring result.

[0030] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, including:

[0031] processor;

[0032] a memory configured to store processor-executable instructions;

[0033] Wherein, the processor is configured to: implement the steps in any one of the user-mode memory monitoring methods in the second aspect when executed.

[0034] According to a fourth aspect of an embodiment of the present disclosure, a non-temporary computer-readable storage medium is provided. When instructions in the storage medium are executed by a processor, the processor is enabled to execute the steps of any one of the user-mode memory monitoring methods in the second aspect above.

[0035] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:

[0036] The present disclosure provides a user-mode memory monitoring device, comprising: a memory management module and a memory tracking module; wherein the memory tracking module is used to monitor user-mode memory operation events and send the memory operation events to the memory management module; the memory operation events at least include memory application events and release events; the memory management module is used to generate memory monitoring results based on the received memory operation events, and send the memory monitoring results to the user program in real time. The device can realize the tracking of the memory in the user mode without relying on the proprietary interface provided by the operating system, and send the memory monitoring results to the user program in real time.

[0037] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0039] Figure 1 is a block diagram of a user-mode memory monitoring device according to an exemplary embodiment;

[0040] Figure 2 is a schematic diagram showing module operation of a user-mode memory monitoring device according to an exemplary embodiment;

[0041] Figure 3 is a schematic diagram of a self-repair process of a user program according to an exemplary embodiment;

[0042] Figure 4 is a flow chart of a user-mode memory monitoring method according to an exemplary embodiment;

[0043] Figure 5 It is a hardware structure block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0044] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0045] To facilitate the understanding of this application, some terms involved in this application are first explained:

[0046] C library (Libc) is a necessary application-side library for all operating systems. The kernel provides memory allocation functions, which can be used to allocate memory.

[0047] Linux: The full name is GNU / Linux, which is a UNIX-like operating system that supports multi-user, multi-tasking, multi-threading and multi-processor (CPU) operating system.

[0048] Virtual Memory (VM): In the kernel of the operating system, such virtual memory is an abstraction of a continuous linear address space, also known as a linear area, which represents a linear interval. It has its own permissions (readable, writable, executable, etc.). Each virtual memory is described by a related virtual memory structure.

[0049] Red Black Tree: A self-balancing binary search tree. In order to improve the search speed, the management of VM is added with a red-black tree on the basis of the traditional two-way linked list. Each VM is a continuous virtual space of a process, in which the units have the same characteristics. All virtual memory areas are linked into a linked list by pointers in order of address. When a page fault occurs, frequent operations are required to search for the VM to the specified area, so a red-black tree is added to the management of VM to reduce the search time.

[0050] Memory space: used to store programs and data when a process is running, also known as executable memory. In a computer, memory space generally refers to the main memory space (physical address space) or the memory space allocated by the system for a user program. Methods for expanding memory space generally include increasing the memory size and virtual memory.

[0051] Physical memory: It is implemented relative to virtual memory. It refers to the memory space obtained through the physical memory bar. It is the physical memory in the kernel and can also be called physical memory page.

[0052] Currently, the physical memory usage in user mode is mainly determined through the unified and proprietary interface provided by the operating system, such as the procfs node / proc / <pid> / smaps, free command, etc. to obtain the memory usage of the process. The memory information obtained through such interfaces is relatively general, and the memory usage can only determine the overall situation of which function occupies the memory. For example, the terminal's memory usage can determine that the size of the camera's memory is A megabytes, and the size of the SMS function's memory is B megabytes, but it cannot determine the size of the memory occupied by each sub-function of the camera, such as the beauty function, face-slimming function, and filter function, and the size of the memory occupied by spam SMS, advertising SMS, and promotional SMS in the SMS function. When optimizing each function, it is not possible to optimize the functions that occupy relatively large memory in a targeted manner.

[0053] Another way to determine the physical memory usage in user mode is to add a proprietary kernel module / code, such as a custom kernel module program, Berkeley packet filtering (BPF) code, etc., to track the memory usage by running in the kernel and then report it to the corresponding user program. This method is difficult to implement and requires developers to have the corresponding kernel development skills and rely on the necessary access rights at the system level, such as read, write, modify, etc.

[0054] To this end, the present disclosure proposes a user-mode memory monitoring device, through which the memory tracking in the user mode can be realized without relying on the proprietary interface provided by the operating system, and the memory monitoring result can be sent to the user program in real time.

[0055] Figure 1 is a block diagram of a user-mode memory monitoring device according to an exemplary embodiment. Figure 1 As shown, the device mainly includes:

[0056] Memory tracking module 10 and memory management module 20; wherein,

[0057] The memory tracking module 10 is used to monitor the memory operation events in the user state and send the memory operation events to the memory management module; the memory operation events at least include memory application events and release events;

[0058] The memory management module 20 is used to generate a memory monitoring result based on the received memory operation event, and send the memory monitoring result to the user program in real time.

[0059] In the disclosed embodiment, the user-mode memory monitoring device can realize the tracking of the memory in the user mode without relying on the proprietary interface provided by the operating system, and send the memory monitoring results to the user program in real time. In this way, the user program can perform self-detection and self-repair based on the real-time memory monitoring results.

[0060] In a specific implementation, when the terminal receives an instruction to start an application, and the application executes an operation to implement the function, it needs to call a corresponding process, and the process needs to occupy memory, so it needs to call a memory application function and a memory release function. When the terminal receives an instruction that at least one process calls a memory application function and a memory release function, it determines the memory size applied for and the memory size released by each process.

[0061] By monitoring the actual memory size occupied by each user program in real time through the embodiments of the present disclosure, the actual memory size occupied by each user program can be clearly known, and when performing optimization operations, the functional processes that occupy abnormal memory can be optimized in a targeted manner.

[0062] In the disclosed embodiment, real-time statistics can be performed on process memory calls, thereby achieving real-time statistics and monitoring of the memory used by each user program.

[0063] In some embodiments, the memory tracking module 10 includes: a first tracking module 11 and a second tracking module 12; wherein,

[0064] The first tracking module 11 is used to monitor the application event of the virtual memory and send the application event of the virtual memory to the memory management module;

[0065] The second tracking module 12 is used to monitor the release event of the virtual memory and the application event and release event of the physical memory, and send the release event of the virtual memory and the application event and release event of the physical memory to the memory management module.

[0066] In some embodiments, the memory operation events include application events and release events of virtual memory, and application events and release events of physical memory.

[0067] In the embodiment of the present disclosure, the virtual memory and physical memory size requested by the user program and the released virtual memory and physical memory size can be determined through the first tracking module 11 and the second tracking module 12. The memory monitoring result generated by the memory management module 20 based on the received memory operation event includes the memory size requested by the user program and the released memory size, so that the user program can know the usage of its physical memory based on the memory monitoring result, and can perform self-detection and self-repair based on the usage of the physical memory.

[0068] In some embodiments, the memory monitoring result includes the memory size requested by the user program and the memory size released, and the memory size can be in the granularity of a storage page. Here, a storage page, that is, the size of a page can be 4KB. In the embodiment of the present disclosure, the memory monitoring result can be sent to the user program in real time in units of storage pages.

[0069] In some embodiments, the first tracking module 11 is specifically used to monitor the system call through a hook function to obtain the application event of the virtual memory.

[0070] In some embodiments, the hook function can also be called Hook technology, which is to dynamically attach additional code to the current process when the process is running, so as to achieve the purpose of replacing the existing processing logic or inserting additional functions. In the embodiment of the present disclosure, whenever the process starts to call the application function of the virtual memory, the set Hook code is dynamically injected into the target process of the process starting to call the application function of the virtual memory, so as to intercept and monitor the memory size occupied by the process before the message of the process starting to call the application function of the virtual memory is transmitted to the end point.

[0071] In some embodiments, the second tracking module 12 is specifically used to call the page fault file descriptor to obtain the release event of the virtual memory and the application event and release event of the physical memory.

[0072] Here, userfaultfd (page fault file descriptor) can be used to call, pass and process page faults. In addition to obtaining the size of the virtual memory applied for and deregistered, by calling userfaultfd, you can also obtain the application and release events of the physical memory based on the physical memory page recycling events corresponding to the virtual memory area and the physical memory page events corresponding to the virtual memory area application. Before calling userfaultfd, you need to create an uffd descriptor. The subsequent memory interval application, configuration and page fault processing involved need to be implemented through this uffd descriptor operation.

[0073] In the disclosed embodiment, the second tracking module 12 can be used to obtain application events and release events of the user program's physical memory, thereby obtaining the physical memory usage of the user program in real time without using a proprietary interface provided by the operating system.

[0074] In some embodiments, the memory management module 20 is specifically used to establish a red-black tree data structure, manage the nodes of the red-black tree based on the memory operation events, and generate memory monitoring results based on the nodes of the red-black tree.

[0075] In the disclosed embodiment, a red-black tree data structure is used to manage user-state memory. When the user-state memory requests its memory usage, a memory monitoring result can be generated based on the nodes of the red-black tree.

[0076] In some embodiments, the memory management module 20 is specifically used to establish a red-black tree data structure, add corresponding nodes in the red-black tree based on the virtual memory application event; delete corresponding nodes in the red-black tree based on the virtual memory release event; mark corresponding nodes in the red-black tree based on the physical memory application event; delete the mark of corresponding nodes in the red-black tree based on the physical memory release event; and generate memory monitoring results based on the nodes of the red-black tree.

[0077] In a specific example, when a virtual memory application is made, the update of the red-black tree is triggered, a node is inserted into the red-black tree, and a corresponding structure is added. The data structure of the red-black tree maintains a virtual memory interval on each node. The virtual memory interval range larger than the parent node is located on the left side of the parent node; the virtual memory interval range smaller than the parent node is located on the right side of the parent node.

[0078] In a specific example, the update of the red-black tree is triggered when the virtual memory is released, and the matching node is searched and found in the red-black tree according to the release address of the virtual memory, and the node of the red-black tree and the structure data corresponding to the node are deleted.

[0079] In a specific example, when applying for physical memory, the update of the red-black tree is triggered, a matching node (virtual memory interval) is searched in the red-black tree, and the node is marked to indicate that the node has applied for physical memory.

[0080] In a specific example, when the physical memory is released, the update of the red-black tree is triggered, a node matching the virtual memory corresponding to the physical memory is searched in the red-black tree, and the mark of the physical memory corresponding to the node is deleted.

[0081] In the disclosed embodiment, the first tracking module 11 and the second tracking module 12 can monitor the memory size applied for and released by each user program in real time. The memory management module 20 can also count the actual memory size occupied by each user program in real time, and output the counted memory size actually occupied by each user program.

[0082] Figure 2 The figure is a schematic diagram showing the module operation of a user-mode memory monitoring device according to an exemplary embodiment.

[0083] The operation process of each module in the user-mode memory monitoring device is as follows:

[0084] When the user program starts, the user-mode memory monitoring device is loaded and initialized. The process specifically includes:

[0085] A. Create a red-black tree to manage memory;

[0086] B. Use Hook technology to intercept the system call interface;

[0087] C. Create uffd descriptor and call the page fault file descriptor.

[0088] The memory management module receives memory operation events and processes them as follows:

[0089] A. When receiving a virtual memory application event, the virtual memory interval and other information are used as a node and inserted into the red-black tree;

[0090] B. When receiving a virtual memory release event, find the node matching the virtual memory interval in the red-black tree and delete it;

[0091] C. When receiving a physical memory application event, find the matching node (virtual memory interval) in the red-black tree and mark the node as having applied for physical memory;

[0092] D. When receiving a physical memory release event, search the red-black tree for a node that matches the virtual memory corresponding to the physical memory, and then delete the mark of the physical memory corresponding to the node.

[0093] The user program calls the interface provided by the user state memory monitoring device to learn the current usage of its physical memory.

[0094] It should be noted that after the user program calls the interface provided by the user state memory monitoring device, the user state memory monitoring device sends the current usage of its physical memory to the corresponding user program.

[0095] In some embodiments, the apparatus further comprises:

[0096] The user program 30 is used for performing self-detection and self-repair based on the received memory monitoring result.

[0097] Figure 3 FIG. 1 is a schematic diagram of a self-repair process of a user program according to an exemplary embodiment. Figure 3 As shown, after the user program learns about its current physical memory usage, the self-repair module inside the user program can determine whether it has memory usage anomalies based on its current physical memory usage and handle the memory usage anomalies. The self-repair module can specifically include the following functions:

[0098] Function 1: When you find that the overall memory usage is too large and has a serious impact on the system, you can choose to exit the program directly. Compared with being directly "killed" by the system, the advantage of this self-exit method is that the user program is actively exited. Before the user program exits, it can retain relevant debugging information and dot information for subsequent offline debugging and diagnosis, laying the foundation for future program optimization;

[0099] Function 2: If it is found that the memory usage of a submodule inside the user program is large, you can choose to dynamically unload the submodule to relieve the tight memory pressure, thereby achieving the purpose of service degradation;

[0100] Function three: If the user program finds abnormal memory usage, such as memory application or release that does not meet design expectations, in this case you can choose to report the corresponding abnormal information to the system's abnormal monitoring module or management module, so as to achieve the purpose of abnormal alarm and notification.

[0101] It should be noted that the self-repair operation of the above-mentioned user program is only an example and is not a specific limitation of the present disclosure. The present disclosure is not only applicable to the self-repair operation of the above-mentioned user program, but can also be applied to other self-repair operations.

[0102] Analyze one or more determined user programs to determine the allocation of memory occupied by each user program, in other words, determine the detailed occupancy information of the user program. For example, if the terminal includes a third-party map application, by analyzing multiple submodules included in the third-party map application, the memory size occupied by each function in the third-party camera application can be determined, such as the memory size occupied by the positioning function, the memory size occupied by the route planning function, etc.

[0103] For example, if the memory size occupied by the positioning function included in the third-party map application exceeds a preset threshold, it is determined that the positioning function has abnormal memory usage. Therefore, the allocation of the occupied memory by the third-party map application can be determined, that is, the allocation position of the occupied memory by the third-party map application and the memory size corresponding to each allocation position.

[0104] In the embodiments of the present disclosure, the user program can analyze its own memory through the memory monitoring results to obtain the allocation information of its memory, so that the user program can use the memory allocation information to optimize the functions included therein and the specific next-level functions in each function in a targeted manner. Of course, the present disclosure is only illustrated by taking a third-party application as an example, and is not a specific limitation of the present disclosure. The present disclosure is not only applicable to third-party applications, but also to the applications corresponding to the terminal itself. It can be understood that the third-party map application of the present disclosure is also explained for ease of understanding, and the present disclosure is applicable to all third-party applications.

[0105] The present disclosure provides a user-mode memory monitoring device, including: a memory management module, a memory tracking module and an interface module; wherein the memory tracking module is used to monitor user-mode memory operation events, and send the memory operation events to the memory management module; the memory operation events at least include memory application events and release events; the memory management module is used to generate memory monitoring results based on the received memory operation events, and send the memory monitoring results to the user program in real time through the interface module. The device can realize the tracking of memory in the user mode without relying on the proprietary interface provided by the operating system, and send the memory monitoring results to the user program in real time.

[0106] Figure 4 FIG. 1 is a flow chart of a method for monitoring user-mode memory according to an exemplary embodiment. Figure 4 As shown, the method mainly includes the following steps:

[0107] In step 41, the memory operation events in the user state are monitored; the memory operation events at least include memory application events and release events;

[0108] In step 42, a memory monitoring result is generated based on the memory operation event, and the memory monitoring result is sent to the user program in real time.

[0109] In some embodiments, monitoring the memory operation events of the user state memory includes:

[0110] The system call is monitored through a hook function to obtain the application event of the virtual memory.

[0111] In some embodiments, monitoring the memory operation events of the user state memory includes:

[0112] Call the page fault file descriptor to obtain the release event of virtual memory and the application event and release event of physical memory.

[0113] In some embodiments, generating a memory monitoring result based on the memory operation event includes:

[0114] A red-black tree data structure is established, nodes of the red-black tree are managed based on the memory operation events, and memory monitoring results are generated based on the nodes of the red-black tree.

[0115] In some embodiments, generating a memory monitoring result based on the memory operation event includes:

[0116] A red-black tree data structure is established, and corresponding nodes are added to the red-black tree based on the application event of the virtual memory; corresponding nodes are deleted from the red-black tree based on the release event of the virtual memory; corresponding nodes are marked in the red-black tree based on the application event of the physical memory; the mark of the corresponding node in the red-black tree is deleted based on the release event of the physical memory; and memory monitoring results are generated based on the nodes of the red-black tree.

[0117] In some embodiments, the method further comprises:

[0118] The user program performs self-detection and self-repair based on the received memory monitoring result.

[0119] Figure 5 5 is a hardware structure block diagram of an electronic device according to an exemplary embodiment. For example, the electronic device 500 may be a mobile phone, a mobile computer, etc.

[0120] Reference Figure 5 , the electronic device 500 may include one or more of the following components: a processing component 502 , a memory 504 , a power component 506 , a multimedia component 508 , an audio component 510 , an input / output (I / O) interface 512 , a sensor component 514 , and a communication component 516 .

[0121] The processing component 502 generally controls the overall operation of the electronic device 500, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 502 may include one or more processors 520 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 502 may include one or more modules to facilitate the interaction between the processing component 502 and other components. For example, the processing component 502 may include a multimedia module to facilitate the interaction between the multimedia component 508 and the processing component 502.

[0122] The memory 504 is configured to store various types of data to support operations on the electronic device 500. Examples of such data include instructions for any application or method operating on the electronic device 500, contact data, phone book data, messages, pictures, videos, etc. The memory 504 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0123] The power supply component 506 provides power to the various components of the electronic device 500. The power supply component 506 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 500.

[0124] The multimedia component 508 includes a screen that provides an output interface between the electronic device 500 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 508 includes a front camera and / or a rear camera. When the electronic device 500 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0125] The audio component 510 is configured to output and / or input audio signals. For example, the audio component 510 includes a microphone (MIC), and when the electronic device 500 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 504 or sent via the communication component 516. In some embodiments, the audio component 510 also includes a speaker for outputting audio signals.

[0126] I / O interface 512 provides an interface between processing component 502 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.

[0127] The sensor assembly 514 includes one or more sensors for providing various aspects of status assessment for the electronic device 500. For example, the sensor assembly 514 can detect the open / closed state of the electronic device 500, the relative positioning of components, such as the display and keypad of the electronic device 500, and the sensor assembly 514 can also detect the position change of the electronic device 500 or a component of the electronic device 500, the presence or absence of user contact with the electronic device 500, the orientation or acceleration / deceleration of the electronic device 500, and the temperature change of the electronic device 500. The sensor assembly 514 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 514 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 514 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0128] The communication component 516 is configured to facilitate wired or wireless communication between the electronic device 500 and other devices. The electronic device 500 can access a wireless network based on a communication standard, such as Wi-Fi, 4G or 5G, or a combination thereof. In an exemplary embodiment, the communication component 516 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 516 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0129] In an exemplary embodiment, the electronic device 500 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.

[0130] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 504 including instructions, and the instructions can be executed by a processor 520 of an electronic device 500 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0131] A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor, enables the processor to perform a user-mode memory monitoring method, the method comprising:

[0132] Monitoring memory operation events in user mode; the memory operation events at least include memory application events and release events;

[0133] A memory monitoring result is generated based on the memory operation event, and the memory monitoring result is sent to a user program in real time.

[0134] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0135] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.< / pid>

Claims

1. A user-mode memory monitoring device, characterized in that: include: Memory management module and memory tracking module; wherein, The memory tracking module is used to monitor the memory operation events in the user state and send the memory operation events to the memory management module; the memory operation events at least include memory application events and release events; The memory management module is used to generate a memory monitoring result based on the received memory operation event, and send the memory monitoring result to the user program in real time.

2. The device according to claim 1, characterized in that The memory tracking module includes: a first tracking module and a second tracking module; wherein, The first tracking module is used for monitoring the application event of the virtual memory and sending the application event of the virtual memory to the memory management module; The second tracking module is used to monitor the release event of the virtual memory and the application event and release event of the physical memory, and send the release event of the virtual memory and the application event and release event of the physical memory to the memory management module.

3. The device according to claim 2, characterized in that The first tracking module is specifically used to monitor the system call through a hook function to obtain the application event of the virtual memory.

4. The device according to claim 2, characterized in that The second tracking module is specifically used to call the page fault file descriptor to obtain the release event of the virtual memory and the application event and release event of the physical memory.

5. The device according to claim 1, characterized in that The memory management module is specifically used to establish a red-black tree data structure, manage the nodes of the red-black tree based on the memory operation events, and generate memory monitoring results based on the nodes of the red-black tree.

6. The device according to claim 2, characterized in that The memory management module is specifically used to establish a red-black tree data structure, and to add corresponding nodes in the red-black tree based on the application event of the virtual memory; Deleting a corresponding node in the red-black tree based on a release event of the virtual memory; Marking corresponding nodes in the red-black tree based on the application event of the physical memory; Deleting the mark of the corresponding node in the red-black tree based on the release event of the physical memory; And generate memory monitoring results based on the nodes of the red-black tree.

7. The device according to any one of claims 1 to 6, characterized in that: The device also includes: A user program is used to perform memory self-detection and self-repair based on the received memory monitoring result.

8. A user-mode memory monitoring method, characterized in that: The method comprises: Monitoring memory operation events in user mode; the memory operation events at least include memory application events and release events; A memory monitoring result is generated based on the memory operation event, and the memory monitoring result is sent to a user program in real time.

9. The method according to claim 8, characterized in that The memory operation event of monitoring the user state memory includes: The system call is monitored through the hook function to obtain the virtual memory application events.

10. The method according to claim 9, characterized in that The memory operation event of monitoring the user state memory includes: Call the page fault file descriptor to obtain the release event of virtual memory and the application event and release event of physical memory.

11. The method according to claim 8, characterized in that The generating a memory monitoring result based on the memory operation event includes: A red-black tree data structure is established, nodes of the red-black tree are managed based on the memory operation events, and memory monitoring results are generated based on the nodes of the red-black tree.

12. The method according to claim 10, characterized in that The generating a memory monitoring result based on the memory operation event includes: A red-black tree data structure is established, and corresponding nodes are added to the red-black tree based on the application event of the virtual memory; corresponding nodes are deleted from the red-black tree based on the release event of the virtual memory; corresponding nodes are marked in the red-black tree based on the application event of the physical memory; the mark of the corresponding node in the red-black tree is deleted based on the release event of the physical memory; and memory monitoring results are generated based on the nodes of the red-black tree.

13. The method according to claim 8, characterized in that The method further comprises: The user program performs self-detection and self-repair based on the received memory monitoring result.

14. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to: implement the steps in any one of the user-mode memory monitoring methods in claims 8 to 13 when executed.

15. A non-transitory computer-readable storage medium, when the instructions in the storage medium are executed by a processor, enables the processor to perform the steps in any one of the user-mode memory monitoring methods in claims 8 to 13.