Memory sharing methods, devices, electronic devices, vehicles, and readable storage media
By combining a two-dimensional bitmap matrix and a hash table, the problem of inaccurate memory block state tracking in cross-domain shared memory is solved, achieving fine-grained memory management and system state consistency, which is suitable for multi-functional domain data interaction in intelligent vehicles.
Patent Information
- Application Number
- CN202611246809.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-17
- Publication Date
- 2026-11-17
AI Technical Summary
Existing cross-domain shared memory mechanisms lack fine-grained tracking of memory block usage status, leading to illegal access and memory leaks. Furthermore, their reliance on hypervisors results in rigid configurations and inflexible management.
It uses a two-dimensional bitmap matrix and hash table to record the memory block occupancy status, and implements a lightweight architecture through dynamic configuration of device tree, providing fine-grained status tracking and lifecycle management to avoid unauthorized access and memory leaks.
It achieves zero-copy, low-latency direct sharing of physical memory across multiple domains, ensuring system state consistency and flexible configuration, reducing traversal overhead, and is suitable for lightweight embedded platforms without a hypervisor or with limited resources.
Smart Images

Figure CN123114791A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent vehicle technology, and more specifically to a memory sharing method, apparatus, electronic device, vehicle, and readable storage medium. Background Technology
[0002] The intelligent cockpit of intelligent vehicles needs to run multiple functional domains on the same hardware platform. These functional domains often use shared memory to achieve zero-copy data transmission, thereby improving data interaction efficiency.
[0003] Currently, existing cross-domain shared memory mechanisms use coarse-grained memory block status tracking. Once a memory block in shared memory is occupied by a certain domain, other domains cannot know its current status, which can easily lead to illegal access and other situations. Summary of the Invention
[0004] One objective of this invention is to provide a memory sharing method to solve the problem that, in the current memory sharing process, when a memory block is occupied by a certain domain, other domains cannot detect the occupied status of the memory block, leading to illegal access by other domains; a second objective is to provide a memory sharing device; a third objective is to provide an electronic device; a fourth objective is to provide a vehicle; and a fifth objective is to provide a computer-readable storage medium.
[0005] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0006] A memory sharing method, comprising:
[0007] Obtain a two-dimensional bitmap matrix for each virtual machine, which is used to record the occupancy status of each memory block in the shared memory among the virtual machines;
[0008] When a memory block occupancy request from the first virtual machine is received, the first target memory block to be occupied is determined in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and the occupancy status of the first target memory block is updated in the two-dimensional bitmap matrix.
[0009] When a memory block release request is received from the first virtual machine, a second target memory block to be released is determined based on the memory block release request and the two-dimensional bitmap matrix, and the occupancy status of the second target memory block is cleared in the two-dimensional bitmap matrix.
[0010] Furthermore, the occupancy status of the memory block includes the memory block idle status, the memory block allocated status, and the memory block accessed status.
[0011] Furthermore, the step of determining the first target memory block to be occupied in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and updating the occupancy status of the first target memory block in the two-dimensional bitmap matrix, includes:
[0012] Read the virtual machine identifier from the memory block occupancy request;
[0013] If the virtual machine identifier is the first identifier of the first virtual machine, then according to the two-dimensional bitmap matrix of the first virtual machine, a free memory block is selected in the memory region of the first virtual machine and determined as the first target memory block;
[0014] Allocate the first target memory block to the first virtual machine;
[0015] Update the occupied status of the first target memory block to the allocated status of the memory block.
[0016] Furthermore, the step of determining the first target memory block to be occupied in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and updating the occupancy status of the first target memory block in the two-dimensional bitmap matrix, includes:
[0017] If the virtual machine identifier in the memory block occupancy request is the second identifier of the second virtual machine, then the first target memory block is determined in the memory region of the second virtual machine according to the two-dimensional bitmap matrix of the second virtual machine.
[0018] Update the occupied status of the first target memory block to the accessed status of the memory block.
[0019] Furthermore, determining the second target memory block to be released based on the memory block release request and the two-dimensional bitmap matrix includes:
[0020] Read the virtual machine identifier and block offset from the memory block release request;
[0021] If the virtual machine identifier in the memory block release request is the first identifier of the first virtual machine, then the first memory index is determined based on the block offset and the minimum granularity of the memory block of the first virtual machine.
[0022] The second target memory block is determined from the memory region of the first virtual machine based on the first memory index.
[0023] Furthermore, determining the second target memory block to be released based on the memory block release request and the two-dimensional bitmap matrix includes:
[0024] If the virtual machine identifier of the memory block release request is the second identifier of the second virtual machine, then the second memory index is determined based on the block offset in the memory block release request and the minimum granularity of the memory block of the second virtual machine.
[0025] The second target memory block is determined from the memory region of the second virtual machine based on the second memory index.
[0026] Furthermore, it also includes:
[0027] Obtain the hash table for each virtual machine, which is used to store the context information of each memory block;
[0028] When the memory block occupancy request is received, the context information of the first target memory block is recorded in the hash table of the first virtual machine;
[0029] When the memory block release request is received, the context information of the second target memory block is cleared from the hash table of the second virtual machine.
[0030] Furthermore, it also includes:
[0031] Obtain the process identifier of the target process, wherein the target process is the process occupying the first target memory block;
[0032] Insert a hash node into the hash table of the first virtual machine, the hash node including the process identifier and the index of the first target memory block;
[0033] If the target process is detected to be released or abnormally exited, the hash node in the hash table, the context information of the first target memory block, and the occupancy status of the first target memory block in the two-dimensional bitmap matrix are cleared.
[0034] Furthermore, before obtaining the two-dimensional bitmap matrix of each virtual machine, the method further includes: reading configuration parameters from the device tree of the shared memory; and constructing a two-dimensional bitmap matrix, a hash table, and a memory region for each virtual machine based on the configuration parameters.
[0035] Furthermore, the step of constructing a two-dimensional bitmap matrix, hash table, and memory region for each virtual machine based on the configuration parameters includes:
[0036] Based on the configuration parameters, the master and slave machines are determined in each virtual machine;
[0037] The host is used to construct global control information, which includes a two-dimensional bitmap matrix for each virtual machine, a hash table for each virtual machine, and a memory region corresponding to each virtual machine.
[0038] The global control information is synchronized to each slave device to construct a two-dimensional bitmap matrix, a hash table, and a corresponding memory area for each slave device.
[0039] A memory sharing device, comprising:
[0040] The acquisition module is used to acquire a two-dimensional bitmap matrix for each virtual machine, wherein the two-dimensional bitmap matrix is used to record the occupancy status of each memory block in the shared memory among the virtual machines;
[0041] The occupancy module is used to, when receiving a memory block occupancy request from the first virtual machine, determine the first target memory block to be occupied in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and update the occupancy status of the first target memory block in the two-dimensional bitmap matrix;
[0042] The release module is used to determine the second target memory block to be released based on the memory block release request and the two-dimensional bitmap matrix when it receives the memory block release request from the first virtual machine, and to clear the occupancy status of the second target memory block in the two-dimensional bitmap matrix.
[0043] An electronic device includes: a memory and a processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, causing the processor to perform the method described above.
[0044] A vehicle includes a vehicle body and an electronic device disposed in the vehicle body, the electronic device being used to perform the method described above.
[0045] A computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method described above.
[0046] The beneficial effects of this invention are:
[0047] (1) Through the memory sharing mechanism, zero-copy, low-latency direct sharing of physical memory between multiple domains is achieved;
[0048] (2) By recording the ownership and access relationship of each memory block through a two-dimensional bitmap matrix, it provides fine-grained memory block status tracking capability, which can accurately manage the allocation, access status and ownership relationship of each memory block, and avoid illegal access and memory leaks.
[0049] (3) Use hash tables to quickly locate context information, reduce traversal overhead, achieve cross-domain resource cleanup, and ensure that the system state remains consistent even when the process exits abnormally;
[0050] (4) The system parameters are dynamically configured through the device tree, and the master-slave collaborative mode is adopted to achieve lightweight initialization and synchronization, making the system configuration more flexible and a lightweight architecture that does not depend on the Hypervisor. Attached Figure Description
[0051] Figure 1 A flowchart illustrating the memory sharing method provided in an embodiment of this application;
[0052] Figure 2 This is a schematic diagram of the shared memory driver architecture provided in an embodiment of this application;
[0053] Figure 3 A schematic diagram of the layout of shared memory provided in an embodiment of this application;
[0054] Figure 4 A device initialization flowchart provided for embodiments of this application;
[0055] Figure 5 A flowchart of memory block allocation provided for embodiments of this application;
[0056] Figure 6 This is a flowchart illustrating cross-domain memory access provided in an embodiment of this application.
[0057] Figure 7 A schematic diagram of the memory sharing device provided in this application;
[0058] Figure 8 A schematic diagram of the structure of the electronic device provided in this application. Detailed Implementation
[0059] The embodiments of the present invention will be described below with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention and not for limiting the scope of protection of the present invention.
[0060] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0061] As the complexity of embedded systems increases, scenarios such as smart cockpits often require running multiple functional domains on the same hardware platform, such as Android infotainment systems, real-time instrumentation systems, and telematics boxes (T-Box) communication systems. These domains require efficient data interaction. Traditional inter-process communication mechanisms, such as sockets and message queues, suffer from multiple data copies, high latency, and significant CPU overhead, making it difficult to meet the demands for low-latency, high-throughput data sharing. Therefore, a cross-domain memory sharing scheme has been proposed in related technologies. Shared memory is an efficient inter-process communication method that enables zero-copy data transfer.
[0062] However, the shared memory mechanism in related technologies faces the following challenges when applied to multi-domain (multi-virtual machine or multi-operating system) scenarios: (1) Coarse state management: The shared memory mechanism in related technologies lacks fine-grained tracking of the usage state of memory blocks. After a memory block is allocated by a domain, other domains cannot know its current state (e.g., whether it has been released or accessed by other domains), which can easily lead to illegal access, memory leaks or dangling pointers. (2) Lack of cross-domain collaborative management: When a process in a domain exits abnormally, it may have allocated or accessed memory blocks in multiple domains. Existing solutions lack a consistent cleanup mechanism to reclaim these resources across domains, which poses a risk of inconsistent system states. (3) Rigid configuration and reliance on specific middleware: Some existing cross-domain memory sharing solutions heavily rely on the virtual machine monitor (Hypervisor) as the central management hub. This solution manages shared memory partitions through the Hypervisor and uses complex dynamic priority scheduling algorithms and DMA channel arbitration to ensure the real-time transmission of critical data. Its architecture has the following limitations: ① Centralized bottleneck: All cross-domain communication must go through the Hypervisor, which increases the data path length and software complexity. ② Limited Management Dimension: Its shared memory serves only as a data buffer, focusing on data scheduling and transmission rather than the lifecycle and state tracking of the memory resources themselves. It cannot answer the question of "who currently owns and uses a specific block of memory." ③ Limited Applicability: It heavily relies on the hypervisor and specific DMA hardware, making it difficult to port to lightweight embedded platforms without a hypervisor or with limited resources. ④ Inflexible Configuration: Expanding to new functional domains typically requires modifying the hypervisor configuration, failing to achieve driver-level plug-and-play functionality. Therefore, the industry urgently needs a lightweight cross-domain memory sharing solution that provides fine-grained state tracking and lifecycle management to overcome the shortcomings of the aforementioned technologies.
[0063] To address the aforementioned issues, this application provides a memory sharing method. Based on the shared memory mechanism, this method introduces a two-dimensional bitmap matrix to achieve fine-grained state tracking of cross-domain shared memory, enabling the system to perceive the current state of any memory block in real time, thereby avoiding risks such as illegal access and memory leaks.
[0064] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0065] Figure 1 This is a flowchart illustrating the memory sharing method provided in an embodiment of this application. Figure 1 As shown, this memory sharing method can be implemented through the following steps:
[0066] Step 110: Obtain the two-dimensional bitmap matrix for each virtual machine. The two-dimensional bitmap matrix is used to record the occupancy status of each memory block in the shared memory among the virtual machines.
[0067] Step 120: When a memory block occupancy request from the first virtual machine is received, the first target memory block to be occupied is determined in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and the occupancy status of the first target memory block is updated in the two-dimensional bitmap matrix.
[0068] Step 130: When a memory block release request is received from the first virtual machine, the second target memory block to be released is determined according to the memory block release request and the two-dimensional bitmap matrix, and the occupancy status of the second target memory block is cleared in the two-dimensional bitmap matrix.
[0069] The method provided in this embodiment can be implemented by a hardware platform that supports virtualization. For example, this hardware platform can be deployed in an electronic device of a smart vehicle.
[0070] In step 110 above, multiple independent virtual machines (VMs) can run on the virtualized hardware platform, and the shared memory between the virtual machines includes multiple memory blocks.
[0071] Shared memory is a physical memory region that can be accessed by multiple virtual machines. This physical memory region is divided into multiple memory blocks of fixed size. Among them, memory blocks participate in subsequent acquisition, querying, and release processes as the smallest unit of management.
[0072] For example, the occupancy status of each memory block includes a memory block free state, a memory block allocated state, and a memory block accessed state. Specifically, a memory block free state means that the memory block has not been allocated to a virtual machine or has not been accessed by a virtual machine; a memory block allocated state means that the memory block has been allocated to a virtual machine; and a memory block accessed state means that the memory block is currently being accessed by a virtual machine.
[0073] In the smart cockpit scenario, the virtual machine can be the aforementioned Android infotainment system, real-time instrument system, and T-Box communication system, with each virtual machine running an independent operating system instance.
[0074] In this embodiment, a driver module can be configured in each virtual machine, and the driver module is compiled and loaded with the same code in each virtual machine.
[0075] For example, Figure 2 This is a schematic diagram of the shared memory driver architecture provided in the embodiments of this application, such as... Figure 2 As shown, it includes three virtual machine functional domains: Domain A corresponds to the aforementioned real-time instrumentation system, Domain B corresponds to the aforementioned Android infotainment system, and Domain C corresponds to the aforementioned T-Box communication system. Each domain runs a shared memory driver instance. All driver instances synchronize their states through their respective shared memory device driver structures, which contain a core bitmap area. User-mode processes request and access shared memory through the interfaces provided by the driver and mark it accordingly.
[0076] In the above Figure 2 In this context, at least one two-dimensional bitmap matrix bitmaps[i][j] is maintained for each virtual machine functional domain. The element bitmaps[i][j] in the two-dimensional bitmap matrix indicates whether the memory block managed by virtual machine i is currently used by virtual machine j (e.g., allocated or accessed).
[0077] In the above Figure 2 In this context, vm0 represents the virtual machine of the real-time instrument system, vm1 represents the virtual machine of the Android infotainment system, and vm2 represents the virtual machine of the T-Box communication system. Bits 0 to 12 can correspond to a total of 13 memory blocks. bitmaps[0][0] indicates whether the memory block managed by the real-time instrument system is allocated by the real-time instrument system itself, bitmaps[0][1] indicates whether the memory block managed by the real-time instrument system is accessed by the Android infotainment system, and bitmaps[0][2] indicates whether the memory block managed by the real-time instrument system is accessed by the T-Box communication system.
[0078] In step 120 above, the first virtual machine is the virtual machine that initiates the memory block request. The memory block occupancy request is used to trigger the processing of shared memory block occupancy. The memory block occupancy request may contain information such as virtual machine identifier (id_usr) and user-mode handle (idr).
[0079] When the i-th virtual machine receives a memory block usage request from the first virtual machine, it can query the two-dimensional bitmap matrix bitmaps[i][j] of the i-th virtual machine to determine whether there is a memory block managed by it that is being used by the j-th virtual machine. Specifically, if the same bit in bitmaps[i][0], bitmaps[i][1], ..., bitmaps[i][j] (e.g., ...) is used by the j-th virtual machine, it will determine whether the memory block is being used by the j-th virtual machine. Figure 2 If none of the bits (bit0) in the memory are set (e.g., none of them are 0), then the memory block corresponding to that bit can be determined to be a free memory block. In this case, the free memory block can be identified as the first target memory block and allocated to the first virtual machine.
[0080] Alternatively, the function _set_bit(hitbit, bitmaps[0][0]) can be called to update the corresponding bit in the first virtual machine's own allocation bitmap to 1, which means that the memory block corresponding to that bit is currently in an allocated state. Here, hitbit represents that bit (e.g., bit0).
[0081] In step 130 above, the memory block release request is used to trigger the reclamation process of the occupied shared memory block. The memory block release request may include a block offset (block_offset), which is used to calculate the hitbit mentioned above, i.e., the characteristic bit set to 1 (e.g., bit 0). The second target memory block represents the memory block to be reclaimed determined in this release process based on the request content and the two-dimensional bitmap matrix. It can be a specific memory block or a group of contiguous memory blocks.
[0082] For example, assuming that the second target memory block to be released is exactly the first target memory block mentioned above, the __clear_bit(hitbit, bitmaps[0][0]) function can be called directly to clear the occupied state of the second target memory block in the two-dimensional bitmap matrix and update the corresponding bit of the first virtual machine's own allocated bitmap to 0. At this time, it means that the memory block corresponding to the bit is in the memory block free state.
[0083] The memory sharing method provided in this application maintains the occupancy status of each memory block in the shared memory by constructing a two-dimensional bitmap matrix. This allows the occupancy relationship of each memory block in the shared memory to be tracked, confirmed, and reclaimed block by block. In this way, the state record is kept consistent with the actual occupancy relationship in the scenario where multiple virtual machines concurrently access the same shared physical memory, thus avoiding illegal access, memory leaks, or dangling pointers.
[0084] Before introducing how to determine the target memory block and how to update its occupancy status, we will first introduce the preliminary preparations through some examples. As mentioned above, related technologies use a hypervisor to manage shared memory partitions. All cross-domain communication must go through the hypervisor, increasing data path length and software complexity, and creating a centralized bottleneck. To address this issue, some implementations can read configuration parameters from the shared memory device tree, parse these parameters to distinguish the virtual machine's role (e.g., whether there is a host and multiple slaves among these virtual machines), and construct a two-dimensional bitmap matrix, hash table, and memory region for each virtual machine based on the configuration parameters.
[0085] The hash table is used to quickly locate and record the specific context information (such as process ID and task name) of each used memory block. Each virtual machine has a corresponding hash table to record the context information of each memory block in the memory region of each virtual machine.
[0086] In this implementation, the configuration parameters are first parsed from the shared memory device tree nodes, and the memory region boundary for each virtual machine is calculated accordingly. Then, the memory region is discretized into multiple manageable memory blocks according to the smallest granularity of the memory block. Subsequently, a two-dimensional bitmap matrix is established, with the bit values in the matrix used to record the occupancy status of the corresponding memory block. Simultaneously, a hash table is established for each virtual machine. The hash table uses a chained hash structure or an open addressing structure to store the mapping relationship between memory block indices and context information, facilitating rapid location of block status and associated process information. The memory regions are divided according to the starting address and length defined in the device tree, and correspond one-to-one with the two-dimensional bitmap matrix and hash table, enabling virtual machines to manage memory block occupancy, access, and release within their respective resource boundaries.
[0087] This embodiment achieves dynamic parameter configuration through device tree driving, enabling a flexible and lightweight architecture that does not depend on the hypervisor.
[0088] Furthermore, in some implementations, system initialization can be performed based on the above configuration parameters to determine which virtual machine is the master and which virtual machines are slaves. Then, global control information is constructed through the master and synchronized to each slave to construct a two-dimensional bitmap matrix, a hash table, and a corresponding memory area for each slave.
[0089] The global control information includes a two-dimensional bitmap matrix for each virtual machine, a hash table for each virtual machine, and a memory region corresponding to each virtual machine.
[0090] In this embodiment, during system initialization, a global control information structure is created at the beginning of the reserved physical memory area to record global information such as the total number of virtual machines participating in the sharing, memory block size, and host status. A corresponding virtual machine information structure is created for each virtual machine to record its exclusive physical memory range, number of blocks, etc.
[0091] The system parameters are dynamically configured through a device tree, and one virtual machine is designated as the host to initialize the global structure, while other virtual machines are designated as slaves for synchronization and mapping.
[0092] Host VM Role: The device tree node contains the `host-role` attribute. The host is responsible for initializing global control information (`dsm_control_info`) in shared memory and configuring dedicated memory region information (`dsm_vm_info`) for each virtual machine. The host is typically the virtual machine that is started first (e.g., in an instrumentation domain).
[0093] Slave VM: The device tree node does not contain the host-role attribute. After startup, the slave VM maps the shared memory region that the host has prepared, waits for the host to be ready, and then completes its own initialization.
[0094] For example, Figure 3 This is a schematic diagram of the layout of shared memory provided in an embodiment of this application, as shown below. Figure 3 As shown, the shared memory layout is determined by the host during the initialization phase and written into the global control information structure `dsm_control_info` for all slave devices to read. The shared memory layout and data structure design are as follows:
[0095] a) Global Control Information Area (DCI): This area is described by the struct dsm_control_info structure, which contains fields such as version number, magic number, number of virtual machines, block size, offset of each virtual machine, total memory size, and host status flags.
[0096] b) Virtual Machine Information Area (DVI): Following the Control Information Area, it consists of multiple consecutively arranged `struct dsm_vm_info` structures, describing the physical memory range exclusively occupied by this virtual machine (start address, end address, block size, number of blocks), and also embedding a two-dimensional bitmap matrix. This two-dimensional bitmap matrix is a two-dimensional bitmap array with dimensions [vm_num][vm_num]. `bitmaps[i][j]` represents the block bitmaps in the memory region managed by virtual machine i that are occupied (allocated or marked for access) by virtual machine j. Each structure corresponds to a virtual machine (numbered 0 to vm_num-1).
[0097] Specifically, for virtual machine i: bitmaps[i][i] records the memory blocks allocated (Allocated) by virtual machine i itself. bitmaps[i][j] (i≠j) records the memory blocks of virtual machine i that are marked as accessed (Attached) by virtual machine j. This matrix bitmap design allows any virtual machine to directly know the cross-domain occupancy status of any memory block by querying the bitmap in the shared memory, without the need for additional cross-VM message interaction.
[0098] For example, Figure 4 The device initialization flowchart provided in the embodiments of this application is as follows: Figure 4 As shown, the initialization of the host VM includes the following process:
[0099] a) Parsing device tree basic parameters: The host driver first obtains the following key parameters through the device node: vm_num (the total number of virtual machines participating in sharing in the system), host-name (host name), block-size (the smallest granularity of memory allocation), and control (a pointer to a reserved memory node describing control information).
[0100] b) Mapping global control information memory: After the host reads the physical address and size of the control node, it maps it to the kernel virtual address space and fills the DCI global control information area members, which include: vm_num, block_size, phy_start_addr and size (the physical range of the entire shared memory block), host_state (as a synchronization signal for the slave to start initialization);
[0101] c) Initialize the information area of each virtual machine: The host traverses vm_num times, performing the following operations for each virtual machine i: Calculate the address of the i-th virtual machine information structure dvi based on the structure size (calculation formula: dvi = dci pointer address + control information structure size + i * planned size of each dvi structure); then read the device tree and fill in the reserved memory information belonging to this virtual machine, phy_start_addr, end_addr, and block_num (number of blocks). Finally, mark dvi->state = VM_SLAVE_READY, indicating that the slave's information configuration is complete.
[0102] d) Initialize the bitmap matrix pointer: Maintain a pointer array dsmdev->bitmaps[i][j] locally on the host (address calculation formula: DVI pointer address + planned size of each DVI structure + j * the maximum number of bits that each bitmap can store), and make it point to the shared memory of global control information, so that any virtual machine can obtain the status of the memory to be allocated by querying the bitmap in the shared memory.
[0103] e) Allocate a host-side hash table: Allocate a kernel hash table hash_table[i] for itself to record information about blocks requested or accessed by the current host from other virtual machines (including which process and which user handle occupied which block). This hash table exists only in the private memory of each virtual machine and is not shared.
[0104] Based on the above steps, the host writes the complete shared memory layout information to physical memory and sets host_state to VM_HOST_READY. Once the slave detects that the host is ready, it can begin the slave initialization process.
[0105] Continue to refer to the above. Figure 4 Slave VM initialization:
[0106] a) Mapping Global Control Information Memory: After reading the physical address and size of the control node, the host maps it to a kernel virtual address to obtain the DCI global control information. At this point, the host state (host_state) is checked. If the state is VM_HOST_READY, the initialization process continues; otherwise, it waits one second and retryes. If it is not ready after a timeout (e.g., more than 3 seconds), the initialization fails. This mechanism ensures that the host completes memory layout initialization first. If initialization is successful, various information about the host initialization can be obtained, such as vm_num, block_size, phy_start_addr, size, and host_state.
[0107] b) Locate each virtual machine information area and establish a local view: The slave machine maps the information structure dvi of each virtual machine in the same way. For each virtual machine i, the slave machine performs the following: establish a local bitmap pointer array bitmaps[i][j], pointing to the corresponding bitmap area in shared memory, allocate its own hash table hash_table[i], and clear the corresponding bitmaps[i][local ID] area.
[0108] After the slave device completes the above steps, it establishes a complete view of the shared memory with the host and other virtual machines, and can begin to respond to memory block occupancy requests and memory block release requests from user space.
[0109] The following examples detail how to determine the target memory block and how to update and maintain the occupancy status of the target memory block.
[0110] In some implementations, the virtual machine identifier in the memory block occupancy request can be read; if the virtual machine identifier is the first identifier of the first virtual machine, then a free memory block is selected in the memory region of the first virtual machine according to the two-dimensional bitmap matrix of the first virtual machine, and determined as the first target memory block; then the first target memory block is allocated to the first virtual machine; and the occupancy status of the first target memory block is updated to the memory block allocation status.
[0111] This implementation mainly introduces scenario one: the case where the local machine requests its own memory block allocation (Alloc, i.e., id_usr == local machine ID). For ease of explanation, the first virtual machine is referred to as the local machine, and the local machine ID is used to represent the first identifier of the first virtual machine.
[0112] If a local machine needs to request a free memory block from its own dedicated memory region, it can initiate a memory block allocation request, specifying the virtual machine identifier (id_usr = local machine ID) in the request. The virtual machine identifier in the memory block allocation request is the primary identifier. The subsequent process for the local machine to request its own memory block allocation is as follows:
[0113] a) Find free memory blocks: Call the find_first_all_zero_bit function, and check the three two-dimensional bitmap matrices of the local machine: bitmaps[local ID][METER], bitmaps[local ID][ANDROID], and bitmaps[local ID][TBOX].
[0114] Among them, the local ID can be = METER, where METER is the number 0, representing the virtual machine of the real-time instrument system; ANDROID is the number 1, representing the virtual machine of the Android infotainment system; TBOX is the number 2, representing the virtual machine of the T-Box communication system.
[0115] The `find_first_all_zero_bit` function searches for the first bit in each of the three two-dimensional bitmap matrices that is all zero. This means that the memory block corresponding to this bit has neither been allocated by the native machine nor marked for access by any other virtual machine.
[0116] For example, Figure 5 The memory block allocation flowchart provided in the embodiments of this application is as follows: Figure 5 As shown, the user initiates a memory request operation through the ioctl command in step ①; and in step ②, the user finds the bit (i.e., bit0) in the first three bitmap matrices where all corresponding bits are 0, which is considered a free memory block.
[0117] b) Out-of-bounds check: If the found bit index hitbit is greater than or equal to the total number of blocks on the local machine block_num, then return a no-memory error.
[0118] When the first bit 0 in the three two-dimensional bitmap matrices (i.e., bitmaps[0][0], bitmaps[0][1] and bitmaps[0][2]) is all zero, the memory block corresponding to the bit 0 can be regarded as a free memory block.
[0119] c) Update the local machine's two-dimensional bitmap matrix and hash table: Call the __set_bit(hitbit, bitmaps[local ID][local ID]) function to set the corresponding bit (i.e., bit0 above) in the local machine's own two-dimensional bitmap matrix to 1; call the dsm_insert_hash_node function to insert a record into the local machine's hash table hash_table[local ID], which contains information such as hitbit, idr, process identifier (PID) and process name.
[0120] d) Return block offset: Calculate the block offset block_offset=hitbit*block_size and return it to the user space via copy_to_user for subsequent mmap use.
[0121] This implementation uses a two-dimensional bitmap matrix to perform fine-grained marking of specific memory blocks in the first virtual machine memory region. The allocation results and status updates are completed synchronously, thereby keeping the occupancy information in the shared memory consistent and providing an accurate state basis for subsequent release, query and cross-domain scheduling.
[0122] Furthermore, in some implementations, if the virtual machine is identified as the second identifier of the second virtual machine, then the first target memory block is determined in the memory region of the second virtual machine according to the two-dimensional bitmap matrix of the second virtual machine; and the occupancy status of the first target memory block is updated to the memory block accessed status.
[0123] This implementation mainly introduces scenario two: cross-domain access to memory and marking (attach, i.e., id_usr ≠ local ID, but id_usr = second identifier). For ease of explanation, the first virtual machine is referred to as the local machine, the local ID is used to represent the first identifier of the first virtual machine, and the second virtual machine is referred to as the virtual machine accessed across domains.
[0124] If the local machine needs to access a memory block in a memory region exclusively occupied by the second virtual machine across domains, the local machine can also initiate a memory block acquisition request and provide the virtual machine identifier (id_usr) in the memory block acquisition request. Figure 6 The flowchart for cross-domain memory access provided in the embodiments of this application is as follows: Figure 6 As shown, it includes at least two steps: Step ① The user initiates a memory access marking operation via the ioctl command; Step ② Locates and marks the first target memory block based on the passed block_offset. The specific cross-domain access process is as follows:
[0125] a) Calculate the target block index: Calculate the hitbit based on the block offset (block_offset) in the user's memory block allocation request, using the formula (block_offset / block_size). Here, the memory block corresponding to the hitbit is the first target memory block, and block_size represents the smallest granularity of memory allocation.
[0126] b) Permission verification: Check if the hitbit in the two-dimensional bitmap matrix bitmaps[id_usr][id_usr] allocated by the second virtual machine is 1. Only blocks that have been allocated (Allocated) by the second virtual machine are allowed to be accessed by other virtual machines; if not allocated, an error is returned.
[0127] c) Update bitmap and hash table: Call __set_bit(hitbit, bitmaps[id_usr][local ID]) to mark the local machine as accessing the first target memory block in the two-dimensional bitmap matrix of the second virtual machine; call dsm_insert_hash_node to insert the process's idr into the local hash table hash_table[id_usr].
[0128] d) User access to memory: After a successful operation, the user space can use block_offset, which can be further mapped to the address space of the current process via mmap.
[0129] This implementation marks the first target memory block as accessed when the second virtual machine initiates an access request. This allows the two-dimensional bitmap matrix to continuously reflect the actual access relationships of shared memory, thereby ensuring consistency in memory block location, status updates, and subsequent management. Since the selection of the first target memory block directly depends on the two-dimensional bitmap matrix of the second virtual machine, the system has a more granular recording capability for the access boundaries and occupancy relationships of different virtual machines. Therefore, it can improve the accuracy of shared memory status tracking and ensure that cross-domain memory management results are consistent with actual access behavior.
[0130] In some implementations, for memory block release, the virtual machine identifier and block offset in the memory block release request can be read. If the virtual machine identifier in the memory block release request is the first identifier of the first virtual machine, the first memory index is determined based on the block offset and the minimum granularity of the memory block of the first virtual machine. Then, the second target memory block is determined in the memory region of the first virtual machine based on the first memory index.
[0131] The release of memory blocks is divided into two cases: local release and removal of cross-domain access flags. This implementation describes the local release operation. In this case, user space initiates the release operation through the ioctl command DSM_FREE_BLOCK or DSM_UNATTCH_BLOCK, and the core processing function is dsm_dispose_block.
[0132] For scenario three: local release (Free, i.e., id_usr == local ID), the specific process is as follows:
[0133] a) Calculate the target block index: Calculate the hitbit (i.e., the first memory index mentioned in this implementation) based on the block offset block_offset passed by the user. The calculation formula is: hitbit = block_offset / block_size;
[0134] b) Update bitmap and hash table: Call the dsm_delete_nodeh function to remove the record of the corresponding process IDR from the local hash table hash_table[local ID], and call the __clear_bit(hitbit, bitmaps[local ID][local ID]) function to clear the local allocation bitmap. At this time, the second target memory block becomes free. After other VMs no longer access the memory block, the memory block can be reallocated.
[0135] In this implementation, memory block release requests can be directly mapped to a second target memory block in the first virtual machine memory region through the virtual machine identifier and block offset, reducing release positioning errors and ensuring that the clearing of the occupied state is consistent with the actual reclamation of the memory block, thereby improving the accuracy of shared memory state recording.
[0136] Furthermore, the removal of cross-domain access markers during memory block release is described below through another implementation method. In this implementation, the second target memory block can be determined as follows: if the virtual machine identifier in the memory block release request is the second identifier of the second virtual machine, then the second memory index is determined based on the block offset and the minimum granularity of the memory block of the second virtual machine; based on the second memory index, the second target memory block is determined in the memory region of the second virtual machine.
[0137] In this implementation, for scenario four: removing the access marker (Unattach, i.e., id_usr ≠ local ID), it can be achieved through the following steps:
[0138] a) Calculate the target block index: Calculate the hitbit (i.e., the second memory index in this embodiment) based on the block_offset passed by the user. The calculation formula is hitbit=block_offset / block_size. The memory block corresponding to the hitbit is the second target memory block.
[0139] b) Update bitmap and hash table: Call dsm_delete_node to remove the record of the corresponding process idr from the local hash table hash_table[local ID], and call __clear_bit(hitbit, bitmaps[id_usr][local ID]) to clear the bitmap. At this time, it only means that the local machine will no longer access the second target memory block.
[0140] In this implementation, after a memory block release request arrives, the block offset can be directly mapped to the target block location result within the second virtual machine. Then, the release confirmation is completed by combining the corresponding status record in the two-dimensional bitmap matrix. Since the second memory index corresponds one-to-one with the memory region of the second virtual machine, the specific memory block to be released can still be accurately located even when multiple virtual machines are concurrently occupying the shared memory. This ensures that the subsequent state clearing of the two-dimensional bitmap matrix is consistent with memory reclamation, thereby improving the release positioning accuracy and state maintenance consistency of cross-virtual machine shared memory.
[0141] As mentioned above, each virtual machine has a corresponding hash table to record the context information of each virtual machine's memory blocks. For example, the context information may include the process ID and task name occupying the memory block. In some embodiments, when a memory block is allocated, accessed, or released, its context information also needs to be updated simultaneously. The specific update process can be divided into the following two cases:
[0142] (1) When a memory block occupancy request is received, the context information of the first target memory block is recorded in the hash table of the first virtual machine;
[0143] (2) When a memory block release request is received, the context information of the second target memory block is cleared in the hash table of the second virtual machine.
[0144] Upon receiving a memory block occupancy request, the system first determines the first target memory block based on the virtual machine identifier or block offset carried in the request. Then, it writes the context information corresponding to the first target memory block into the hash table of the first virtual machine. This context information may include the first target memory block currently occupied by the first virtual machine, the source of the occupation, and associated resource information, thereby ensuring that the hash table remains consistent with the occupancy status in the two-dimensional bitmap matrix.
[0145] Upon receiving a memory block release request, the system determines the second target memory block based on the virtual machine identifier and block offset in the memory block release request, and clears the context information corresponding to the second target memory block from the hash table of the second virtual machine.
[0146] The cleanup operation can be either deleting a table entry or invalidating the entry and synchronously reclaiming the associated fields, so that the hash table no longer retains any trace of the memory block's occupancy after the memory block is released. Because the hash table stores the memory block's context information, in scenarios such as abnormal exit, duplicate release, or cross-virtual machine synchronization, the historical associations of the target memory block can still be quickly identified based on the table entry content, and the cleanup can be completed by matching it with the memory block release request.
[0147] This embodiment records and clears memory block context information in the hash table corresponding to each virtual machine. This allows the system to fine-grained bind of memory block allocation, access, and release states, forming a dual verification relationship with a two-dimensional bitmap matrix. This makes memory block state tracking more accurate when multiple virtual machines share physical memory, and allows for timely cleanup of residual information after release, thereby improving the consistency and operational stability of shared memory management.
[0148] Furthermore, in some implementations, when a memory block occupancy request is detected, the process identifier of the target process is obtained; a hash node is inserted into the hash table of the first virtual machine; if the target process is detected to be released or abnormally exited, the hash node, the context information of the first target memory block, and the occupancy status of the first target memory block are cleared.
[0149] The target process is the process that occupies the first target memory block, and the hash node includes the process identifier and the index of the first target memory block.
[0150] This implementation method mainly introduces the clearing of memory block release or access status:
[0151] When releasing a local memory block or ending access to a cross-domain memory block, the bitmap index is calculated based on the virtual machine ID and block offset, the corresponding bitmap bits (bitmaps[self][self] or bitmaps[target][self]) are cleared, and the relevant node is deleted from the hash table of the corresponding virtual machine.
[0152] Specifically, to prevent shared memory block leaks caused by abnormal user process exits, a user handle management and exception handling mechanism based on IDR (IDRadix) is introduced, as follows:
[0153] a) Handle Allocation (DSM_ALLOC_IDR): After a user process opens the device, it first requests a globally unique integer IDr via ioctl. This ID is allocated by the kernel's IDR mechanism and bound to the current process;
[0154] b) Handle-to-block binding: When allocating or marking memory block access, the user must pass a valid IDR. The driver records the IDR along with the corresponding hitbit in a hash table node;
[0155] c) Handle Release and Cleanup (DSM_FREE_IDR): When a user process actively releases the IDR or the process exits, causing the file descriptor to close, the driver calls the remove_info_for_each_hashlist function. This function iterates through all hash tables of the current virtual machine, deletes all nodes that match the IDR, and synchronously clears the corresponding bits in the shared memory bitmap (clearing the allocation bit if it is a block allocated locally, and clearing the marking bit if it is a block marked for access).
[0156] The cleanup mechanism provided in this implementation ensures that the shared memory resources occupied by a process can be reclaimed in a timely manner, regardless of whether the process exits normally or crashes, thus guaranteeing the robustness of the system.
[0157] Figure 7 A schematic diagram of the structure of the memory sharing device provided in this application is shown below. Figure 7 As shown, the memory sharing device 70 provided in this embodiment includes:
[0158] The acquisition module 701 is used to acquire the two-dimensional bitmap matrix of each virtual machine. The two-dimensional bitmap matrix is used to record the occupancy status of each memory block in the shared memory between virtual machines.
[0159] The occupancy module 702 is used to, when receiving a memory block occupancy request from the first virtual machine, determine the first target memory block to be occupied in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and update the occupancy status of the first target memory block in the two-dimensional bitmap matrix.
[0160] The release module 703 is used to determine the second target memory block to be released based on the memory block release request and the two-dimensional bitmap matrix when a memory block release request is received from the first virtual machine, and to clear the occupancy status of the second target memory block in the two-dimensional bitmap matrix.
[0161] Optionally, the occupancy status of a memory block includes the memory block free status, the memory block allocated status, and the memory block accessed status.
[0162] Optionally, the occupying module can be specifically used for:
[0163] Read the virtual machine identifier from the memory block occupancy request;
[0164] If the virtual machine identifier is the first identifier of the first virtual machine, then according to the two-dimensional bitmap matrix of the first virtual machine, a free memory block is selected in the memory region of the first virtual machine and determined as the first target memory block;
[0165] Allocate the first target memory block to the first virtual machine;
[0166] Update the occupied status of the first target memory block to the allocated status.
[0167] Optionally, the occupancy module can be specifically used to: if the virtual machine identifier in the memory block occupancy request is the second identifier of the second virtual machine, then determine the first target memory block in the memory region of the second virtual machine according to the two-dimensional bitmap matrix of the second virtual machine; and update the occupancy status of the first target memory block to the memory block accessed status.
[0168] Optionally, the release module can be specifically used for:
[0169] Read the virtual machine identifier and block offset from the memory block release request;
[0170] If the virtual machine identifier in the memory block release request is the first identifier of the first virtual machine, then the first memory index is determined based on the block offset and the minimum granularity of the memory block of the first virtual machine.
[0171] The second target memory block is determined from the memory region of the first virtual machine based on the first memory index.
[0172] Optionally, the release module can be specifically used to: if the virtual machine identifier of the memory block release request is the second identifier of the second virtual machine, then determine the second memory index based on the block offset in the memory block release request and the minimum granularity of the memory block of the second virtual machine; and determine the second target memory block from the memory region of the second virtual machine based on the second memory index.
[0173] Optionally, the memory-sharing device also includes a hash table building module for:
[0174] Obtain the hash table for each virtual machine; the hash table is used to store the context information of each memory block.
[0175] When a memory block occupancy request is received, the context information of the first target memory block is recorded in the hash table of the first virtual machine;
[0176] When a memory block release request is received, the context information of the second target memory block is cleared from the hash table of the second virtual machine.
[0177] Optionally, the memory-sharing device further includes a cleanup module for:
[0178] Obtain the process ID of the target process, which is the process occupying the first target memory block;
[0179] Insert a hash node into the hash table of the first virtual machine. The hash node includes the process identifier and the index of the first target memory block.
[0180] If the target process is detected to be released or exited abnormally, the hash nodes in the hash table, the context information of the first target memory block, and the occupancy status of the first target memory block in the two-dimensional bitmap matrix are cleared.
[0181] Optionally, the memory sharing device also includes a configuration module for reading configuration parameters from the device tree of the shared memory; and constructing a two-dimensional bitmap matrix, hash table, and memory region for each virtual machine based on the configuration parameters.
[0182] Optionally, the configuration module is specifically used for:
[0183] Based on configuration parameters, the master and slave devices are determined in each virtual machine;
[0184] Global control information is constructed using the host, which includes a two-dimensional bitmap matrix for each virtual machine, a hash table for each virtual machine, and a memory region corresponding to each virtual machine.
[0185] Global control information is synchronized to each slave device to construct a two-dimensional bitmap matrix, a hash table, and a corresponding memory area for each slave device.
[0186] The memory sharing device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.
[0187] Figure 8 A schematic diagram of the structure of the electronic device provided in this application. Figure 8 As shown, the electronic device 80 provided in this embodiment includes at least one processor 801 and a memory 802. Optionally, the electronic device 80 further includes a communication component 803. The processor 801, memory 802, and communication component 803 are connected via a bus.
[0188] In a specific implementation, at least one processor 801 executes computer execution instructions stored in memory 802, causing at least one processor 801 to perform the above-described method.
[0189] The specific implementation process of processor 801 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0190] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0191] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.
[0192] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0193] This application also provides a vehicle, which includes a vehicle body and an electronic device disposed in the vehicle body. The electronic device may be the cockpit domain controller mentioned above, used to perform the steps of the above method.
[0194] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0195] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.
[0196] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0197] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0198] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0199] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0200] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0201] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0202] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0203] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
[0204] The above embodiments are merely preferred embodiments provided to fully illustrate the present invention, and the scope of protection of the present invention is not limited thereto. Equivalent substitutions or modifications made by those skilled in the art based on the present invention are all within the scope of protection of the present invention.
Claims
1. A memory sharing method, characterized in that, include: Obtain a two-dimensional bitmap matrix for each virtual machine, which is used to record the occupancy status of each memory block in the shared memory among the virtual machines; When a memory block occupancy request from the first virtual machine is received, the first target memory block to be occupied is determined in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and the occupancy status of the first target memory block is updated in the two-dimensional bitmap matrix. When a memory block release request is received from the first virtual machine, a second target memory block to be released is determined based on the memory block release request and the two-dimensional bitmap matrix, and the occupancy status of the second target memory block is cleared in the two-dimensional bitmap matrix.
2. The method according to claim 1, characterized in that, The memory block occupancy status includes memory block free status, memory block allocated status, and memory block accessed status.
3. The method according to claim 2, characterized in that, The step of determining the first target memory block to be occupied in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and updating the occupancy status of the first target memory block in the two-dimensional bitmap matrix, includes: Read the virtual machine identifier from the memory block occupancy request; If the virtual machine identifier is the first identifier of the first virtual machine, then according to the two-dimensional bitmap matrix of the first virtual machine, a free memory block is selected in the memory region of the first virtual machine and determined as the first target memory block; Allocate the first target memory block to the first virtual machine; Update the occupied status of the first target memory block to the allocated status of the memory block.
4. The method according to claim 2, characterized in that, The step of determining the first target memory block to be occupied in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and updating the occupancy status of the first target memory block in the two-dimensional bitmap matrix, includes: If the virtual machine identifier in the memory block occupancy request is the second identifier of the second virtual machine, then the first target memory block is determined in the memory region of the second virtual machine according to the two-dimensional bitmap matrix of the second virtual machine. Update the occupied status of the first target memory block to the accessed status of the memory block.
5. The method according to claim 1, characterized in that, The step of determining the second target memory block to be released based on the memory block release request and the two-dimensional bitmap matrix includes: Read the virtual machine identifier and block offset from the memory block release request; If the virtual machine identifier in the memory block release request is the first identifier of the first virtual machine, then the first memory index is determined based on the block offset and the minimum granularity of the memory block of the first virtual machine. The second target memory block is determined from the memory region of the first virtual machine based on the first memory index.
6. The method according to claim 1, characterized in that, The step of determining the second target memory block to be released based on the memory block release request and the two-dimensional bitmap matrix includes: If the virtual machine identifier of the memory block release request is the second identifier of the second virtual machine, then the second memory index is determined based on the block offset in the memory block release request and the minimum granularity of the memory block of the second virtual machine. The second target memory block is determined from the memory region of the second virtual machine based on the second memory index.
7. The method according to any one of claims 1-6, characterized in that, Also includes: Obtain the hash table for each virtual machine, which is used to store the context information of each memory block; When the memory block occupancy request is received, the context information of the first target memory block is recorded in the hash table of the first virtual machine; When the memory block release request is received, the context information of the second target memory block is cleared from the hash table of the second virtual machine.
8. The method according to claim 7, characterized in that, Also includes: Obtain the process identifier of the target process, wherein the target process is the process occupying the first target memory block; Insert a hash node into the hash table of the first virtual machine, the hash node including the process identifier and the index of the first target memory block; If the target process is detected to be released or abnormally exited, the hash node in the hash table, the context information of the first target memory block, and the occupancy status of the first target memory block in the two-dimensional bitmap matrix are cleared.
9. The method according to any one of claims 1-6, characterized in that, Before obtaining the two-dimensional bitmap matrix for each virtual machine, the method further includes: Read configuration parameters from the device tree of the shared memory; Based on the configuration parameters, a two-dimensional bitmap matrix, hash table, and memory region are constructed for each virtual machine.
10. The method according to claim 9, characterized in that, The step of constructing a two-dimensional bitmap matrix, hash table, and memory region for each virtual machine based on the configuration parameters includes: Based on the configuration parameters, the master and slave machines are determined in each virtual machine; The host is used to construct global control information, which includes a two-dimensional bitmap matrix for each virtual machine, a hash table for each virtual machine, and a memory region corresponding to each virtual machine. The global control information is synchronized to each slave device to construct a two-dimensional bitmap matrix, a hash table, and a corresponding memory area for each slave device.
11. A memory sharing device, characterized in that, include: The acquisition module is used to acquire a two-dimensional bitmap matrix for each virtual machine, wherein the two-dimensional bitmap matrix is used to record the occupancy status of each memory block in the shared memory among the virtual machines; The occupancy module is used to, when receiving a memory block occupancy request from the first virtual machine, determine the first target memory block to be occupied in each memory block according to the memory block occupancy request and the two-dimensional bitmap matrix, and update the occupancy status of the first target memory block in the two-dimensional bitmap matrix; The release module is used to determine the second target memory block to be released based on the memory block release request and the two-dimensional bitmap matrix when it receives the memory block release request from the first virtual machine, and to clear the occupancy status of the second target memory block in the two-dimensional bitmap matrix.
12. An electronic device, characterized in that, include: Memory and processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-10.
13. A vehicle, characterized in that, include: A vehicle body and an electronic device disposed therein, the electronic device being used to perform the method as described in any one of claims 1-10.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by an electronic device, are used to implement the method as described in any one of claims 1-10.
