Equipment memory expansion method and device, equipment and storage medium
By dividing the hardware device memory into memory subblocks and creating memory swap areas, the problems of low flexibility and reduced processing efficiency caused by insufficient hardware device memory are solved, and virtual expansion of device memory and resource utilization are improved.
Patent Information
- Application Number
- CN202411721099.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-03-18
AI Technical Summary
When traditional hardware devices are insufficient memory, they need to replace the device to expand the memory, resulting in low flexibility and reduced processing efficiency.
By dividing the hardware device memory into preset memory subblocks, generating device memory blocks, creating memory swap areas, allocating device memory blocks to process data pending with user processes, realizing virtual expansion of device memory.
There is no need to upgrade physical hardware devices, quickly realize virtual expansion of device memory, improve hardware resource utilization and device processing efficiency, and is suitable for scenarios where hardware devices are not convenient to replace.
Smart Images

Figure CN119645639A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of memory management technology, and in particular to a device memory expansion method, apparatus, device and storage medium. Background Art
[0002] With the continuous development of computers and hardware devices, hardware peripherals can be used to execute more, larger, and more complex application scenarios, which further leads to the emergence of scenarios in which multiple access terminals request the use of devices, which places higher requirements on the processing power and memory capacity of hardware peripherals.
[0003] In the traditional processing method, when the hardware device memory is insufficient when requesting device use, it is usually necessary to upgrade the hardware device to meet resource requirements. Since the hardware device parameter configuration is usually fixed, users usually need to choose to replace the hardware device to expand the memory.
[0004] However, the method of replacing a device has low flexibility and requires time to replace the device, which may cause the device to be less efficient in processing user processes. Summary of the invention
[0005] In order to help solve the problem that the flexibility of replacing devices is low and it takes time to replace devices, which leads to reduced efficiency of the device when processing user processes, the present application provides a device memory expansion method, apparatus, device and storage medium.
[0006] In a first aspect, the present application provides a device memory expansion method, which adopts the following technical solution: the method is applied to a device memory expansion system, the device memory expansion system includes a hardware device unit, and the method includes:
[0007] Dividing the memory of the hardware device unit into memory sub-blocks of a preset size to generate a plurality of device memory blocks;
[0008] Acquire the user process data to be processed and create a memory swap area, and cache the user process data to be processed in the memory swap area;
[0009] Allocate a device memory block for the data to be processed by the user process according to the number of all the user processes obtained;
[0010] Determine whether the total memory of the device memory blocks allocated to the data to be processed by the user process satisfies the size of the data to be processed by the user process;
[0011] According to the judgment result, the user process to-be-processed data in the memory swap area is transferred to the corresponding device memory block for processing.
[0012] In a specific implementation scheme, caching the user process to-be-processed data to the memory swap area includes:
[0013] Creating a number of virtual memory blocks according to the memory size of the device memory block;
[0014] Dividing the to-be-processed data of the user process into sub-data blocks according to the memory size of the virtual memory block, and caching the sub-data blocks into the virtual memory block to obtain an occupied virtual memory block;
[0015] The occupied virtual memory block is cached in the memory swap area.
[0016] In a specific implementation scheme, transferring the user process to-be-processed data in the memory swap area to the corresponding device memory block for processing according to the judgment result includes:
[0017] If the total memory of the device memory blocks allocated for the data to be processed by the user process meets the size of the data to be processed by the user process, the occupied virtual memory blocks are mapped to the device memory blocks corresponding to the user process for processing;
[0018] If the total memory of the device memory blocks allocated for the data to be processed by the user process does not meet the size of the data to be processed by the user process, the occupied virtual memory blocks are mapped in batches to the device memory blocks corresponding to the user process for processing.
[0019] In a specific implementation scheme, mapping the occupied virtual memory block to a device memory block corresponding to the user process for processing includes:
[0020] Loading the sub-data block of the occupied virtual memory block into the device memory block corresponding to the user process for processing;
[0021] The sub-data block is loaded from the virtual memory block to the device memory block by using a DMA transmission method.
[0022] In a specific implementation scheme, mapping the occupied virtual memory blocks in batches to device memory blocks corresponding to the user processes for processing includes:
[0023] Divide the occupied virtual memory blocks into several processing batches according to the device memory blocks allocated by the user process for the data to be processed, determine the virtual memory blocks to be processed in the current batch and set them as the current memory blocks to be processed;
[0024] Loading the sub-data blocks of the current memory block to be processed into the corresponding device memory block for processing;
[0025] Determine whether the sub-data blocks in the current memory block to be processed have been processed;
[0026] If the processing is completed, the sub-data blocks of the next batch of virtual memory blocks to be processed are loaded into the corresponding device memory blocks for processing until all the data to be processed by the user process are processed.
[0027] In a specific implementation scheme, the device memory expansion system further includes a device memory management unit, and determining the current batch of virtual memory blocks to be processed and setting them as current memory blocks to be processed includes:
[0028] Creating a memory processing status table while creating the memory exchange area, the memory processing status table including the correspondence between the virtual memory block and the device memory block, and the execution status of the virtual memory block;
[0029] Controlling the device memory management unit to search for the unexecuted occupied virtual memory block according to the memory processing status table to obtain the unexecuted memory block;
[0030] The device memory block allocated to the data to be processed by the user process is set as the hardware execution memory block;
[0031] The unexecuted memory blocks having the same number as the hardware execution memory blocks are sequentially determined as the virtual memory blocks to be processed in the current batch, and are set as the current memory blocks to be processed.
[0032] In a specific possible implementation scheme, before loading the sub-data blocks of the next batch of virtual memory blocks to be processed into the corresponding device memory blocks for processing, the method further includes:
[0033] Release the occupied virtual memory block corresponding to the processed sub-data block and mark it as executed;
[0034] The execution status of the virtual memory block in the memory usage table is updated.
[0035] In a second aspect, the present application provides a device memory expansion apparatus, which adopts the following technical solution: the apparatus is applied to a device memory expansion system, the device memory expansion system includes a hardware device unit, and the apparatus includes:
[0036] A memory block division module, used for dividing the memory of the hardware device unit into memory sub-blocks of a preset size to generate a plurality of device memory blocks;
[0037] A process data cache module, used to obtain the user process data to be processed and create a memory swap area, and cache the user process data to be processed in the memory swap area;
[0038] A memory block allocation module, used for allocating device memory blocks for the data to be processed by the user processes according to the number of all the acquired user processes;
[0039] A memory requirement judgment module, used to judge whether the total memory of the device memory blocks allocated to the data to be processed by the user process meets the size of the data to be processed by the user process;
[0040] The device memory processing module is used to transfer the user process to-be-processed data in the memory exchange area to the corresponding device memory block for processing according to the judgment result.
[0041] In a third aspect, the present application provides a computer device, which adopts the following technical solution: it includes a memory and a processor, and the memory stores a computer program that can be loaded by the processor and execute any of the above-mentioned device memory expansion methods.
[0042] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution: storing a computer program that can be loaded by a processor and execute any of the above-mentioned device memory expansion methods.
[0043] In summary, this application has the following beneficial technical effects:
[0044] 1. Through the design of virtual memory blocks, virtual expansion of device memory can be quickly realized without upgrading physical hardware devices, which is convenient for rapid expansion using limited resources and improves the utilization rate of hardware resources and device processing efficiency;
[0045] 2. The exchange of virtual memory blocks and the operation of hardware devices are completed at the driver layer, which is transparent to the user process and is conducive to the development of user processes;
[0046] 3. Combined with the memory block allocation strategy, the device can be allocated to multiple processes at the same time to improve the reusability of the device. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 is a flowchart of a method for expanding device memory in an embodiment of the present application;
[0048] Figure 2 It is a schematic diagram of the overall architecture of device memory expansion in an embodiment of the present application;
[0049] Figure 3 It is a flowchart of the device memory expansion architecture in an embodiment of the present application;
[0050] Figure 4 is a schematic diagram of a device memory expansion apparatus in an embodiment of the present application;
[0051] Figure 5 It is a schematic diagram used to embody a computer device in an embodiment of the present application.
[0052] Figure numerals: 401, memory block division module; 402, process data cache module; 403, memory block allocation module; 404, memory demand judgment module; 405, device memory processing module. DETAILED DESCRIPTION
[0053] The following combination Figure 1-Figure 5 This application is described in further detail.
[0054] The embodiment of the present application discloses a device memory expansion method, which is applied to a device memory expansion system. The device memory expansion method can be used to implement virtual expansion of hardware device memory. In some use scenarios where it is difficult to replace devices or for some use scenarios where the performance requirements of hardware devices are not high, the method can be used to complete the processing of one or more user processes using the original hardware device when the original hardware device memory does not meet the user process requirements, so that limited resources can be used for rapid expansion without upgrading the physical hardware device, so as to improve the processing efficiency of the hardware device.
[0055] With the continuous development of computers and hardware devices, hardware peripherals can be used to execute more, larger, and more complex application scenarios, which further leads to the emergence of scenarios where multiple access terminals request the use of devices, which places higher demands on the processing power and memory capacity of hardware peripherals. In traditional processing methods, when the request device uses insufficient memory of the hardware device, it is usually necessary to upgrade the hardware device to meet resource requirements. Since the hardware device parameter configuration is usually fixed, users usually need to choose to replace the hardware device to expand the memory.
[0056] However, the memory expansion method of replacing the device is achieved by directly upgrading the physical memory of the hardware device, which has low flexibility. For some scenarios where it is inconvenient to replace the hardware device and for usage scenarios where the performance requirements of the hardware device are not high, it may take a lot of time to replace the device, which may cause the hardware device to be less efficient when processing user tasks. In order to help improve the flexibility of the memory expansion method and improve the processing efficiency of the hardware device, the present application provides a device memory expansion method.
[0057] Reference Figure 1 , the method comprises the following steps:
[0058] S10, dividing the memory of the hardware device unit into memory sub-blocks of a preset size to generate a plurality of device memory blocks.
[0059] Specifically, refer to Figure 2, divide the device memory of the hardware device into several small memory blocks to obtain several device memory blocks. Among them, the size of the memory block can be set according to actual needs. For example, the memory of the hardware device can be divided into 512 bytes, 1024 bytes, 2048 bytes or other sizes. If the memory blocks are divided according to 512 bytes, the size of each sub-memory block after the hardware device memory is divided is 512 bytes. The same is true for dividing the memory blocks according to 1024 bytes, 2048 bytes or other sizes. It should be noted that the block processing of the memory of the hardware device does not mean dividing the actual memory of the hardware device, but rather virtually blocks the memory of the hardware device, so that the user processes with larger memory can be processed in batches according to the memory blocks in the future, so as to realize the virtual expansion of the hardware device memory.
[0060] S20, obtaining the data to be processed by the user process and creating a memory swap area, and caching the data to be processed by the user process in the memory swap area.
[0061] Specifically, according to the user process that needs to be processed, the data to be processed is obtained from the user process, and a memory swap area is created. A user process may contain a variety of data. For the data that needs to be processed by the hardware device, it can be immediately transmitted to the device driver for processing preparation. At this time, the data to be processed can be extracted from the user process and set as the data to be processed by the user process; refer to Figure 2 The memory swap area is used to cache the data to be processed by the user process. Later, according to the judgment result of the memory size, the cached user process can be loaded into the hardware device memory for processing. Among them, the number of user processes processed by the hardware device is not limited. When using this method to process user processes, only one user process can be processed, or multiple user processes can be processed at the same time. In addition, during the processing of the current user process, a new user process can also be added for processing.
[0062] S30, allocating device memory blocks for the user process data to be processed according to the acquired number of all user processes.
[0063] Specifically, all device memory blocks are allocated to different user processes according to the number of user processes obtained. For example, when the number of user processes is 1, all device memory blocks are allocated to the user process; when the number of user processes is greater than 1, all device memory blocks are evenly allocated to all user processes. For example, assuming that the number of user processes is 5 and the number of device memory blocks after division is 15, each user process can be allocated 3 device memory blocks. It should be noted that the allocation of device memory blocks can be evenly allocated, or other allocation methods can be used to allocate device memory blocks according to user needs. For example, all device memory blocks can be allocated to different user processes in proportion according to the total size of device memory required by each user process. User processes that require larger device memory will be allocated more device memory blocks, and user processes that require smaller device memory will be allocated fewer device memory blocks. The specific allocation strategy can be set by the user according to needs, and is not limited here.
[0064] S40, determining whether the total memory amount of the device memory blocks allocated for the data to be processed by the user process satisfies the size of the data to be processed by the user process.
[0065] Specifically, a certain number of device memory block resources are allocated to each user process so that each process obtains a certain amount of hardware memory to facilitate multiple user processes to execute tasks at the same time; since the size of the data to be processed by different user processes is different, some of the data to be processed is small, and some of the data to be processed is large, it is necessary to first determine whether the total memory of the device memory blocks allocated to the data to be processed by each user process can meet the size of the data to be processed by the user process.
[0066] S50, transferring the to-be-processed data of the user process in the memory swap area to the corresponding device memory block for processing according to the determination result.
[0067] Specifically, according to the judgment result of the memory, the data to be processed of the user process cached in the memory swap area is directly or in batches loaded into the hardware memory for processing. Specifically, if the total memory of the device memory blocks allocated for the data to be processed by the user process is larger than the size of the data that the user process needs to process, the data to be processed by the user process can be directly loaded into the corresponding device memory block for processing and the processing result can be obtained; if the total memory of the device memory blocks allocated for the data to be processed by the user process is smaller than the size of the user process, the data to be processed in the user process needs to be divided and loaded into the hardware memory in batches for processing. By processing in blocks and batches, the user process can be processed step by step when hardware resources are limited, thereby improving resource utilization and flexibility of use.
[0068] In the present application scheme, by means of hardware device memory block processing, when hardware resources are limited, the data to be processed by the user process is loaded and processed in batches to realize virtual expansion of device memory, thereby improving resource utilization and the flexibility of hardware device use, and can be applied to scenarios where it is inconvenient to replace hardware devices and the performance requirements of hardware devices are not high. In addition, by allocating device memory blocks to different user processes, the hardware device can process multiple processes at the same time, improving the reusability and processing efficiency of the device.
[0069] In one embodiment, the step of caching the user process to-be-processed data into the memory swap area may be specifically performed as follows:
[0070] First, create several virtual memory blocks. The memory size of the virtual memory blocks is consistent with the memory size of the device memory blocks. Generally, the number of virtual memory blocks created will be greater than the number of device memory blocks, and the total memory size of the virtual memory blocks will not be less than the size of the data to be processed by the user process. Figure 3 When the system obtains the user process, it will first analyze the size of the data to be processed and apply for the corresponding resources from the driver layer of the upper computer. On the driver side, the data to be processed by the user process is divided into sub-data blocks according to the size of the virtual memory block, and the sub-data blocks are cached in the virtual memory block to obtain the occupied virtual memory block. The occupied virtual memory block can also be understood as a virtual memory block with sub-data blocks cached, and the tasks to be processed are cached in the memory block. When all sub-data blocks are allocated to the virtual memory block, the occupied virtual memory block is cached in the memory swap area, that is, the data to be processed of the user process is cached in the memory swap area.
[0071] In the present application scheme, the size of the virtual memory block is made consistent with the device memory block through the design of the virtual memory block. When the data to be processed by the user process is too large, resulting in insufficient hardware device resources, the complete data to be processed can be cached on the driver side first, and the number of virtual memory blocks required can be calculated, which is helpful for subsequent judgment of the memory requirements for the data to be processed; in addition, it can also avoid as much as possible the situation where the user process is too large and is directly loaded into the hardware device, causing the hardware device to have difficulty in normal operation, thereby causing hardware device failure, etc.
[0072] In one embodiment, the step of transferring the user process to-be-processed data in the memory swap area to the corresponding device memory block for processing according to the judgment result may be specifically performed as follows:
[0073] If the total memory of the device memory blocks allocated for the data to be processed by the user process meets the size of the data to be processed by the user process, that is, the total memory of the device memory blocks allocated for the data to be processed by the user process can support the completion of the task processing of the data to be processed by the user in the user process, then the occupied virtual memory block is mapped to the device memory block corresponding to the data to be processed by the user process for processing; specifically, the sub-data blocks in the occupied virtual memory block are loaded into the device memory block corresponding to the user process for processing, which can also be understood as loading all the sub-data blocks cached in the memory exchange area into the corresponding device memory block for processing. Among them, the sub-data blocks are loaded from the virtual memory block to the device memory block using the DMA transmission method. DMA (Direct Memory Access) is a technology that allows peripheral devices (such as network interface cards, hard disk controllers, etc.) to directly exchange data with the main memory without the intervention of the CPU. This technology aims to improve the efficiency of data transmission, reduce the burden on the CPU, and enable the CPU to concentrate on processing more complex computing tasks.
[0074] Reference Figure 3 , if the total memory of the device memory blocks allocated for the data to be processed by the user process does not meet the memory size of the data to be processed by the user process, that is, the total memory of the device memory blocks allocated for the data to be processed by the user process is not enough to support the completion of the task of the data to be processed in the user process, then the occupied virtual memory blocks are mapped in batches to the device memory blocks corresponding to the user process for processing, and the device driver layer loads the sub-data blocks in the virtual memory blocks in the memory swap area to the hardware device, and the hardware device returns partial results after execution, and executes in a loop until all sub-data blocks are processed. Specifically, the occupied virtual memory blocks are divided into several processing batches according to the device memory blocks allocated by the user process, and the virtual memory blocks to be processed in the current batch are determined and set as the current memory blocks to be processed; the sub-data blocks in the current memory blocks to be processed are loaded into the corresponding device memory blocks for processing; it is determined whether the sub-data blocks in the current memory blocks to be processed have been processed; if the processing is completed, the sub-data blocks of the virtual memory blocks to be processed in the next batch are loaded into the corresponding device memory blocks for processing, until all the data to be processed in the user process are processed.
[0075] For example, the data to be processed by a user process can be divided into 15 sub-data blocks according to the size of the virtual memory and the sub-data blocks are cached in the virtual memory blocks, that is, 15 occupied virtual memory blocks are obtained, and there are only 3 available device memory blocks allocated for processing the user process, then the 15 virtual memory blocks are divided into 5 batches with 3 as a batch, and each batch processes the sub-data blocks in 3 virtual memory blocks; during the first processing, virtual memory blocks 1-3 are set as the current memory blocks to be processed in sequence, and the sub-data blocks in the memory blocks to be processed are loaded into the corresponding device memory blocks for processing and obtain partial processing results, and then, it is determined whether the sub-data blocks in virtual memory blocks 1-3 are processed, and if the processing is completed, the sub-data in virtual memory blocks 4-6 are loaded into the hardware memory, and the execution is repeated until the data in the 15 occupied virtual memory blocks are all processed and the final result is obtained.
[0076] In the present application, the virtual memory block and the device memory block are used together with the driver to realize the rapid expansion of the memory of the hardware device. When the performance requirements are not sensitive, the virtual memory block can be used to transfer part of the data to the device memory block in batches for processing and obtaining results, thereby realizing the rapid expansion of the available memory of the device. At the same time, the virtual memory expansion method is user-friendly, and the user process can quickly use the virtual device memory without being restricted by the actual hardware device.
[0077] In one embodiment, the device memory expansion system further includes a device memory management unit, and the step of determining the current batch of virtual memory blocks to be processed and setting them as the current memory blocks to be processed can be specifically performed as follows:
[0078] First, a memory processing status table is created while creating a memory swap area. The memory processing status table includes the correspondence between virtual memory blocks and device memory blocks and the execution status of virtual memory blocks. The correspondence between virtual memory blocks and device memory blocks can be understood as the device memory blocks allocated to the currently processed user process and the virtual memory blocks with cached data. The two are recorded in correspondence to avoid cross errors in multi-process situations. The execution status of virtual memory blocks is to mark the virtual memory blocks as executed or not executed. Afterwards, the control device memory management unit searches for unexecuted occupied virtual memory blocks according to the memory processing status table and obtains unexecuted memory blocks. The memory processing status table stores and records the execution and non-execution of virtual memory blocks. Unexecuted virtual memory blocks can be found by searching the memory status table. Unexecuted and occupied virtual memory blocks are also unexecuted memory blocks. Finally, the device memory blocks allocated for the user process's pending data are set as the hardware allocated memory blocks, and the unexecuted memory blocks that are consistent with the number of hardware allocated memory blocks are sequentially determined as the virtual memory blocks to be processed in the current batch, and are set as the current memory blocks to be processed; for example, assuming that the data that a user process needs to process can be divided into 15 sub-data blocks according to the size of the virtual memory, and the data blocks are cached in the virtual memory blocks, that is, 15 occupied virtual memory blocks are obtained, and the user process has only 3 available device memory blocks allocated. In the first When loaded into the device memory block for processing, the device memory management unit searches the memory processing status table and finds that the 15 occupied virtual memory blocks are all executed, so the 15 are grouped into batches of 3, and the occupied virtual memory blocks 1-3 in order are the current memory blocks to be processed. After the data in virtual memory blocks 1-3 are processed, they are marked as executed. During the second processing, 4-15 are not executed, so the remaining 12 are grouped into batches of 3, and the occupied virtual memory blocks 4-6 in the original order are the current memory blocks to be processed, and so on.
[0079] In one embodiment, considering that the virtual memory does not mark the execution status, the system may confuse the executed and unexecuted data. Therefore, before loading the sub-data blocks of the next batch of virtual memory blocks to be processed into the corresponding device memory blocks for processing, the following steps may be performed:
[0080] The occupied virtual memory block corresponding to the processed sub-data block is marked as executed; then, the execution status of the virtual memory block in the memory processing status table is updated.
[0081] In the present application scheme, through the design of the device memory management module and the memory status table, the execution status of the memory status table is updated and maintained in a timely manner, so that the system can timely understand the execution and execution of user processes in the virtual memory block. The device memory management module can switch and schedule the virtual memory blocks that need to be executed, and load part of the data in the virtual memory blocks that need to be executed into the hardware memory, making the entire processing process clearer and avoiding operations on empty virtual memory blocks as much as possible, thereby improving the efficiency of task processing.
[0082] Figure 1 FIG. 1 is a flow chart of a method for extending device memory in one embodiment. It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but the steps are not necessarily executed in the order indicated by the arrows; unless otherwise specified in this document, there is no strict order restriction for the execution of the steps, and the steps may be executed in other orders; and Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0083] Based on the above method, an embodiment of the present application also discloses a device memory expansion apparatus.
[0084] Reference Figure 4 , the device includes the following modules:
[0085] The memory block division module 401 is used to divide the memory of the hardware device unit into memory sub-blocks of a preset size to generate a plurality of device memory blocks;
[0086] The process data cache module 402 is used to obtain the user process data to be processed and create a memory swap area, and cache the user process data to be processed in the memory swap area;
[0087] A memory block allocation module 403 is used to allocate device memory blocks for the user process data to be processed according to the number of all the user processes acquired;
[0088] A memory requirement determination module 404 is used to determine whether the total memory of the device memory block allocated to the data to be processed by the user process satisfies the size of the data to be processed by the user process;
[0089] The device memory processing module 405 is used to transfer the user process to-be-processed data in the memory swap area to the corresponding device memory block for processing according to the judgment result.
[0090] In one embodiment, the process data cache module 402 is specifically used to create a number of virtual memory blocks according to the memory size of the device memory block; divide the user process data to be processed into sub-data blocks according to the memory size of the virtual memory block, and cache the sub-data blocks to the virtual memory block to obtain occupied virtual memory blocks; cache the occupied virtual memory blocks to the memory swap area.
[0091] In one embodiment, the device memory processing module 405 is specifically used to map the occupied virtual memory blocks to the device memory blocks corresponding to the user process for processing if the total memory sum of the device memory blocks allocated for the data to be processed by the user process meets the size of the data to be processed by the user process; if the total memory sum of the device memory blocks allocated for the data to be processed by the user process does not meet the size of the data to be processed by the user process, then map the occupied virtual memory blocks in batches to the device memory blocks corresponding to the user process for processing.
[0092] In one embodiment, the device memory processing module 405 is specifically used to load the sub-data blocks of the occupied virtual memory blocks into the device memory blocks corresponding to the user process for processing; wherein, the sub-data blocks are loaded from the virtual memory blocks to the device memory blocks using DMA transmission.
[0093] In one embodiment, the device memory processing module 405 is specifically used to divide the occupied virtual memory blocks into several processing batches according to the device memory blocks allocated according to the user process data to be processed, determine the virtual memory blocks to be processed in the current batch and set them as the current memory blocks to be processed; load the sub-data blocks of the current memory blocks to be processed into the corresponding device memory blocks for processing; determine whether the sub-data blocks in the current memory blocks to be processed have been processed; if the processing has been completed, load the sub-data blocks of the next batch of virtual memory blocks to be processed into the corresponding device memory blocks for processing, until all the user process data to be processed have been processed.
[0094] In one embodiment, the device memory processing module 405 is also used to create a memory processing status table while creating a memory swap area, the memory processing status table including the correspondence between virtual memory blocks and device memory blocks, and the execution status of virtual memory blocks; control the device memory management unit to search for unexecuted occupied virtual memory blocks according to the memory processing status table to obtain unexecuted memory blocks; set the device memory blocks allocated to the user process to be processed data as hardware allocated memory blocks; and sequentially determine the unexecuted memory blocks that are consistent with the number of hardware allocated memory blocks as virtual memory blocks to be processed in the current batch, and set them as current memory blocks to be processed.
[0095] In one embodiment, the device memory processing module 405 is further used to mark the occupied virtual memory block corresponding to the processed sub-data block as executed; and update the execution status of the virtual memory block in the memory processing status table.
[0096] The device memory expansion apparatus provided in the embodiment of the present application can be applied to the device memory expansion method provided in the above embodiment. For relevant details, refer to the above method embodiment. The implementation principle and technical effect are similar and will not be repeated here.
[0097] It should be noted that: the device memory expansion device provided in the embodiment of the present application only uses the division of the above-mentioned functional modules / functional units as an example when performing device memory expansion. In actual applications, the above-mentioned functions can be assigned to different functional modules / functional units as needed, that is, the internal structure of the device memory expansion device is divided into different functional modules / functional units to complete all or part of the functions described above. In addition, the implementation method of the device memory expansion method provided in the above method embodiment and the implementation method of the device memory expansion device provided in this embodiment belong to the same concept. The specific implementation process of the device memory expansion device provided in this embodiment is detailed in the above method embodiment, which will not be repeated here.
[0098] The embodiment of the present application also discloses a computer device.
[0099] Specifically, if Figure 5 As shown, the computer device can be a computer device such as a desktop computer, a laptop computer, a PDA, and a cloud server. The computer device may include, but is not limited to, a processor and a memory. The processor and the memory may be connected via a bus or otherwise. The processor may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, graphics processors (GPU), embedded neural network processors (NPU) or other dedicated deep learning coprocessors, discrete gates or transistor logic devices, discrete hardware components and other chips, or a combination of the above-mentioned various chips.
[0100] As a non-transient computer-readable storage medium, the memory can be used to store non-transient software programs, non-transient computer executable programs and modules, such as program instructions / modules corresponding to the methods in the above-mentioned embodiments of the present application. The processor executes various functional applications and data processing of the processor by running the non-transient software programs, instructions and modules stored in the memory, that is, the method in the above-mentioned method implementation is realized. The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network and a combination thereof.
[0101] The embodiment of the present application also discloses a computer-readable storage medium.
[0102] Specifically, a computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the method in the above-mentioned method implementation is implemented. Those skilled in the art will understand that the implementation of all or part of the process in the above-mentioned implementation method of the present application can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and the program, when executed, may include the process of the implementation of the above-mentioned methods. Among them, the storage medium may be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (Hard Disk Drive, abbreviated as: HDD) or a solid-state drive (SSD), etc.; the storage medium may also include a combination of the above-mentioned types of memory.
[0103] This specific embodiment is merely an explanation of the present invention and is not a limitation of the present invention. After reading this specification, those skilled in the art may make non-creative modifications to the present embodiment as needed. However, as long as they are within the scope of the claims of the present invention, they are protected by the patent law.
Claims
1. A method for expanding device memory, characterized in that: The method is applied to a device memory expansion system, the device memory expansion system includes a hardware device unit, and the method includes: Dividing the memory of the hardware device unit into memory sub-blocks of a preset size to generate a plurality of device memory blocks; Acquire the user process data to be processed and create a memory swap area, and cache the user process data to be processed in the memory swap area; Allocate a device memory block for the data to be processed by the user process according to the number of all the user processes obtained; Determine whether the total memory of the device memory blocks allocated to the data to be processed by the user process satisfies the size of the data to be processed by the user process; According to the judgment result, the user process to-be-processed data in the memory swap area is transferred to the corresponding device memory block for processing.
2. The method according to claim 1, characterized in that: The step of caching the user process to-be-processed data in the memory swap area comprises: Creating a number of virtual memory blocks according to the memory size of the device memory block; Dividing the user process to-be-processed data into sub-data blocks according to the memory size of the virtual memory block, and caching the sub-data blocks into the virtual memory block to obtain an occupied virtual memory block; The occupied virtual memory block is cached in the memory swap area.
3. The method according to claim 2, characterized in that: The transferring of the user process to-be-processed data in the memory swap area to the corresponding device memory block for processing according to the judgment result comprises: If the total memory of the device memory blocks allocated for the data to be processed by the user process meets the size of the data to be processed by the user process, the occupied virtual memory blocks are mapped to the device memory blocks corresponding to the user process for processing; If the total memory of the device memory blocks allocated for the data to be processed by the user process does not meet the size of the data to be processed by the user process, the occupied virtual memory blocks are mapped in batches to the device memory blocks corresponding to the user process for processing.
4. The method according to claim 3, characterized in that: Mapping the occupied virtual memory block to a device memory block corresponding to the user process for processing includes: Loading the sub-data block of the occupied virtual memory block into the device memory block corresponding to the user process for processing; The sub-data block is loaded from the virtual memory block to the device memory block by using a DMA transmission method.
5. The method according to claim 3, characterized in that: Mapping the occupied virtual memory blocks in batches to device memory blocks corresponding to the user processes for processing includes: Divide the occupied virtual memory blocks into several processing batches according to the device memory blocks allocated by the user process to be processed data, determine the virtual memory blocks to be processed in the current batch and set them as the current memory blocks to be processed; Loading the sub-data blocks of the current memory block to be processed into the corresponding device memory block for processing; Determine whether the sub-data blocks in the current memory block to be processed have been processed; If the processing is completed, the sub-data blocks of the next batch of virtual memory blocks to be processed are loaded into the corresponding device memory blocks for processing until all the data to be processed by the user process are processed.
6. The method according to claim 5, characterized in that: The device memory expansion system further includes a device memory management unit, and the step of determining a current batch of virtual memory blocks to be processed and setting them as current memory blocks to be processed includes: Creating a memory processing status table while creating the memory exchange area, the memory processing status table including the correspondence between the virtual memory block and the device memory block, and the execution status of the virtual memory block; Controlling the device memory management unit to search for the unexecuted occupied virtual memory block according to the memory processing status table to obtain the unexecuted memory block; The device memory block obtained by allocating the data to be processed by the user process is set as the hardware allocated memory block; The unexecuted memory blocks having the same number as the memory blocks allocated by the hardware are determined in sequence as the virtual memory blocks to be processed in the current batch, and are set as the current memory blocks to be processed.
7. The method according to claim 6, characterized in that: Before loading the sub-data blocks of the next batch of virtual memory blocks to be processed into the corresponding device memory blocks for processing, the method further includes: Mark the occupied virtual memory block corresponding to the processed sub-data block as executed; The execution status of the virtual memory block in the memory processing status table is updated.
8. A device memory expansion device, characterized in that: The device is applied to a device memory expansion system, the device memory expansion system includes a hardware device unit, and the device includes: A memory block division module (401) is used to divide the memory of the hardware device unit into memory sub-blocks of a preset size to generate a plurality of device memory blocks; A process data cache module (402), used for acquiring the user process data to be processed and creating a memory swap area, and caching the user process data to be processed in the memory swap area; A memory block allocation module (403) is used to allocate device memory blocks for the data to be processed by the user processes according to the number of all the user processes acquired; A memory requirement determination module (404) is used to determine whether the total memory of the device memory blocks allocated to the data to be processed by the user process meets the size of the data to be processed by the user process; The device memory processing module (405) is used to transfer the user process to-be-processed data in the memory exchange area to the corresponding device memory block for processing according to the judgment result.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program which can be loaded by the processor and executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program is stored which can be loaded by a processor and execute the method according to any one of claims 1 to 7.