Memory management function testing methods, systems, electronic devices and storage media

By introducing task priority and memory preemption into the real-time operating system, various memory environments are simulated, solving the problem of uncertain load on memory management algorithms in real-time systems and improving system reliability and detection efficiency.

CN120066831BActive Publication Date: 2026-04-03BEIJING SMARTCHIP MICROELECTRONICS TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-02
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

In existing technologies, memory management algorithms in real-time operating systems suffer from insufficient load construction complexity, leading to uncertain memory allocation times, which affects system responsiveness and reliability. Existing detection methods fail to fully consider diverse memory environments, increasing the failure rate.

Method used

By introducing task priorities, a high-load and fragmented memory environment is simulated, memory preemption is performed, execution time is recorded, and it is determined whether a preset threshold is exceeded to detect abnormalities in memory management functions.

Benefits of technology

It improves the lifespan of the real-time operating system and the reliability of the equipment, meets the real-time requirements of detection, reduces the failure rate, and enhances the diversity of memory management functions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066831B_ABST
    Figure CN120066831B_ABST
Patent Text Reader

Abstract

This invention relates to the field of computer memory management technology, and discloses a method, system, electronic device, and storage medium for detecting memory management functions. The method includes: establishing a high-load and fragmented memory environment for an initial memory pool of a target system to obtain a target memory pool; performing a memory preemption operation of a first target task on the target memory pool within the memory environment; recording the first execution time of the preempted load memory blocks and fragmented memory blocks of the first target task; determining whether the first execution time exceeds a first preset time threshold; and determining that the memory management function of the target system is abnormal if the first execution time exceeds the first preset time threshold. This invention's detection method, by introducing task priority to induce memory preemption, comprehensively detects memory management, avoids high failure rates after the real-time operating system is put into use, improves the lifespan of the real-time operating system, enhances device reliability, and meets the real-time requirements of detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer memory management technology, and in particular to a method for detecting memory management functions, a system for detecting memory management functions, an electronic device, and a computer-readable storage medium. Background Technology

[0002] Currently, memory management algorithms need to search for a free memory block in memory that matches the length of the data to be stored, and then store the data there. The time required to find such a free memory block is uncertain. Real-time operating systems must ensure that the memory block allocation process is completed within a predictable and definite time; otherwise, the response of real-time tasks to external events will also become unpredictable. Therefore, to ensure the functionality, performance, and reliability of a real-time operating system, the memory management function needs to be tested.

[0003] In related technologies, memory testing tools are used for detection. Most testing methods only study one aspect of the memory performance indicators of real-time operating systems, which has the limitation of considering less application load. Among them, most methods only consider test evaluation under no-load conditions, and the few test methods that consider load conditions only set up load environments with unclear magnitude and priority. This increases the failure rate of the real-time operating system after it is put into use, reduces the lifespan of the real-time operating system, and reduces the reliability of the device. Summary of the Invention

[0004] This invention aims to at least partially solve one of the technical problems in related technologies. Therefore, the first objective of this invention is to propose a method for detecting memory management functions. By introducing task priorities and inducing memory preemption, a comprehensive detection of memory management can be performed. The load rate can be adjusted according to actual conditions, creating situations where different memory load rates and memory fragmentation coexist. This simulates multiple memory environments during memory management, increasing the diversity of memory management functions, reducing the failure rate after the real-time operating system is put into use, extending the lifespan of the real-time operating system, improving device reliability, and meeting the real-time requirements of detection.

[0005] The second objective of this invention is to provide a detection system for memory management functions.

[0006] The third objective of this invention is to provide an electronic device.

[0007] The fourth objective of this invention is to provide a computer-readable storage medium.

[0008] To achieve the above objectives, a first aspect of the present invention proposes a method for detecting memory management functionality. This method establishes a high-load and fragmented memory environment for an initial memory pool of a target system to obtain a target memory pool. The target memory pool includes a load memory block and fragmented memory blocks. In this memory environment, a memory preemption operation for a first target task is performed on the target memory pool, and the first execution time for the first target task to preempt the load memory block and fragmented memory block is recorded. The memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of a preset memory task stored in the load memory block. It is determined whether the first execution time exceeds a first preset time threshold. In response to the first execution time exceeding the first preset time threshold, it is determined that the memory management functionality of the target system is abnormal.

[0009] In addition, the memory management function detection method according to the above embodiments of the present invention may also have the following additional technical features:

[0010] According to some embodiments of the present invention, the above method further includes: performing a memory allocation operation for a second target task on a target memory pool in a memory environment, and recording the second execution time of the second target task occupying the fragmented memory block; wherein the memory space required by the second target task is not greater than the memory space of the fragmented memory block; determining whether the second execution time exceeds a second preset time threshold; and determining that the memory management function of the target system is abnormal in response to the second execution time exceeding the second preset time threshold.

[0011] According to some embodiments of the present invention, a high-load and fragmented memory environment is established for the initial memory pool of the target system to obtain the target memory pool, including: establishing a number of preset memory tasks, allocating corresponding free memory blocks from the initial memory pool to the preset memory tasks to obtain a load memory block; in response to the memory space of the remaining free memory blocks in the initial memory pool being less than the memory space required by a single preset memory task, releasing at least one memory block in the initial memory pool that has been occupied by a preset memory task according to a preset load rate to obtain a fragmented memory block; and obtaining the target memory pool based on the load memory block and the fragmented memory block.

[0012] According to some embodiments of the present invention, in a memory environment, performing a memory preemption operation on a target memory pool for a first target task and recording the first execution time of the first target task preempting the load memory block and fragmented memory block includes: establishing at least one first target task; wherein the priority of the first target task is higher than that of a preset memory task; recording a first timestamp in response to starting the memory preemption operation on the target memory pool for the first target task; determining that the memory preemption operation has been completed in response to the memory space required by the first target task being fully allocated to the load memory block and fragmented memory block, and recording a second timestamp; calculating the difference between the second timestamp and the first timestamp to obtain the first execution time.

[0013] According to some embodiments of the present invention, before responding to the memory preemption operation of starting to execute the first target task on the target memory pool, the method further includes: determining whether the memory space required by the first target task is greater than the memory space of the fragmented memory block; and determining to start the memory preemption operation of starting to execute the first target task on the target memory pool in response to the memory space required by the first target task being greater than the memory space of the fragmented memory block.

[0014] According to some embodiments of the present invention, before responding to the memory preemption operation of starting to execute the first target task on the target memory pool, the method further includes: in response to the memory space required by the first target task not being greater than the memory space of the fragmented memory blocks, determining whether all fragmented memory blocks are fully occupied; in response to the fact that all fragmented memory blocks are fully occupied, determining whether there is an unallocated first target task; and in response to the existence of an unallocated first target task, determining to start the memory preemption operation of starting to execute the first target task on the target memory pool.

[0015] According to some embodiments of the present invention, in a memory environment, performing a memory allocation operation for a second target task on a target memory pool and recording a second execution time of the second target task occupying fragmented memory blocks includes: establishing at least one second target task; wherein the priority of the second target task is equal to that of a preset memory task; recording a third timestamp in response to starting the memory allocation operation for the second target task on the target memory pool; determining that the memory allocation operation has been completed in response to the memory space required by the second target task being fully allocated to fragmented memory blocks, and recording a fourth timestamp; calculating the difference between the fourth timestamp and the third timestamp to obtain the second execution time.

[0016] According to some embodiments of the present invention, the above method further includes: in response to an anomaly in the memory management function of the target system, determining the cause of the anomaly in the memory management function; and optimizing the memory management function based on the cause of the anomaly.

[0017] According to some embodiments of the present invention, the method further includes: during the memory preemption operation of the first target task performed on the target memory pool, monitoring the number of fragmented memory blocks in the target memory pool in real time; in response to the number exceeding a preset fragmentation threshold, stopping the memory preemption operation of the first target task performed on the target memory pool, and optimizing the memory management function of the target system.

[0018] According to the memory management function detection method of the present invention, a high-load and fragmented memory environment is established for the initial memory pool of the target system to obtain a target memory pool; wherein, the target memory pool includes a load memory block and a fragmented memory block; in the memory environment, a memory preemption operation of a first target task is performed on the target memory pool, and the first execution time of the first target task preempting the load memory block and the fragmented memory block is recorded; wherein, the memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory task stored in the load memory block; it is determined whether the first execution time exceeds a first preset time threshold; in response to the first execution time exceeding the first preset time threshold, it is determined that the memory management function of the target system is abnormal. Therefore, this method can comprehensively detect the memory management situation by introducing task priority to trigger memory preemption, and can adjust the load rate according to the actual situation to create situations where different memory load rates and memory fragmentation coexist, so as to simulate multiple memory environments during memory management, increase the diversity of memory management functions, reduce the failure rate after the real-time operating system is put into use, improve the lifespan of the real-time operating system, improve the reliability of the device, and meet the real-time requirements of detection.

[0019] The second objective of this invention is to propose a memory management function detection system. By introducing task priorities, memory preemption is triggered, and a comprehensive detection of memory management is performed. The load rate can be adjusted according to the actual situation to create situations where different memory load rates and memory fragmentation coexist, thereby simulating multiple memory environments during memory management. This increases the diversity of memory management functions, reduces the failure rate after the real-time operating system is put into use, improves the lifespan of the real-time operating system, enhances the reliability of the device, and meets the real-time requirements of detection.

[0020] To achieve the above objectives, a second aspect of the present invention provides a memory management function detection system, comprising an environment simulation module configured to establish a high-load and fragmented memory environment for an initial memory pool of a target system to obtain a target memory pool; wherein the target memory pool includes a load memory block and a fragmented memory block; a preemption module configured to perform a memory preemption operation of a first target task on the target memory pool in the memory environment, and record the first execution time of the first target task preempting the load memory block and the fragmented memory block; wherein the memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory task stored in the load memory block; a judgment module configured to judge whether the first execution time exceeds a first preset time threshold; and a detection module configured to determine that the memory management function of the target system is abnormal in response to the first execution time exceeding the first preset time threshold.

[0021] According to an embodiment of the present invention, a memory management function detection system includes an environment simulation module that establishes a high-load and fragmented memory environment for the initial memory pool of the target system to obtain a target memory pool. The target memory pool includes a load memory block and fragmented memory blocks. A preemption module performs a memory preemption operation on the target memory pool for a first target task within the memory environment, recording the first execution time of the first target task preempting the load memory block and fragmented memory block. The memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory tasks stored in the load memory block. A judgment module determines whether the first execution time exceeds a first preset time threshold. A detection module, responding to the first execution time exceeding the first preset time threshold, determines that the memory management function of the target system is abnormal. Therefore, this system, by introducing task priority and triggering memory preemption, comprehensively detects the memory management situation. It can adjust the load rate according to the actual situation, creating situations where different memory load rates and memory fragmentation coexist, simulating multiple memory environments during memory management. This increases the diversity of memory management functions, reduces the failure rate after the real-time operating system is put into use, improves the lifespan of the real-time operating system, enhances the reliability of the device, and meets the real-time requirements of detection.

[0022] To achieve the above objectives, a third aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described memory management function detection method.

[0023] According to the present invention, the electronic device, by executing the above-described memory management function detection method, introduces task priority to trigger memory preemption and comprehensively detects the memory management situation. It can adjust the load rate according to the actual situation, create situations where different memory load rates and memory fragmentation coexist, simulate multiple memory environments during memory management, increase the diversity of memory management functions, reduce the failure rate after the real-time operating system is put into use, improve the lifespan of the real-time operating system, improve the reliability of the device, and meet the real-time requirements of detection.

[0024] To achieve the above objectives, a fourth aspect of the present invention provides a computer-readable storage medium that stores computer instructions for causing a computer to perform the above-described memory management function detection method.

[0025] According to the computer-readable storage medium of the present invention, by executing the above-described memory management function detection method, by introducing task priorities and triggering memory preemption, a comprehensive detection of memory management can be performed. The load rate can be adjusted according to the actual situation, creating a situation where different memory load rates and memory fragmentation coexist, so as to simulate multiple memory environments during memory management, increase the diversity of memory management functions, reduce the failure rate after the real-time operating system is put into use, improve the lifespan of the real-time operating system, improve the reliability of the device, and meet the real-time requirements of detection.

[0026] Additional aspects and advantages of the invention 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 invention. Attached Figure Description

[0027] Figure 1 This is a flowchart of a method for detecting memory management functions according to some embodiments of the present invention;

[0028] Figure 2 A block diagram of an initial memory pool according to some embodiments of the present invention;

[0029] Figure 3 A block diagram of a target memory pool according to some embodiments of the present invention;

[0030] Figure 4 This is a schematic diagram of a method for detecting memory management functions according to other embodiments of the present invention;

[0031] Figure 5 This is a schematic diagram of a method for detecting memory management functions according to some embodiments of the present invention;

[0032] Figure 6 This is a schematic diagram of a method for detecting memory management functions according to some embodiments of the present invention;

[0033] Figure 7 This is a block diagram of a memory management function detection system according to some embodiments of the present invention;

[0034] Figure 8 This is a block diagram of an electronic device according to some embodiments of the present invention. Detailed Implementation

[0035] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to specific embodiments and accompanying drawings.

[0036] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this invention should have the ordinary meaning understood by those skilled in the art. The terms "first," "second," and similar terms used in the embodiments of this invention do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word covers the element or object listed after the word and its equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are only used to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0037] As mentioned in the background section, embedded devices typically have limited memory resources. Effective memory management can maximize the use of memory space, reduce memory fragmentation, and improve memory utilization. In order to ensure the functionality, performance, and reliability of the real-time operating system, it is necessary to test the memory management function.

[0038] In related technologies, memory testing tools are typically used for detection, such as Memtester, Stressapptest, and Rhealstone, which each have different focuses.

[0039] Memtester is a lightweight testing tool with low system resource requirements. It can test memory stability and detect memory errors. Memtester's main tests include random value calculations, XOR comparisons, subtraction, multiplication, division, and AND / OR operations. By specifying the size and number of tests, it can perform these tests on the system's existing memory. By specifying the physical address, memtester can also be used to test memory-mapped I / O devices and similar devices.

[0040] Stressapptest can simulate concurrent memory access, create memory stress, and test memory stability. It simulates real-world workloads by injecting large loads into the system, thereby testing the system's stability and resilience. By continuously increasing the load, the system's performance limits can be discovered, and its performance under different workloads can be evaluated. By stress testing various components of the system, potential problems can be identified and resolved promptly, ensuring the system's stability and reliability.

[0041] Rhealstone provides a comprehensive understanding of a real-time operating system's performance and potential bottlenecks through multi-dimensional testing. Rhealstone tests memory read and write speeds and performance by accessing system memory. These memory access operations load the system's memory system, helping to evaluate the system's performance when handling memory-intensive tasks.

[0042] In developing this invention, the applicant discovered that most current testing methods only focus on one aspect of memory performance testing for real-time operating systems, and generally suffer from limitations in considering application load. Most methods only consider testing under no-load conditions, and the few that do consider load conditions only set up load environments with unclear magnitude and priority. However, in practical applications, the runtime environment of real-time operating systems is complex and diverse, memory resources are extremely limited, and time requirements are particularly stringent.

[0043] The following description, with reference to the accompanying drawings, outlines the method, system, electronic device, and storage medium for detecting memory management functions according to embodiments of the present invention.

[0044] refer to Figure 1 This is a flowchart of a method for detecting memory management functions according to some embodiments of the present invention.

[0045] like Figure 1 As shown, the method for detecting memory management functions in this embodiment of the invention may include the following steps:

[0046] S101, establish a high-load and fragmented memory environment for the initial memory pool of the target system to obtain the target memory pool; wherein, the target memory pool includes load memory blocks and fragmented memory blocks.

[0047] Specifically, refer to Figure 2The diagram below is a block diagram of an initial memory pool according to some embodiments of the present invention. The initial memory pool of the target system includes multiple free memory blocks. Multiple pre-set memory tasks are then set, wherein the multiple pre-set memory tasks have the same priority. The multiple free memory blocks in the initial memory pool are allocated to the multiple corresponding pre-set memory tasks in sequence. The allocated memory blocks become load memory blocks.

[0048] When the remaining free memory blocks in the initial memory pool are insufficient to store the memory space required for a pre-defined memory task, it can be understood that the free memory blocks in the initial memory pool have been fully allocated. At this point, the loaded memory blocks are released. After the loaded memory blocks are released, they become fragmented memory blocks. The memory pool at this time includes both loaded and fragmented memory blocks. This current memory pool is used as the target memory pool. (Refer to...) Figure 3 The diagram shows a block diagram of a target memory pool according to some embodiments of the present invention. Therefore, a high-load and fragmented memory environment exists within the target memory pool.

[0049] In some embodiments of the present invention, establishing a high-load and fragmented memory environment for the initial memory pool of the target system to obtain the target memory pool includes: establishing a plurality of preset memory tasks; allocating corresponding free memory blocks from the initial memory pool to the plurality of preset memory tasks to obtain loaded memory blocks; responding to the fact that the memory space of the remaining free memory blocks in the initial memory pool is less than the memory space required by a single preset memory task, releasing at least one memory block in the initial memory pool that has been occupied by a preset memory task according to a preset load rate to obtain fragmented memory blocks; and obtaining the target memory pool based on the loaded memory blocks and fragmented memory blocks. The preset memory tasks can be set according to actual conditions.

[0050] Specifically, several preset memory tasks are created based on the initial memory pool size and memory task requirements. These preset memory tasks have the same priority, and each requires the same amount of memory space. The initial memory pool includes multiple free memory blocks. A memory allocation function is called to sequentially allocate corresponding free memory blocks from the initial memory pool to the preset memory tasks. The allocated memory blocks become load blocks. If the remaining free memory space in the initial memory pool is less than the memory space required by a single preset memory task, it indicates that the remaining free memory space in the initial memory pool is insufficient to store the memory space required by a single preset memory task (allocation failure). In this case, a release function is called based on a preset load rate to release the load blocks. The preset load rate is set according to the task memory requirements, and the number of blocks to be released is also set based on the preset load rate. After the load blocks are released, they become fragmented memory blocks. At this point, the memory pool includes both load blocks and fragmented memory blocks. This current memory pool is used as the target memory pool. Therefore, the target memory pool contains a high-load and fragmented memory environment.

[0051] As a specific implementation, when the preset load rate is 50% (i.e., the memory pool should contain 1 / 2 loaded memory blocks and 1 / 2 fragmented memory blocks), to prevent two adjacent fragmented memory blocks from merging into one fragmented memory block, odd-numbered or even-numbered loaded memory blocks are released to ensure that no two fragmented memory blocks are adjacent. When the preset load rate is 80% (i.e., the memory pool should contain 4 / 5 loaded memory blocks and 1 / 5 fragmented memory blocks), load memory blocks that are multiples of 5 are released (i.e., every 4 loaded memory blocks are connected to one fragmented memory block).

[0052] As a specific example, such as Figure 4 As shown, the flowchart of the memory management function detection method of the present invention may include the following steps:

[0053] S401 creates several preset memory tasks.

[0054] S402 allocates corresponding free memory blocks from the initial memory pool to several preset memory tasks to obtain the load memory blocks.

[0055] S403, when the remaining free memory block in the initial memory pool is less than the memory space required by a single preset memory task, release at least one memory block in the initial memory pool that has been occupied by a preset memory task according to the preset load rate, and obtain fragmented memory blocks.

[0056] S404 obtains the target memory pool based on the loaded memory blocks and fragmented memory blocks.

[0057] S102, In the memory environment, perform a memory preemption operation for the first target task on the target memory pool, and record the first execution time of the first target task preempting the load memory block and the fragmented memory block; wherein, the memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory task stored in the load memory block.

[0058] Specifically, in a high-load and fragmented memory environment, a first target task is established, with a higher priority than the preset memory tasks. For example, the preset memory tasks can be low- or medium-priority tasks, while the first target task can be a high-priority task. If the memory space required by the first target task exceeds the memory space of the fragmented memory blocks, it indicates that the memory space of the fragmented memory blocks cannot store the memory space required by the first target task. At this point, a memory preemption operation for the first target task is performed on the target memory pool. When the memory preemption operation for the first target task begins on the target memory pool, the current time point is recorded. Then, the memory preemption operation for the first target task is performed on the target memory pool. When the memory preemption operation for the first target task is completed on the target memory pool, the current time point is recorded. Based on the difference between the time point before preemption and the time point when the preemption operation is completed, the execution time of the first target task occupying the load memory block and the fragmented memory block can be obtained, and this is recorded as the first execution time. This operation is repeated until memory preemption on the target system fails. When memory preemption fails, the memory usage of the target system is checked, and the memory management of the target system is evaluated based on the memory usage.

[0059] S103, determine whether the first execution time exceeds the first preset time threshold, wherein the first preset time threshold can be calibrated according to the actual situation.

[0060] The determination of whether the first execution time exceeds the first preset time threshold is to determine the working status of the target system's memory management function.

[0061] S104, in response to the first execution time exceeding the first preset time threshold, it is determined that there is an anomaly in the memory management function of the target system.

[0062] Specifically, the system determines whether the first execution time exceeds a preset time threshold. If the first execution time exceeds the threshold, it indicates a long execution time and poor detection efficiency, suggesting an anomaly in the target system's memory management function. If the first execution time does not exceed the threshold, it indicates the execution time is within the specified time, and the detection efficiency is good, suggesting the target system's memory management function is normal. This allows for comprehensive memory management testing by introducing task priorities and inducing memory contention. The system can adjust the load rate according to actual conditions, creating situations where different memory load rates and memory fragmentation coexist, thus avoiding high failure rates after the real-time operating system is deployed, extending its lifespan, improving device reliability, and meeting real-time testing requirements.

[0063] In some embodiments of the present invention, the method further includes: performing a memory allocation operation for a second target task on a target memory pool in a memory environment, and recording the second execution time of the second target task occupying fragmented memory blocks; wherein the memory space required by the second target task is not greater than the memory space of the fragmented memory blocks; determining whether the second execution time exceeds a second preset time threshold; and determining that the memory management function of the target system is abnormal in response to the second execution time exceeding the second preset time threshold. The second preset time threshold can be calibrated according to actual conditions.

[0064] Furthermore, in some embodiments of the present invention, in a memory environment, performing a memory allocation operation for a second target task on a target memory pool and recording a second execution time of the second target task occupying fragmented memory blocks includes: establishing at least one second target task; wherein the priority of the second target task is equal to that of a preset memory task; recording a third timestamp in response to starting the memory allocation operation for the second target task on the target memory pool; determining that the memory allocation operation has been completed in response to the memory space required by the second target task being fully allocated to fragmented memory blocks, and recording a fourth timestamp; calculating the difference between the fourth timestamp and the third timestamp to obtain the second execution time.

[0065] Specifically, in a high-load and fragmented memory environment, the computer first runs the load memory blocks in the target memory pool and establishes at least one second target task. The priority of the second target task is equal to that of the preset memory task. For example, the second target task can be a low-priority task, and the preset memory task can also be a low-priority task. The memory space required by the second target task is less than or equal to the memory space of the fragmented memory block (i.e., the memory space of the fragmented memory block can be allocated to the second target task for storage). When the memory allocation operation of the second target task is started on the target memory pool, the current time node is recorded as the third timestamp. Then, the memory allocation operation of the second target task is performed on the target memory pool. When the memory space required by the first target task is completely allocated to the fragmented memory block, it indicates that the memory space required by the first target task has been allocated. At this time, it is determined that the memory allocation operation has been completed, and the current time node is recorded as the fourth timestamp. Based on the difference between the time node before allocation and the time node after the allocation operation is completed, the execution time of the second target task occupying the fragmented memory block can be obtained and recorded as the second execution time. The above operation is repeated until all available memory space of the target system is allocated. Next, it is determined whether the second execution time exceeds the second preset time threshold. If the second execution time exceeds the second preset time threshold, it indicates that the second execution time is too long and the detection efficiency is poor. In this case, it is determined that the memory management function of the target system is abnormal. If the second execution time does not exceed the second preset time threshold, it indicates that the second execution time is within the specified time and the detection efficiency is good. In this case, it is determined that the memory management function of the target system is normal.

[0066] If allocation fails, the possible reason is insufficient available memory space in the target system. In this case, check the memory usage of the target system and evaluate the memory management based on the memory usage.

[0067] As a specific embodiment, when multiple second target tasks are established, the priority of the second target tasks is equal to that of the preset memory task. For example, the second target task can be a low-priority task, and the preset memory task can be a low-priority task. Since the priority of the second target task and the priority of the preset memory task are the same, the second target task cannot perform preemption operations. When the memory space of the remaining free memory blocks in the initial memory pool is less than the memory space required by the multiple second target tasks, it means that the memory space of the remaining free memory blocks in the initial memory pool is insufficient and cannot store the memory space required by the multiple second target tasks. At this time, the allocation fails.

[0068] As a specific example, such as Figure 5 As shown, the flowchart of the memory management function detection method of the present invention may include the following steps:

[0069] S501, establish a second target task, the second target task includes at least one second memory task.

[0070] S502, when starting the memory allocation operation for the second target task in the target memory pool, records a third timestamp.

[0071] S503, when the memory space required by the first target task is fully allocated to the fragmented memory block, determines that the memory allocation operation has been completed and records the fourth timestamp.

[0072] S504, calculate the difference between the fourth timestamp and the third timestamp to obtain the second execution time.

[0073] S505, determine whether the second execution time exceeds the second preset time threshold. If yes, proceed to step S506; if no, proceed to step S507.

[0074] S506, It has been determined that there is an anomaly in the memory management function of the target system.

[0075] S507 indicates that the target system's memory management function is normal.

[0076] In some embodiments of the present invention, in a memory environment, performing a memory preemption operation on a target memory pool for a first target task and recording the first execution time of the first target task preempting the load memory block and fragmented memory block includes: establishing at least one first target task; wherein the priority of the first target task is higher than that of a preset memory task; recording a first timestamp in response to starting the memory preemption operation on the target memory pool for the first target task; determining that the memory preemption operation has been completed in response to the memory space required by the first target task being fully allocated to the load memory block and fragmented memory block, and recording a second timestamp; calculating the difference between the second timestamp and the first timestamp to obtain the first execution time.

[0077] Specifically, in a high-load and fragmented memory environment, the computer first runs the load memory blocks in the target memory pool and establishes a first target task. The first target task has a higher priority than the preset memory tasks. The first target task can be a high-priority task, while the preset memory tasks can be low-priority or medium-priority tasks. Due to the higher priority of the first memory task, it will preempt lower-priority memory tasks to ensure that the high-priority memory tasks are executed first. When the memory preemption operation for the first target task begins, the current time point is recorded as the first timestamp. The memory preemption operation continues until the memory space required by the first target task is fully allocated to the load memory blocks and fragmented memory blocks. At this point, the memory preemption operation is considered complete, and the current time point is recorded as the second timestamp. The difference between the time point before preemption and the time point after the preemption operation is completed yields the execution time of the first target task occupying the fragmented memory blocks, which is recorded as the first execution time.

[0078] In some embodiments of the present invention, before responding to the memory preemption operation of starting to execute the first target task on the target memory pool, the method further includes: determining whether the memory space required by the first target task is greater than the memory space of the fragmented memory block; and determining to start the memory preemption operation of starting to execute the first target task on the target memory pool in response to the memory space required by the first target task being greater than the memory space of the fragmented memory block.

[0079] Specifically, before starting the memory preemption operation for the first target task in the target memory pool, it is determined whether the memory space required by the first target task is greater than the memory space of the fragmented memory block. If the memory space required by the first target task is greater than the memory space of the fragmented memory block, it means that the memory space of the fragmented memory block can no longer store the memory space required by the first target task. At this time, some memory needs to be released to meet the memory space required by the first target task. Therefore, the memory preemption operation for the first target task is started in the target memory pool so that the target memory pool can store the memory space required by the first target task.

[0080] In some embodiments of the present invention, before responding to the memory preemption operation of starting to execute the first target task on the target memory pool, the method further includes: in response to the memory space required by the first target task not being greater than the memory space of the fragmented memory blocks, determining whether all fragmented memory blocks are fully occupied; in response to the fact that all fragmented memory blocks are fully occupied, determining whether there is an unallocated first target task; and in response to the existence of an unallocated first target task, determining to start the memory preemption operation of starting to execute the first target task on the target memory pool.

[0081] Specifically, if the memory space required by the first target task is less than or equal to the memory space of the fragmented memory blocks, it means that the memory space of the fragmented memory blocks can store the memory space required by the first target task. Next, it is determined whether all fragmented memory blocks are fully occupied. If all fragmented memory blocks are fully occupied, it means that although the memory space of the fragmented memory blocks can store the memory space required by the first target task, there is no extra fragmented memory block space available for storage. Then, it is determined whether there are any unallocated first target tasks. If there are unallocated first target tasks, it means that the first target task has not been allocated even though all fragmented memory blocks are fully occupied. At this point, a memory preemption operation for the first target task is performed on the target memory pool to ensure that the target memory pool can store the memory space required by the first target task.

[0082] When determining whether all fragmented memory blocks are fully occupied, if none of the fragmented memory blocks are fully occupied, it means that there is at least one fragmented memory block available to store the memory space required by the first target task.

[0083] As a specific embodiment, when the memory space required by the first target task is greater than the memory space of the fragmented memory block, and the memory space required by the first target task is the size of two memory blocks in the target memory pool, a memory preemption operation for the first target task needs to be performed on one loaded memory block and one fragmented memory block in the target memory pool to ensure that the memory space required by the first target task is no greater than the memory space of the fragmented memory block. When the memory space required by the first target task is 1.5 times the size of the memory block in the target memory pool, a memory preemption operation for the first target task needs to be performed on one fragmented memory block and half a loaded memory block in the target memory pool to ensure that the memory space required by the first target task is no greater than the memory space of the fragmented memory block.

[0084] In a specific embodiment, when establishing multiple first target tasks, the priority of the first target tasks is higher than that of the preset memory tasks. For example, the first target tasks can be high-priority tasks, and the preset memory tasks can be low-priority tasks. Since the priorities of the first target tasks and the preset memory tasks are different, the first target tasks can perform preemption operations. When the remaining free memory blocks in the initial memory pool are less than the memory space required by the multiple first target tasks, it indicates that the remaining free memory blocks in the initial memory pool are insufficient to store the memory space required by the multiple first target tasks. At this time, the first target tasks perform preemption operations, preempting the loaded memory blocks in the target memory pool until the remaining free memory blocks in the initial memory pool are greater than or equal to the memory space required by the multiple first target tasks, at which point the preemption operation stops.

[0085] In some embodiments of the present invention, the method further includes: in response to an anomaly in the memory management function of the target system, determining the cause of the anomaly in the memory management function; and optimizing the memory management function based on the cause of the anomaly.

[0086] Specifically, when the target system's memory management function malfunctions, it indicates poor detection efficiency. It's necessary to determine the cause of the memory management anomaly and optimize the function accordingly to restore its normal operation. For example, if memory allocation fails but is still used, the pointer should be checked for NULL before using the memory. If pointer p is a function parameter, `assert(p != NULL)` should be used at the function's entry point to check. If memory is allocated using `malloc` or `new`, error prevention should be implemented using `if(p == NULL)` or `if(p != NULL)`. Furthermore, if memory allocation succeeds but is referenced before initialization, initialization should be applied when creating the array.

[0087] In some embodiments of the present invention, the method further includes: during the memory preemption operation of the first target task on the target memory pool, monitoring the number of fragmented memory blocks in the target memory pool in real time; in response to the number exceeding a preset fragmentation threshold, stopping the memory preemption operation of the first target task on the target memory pool, and optimizing the memory management function of the target system. The preset fragmentation threshold can be calibrated according to actual conditions.

[0088] Specifically, during the memory preemption operation of the first target task on the target memory pool, a counter set within the target memory pool can be used to count the number of fragmented memory blocks in the target memory pool, allowing for real-time monitoring to determine whether to continue the preemption operation. When the number of fragmented memory blocks exceeds a preset fragmentation threshold, it indicates an anomaly in the target system's memory management function. At this point, the memory preemption operation of the first target task on the target memory pool is stopped, and the target system's memory management function is optimized to restore it to a normal state.

[0089] In some embodiments, the embedded real-time operating system needs to ensure that high-priority tasks can be allocated the necessary memory within a specified time and thus be executed smoothly under limited resource conditions (limited memory) and after long-term operation (with significant memory fragmentation). This operating state is simulated to dynamically test the memory management system and ensure that the embedded real-time operating system's memory management module meets the functional and performance requirements.

[0090] Compared to the Stressapptest method, this invention fully considers the characteristics and usage scenarios of embedded real-time operating systems. By creating different memory load rates, it simulates memory fragmentation after long-term system operation and achieves dynamic testing of memory management functions by recording the memory allocation time of real-time tasks. Compared to the Stressapptest method, this invention not only considers a large load to simulate real-world workloads but also simulates memory fragmentation, making it more effective at identifying problems in practical applications than simple load testing. Compared to the Stressapptest method, this invention does not merely increase the number of concurrent tasks to increase the load but also introduces task priorities to trigger memory preemption, comprehensively testing memory management. By adjusting the load rate and task priorities, it checks whether the time for task allocation / memory detection remains within a stable range. If the time is less than the required threshold, it proves that the reliability of the system's memory management function meets the requirements, demonstrating the effectiveness of this testing method.

[0091] As a specific example, such as Figure 6 As shown, the flowchart of the memory management function detection method of the present invention may include the following steps:

[0092] S601, establish a first target task, the first target task includes at least one first memory task.

[0093] S602, determine whether the memory space required by any first target task is greater than the memory space of any fragmented memory block. If yes, proceed to step S603; if no, proceed to step S610.

[0094] S603, determine to start the memory preemption operation for the first target task to be executed on the target memory pool.

[0095] S604 records the first timestamp when it begins to perform memory preemption operation for the first target task on the target memory pool.

[0096] S605, when the memory space required by the first target task is fully allocated to the load memory block and fragmented memory block, determines that the memory preemption operation has been completed and records the second timestamp.

[0097] S606, calculate the difference between the second timestamp and the first timestamp to obtain the first execution time.

[0098] S607, determine whether the first execution time exceeds the first preset time threshold. If yes, proceed to step S608; if no, proceed to step S609.

[0099] S608 indicates that the target system's memory management function is malfunctioning.

[0100] S609 indicates that the target system's memory management function is normal.

[0101] S610, determine whether all fragmented memory blocks are fully occupied. If so, proceed to step S611.

[0102] S611, determine if there is a first target task that has not been assigned. If yes, proceed to step S612.

[0103] S612, determine to start the memory preemption operation for the first target task to be executed on the target memory pool.

[0104] Therefore, this invention creates multiple tasks with the same priority, allocates memory, and then releases memory at intervals based on load rate, creating a situation where different memory load rates and memory fragmentation coexist, thus simulating actual operating conditions. Under these conditions, ordinary memory allocation tests and memory preemption tests were performed, and the memory allocation time of each task was recorded. The memory allocation time should be within a certain threshold range; otherwise, the memory management algorithm should be optimized. At the end of the loop, the memory status needs to be checked; during the task preemption process, the memory fragmentation status is checked, and if there is too much fragmentation, the memory management algorithm should be optimized.

[0105] By adjusting the preset load rate, the initial memory allocation, the number of tasks, and the memory allocation per task, a comprehensive test of the embedded system's memory can be performed under different conditions. By allocating memory for ordinary tasks and preempting memory for high-priority tasks, and recording the time, the real-time requirements of the testing system can be met. By examining the memory allocation status through multi-task memory allocation and preemption, the superiority of the dynamic memory management function can be demonstrated, improving the reliability and reproducibility of the testing method.

[0106] In summary, the memory management function detection method according to embodiments of the present invention establishes a high-load and fragmented memory environment for the initial memory pool of the target system to obtain a target memory pool. The target memory pool includes a load memory block and fragmented memory blocks. Under this memory environment, a memory preemption operation for a first target task is performed on the target memory pool, and the first execution time of the first target task preempting the load memory block and fragmented memory block is recorded. The memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory task stored in the load memory block. It is determined whether the first execution time exceeds a first preset time threshold. In response to the first execution time exceeding the first preset time threshold, it is determined that the memory management function of the target system is abnormal. Therefore, this method, by introducing task priority and triggering memory preemption, comprehensively detects the memory management situation. It can adjust the load rate according to the actual situation, creating situations where different memory load rates and memory fragmentation coexist, simulating multiple memory environments during memory management. This increases the diversity of memory management functions, reduces the failure rate after the real-time operating system is put into use, improves the lifespan of the real-time operating system, enhances the reliability of the device, and meets the real-time requirements of detection.

[0107] It should be noted that the method of this embodiment can be executed by a single device, such as a computer or server. The method of this embodiment can also be applied to a distributed scenario, where multiple devices cooperate to complete the task. In such a distributed scenario, one of these devices may execute only one or more steps of the method of this embodiment, and the multiple devices will interact with each other to complete the above method.

[0108] It should be noted that the above description describes some embodiments of the present invention. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in a different order than that shown in the above embodiments and still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0109] Corresponding to the above embodiments, the present invention also proposes a detection system for memory management functions.

[0110] like Figure 7 As shown, the memory management function detection system of this embodiment may include: an environment simulation module 710, a preemption module 720, a judgment module 730, and a detection module 740.

[0111] The environment simulation module 710 is configured to establish a high-load and fragmented memory environment for the initial memory pool of the target system, thereby obtaining the target memory pool, which includes a load memory block and fragmented memory blocks. The preemption module 720 is configured to perform a memory preemption operation on the target memory pool for a first target task within the memory environment, recording the first execution time of the first target task preempting the load memory block and fragmented memory block; wherein the memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory tasks stored in the load memory block. The judgment module 730 is configured to determine whether the first execution time exceeds a first preset time threshold. The detection module 740 is configured to determine that the memory management function of the target system is abnormal in response to the first execution time exceeding the first preset time threshold.

[0112] In some embodiments of the present invention, the determination module 730 is further configured to, in a memory environment, perform a memory allocation operation for a second target task on the target memory pool, and record the second execution time of the second target task occupying the fragmented memory block; wherein the memory space required by the second target task is not greater than the memory space of the fragmented memory block; determine whether the second execution time exceeds a second preset time threshold; and the detection module 740 determines that the memory management function of the target system is abnormal in response to the second execution time exceeding the second preset time threshold.

[0113] In some embodiments of the present invention, the environment simulation module 710 establishes a high-load and fragmented memory environment for the initial memory pool of the target system to obtain the target memory pool. Specifically, it is used to: establish a number of preset memory tasks, allocate corresponding free memory blocks from the initial memory pool to the number of preset memory tasks to obtain a load memory block; in response to the fact that the memory space of the remaining free memory blocks in the initial memory pool is less than the memory space required by a single preset memory task, release at least one memory block in the initial memory pool that has been occupied by a preset memory task according to a preset load rate to obtain a fragmented memory block; and obtain the target memory pool based on the load memory block and the fragmented memory block.

[0114] In some embodiments of the present invention, the preemption module 720 performs a memory preemption operation on a target memory pool for a first target task in a memory environment, and records the first execution time of the first target task preempting the load memory block and the fragmented memory block. Specifically, it is used to: establish at least one first memory task; record a first timestamp in response to starting the memory preemption operation on the target memory pool for the first target task; determine that the memory preemption operation has been completed in response to the memory space required by the first target task being fully allocated to the load memory block and the fragmented memory block, and record a second timestamp; calculate the difference between the second timestamp and the first timestamp to obtain the first execution time.

[0115] In some embodiments of the present invention, the preemption module 720 is further configured to, before starting a memory preemption operation to execute a first target task on the target memory pool, determine whether the memory space required by the first target task is greater than the memory space of the fragmented memory block; and, in response to the memory space required by the first target task being greater than the memory space of the fragmented memory block, determine to start a memory preemption operation to execute the first target task on the target memory pool.

[0116] In some embodiments of the present invention, the preemption module 720 is further configured to, before starting a memory preemption operation to execute a first target task on the target memory pool, determine whether all fragmented memory blocks are fully occupied, in response to the memory space required by the first target task not being greater than the memory space of the fragmented memory blocks; in response to all fragmented memory blocks being fully occupied, determine whether there is an unallocated first target task; and in response to the existence of an unallocated first target task, determine to start a memory preemption operation to execute the first target task on the target memory pool.

[0117] In some embodiments of the present invention, the environment simulation module 710 performs a memory allocation operation for a second target task on the target memory pool in a memory environment, and records a second execution time of the second target task occupying fragmented memory blocks. Specifically, it is used to: establish at least one second memory task; record a third timestamp in response to starting the memory allocation operation for the second target task on the target memory pool; determine that the memory allocation operation has been completed in response to the memory space required by the second target task being fully allocated to fragmented memory blocks, and record a fourth timestamp; calculate the difference between the fourth timestamp and the third timestamp to obtain the second execution time.

[0118] In some embodiments of the present invention, the detection module 740 is further configured to, in response to an anomaly in the memory management function of the target system, determine the cause of the anomaly in the memory management function; and optimize the memory management function based on the cause of the anomaly.

[0119] In some embodiments of the present invention, the preemption module 720 is further configured to monitor the number of fragmented memory blocks in the target memory pool in real time during the memory preemption operation of the first target task on the target memory pool; and in response to the number exceeding a preset fragmentation threshold, stop the memory preemption operation of the first target task on the target memory pool and optimize the memory management function of the target system.

[0120] It should be noted that for details not disclosed in the memory management function detection system of this embodiment of the invention, please refer to the details disclosed in the memory management function detection method of this embodiment of the invention, which will not be repeated here.

[0121] In summary, according to the memory management function detection system of this embodiment, the environment simulation module establishes a high-load and fragmented memory environment for the initial memory pool of the target system to obtain the target memory pool; wherein, the target memory pool includes a load memory block and a fragmented memory block; the preemption module performs a memory preemption operation of a first target task on the target memory pool in the memory environment, and records the first execution time of the first target task preempting the load memory block and the fragmented memory block; wherein, the memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory task stored in the load memory block; the judgment module judges whether the first execution time exceeds a first preset time threshold; the detection module determines that the memory management function of the target system is abnormal in response to the first execution time exceeding the first preset time threshold. Therefore, this system, by introducing task priority and triggering memory preemption, comprehensively detects the memory management situation. It can adjust the load rate according to the actual situation, creating situations where different memory load rates and memory fragmentation coexist, simulating multiple memory environments during memory management, increasing the diversity of memory management functions, reducing the failure rate after the real-time operating system is put into use, improving the lifespan of the real-time operating system, improving the reliability of the device, and meeting the real-time requirements of detection.

[0122] For ease of description, the above system is described by dividing it into various modules based on their functions. Of course, in implementing this invention, the functions of each module can be implemented in one or more software and / or hardware components.

[0123] The system described in the above embodiments is used to implement the corresponding method in any of the foregoing embodiments and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0124] Corresponding to the above embodiments, the present invention also proposes an electronic device.

[0125] refer to Figure 8 The diagram below is a block diagram of an electronic device according to some embodiments of the present invention. It illustrates a more specific hardware structure of the electronic device provided in this embodiment. The device may include: a processor 810, a memory 820, an input / output interface 830, a communication interface 840, and a bus 850. The processor 810, memory 820, input / output interface 830, and communication interface 840 are interconnected internally via the bus 850.

[0126] The processor 810 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0127] The memory 820 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 820 can store the operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program code is stored in the memory 820 and is called and executed by the processor 810.

[0128] The input / output interface 830 is used to connect input / output modules to enable information input and output. Input / output modules can be configured as components within the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Input devices may include keyboards, mice, touchscreens, microphones, various sensors, etc., while output devices may include displays, speakers, vibrators, indicator lights, etc.

[0129] The communication interface 840 is used to connect a communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (e.g., USB, Ethernet cable) or wireless means (e.g., mobile network, Wi-Fi, Bluetooth).

[0130] Bus 850 includes a pathway for transmitting information between various components of the device, such as processor 810, memory 820, input / output interface 830, and communication interface 840.

[0131] It should be noted that although the above-described device only shows the processor 810, memory 820, input / output interface 830, communication interface 840, and bus 850, in specific implementations, the device may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the components necessary for implementing the embodiments of this specification, and not necessarily all the components shown in the figures.

[0132] The electronic devices described above are used to implement the corresponding methods in any of the foregoing embodiments and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0133] Based on the same inventive concept, corresponding to the methods of any of the above embodiments, the present invention also provides a non-transitory computer-readable storage medium that stores computer instructions for causing a computer to perform the methods of any of the above embodiments.

[0134] The aforementioned non-transitory computer-readable storage media can be any available medium or data storage device that a computer can access, including but not limited to magnetic storage (e.g., floppy disks, hard disks, magnetic tapes, magneto-optical disks (MOs), etc.), optical storage (e.g., CDs, DVDs, BDs, HVDs, etc.), and semiconductor storage (e.g., ROMs, EPROMs, EEPROMs, non-volatile memory (NAND flash), solid-state drives (SSDs)).

[0135] The computer instructions stored in the storage medium of the above embodiments are used to cause the computer to perform the methods of any of the above exemplary method sections, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0136] Furthermore, although the operations of the method of the present invention are described in a specific order in the accompanying drawings, this does not require or imply that these operations must be performed in that specific order, or that all of the operations shown must be performed to achieve the desired result. Rather, the steps depicted in the flowchart may be performed in a different order. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps.

[0137] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0138] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this invention should have the ordinary meaning understood by those skilled in the art. The terms "first," "second," and similar terms used in the embodiments of this invention do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word covers the element or object listed after the word and its equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are only used to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0139] While the spirit and principles of the invention have been described with reference to several specific embodiments, it should be understood that the invention is not limited to the disclosed specific embodiments, and the division of aspects does not imply that features in these aspects cannot be combined for benefit; such division is merely for ease of description. The invention is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims. The scope of the appended claims is to be interpreted in the broadest sense, thereby encompassing all such modifications and equivalent structures and functions.

Claims

1. A method for detecting memory management functions, characterized in that, include: A high-load and fragmented memory environment is established for the initial memory pool of the target system to obtain the target memory pool; wherein, the target memory pool includes loaded memory blocks and fragmented memory blocks; In the memory environment, a memory preemption operation for a first target task is performed on the target memory pool, and the first execution time of the first target task preempting the load memory block and the fragmented memory block is recorded; wherein, the memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory task stored in the load memory block; Determine whether the first execution time exceeds a first preset time threshold; In response to the first execution time exceeding the first preset time threshold, it is determined that the memory management function of the target system is abnormal; The process of establishing a high-load and fragmented memory environment for the initial memory pool of the target system to obtain the target memory pool includes: Several preset memory tasks are established, and corresponding free memory blocks are allocated to the several preset memory tasks from the initial memory pool to obtain the load memory block; In response to the fact that the remaining free memory block in the initial memory pool is less than the memory space required by a single preset memory task, at least one memory block in the initial memory pool that has been occupied by the preset memory task is released according to a preset load rate, thereby obtaining the fragmented memory block; The target memory pool is obtained based on the loaded memory block and the fragmented memory block; The method further includes: In the memory environment, a memory allocation operation for a second target task is performed on the target memory pool, and the second execution time of the second target task occupying the fragmented memory block is recorded; wherein, the memory space required by the second target task is not greater than the memory space of the fragmented memory block; Determine whether the second execution time exceeds the second preset time threshold; In response to the second execution time exceeding a second preset time threshold, it is determined that the memory management function of the target system is abnormal.

2. The method for detecting memory management function according to claim 1, characterized in that, In the memory environment, the process of performing a memory preemption operation on the target memory pool for a first target task, and recording the first execution time of the first target task preempting the load memory block and the fragmented memory block, includes: Establish at least one first target task; wherein the first target task has a higher priority than the preset memory task; In response to initiating a memory preemption operation to execute the first target task on the target memory pool, a first timestamp is recorded; In response to the fact that the memory space required by the first target task is fully allocated to the load memory block and the fragmented memory block, it is determined that the memory preemption operation has been completed, and a second timestamp is recorded; The difference between the second timestamp and the first timestamp is calculated to obtain the first execution time.

3. The method for detecting memory management function according to claim 2, characterized in that, Prior to the memory preemption operation in response to initiating the execution of the first target task on the target memory pool, the method further includes: Determine whether the memory space required by the first target task is greater than the memory space of the fragmented memory block; In response to the fact that the memory space required by the first target task is greater than the memory space of the fragmented memory block, it is determined to start the memory preemption operation of the first target task on the target memory pool.

4. The method for detecting memory management function according to claim 3, characterized in that, Prior to the memory preemption operation in response to initiating the execution of the first target task on the target memory pool, the method further includes: In response to the fact that the memory space required by the first target task is not greater than the memory space of the fragmented memory blocks, it is determined whether all the fragmented memory blocks are fully occupied; In response to all said fragmented memory blocks being fully occupied, determine whether there is an unallocated first target task; In response to the existence of an unallocated first target task, a memory preemption operation is determined to begin executing the first target task on the target memory pool.

5. The method for detecting memory management function according to claim 1, characterized in that, In the memory environment, the process of performing a memory allocation operation for the second target task on the target memory pool and recording the second execution time of the second target task occupying the fragmented memory block includes: Establish at least one second target task; wherein the priority of the second target task is equal to that of the preset memory task; In response to initiating a memory allocation operation for the second target task in the target memory pool, a third timestamp is recorded; In response to the fact that the memory space required by the second target task has been fully allocated to the fragmented memory block, the memory allocation operation is determined to be completed, and a fourth timestamp is recorded; The difference between the fourth timestamp and the third timestamp is calculated to obtain the second execution time.

6. The method for detecting memory management function according to claim 1, characterized in that, The method further includes: In response to an anomaly in the memory management function of the target system, determine the cause of the anomaly in the memory management function; The memory management function is optimized based on the cause of the anomaly.

7. The method for detecting memory management function according to claim 5, characterized in that, The method further includes: During the memory preemption operation of the first target task on the target memory pool, the number of fragmented memory blocks in the target memory pool is monitored in real time. In response to the number exceeding a preset fragment threshold, the memory preemption operation for the first target task in the target memory pool is stopped, and the memory management function of the target system is optimized.

8. A memory management function detection system, characterized in that, include: The environment simulation module is configured to establish a high-load and fragmented memory environment for the initial memory pool of the target system to obtain the target memory pool; wherein, the target memory pool includes loaded memory blocks and fragmented memory blocks; The preemption module is configured to perform a memory preemption operation of a first target task on the target memory pool in the memory environment, and record the first execution time of the first target task preempting the load memory block and the fragmented memory block; wherein, the memory space required by the first target task is greater than the memory space of the fragmented memory block, and the priority of the first target task is greater than the priority of the preset memory task stored in the load memory block; The judgment module is configured to determine whether the first execution time exceeds a first preset time threshold. The detection module is configured to determine that the memory management function of the target system is abnormal in response to the first execution time exceeding the first preset time threshold. The environment simulation module is specifically used for: Several preset memory tasks are established, and corresponding free memory blocks are allocated to the several preset memory tasks from the initial memory pool to obtain the load memory block; In response to the fact that the remaining free memory block in the initial memory pool is less than the memory space required by a single preset memory task, at least one memory block in the initial memory pool that has been occupied by the preset memory task is released according to a preset load rate, thereby obtaining the fragmented memory block; The target memory pool is obtained based on the loaded memory block and the fragmented memory block; The environment simulation module is further configured to: perform a memory allocation operation for a second target task on the target memory pool in the memory environment, and record the second execution time of the second target task occupying the fragmented memory block; wherein the memory space required by the second target task is not greater than the memory space of the fragmented memory block; Determine whether the second execution time exceeds the second preset time threshold; In response to the second execution time exceeding a second preset time threshold, it is determined that the memory management function of the target system is abnormal.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The detection method for implementing the memory management function as described in any one of claims 1 to 5 when the processor executes the program.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to perform the detection method for the memory management function according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Memory exception monitoring method and device and computer storage medium

    CN113835920A