A memory crash prevention method and device based on Linux environment

By building the correspondence between memory blocks in the Linux environment and verifying their properties, the problem of Mempool leakage and release errors is solved, which improves the accuracy and security of memory usage and reduces the programming burden.

CN114860436BActive Publication Date: 2024-12-31CHINA FAW CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210450899.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-26
Publication Date
2024-12-31
Estimated Expiration
2042-04-26

AI Technical Summary

Technical Problem

Mempool leaks, release errors and memory reference errors in Linux Kernel often cause system crashes, and developers need to artificially maintain and verify the correct use of Mempool, which increases the programming burden.

Method used

By obtaining the first address, size and attributes of the memory block, the correspondence between user information and the memory block is constructed, and the matching is verified when released, ensuring the accurate release of the memory block and reducing programming burden.

Benefits of technology

Improves the accuracy and security of memory usage, reduces the programming burden of Mempool users, and reduces the frequency of memory crashes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114860436B_ABST
    Figure CN114860436B_ABST
Patent Text Reader

Abstract

The present application provides a memory crash prevention method and device based on a Linux environment, the method comprising: obtaining the first address, size and attributes of each memory block; when a user applies for a memory block, constructing a correspondence between user information and the memory block, and storing the first address, size and attributes of the applied memory block; when a user releases a memory block, verifying whether the first address, size and attributes of the stored memory block match the first address, size and attributes of the released memory block based on the constructed correspondence between user information and the memory block; if they match, allowing the release. In the above technical solution, by establishing a correspondence between users and memory blocks, and verifying the first address, size and attributes of the memory block, the accuracy of the memory block when released is guaranteed, and the programming burden of the Mempool user is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of automobile technology, and more particularly to a memory crash prevention method and device based on a Linux environment. Background Art

[0002] Linux kernel development requires engineers to work in KernelSpace. The difference between Kernel Space and UserSpace is that Kernel programs and operating systems are in the same space and time dimensions, rather than being strictly isolated from each other in space and time like applications. Therefore, once a program in the Kernel has a defect, it will lead to systemic errors, which may lead to incorrect results or system crashes.

[0003] The Linux Kernel is currently updated to version 5.17. In all releases including this version, a method called Mempool technology is provided to ensure that programs can apply for memory.

[0004] The basic idea of ​​this technology is to reserve a specified number of fixed-size memory blocks for the program, rather than applying for them as needed; this is to prevent the situation where memory cannot be applied for.

[0005] Mempool technology provides programmers with a basic pre-allocated memory mechanism, and also avoids the massive generation of memory fragments to a certain extent; however, this mechanism also has certain risks in use.

[0006] Mempool leaks, release errors, and memory reference errors are usually the most important and most frequent causes of kernel crashes.

[0007] In the currently released Linux code, programming developers need to manually maintain, verify, and ensure the correct use of Mempool; to a certain extent, this also increases the programming burden of Mempool users. Summary of the invention

[0008] In view of this, the purpose of one or more embodiments of this specification is to propose a memory crash prevention method based on a Linux environment and a memory crash prevention device based on a Linux environment to improve the use effect of the memory in the Linux environment.

[0009] In the first aspect, a memory crash prevention method based on a Linux environment is provided, and the memory crash prevention method based on a Linux environment includes the following steps: obtaining the first address, size and attributes of each memory block; when a user applies for a memory block, constructing a correspondence between user information and the memory block, and storing the first address, size and attributes of the applied memory block; when a user releases a memory block, verifying whether the first address, size and attributes of the stored memory block match the first address, size and attributes of the released memory block based on the constructed correspondence between user information and the memory block; and allowing release if they match. In the above technical solution, by establishing a correspondence between users and memory blocks, and by verifying the first address, size and attributes of the memory block, the accuracy of the memory block when released is guaranteed, and the programming burden of Mempool users is reduced.

[0010] In a specific implementation scheme, the attributes of the memory block include a random fingerprint and a flag indicating whether it is allocated.

[0011] In a specific possible implementation scheme, the method further includes determining a random fingerprint of the memory block based on a first address of the memory block and a size of the memory block.

[0012] In a specific possible implementation scheme, the method further includes querying available memory blocks before the user applies for the memory blocks; and when the queried memory blocks are less than the required memory blocks, stopping the allocation of memory blocks.

[0013] In a specific possible implementation scheme, the method further includes: constructing a memory pool, and when constructing the memory pool, determining the first address of each memory block, the size of the memory block, and the attributes of the memory block.

[0014] In a specific possible implementation manner, the method further comprises: updating the attribute of the memory block after the user releases the memory block.

[0015] In a specific possible implementation scheme, the method further includes destroying the memory pool; and when destroying the memory pool, querying whether all memory blocks are allocated; if all memory blocks are not allocated, destroying the memory pool.

[0016] In a second aspect, a memory crash prevention device based on a Linux environment is provided, the device comprising:

[0017] The information collection module is used to record the allocated memory blocks in the memory pool; and obtain the first address of each memory block, the size of the memory block and the attributes of the memory block;

[0018] The data processing module is used to construct a correspondence between user information and a memory block when a user applies for a memory block, and store the first address, size and attributes of the applied memory block; when a user releases a memory block, verify whether the first address, size and attributes of the stored memory block match the first address, size and attributes of the released memory block based on the constructed correspondence between the user information and the memory block; and allow release if they match.

[0019] In the above technical solution, by establishing a corresponding relationship between users and memory blocks and verifying the first address, size and attributes of the memory blocks, the accuracy of the memory blocks when released is guaranteed, thereby reducing the programming burden of Mempool users.

[0020] In a specific implementation scheme, the attributes of the memory block include a random fingerprint and a flag indicating whether it is allocated.

[0021] In a specific implementation scheme, the data processing module is further used to determine the random fingerprint of the memory block according to the first address of the memory block and the size of the memory block.

[0022] In a specific implementation scheme, the data processing module is further used to query available memory blocks before the user applies for the memory blocks; and when the queried memory blocks are less than the required memory blocks, stop allocating memory blocks.

[0023] In a specific possible implementation scheme, the data processing module is also used to construct a memory pool. When constructing the memory pool, the first address of each memory block, the size of the memory block and the attributes of the memory block are determined.

[0024] According to a third aspect, a car is provided, comprising a car body and any one of the above-mentioned memory crash prevention devices based on a Linux environment arranged in the car body.

[0025] In the above technical solution, by establishing a corresponding relationship between users and memory blocks and verifying the first address, size and attributes of the memory blocks, the accuracy of the memory blocks when released is guaranteed, thereby reducing the programming burden of Mempool users.

[0026] In a fourth aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for executing the first aspect and any possible design in the first aspect is implemented.

[0027] In a fifth aspect, a non-transitory computer-readable storage medium is provided, wherein the non-transitory computer-readable storage medium stores computer instructions, wherein the computer instructions are used to cause the computer to execute the method of the first aspect and any possible design of the first aspect.

[0028] In a sixth aspect, a computer program product is also provided, comprising instructions, which, when executed on a computer, enables the computer to execute the method in the first aspect of the present application and any possible design in the first aspect.

[0029] In addition, the technical effects brought about by any possible design method in the fourth to sixth aspects can be referred to the effects brought about by different design methods in the method part, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate one or more embodiments of the present specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only one or more embodiments of the present specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0031] Figure 1 A flowchart of a memory crash prevention method based on a Linux environment provided in an embodiment of the present application;

[0032] Figure 2 A flowchart of a method for constructing a memory pool provided in an embodiment of the present application;

[0033] Figure 3 A flowchart of querying a memory block provided in an embodiment of the present application;

[0034] Figure 4 A flowchart of applying for a memory block provided in an embodiment of the present application;

[0035] Figure 5 A flowchart of releasing a memory block provided in an embodiment of the present application;

[0036] Figure 6 A flowchart of reconstructing a memory pool provided in an embodiment of the present application;

[0037] Figure 7 A flowchart of destroying a memory pool provided in an embodiment of the present application;

[0038] Figure 8 A structural block diagram of a memory crash prevention device based on a Linux environment provided in an embodiment of the present application;

[0039] Fig. 9A structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] In order to make the objectives, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.

[0041] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in one or more embodiments of this specification should be understood by people with ordinary skills in the field to which this disclosure belongs. The "first", "second" and similar words used in one or more embodiments of this specification do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like 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.

[0042] The technical carriers involved in the payment described in the embodiments of this specification may include, for example, Near Field Communication (NFC), WIFI, 3G / 4G / 5G, POS card swiping technology, QR code scanning technology, bar code scanning technology, Bluetooth, infrared, short message service (SMS), multimedia message service (MMS), etc.

[0043] Mempool leakage, release errors and memory reference errors are usually several important reasons for kernel crashes, and they are also several reasons that occur more frequently. Usually, the root cause of the leak is the missing of the last step of the three steps of application-use-release. The root cause of the release error is non-application, repeated release, and release size mismatch. The root cause of the reference error is saving data to an unapplied location or reading data from an unapplied space. In Linux Kernel programming, in order to ensure the efficiency of program memory application, avoid memory fragmentation, and avoid excessive context switching costs caused by paging operations caused by memory application, a technology called Mempool is provided. The embodiment of the present application provides a method for preventing crashes, which acts on Mempool to solve the Mempool usage problems caused by the above-mentioned Linux original mechanism; and provides developers with a more friendly and easy-to-use programming interface.

[0044] To facilitate understanding of the memory crash prevention method based on the Linux environment provided in the embodiment of the present application, the design of the existing Kernel is first explained.

[0045] 1)Mempool structure

[0046] struct mempool_t;

[0047] 2) Constraints on Mempool memory pool properties; size and usage;

[0048] mempool_t*mempool_create(intmin_nr,mempool_alloc_t*,mempool_free_t*,void*);

[0049] The two parameter function pointers in the parameter list serve as the default execution functions for allocating memory:

[0050] typedef void*(mempool_alloc_t)(int gfp_mask,void*pool_data);

[0051] typedef void(mempool_free_t)(void*element,void*pool_data);

[0052] These two parameters are usually passed into mempool_alloc_slab and mempool_free_slab

[0053] 3) Allocate a block from a pool:

[0054] void*mempool_alloc(mempool_t*pool,int gfp_mask);

[0055] 4) Release a block in a pool:

[0056] void mempool_free(void*element,mempool_t*pool);

[0057] 5) Reset a mempool size:

[0058] int mempool_resize(mempool_t*pool,int new_min_nr,int gfp_mask);

[0059] 6) Destroy a mempool:

[0060] void mempool_destroy(mempool_t*pool);

[0061] The above is the code in the design of the kernel in the prior art. It can be seen from the code of the above kernel design that when an erroneous release, unused use, or erroneous reference occurs, it cannot be effectively prevented, which can easily cause a memory crash. The memory crash prevention method provided by the present application is described in detail below in conjunction with specific drawings and embodiments.

[0062] First, the data structure and programming port involved in this application are explained.

[0063] Data structure. In the data structure of this application, the signature is separated from the specific implementation method.

[0064] The signature is placed in the C header file: typedef struct mp_wrapper(pointer)*mp_handle

[0065] The implementation is hidden in the C source file:

[0066]

[0067] Programming port

[0068] mp_handle mp_create(int size,alloc_fn*,free_t*,void*);

[0069] void* mp_alloc(mp_handle*);

[0070] int mp_free(void*blk,mp_handle); / / return error code

[0071] int mp_resize(mp_handle,int new_sz);

[0072] int mp_destory(mp_handle); / / Kernel OOPS caused by improper release can be avoided

[0073] size_t mp_total(mp_handle);

[0074] size_t mp_exhusted(mp_handle);

[0075] refer to Figure 1 The memory crash prevention method based on Linux environment provided in the embodiment of the present application mainly includes the following steps:

[0076] Step 001: Obtain the first address, size and attributes of each memory block;

[0077] Specifically, first build a memory pool. When building the memory pool, determine the first address, size, and attributes of each memory block. By obtaining the first address, size, and attributes of each memory block, each memory block has unique information. When obtaining the first address, size, and attributes of each memory block, refer to Figure 2 , Figure 2 Shows a method for building a memory pool.

[0078] To create a pool, you need to apply for the pointer member mp of the struct mempool_t type. After success, initialize other members. If unsuccessful, NULL is returned, indicating that the creation failed. Specifically, first perform a parameter validity check, which is a check to see if the requested command meets the requirements. For example, if the size of the requested memory pool is 0B or 1000MB, this method is obviously unreasonable. Therefore, the application will be judged as illegal, and the application program will end directly. When the parameter validity meets the requirements, apply for the kernel mempool object, that is, apply for the memory pool. When the application is successful, initialize total, used, size and other information related to the memory block. Among them, total refers to the number of memory blocks; used is the usage of the memory block. When the memory pool is first constructed, used is 0; size is the size of each memory block; after initializing the above information, initialize addrs and indicator; among them, addrs is the first address of each memory block; indicator is each block attribute. After completing the initialization, it ends, thereby realizing the construction of the memory pool. When the memory pool is constructed, the first address, size and attributes of each memory block can be determined.

[0079] The attributes of a memory block include a random fingerprint and a flag indicating whether it is allocated. Specifically, the indicator attribute stores the random fingerprint and the flag indicating whether it is allocated of the memory block, which can be verified when it is released. The values ​​corresponding to the random fingerprint and the flag indicating whether it is allocated will be copied to the last 4B of the memory block when allocating the data block. When creating mp_wrapper, the size of the memory block is automatically increased by 4 to leave extra space for it. This memory layout (the values ​​corresponding to the random fingerprint and the flag indicating whether it is allocated) exists in each memory block, is assigned when it is allocated, and is cleared when it is released.

[0080] When determining the random fingerprint of each memory block, it is determined based on the first address of the memory block and the size of the memory block. Specifically, for each allocated memory block, the fingerprint of the block in the indicator array can be obtained by calculating size and addrs to verify whether the block can be allocated.

[0081] Step 002: When a user applies for a memory block, a corresponding relationship between the user information and the memory block is constructed, and the first address of the applied memory block, the size of the memory block, and the attributes of the memory block are stored;

[0082] Specifically, Figure 3 As shown, Figure 3 The query flow chart of the memory block is shown. First, the validity of the data is verified. Figure 2The method shown is similar and will not be described in detail here. After the legality is achieved, determine whether the memory blocks in the memory pool are completely consumed. When judging the consumption, the query operation of free blocks, total number, block size and other information can be completed through the calculation of total, used, size and other members according to the above process.

[0083] After the query is completed, start applying for memory blocks, such as Figure 4 As shown, Figure 4 The memory block application process is shown in Figure 1. First, the parameter validity check is performed. Figure 3 , Figure 2 The check in is similar and will not be repeated here. After the legality is reached, it is determined whether the memory block has been used up. If used ≥ total, it means that the memory block has been used up, and the application process ends. If used < total, it means that the memory block has not been used up, and the user can apply for a memory block (block space). When the user applies for a memory block, the addrs and indicator and other memory block related information are set to establish a corresponding relationship between the user and the memory block he applied for.

[0084] In addition, to simplify the application process, the available memory blocks can be queried before the user applies for the memory blocks; and when the queried memory blocks are less than the required memory blocks, the memory blocks are stopped from being allocated. That is, when the number of memory blocks in the queried memory pool is less than the number of memory blocks the user needs to apply for, the application process is directly terminated, thereby simplifying the entire application process.

[0085] Step 003: When the user releases the memory block, based on the constructed correspondence between the user information and the memory block, verify whether the first address, size and attributes of the stored memory block match the first address, size and attributes of the released memory block; if they match, allow release.

[0086] Specifically, refer to Figure 5 , Figure 5 The flowchart of releasing the memory block is shown. First, the parameter verification is performed. Figure 3 The parameter verification shown in is similar to the legality, which will not be repeated here. After it is legal, the indicator is checked to see if it is legal, that is, it is judged whether it is legal based on the properties of the released block. Correspondingly, the information of the user and the memory block applied for by the user established in step 002 is used to judge whether the user releases the corresponding memory block when releasing the memory block. When making a specific judgment, verify whether the first address of the stored memory block, the size of the memory block, and the properties of the memory block match the first address, the size of the memory block, and the properties of the memory block of the released memory block; if they match, release is allowed.

[0087] In addition, the properties of the memory block are updated after the user releases the memory block. That is, when the memory block is released, the usage of the memory block is updated, specifically, information such as addrs, indicator, and used are updated.

[0088] It can be seen from the above description that the method disclosed in the present application establishes a corresponding relationship between users and memory blocks and verifies the first address, size and attributes of the memory blocks, thereby ensuring the accuracy of the memory blocks when they are released and reducing the programming burden of Mempool users.

[0089] In addition to the above steps, the method disclosed in the present application may also include the following steps.

[0090] Step 004: Rebuild the memory pool.

[0091] Specifically, refer to Figure 6 , Figure 6 The flowchart of rebuilding the memory pool is shown. First, the parameter validity check is determined. If it is legal, the space is re-applied, and the addrs, indicator, and total information of the memory block in the memory pool are updated in the re-applied space. Users can apply for memory blocks in the re-built memory pool.

[0092] Step 005: Destroy the memory pool.

[0093] Specifically, when destroying a memory pool, check whether all memory blocks are allocated; if all memory blocks are not allocated, the memory pool is destroyed. Figure 7 As shown, Figure 7 The flowchart of destroying the memory pool is shown. First, the parameter validity check is determined. After it is legal, it is determined whether all the memory in the memory pool has been allocated. If all the memory blocks are not allocated, the memory pool is destroyed. Or if the memory in the memory pool has been used, it is detected whether the used memory blocks have been released. If they have been released, the memory pool is destroyed.

[0094] like Figure 8 As shown, an embodiment of the present application also provides a memory crash prevention device based on a Linux environment, and the device includes: an information collection module and a data processing module.

[0095] The information collection module is used to record the allocated memory blocks in the memory pool; and obtain the first address of each memory block, the size of the memory block and the attributes of the memory block;

[0096] The data processing module is used to construct a correspondence between user information and memory blocks when a user applies for a memory block, and store the first address, size and attributes of the memory block applied for; when a user releases a memory block, verify whether the first address, size and attributes of the stored memory block match the first address, size and attributes of the released memory block according to the constructed correspondence between user information and memory blocks; if they match, release is allowed. The attributes of the memory block include a random fingerprint and a mark indicating whether it is allocated.

[0097] Specifically, the data processing module is also used to determine the random fingerprint of the memory block according to the first address of the memory block and the size of the memory block.

[0098] The data processing module is also used to query available memory blocks before the user applies for the memory blocks; and when the queried memory blocks are less than the required memory blocks, stop allocating memory blocks.

[0099] The data processing module is also used to construct a memory pool. When constructing the memory pool, the first address, size and properties of each memory block are determined. The functions of the above information collection module and data processing module can refer to the detailed description of the corresponding method.

[0100] It can be seen from the above description that the device provided by the present application establishes a corresponding relationship between users and memory blocks and verifies the first address, size and attributes of the memory blocks, thereby ensuring the accuracy of the memory blocks when they are released and reducing the programming burden of Mempool users.

[0101] The embodiment of the present application also provides a car, which includes a car body and any one of the above-mentioned memory crash prevention devices based on the Linux environment arranged in the car body. In the above-mentioned technical solution, by establishing a corresponding relationship between the user and the memory block, and by verifying the first address, size and attributes of the memory block, the accuracy of the memory block when it is released is guaranteed, and the programming burden of the Mempool user is reduced.

[0102] An embodiment of the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for executing the first aspect and any possible design in the first aspect is implemented.

[0103] An embodiment of the present application also provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a computer to execute the first aspect and any possible design method in the first aspect.

[0104] An embodiment of the present application also provides a computer program product, including instructions, which, when executed on a computer, enables the computer to execute the method of the first aspect of the present application and any possible design of the first aspect.

[0105] It should be noted that the method of one or more embodiments of this specification can be performed by a single device, such as a computer or server. The method of this embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of one or more embodiments of this specification, and the multiple devices will interact with each other to complete the described method.

[0106] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0107] For the convenience of description, the memory crash prevention device based on Linux environment is described as being divided into various modules according to their functions. Of course, when implementing one or more embodiments of this specification, the functions of each module can be implemented in the same one or more software and / or hardware.

[0108] The memory crash prevention device based on Linux environment in the above embodiment is used to implement the corresponding method in the above embodiment, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.

[0109] Fig. 9 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.

[0110] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an 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.

[0111] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an 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 codes are stored in the memory 1020 and are called and executed by the processor 1010.

[0112] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.

[0113] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).

[0114] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).

[0115] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0116] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.

[0117] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present disclosure (including the claims) is limited to these examples. In line with the present disclosure, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of different aspects of one or more embodiments of the present specification as described above, which are not provided in detail for the sake of simplicity.

[0118] In addition, to simplify the description and discussion, and in order not to make one or more embodiments of the present specification difficult to understand, the known power / ground connections to the integrated circuit (IC) chip and other components may or may not be shown in the provided drawings. In addition, the memory anti-crash device based on the Linux environment can be shown in the form of a block diagram to avoid making one or more embodiments of the present specification difficult to understand, and this also takes into account the fact that the details of the implementation of the memory anti-crash device based on the Linux environment of these block diagrams are highly dependent on the platform on which one or more embodiments of the present specification will be implemented (that is, these details should be fully within the scope of understanding of those skilled in the art). In the case of elaborating specific details (e.g., circuits) to describe exemplary embodiments of the present disclosure, it is obvious to those skilled in the art that one or more embodiments of the present specification can be implemented without these specific details or with changes in these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.

[0119] Although the present disclosure has been described in conjunction with specific embodiments of the present disclosure, many replacements, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.

[0120] One or more embodiments of this specification are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification should be included in the scope of protection of this disclosure.

Claims

1. A memory crash prevention method based on Linux environment, characterized in that: The following steps are involved: Get the first address of each memory block, the size of the memory block, and the properties of the memory block; When a user applies for a memory block, a correspondence between the user information and the memory block is constructed, and the first address of the applied memory block, the size of the memory block, and the attributes of the memory block are stored; When the user releases the memory block, verify whether the first address, size and attributes of the stored memory block match the first address, size and attributes of the released memory block according to the constructed correspondence between the user information and the memory block; if they match, allow the release; The attributes of the memory block include a random fingerprint and a mark indicating whether it is allocated; When the user releases the memory block, based on the constructed correspondence between the user information and the memory block, verify whether the first address, size and attribute of the stored memory block match the first address, size and attribute of the memory block to be released; if they match, allow the release, including: When a user releases a memory block, performing parameter validity verification on the released memory block; If the released memory block is legal, verify whether the first address of the stored memory block, the size of the memory block, the random fingerprint of the memory block, and the mark of whether the memory block is allocated match the first address of the released memory block, the size of the memory block, the random fingerprint of the memory block, and the mark of whether the memory block is allocated, and if they match, allow the release; After the user releases the memory block, at least the first address of the memory block, the usage of the memory block, the random fingerprint of the memory block, and the identification of whether the memory block is allocated are updated.

2. The memory crash prevention method based on Linux environment according to claim 1, characterized in that: The method further comprises determining a random fingerprint of the memory block according to a first address of the memory block and a size of the memory block.

3. The memory crash prevention method based on Linux environment according to any one of claims 1 to 2, characterized in that: The method further includes querying available memory blocks before the user applies for the memory blocks; And when the queried memory blocks are less than the required memory blocks, stop allocating memory blocks.

4. The memory crash prevention method based on Linux environment according to claim 3, characterized in that: The method further comprises: Build a memory pool. When building a memory pool, determine the first address of each memory block, the size of the memory block, and the attributes of the memory block.

5. The memory crash prevention method based on Linux environment according to claim 4, characterized in that: The method further comprises: Update the properties of the memory block after the user releases the memory block.

6. The memory crash prevention method based on Linux environment according to claim 5, characterized in that: The method further includes destroying the memory pool; and when destroying the memory pool, querying whether all memory blocks are allocated; if all memory blocks are not allocated, destroying the memory pool.

7. A memory crash prevention device based on Linux environment, characterized in that: include: An information collection module is used to record the allocated memory blocks in the memory pool; And get the first address of each memory block, the size of the memory block and the properties of the memory block; The data processing module is used to construct a correspondence between user information and a memory block when a user applies for a memory block, and store the first address, size and attributes of the memory block applied for; when a user releases a memory block, verify whether the first address, size and attributes of the stored memory block match the first address, size and attributes of the released memory block according to the constructed correspondence between the user information and the memory block; and allow release if they match; The attributes of the memory block include a random fingerprint and a mark indicating whether it is allocated; The data processing module is specifically used to perform parameter validity verification on the released memory block when the user releases the memory block; and, if the released memory block is legal, verify whether the first address of the stored memory block, the size of the memory block, the random fingerprint of the memory block, and the mark of whether the memory block is allocated match the first address of the released memory block, the size of the memory block, the random fingerprint of the memory block, and the mark of whether the memory block is allocated, and allow release when they match; and, after the user releases the memory block, at least update the first address of the memory block, the usage of the memory block, the random fingerprint of the memory block, and the mark of whether the memory block is allocated.

8. The memory crash prevention device based on Linux environment according to claim 7, characterized in that: The data processing module is also used to determine the random fingerprint of the memory block according to the first address of the memory block and the size of the memory block.

9. The memory crash prevention device based on Linux environment according to claim 8, characterized in that: The data processing module is also used to query available memory blocks before the user applies for the memory blocks; and when the queried memory blocks are less than the required memory blocks, stop allocating memory blocks.

10. The memory crash prevention device based on Linux environment according to claim 9, characterized in that: The data processing module is also used to construct a memory pool. When constructing the memory pool, the first address of each memory block, the size of the memory block and the attributes of the memory block are determined.

11. A car, characterized in that: The invention comprises a vehicle body and a memory anti-crash device based on a Linux environment as claimed in any one of claims 7 to 10 arranged in the vehicle body.

12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the memory crash prevention method based on the Linux environment as described in any one of claims 1 to 6 is implemented.

13. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the memory crash prevention method based on the Linux environment as claimed in any one of claims 1 to 6.