Memory exchange method and device, terminal and computer program product
By allocating memory swap partitions from the reserved space of physical dynamic partitions, the problems of high hardware requirements and low memory swap efficiency in the prior art are solved, and the memory swap effect of efficiently utilizing idle storage space and reducing hardware demand is achieved.
Patent Information
- Application Number
- CN202411551081.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-18
AI Technical Summary
When implementing memory switching in the prior art, hardware requirements are high, and terminals without a dedicated physical partition are difficult to realize memory switching, and memory switching efficiency is low.
Allocate memory swap partitions from the reserved space of physical dynamic partitions, and use this space to exchange memory with memory, avoiding dependence on dedicated physical partitions and improving the efficiency of memory swap.
It effectively utilizes idle storage space, reduces hardware requirements, expands the terminal application scope of memory switching technology, and improves memory switching speed.
Smart Images

Figure CN119473602A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of memory exchange technology, and more particularly to a memory exchange method, device, terminal and computer program product. Background Art
[0002] Memory swapping is a technology used in computer operating systems to increase the availability of physical memory. When the system's physical memory is insufficient to accommodate all currently active processes, the operating system will temporarily move infrequently used memory pages to the hard disk to free up some memory space.
[0003] In the related art, in order to realize memory swapping, a physical partition as a memory swap partition is set in the hard disk, so that data is swapped in and out with the memory by using the physical partition. Summary of the invention
[0004] The embodiments of the present application provide a memory exchange method, device, terminal and computer program product. The technical solution is as follows:
[0005] On the one hand, an embodiment of the present application provides a memory swap method, the method comprising:
[0006] Allocating a memory swap partition from a reserved space of a physical dynamic partition, wherein the reserved space is a space in the physical dynamic partition reserved for system upgrade;
[0007] When there is a memory swap requirement, memory swap is performed between the memory and the memory swap partition.
[0008] On the other hand, an embodiment of the present application provides a memory exchange device, the device comprising:
[0009] An allocation module, configured to allocate a memory swap partition from a reserved space of a physical dynamic partition, wherein the reserved space is a space reserved for system upgrade in the physical dynamic partition;
[0010] The memory exchange module is used to perform memory exchange between the memory and the memory exchange partition when there is a memory exchange demand.
[0011] On the other hand, an embodiment of the present application provides a terminal, which includes a processor and a memory, wherein the memory stores at least one computer instruction, and the at least one computer instruction is loaded and executed by the processor to implement the memory exchange method as described in the above aspects.
[0012] On the other hand, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one computer instruction, and the at least one computer instruction is used to be executed by a processor to implement the memory exchange method as described in the above aspects.
[0013] On the other hand, an embodiment of the present application provides a computer program product, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; a processor reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to implement the memory exchange method described in the above aspects.
[0014] In the solution provided by the embodiment of the present application, since the space reserved for system upgrades in the physical dynamic partition is idle in most cases, allocating memory swap space for memory swapping with the memory from the reserved space of the physical dynamic partition can effectively utilize the idle storage space and avoid wasting storage space; and, a terminal that does not have a dedicated physical partition as a memory swap partition can also use the solution provided by the embodiment of the present application to implement memory swapping, which reduces the hardware requirements for implementing memory swapping and expands the terminal application scope of the memory swapping technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 is a schematic diagram of the structure of a terminal provided by an exemplary embodiment of the present application;
[0016] Figure 2 is a schematic diagram of a data reading and writing and memory exchange process shown in an exemplary embodiment;
[0017] Figure 3 It is a schematic diagram of an implementation of a memory swap process between a dedicated swap partition and a memory according to an exemplary embodiment;
[0018] Figure 4 It is a schematic diagram of an exemplary embodiment showing a process of performing memory exchange between a readable partition and a memory through a swap file;
[0019] Figure 5 A flowchart of a memory swap method provided by an exemplary embodiment of the present application is shown;
[0020] Figure 6 is a schematic diagram of an implementation of allocating a memory swap partition in a reserved space according to an exemplary embodiment of the present application;
[0021] Figure 7 is a schematic diagram of a memory swap configuration interface shown in an exemplary embodiment of the present application;
[0022] Figure 8It is a schematic diagram of an implementation of a data encryption and decryption process in a memory exchange process shown in an exemplary embodiment of the present application;
[0023] Fig. 9 It is a schematic diagram of an implementation of a system upgrade and an upgrade completion process shown in an exemplary embodiment of the present application;
[0024] Fig.10 is a flowchart of a memory swap and system upgrade process shown in an exemplary embodiment of the present application;
[0025] Fig.11 A structural block diagram of a memory exchange device provided by another exemplary embodiment of the present application is shown. DETAILED DESCRIPTION
[0026] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0027] The term "multiple" as used herein refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0028] For ease of understanding, the nouns involved in the embodiments of the present application are explained below.
[0029] Physical partition: A physical partition refers to a partition on a hard disk that is divided using the GPT (GUID Partition Table) table (not a physical partition; the same hard disk can be divided into multiple physical partitions). When the capacity of a physical partition is dynamically adjusted, the GPT table needs to be re-edited.
[0030] Logical partition: Logical partition is a concept relative to physical partition. Its division method is not recorded in the GPT table, but recorded in the form of metadata. Therefore, it is not necessary to re-edit the GPT table after dynamically adjusting the capacity of the logical partition. Usually, a physical partition can contain multiple logical partitions.
[0031] Physical dynamic partition: also known as physical super partition, is a physical partition that packages system, vendor and other partitions. The physical partition table only contains physical dynamic partitions, and no longer configures physical partitions such as system (system) and vendor (vendor) separately, and the sub-partitions in the physical dynamic partition can be dynamically resized. In some embodiments, the physical dynamic partition includes several logical partitions, such as system logical partition, vendor logical partition, odm (original design manufacturer) logical partition, system_dlkm logical partition, vendor_dlkm logical partition, odm_dlkm logical partition and product logical partition, etc. Each logical partition carries a different part of the system.
[0032] Writable partition: refers to a physical partition where data can be written while the operating system is running. Common writable partitions in hard disks include user data partitions.
[0033] See also Figure 1 , Figure 1 1 is a schematic diagram of a terminal structure provided by an exemplary embodiment of the present application. The terminal may be an electronic device such as a smart phone, a tablet computer, a personal computer, a wearable device, etc. The terminal may include one or more of the following components: a processor 110 and a memory 120.
[0034] Optionally, the processor 110 uses various interfaces and lines to connect various parts of the entire electronic device, and executes various functions of the electronic device and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 110 can integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), a neural network processor (NPU), and a baseband chip. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing the content that needs to be displayed on the touch display; the NPU is used to implement artificial intelligence (AI) functions; and the baseband chip is used to process wireless communications. It is understandable that the above baseband chip may not be integrated into the processor 110, but may be implemented by a separate chip.
[0035] The memory 120 may include a random access memory (RAM) or a read-only memory (ROM). Optionally, the memory 120 includes a non-transitory computer-readable storage medium. The memory 120 may be used to store instructions, programs, codes, code sets, or instruction sets. The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function, instructions for implementing the following various method embodiments, etc.; the data storage area may store data created according to the use of the electronic device, etc.
[0036] In addition, those skilled in the art will understand that the structure of the terminal shown in the above figures does not constitute a limitation on the terminal, and the terminal may include more (such as communication components, display components) or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0037] exist Figure 1On the basis of Figure 2 As shown, the processor 110 may be a CPU 111, and the storage 120 includes a memory 121 (belonging to RAM) and a hard disk 122 (belonging to ROM). Since the access speed of the memory 121 is greater than the access speed of the hard disk 122, the data in the hard disk 122 is first loaded into the memory 121, and then the CPU 111 and the memory 121 perform data reading and writing.
[0038] Since the capacity of memory 121 is limited, the operating system will introduce memory swapping technology to improve memory availability. For memory pages that are not frequently used in memory 121 (such as memory pages of inactive processes), the operating system will temporarily write the memory pages to hard disk 122 to free up some memory space for other active processes to use. This process is called swapout. When the swapped-out memory is needed again, the operating system will re-read these memory pages from hard disk 122 into memory 121. This process is called swapin.
[0039] In the related art, in order to realize memory swap, a dedicated physical partition as a memory swap partition needs to be set in the hard disk. Figure 3 As shown, in addition to the physical partition 311, the physical dynamic partition 312 and the writable partition 313 (a physical partition for storing user data, also called a userdata partition) divided in the hard disk 310, it is necessary to additionally divide a swap partition 314 in the hard disk 310 for memory exchange with the memory 320.
[0040] For terminals that do not have dedicated physical partitions, if you want to implement memory swapping, you need to use swap files to write and unwrite files between the memory and the writable partition (which belongs to the physical partition) of the hard disk. Figure 4 As shown, the hard disk 310 is divided into a physical partition 311 , a physical dynamic partition 312 and a writable partition 313 , and memory exchange is achieved between the memory 320 and the writable partition 313 via a swap file 3131 .
[0041] However, using a dedicated swap partition to implement memory swapping requires high hardware resources and is not suitable for terminals that are not equipped with a dedicated swap partition (such as early terminals). When implementing memory swapping through swap files, it is necessary to first read the file mapping information in the hard disk (it takes a certain amount of time to find the address mapping) and then read and write file data based on the file mapping information, resulting in low memory swap efficiency (especially obvious under high load conditions).
[0042] Considering that the space reserved for system upgrades in the physical dynamic partition is idle in most cases, in the embodiment of the present application, the memory swap space for memory exchange with the memory is allocated from the reserved space of the physical dynamic partition, which can effectively utilize the idle storage space and avoid storage space waste; and the terminal that is not set up as a dedicated physical partition for memory exchange partition can also use the scheme provided by the embodiment of the present application to implement memory exchange, which reduces the hardware requirements for implementing memory exchange and expands the terminal application scope of memory exchange technology. In addition, when memory exchange is performed directly through partitioning, since the address is continuously mapped, compared with the memory exchange of the file method, the scheme provided by the embodiment of the present application can increase the memory exchange speed.
[0043] Please refer to Figure 5 , which shows a flowchart of a memory swap method provided by an exemplary embodiment of the present application, and the method may include the following steps.
[0044] Step 501, allocating a memory swap partition from the reserved space of the physical dynamic partition, where the reserved space is the space reserved for system upgrade in the physical dynamic partition.
[0045] After the physical partition table is configured, the capacity of partitions such as system and vendor needs to be adjusted frequently (for example, when the system is upgraded), which leads to the need to frequently modify the physical partition table and re-edit the GPT table.
[0046] After the introduction of physical dynamic partitions (also known as physical super partitions), system, vendor and other partitions are packaged, and the physical partition table only contains physical dynamic partitions, and physical partitions such as system and vendor are no longer configured separately. The subpartitions in physical dynamic partitions can be resized dynamically. During the compilation process, the information of system, vendor and other partitions will be recorded in the form of metadata.
[0047] In some embodiments, partitions such as system and vendor are used as logical partitions in a physical dynamic partition. After the capacity of the logical partition is dynamically adjusted, there is no need to re-edit the GPT table.
[0048] Since the terminals of current terminal manufacturers all support upgrading to several major system versions after release, in order to cope with the growth of system firmware packages during subsequent major version upgrades, some space will be reserved for system upgrades in the physical dynamic area. This space is the reserved space in the embodiment of the present application.
[0049] In some embodiments, the reserved space is space reserved for the system read-only partition, that is, the reserved space is used to expand the size of the system read-only partition.
[0050] The initial size of the reserved space may be pre-configured by the terminal manufacturer, and the size of the reserved space may change as the system is updated.
[0051] Since the reserved space in the physical dynamic partition is not used most of the time, in order to avoid wasting space, in an embodiment of the present application, the terminal allocates all or part of the space from the reserved space as a memory swap partition for memory swapping with the memory.
[0052] In some embodiments, the terminal allocates all or part of the continuous address space in the reserved space as the memory swap control.
[0053] like Figure 6 As shown, the hard disk 61 is divided into a physical partition 611, a physical dynamic partition 612 and a writable partition 613, and the physical dynamic partition 612 is further divided into a plurality of logical partitions 6121 and a reserved space 6122. After the memory swap partition is allocated, the reserved space 6122 includes a memory swap partition 6122A of a specified capacity.
[0054] In some embodiments, when the system is started and the memory swap function is enabled, the terminal allocates the memory swap partition from the reserved space of the physical dynamic partition. The memory swap function can be manually selected by the user to be enabled.
[0055] Step 502: When there is a memory swap requirement, perform memory swap between the memory and the memory swap partition.
[0056] The memory swap requirement includes a memory swap-out requirement and a memory swap-in requirement.
[0057] In some embodiments, when there is a need to swap out memory, the terminal writes the swapped-out data in the memory to the memory swap partition; when there is a need to swap in memory, the terminal writes the swapped-in data in the memory swap partition back to the memory.
[0058] In some embodiments, memory exchange between the memory and the memory swap partition may be performed in plain text, or memory exchange between the memory and the memory swap partition may be performed in cipher text to improve the security of swapped-out data stored in the memory swap partition.
[0059] To sum up, in the solution provided by the embodiment of the present application, since the space reserved for system upgrade in the physical dynamic partition is idle in most cases, allocating memory swap space for memory exchange with the memory from the reserved space of the physical dynamic partition can effectively utilize the idle storage space and avoid wasting storage space; and, a terminal that does not have a dedicated physical partition as a memory swap partition can also adopt the solution provided by the embodiment of the present application to implement memory exchange, which reduces the hardware requirements for implementing memory exchange and expands the terminal application scope of the memory exchange technology.
[0060] Since the data in the reserved space will not be lost naturally when the hard disk is powered off, in order to avoid the currently allocated memory swap partition containing the memory data written during the historical memory swap, resulting in a reduced utilization rate of the memory swap partition, in a possible implementation, after the memory swap partition is allocated, the terminal performs data clearing processing (or data erasing) on the memory swap partition. Since the memory data written during the historical memory swap will no longer be swapped into the memory, clearing the memory swap partition will not affect subsequent memory swaps.
[0061] In some embodiments, when the hard disk is a UFS device, the terminal controls the UFS device to perform a discard operation on the allocated memory swap partition.
[0062] The capacity of the memory swap partition
[0063] In this embodiment, the capacity of the memory swap partition is the target capacity. Optionally, the target capacity can be a fixed value or an adjustable value that supports dynamic adjustment. Generally, the larger the target capacity, the better the memory swap effect.
[0064] In some embodiments, when the target capacity supports dynamic adjustment, the target capacity may be dynamically adjusted by the terminal, and an entry may be provided for the user to manually adjust the target capacity according to demand.
[0065] Since the capacity of the reserved space of the physical dynamic partition is limited and the capacity of the reserved space may change with system updates and upgrades, in order to ensure the feasibility of allocating the memory swap partition, in a possible implementation, before the terminal allocates the memory swap partition, it obtains the available capacity of the reserved space of the physical dynamic partition and compares the available capacity with the target capacity.
[0066] When the available capacity of the reserved space of the physical dynamic partition is greater than or equal to the target capacity, the terminal allocates a memory swap partition of the target capacity from the reserved space, that is, divides all or part of the area from the reserved space as the memory swap partition.
[0067] In a possible implementation manner, the terminal obtains the current available capacity of the reserved space from the meta information of the physical dynamic partition.
[0068] Optionally, when the available capacity of the reserved space of the physical dynamic partition is smaller than the target capacity, the terminal adjusts the size of the target capacity so that the adjusted target capacity is smaller than or equal to the available capacity of the reserved space.
[0069] Regarding the method of adjusting the target capacity, in some embodiments, the terminal can automatically adjust the target capacity based on the available capacity of the reserved space, such as determining the difference between the available capacity and the capacity reservation value as the adjusted target capacity. For example, when the available capacity is 5GB, the target capacity before adjustment is 6GB, and the capacity reservation value is 1GB, the terminal adjusts the target capacity to 4GB.
[0070] In other embodiments, when the terminal provides a capacity configuration entry for a memory swap partition, if the available capacity of the reserved space of the physical dynamic partition is less than the target capacity, the terminal displays a memory swap reconfiguration prompt, which is used to prompt reconfiguration of the target capacity of the memory swap partition.
[0071] Optionally, the memory swap reconfiguration prompt includes an entry identifier. When a trigger operation on the entry identifier is received, the terminal displays a capacity configuration entry for the memory swap partition so that the user can quickly reconfigure the capacity of the memory swap partition.
[0072] Regarding the configuration process of the target capacity, in a possible implementation, the terminal provides a memory exchange configuration interface. In response to the capacity configuration operation in the memory exchange configuration interface, the terminal determines the pre-configured capacity indicated by the capacity configuration operation. When the pre-configured capacity is less than or equal to the available capacity of the reserved space, the terminal determines the pre-configured capacity as the target capacity.
[0073] Optionally, when the pre-configured capacity is greater than the available capacity of the reserved space, the terminal displays a reconfiguration prompt to prompt the user to reset the pre-configured capacity.
[0074] In some embodiments, a capacity input control is provided in the memory swap configuration interface, and the user can manually input the preconfigured capacity of the memory swap partition in the capacity input control, that is, the capacity configuration operation is an input operation on the capacity input control.
[0075] Optionally, in order to improve the rationality of the pre-configured capacity configured by the user, the terminal can display a capacity limit prompt in the memory swap configuration interface based on the current available capacity of the reserved space, prompting the user to set the pre-configured capacity within the capacity limit (less than or equal to the current available capacity).
[0076] In other embodiments, a plurality of candidate capacities are provided in the memory exchange configuration interface for the user to select, and the candidate capacity selected by the user is the pre-configured capacity, that is, the capacity configuration operation is a selection operation of the candidate capacity. Optionally, the candidate capacity can be a preset capacity (which has nothing to do with the available capacity of the reserved space, but is a plurality of pre-set capacities), or a capacity dynamically determined by the terminal according to the current available capacity of the reserved space (to ensure that the pre-configured capacity configured by the user does not exceed the available capacity), which is not limited in this embodiment.
[0077] Indicative, such as Figure 7 As shown, the memory swap configuration interface 71 includes a memory swap function enabling control 72 and a memory swap space capacity setting control 73. When the memory swap function enabling control 72 is set to an enabled state, the user can select the target capacity to be configured through the memory swap space capacity setting control 73.
[0078] Of course, the capacity configuration operation may also be performed in other forms, such as voice configuration instructions, etc. The embodiment of the present application does not limit the specific form of the capacity configuration operation.
[0079] In this embodiment, before allocating the memory swap partition, by detecting whether the current available capacity of the reserved space is greater than the target capacity of the memory swap partition, the feasibility of allocating the memory swap partition in the reserved space is ensured. In addition, the terminal provides an entry for the user to configure the target capacity of the memory swap partition, thereby improving the configuration flexibility of the memory swap partition.
[0080] It should be noted that, when the reserved space can meet the minimum capacity requirement of the memory swap partition, the terminal can implement memory swap by allocating the memory swap partition in the reserved space; when the reserved space cannot meet the minimum capacity requirement of the memory swap partition, the terminal can implement memory swap between the memory and the writable partition by writing to the file.
[0081] When to allocate memory swap partitions
[0082] Since the memory swap partition in the embodiment of the present application is divided from the reserved space for system upgrade, and the reserved space will be used during the system upgrade process, in order to avoid the impact of the system upgrade on the memory swap partition allocation, the allocation of the memory swap partition may include the following two situations depending on whether the system upgrade is performed:
[0083] Case 1: When the system is not upgraded and the system boots successfully, the memory swap partition is allocated from the reserved space of the physical dynamic partition.
[0084] In the case where the system is not upgraded, since the reserved space of the physical dynamic partition is not occupied, the terminal can directly allocate the memory swap partition from the reserved space when the system is successfully started.
[0085] Case 2: When the system is upgraded and booted successfully, snapshots are merged and the copy-on-write partition is released. The copy-on-write partition is used to store the difference data between the new and old systems during the system upgrade. After the snapshot merge and the copy-on-write partition are released, the memory swap partition is allocated from the reserved space of the physical dynamic partition.
[0086] In some embodiments, when performing a virtual A / B system upgrade, a Copy-On-Write (COW) partition is created in the reserved space to store the difference data between the old and new systems during the system upgrade, as well as snapshots. When performing a subsequent system upgrade, if the upgrade fails, the difference data in the snapshot and the Copy-On-Write partition can be used to roll back the system; if the upgrade succeeds, the difference data in the snapshot and the Copy-On-Write partition is merged into the original system partition.
[0087] If the memory swap partition is directly allocated in the reserved space after the system is upgraded and successfully powered on, the memory swap partition may contain differential data in the snapshot or copy-on-write partition, affecting the utilization rate of the memory swap partition (this part of the snapshot or differential data has not been able to be swapped into the memory). Therefore, in this embodiment, when the system is upgraded and the system is successfully powered on, the terminal will allocate the memory swap partition from the reserved space of the physical dynamic partition only after completing the snapshot merge and releasing the copy-on-write partition. Among them, after the copy-on-write partition is released, the differential data used during the system upgrade and the system snapshot are deleted.
[0088] In some embodiments, the terminal may determine whether the system upgrade is performed and whether the snapshot merge and the copy-on-write partition release are completed according to the merge status (mergestatus) of the copy-on-write partition, which is not limited in this embodiment.
[0089] It should be noted that when the system upgrade fails and the system rollback is completed based on the snapshot and the copy-on-write partition and the system boots up successfully, the terminal needs to allocate the memory swap partition from the reserved space of the physical dynamic partition after releasing the copy-on-write partition.
[0090] In this embodiment, when the system is successfully started and the system is upgraded, the terminal allocates the memory swap partition after completing the snapshot merge and releasing the write-time copy partition, so as to avoid the allocated memory swap partition containing data in the original write-time copy partition, affecting the effect of subsequent memory swap.
[0091] Memory swap partition and memory swap process
[0092] In a possible implementation, the memory swap partition and the memory can be exchanged in plain text. When there is a need to swap out memory, the terminal writes the plain text swap-out data in the memory to the memory swap partition; when there is a need to swap in memory, the terminal writes the plain text swap-in data in the memory swap partition back to the memory.
[0093] In this memory swap mode, since the data stored in the memory swap partition is plain text data, and the data in the memory swap partition will not be naturally lost due to power failure (unlike the data in the memory will be naturally lost due to power failure), it may cause the memory data to be illegally obtained.
[0094] In order to improve the security of memory data, in another possible implementation, memory exchange between the memory exchange partition and the memory may be performed in ciphertext.
[0095] Correspondingly, when there is a demand for memory swapping, the terminal determines the swapping data in the memory, and encrypts the swapping data to obtain swapping encrypted data, thereby writing the swapping encrypted data into the memory swap partition.
[0096] When there is a demand for memory swapping, the terminal determines the swap-in encrypted data in the memory swap partition, and swaps in the encrypted data for decryption to obtain the swap-in data, thereby writing the swap-in data into the memory.
[0097] In this memory exchange mode, since the data stored in the memory exchange partition is ciphertext data, even if the ciphertext memory data is subsequently obtained from the memory exchange partition, it cannot be decrypted to obtain the plaintext memory data, thereby ensuring the security of the memory data during the memory exchange process.
[0098] In order to realize encrypted memory exchange, in a possible implementation, when allocating a memory exchange partition, the terminal creates a virtual encryption device corresponding to the memory exchange partition, configures the virtual encryption device to the memory exchange configuration, and activates the virtual encryption device, wherein the memory exchange configuration includes relevant configurations for controlling the memory exchange process.
[0099] In some embodiments, the virtual encryption device is a virtual device running in the memory. Optionally, the virtual encryption device is a program in the memory for triggering encryption and decryption of data, including the key used for encryption and decryption.
[0100] Optionally, the virtual encryption device is used to trigger the terminal's underlying hardware encryption circuit to encrypt and decrypt memory data, wherein the hardware encryption circuit is a hardware circuit independent of the processor, thereby preventing the memory data encryption and decryption process from occupying the processor's processing resources.
[0101] In a possible implementation, each time the terminal creates a virtual encryption device, it regenerates the key for memory data encryption and decryption, and saves the key in the memory (not written to the hard disk). Optionally, the terminal randomly generates the key, that is, each virtual encryption device created uses a different key for encryption and decryption to ensure the security of memory data in the memory swap partition.
[0102] In some embodiments, the process of configuring the virtual encryption device to the memory swap configuration and activating it is to write the virtual encryption device into the control node of the memory swap driver. In this way, the kernel driver can be informed that the memory data can be swapped out and in through the virtual encryption device.
[0103] In some embodiments, the virtual encryption device is destroyed when the terminal is powered off and / or the system is upgraded. When the virtual encryption device is running in the memory, the virtual encryption device is naturally destroyed (lost) when the terminal is powered off; when the system is upgraded (not powered off), the terminal turns off the memory swap function and actively destroys the virtual encryption device.
[0104] When using the created virtual encryption device for memory swapping, the terminal encrypts the swapped-out data through the virtual encryption device that is activated in the memory swap configuration to obtain the swapped-out encrypted data; and / or, decrypts the swapped-in encrypted data through the virtual encryption device that is activated in the memory swap configuration to obtain the swapped-in data.
[0105] Indicatively, in Figure 6 On the basis of Figure 8 As shown, the plaintext swap-out data in the memory is first input into the virtual encryption device 621, and after being encrypted by the virtual encryption device 621, the ciphertext swap-out data is written into the memory swap partition 6122A; the ciphertext swap-in data in the memory swap partition 6122A is first input into the virtual encryption device 621, and after being decrypted by the virtual encryption device 621, the plaintext swap-in data is written into the memory 62.
[0106] In this embodiment, a virtual encryption device is created for the memory swap partition, and the swapped-in and swapped-out data in the memory swap process is encrypted and decrypted by the virtual encryption device, so that only memory data in ciphertext form is stored in the memory swap partition, thereby avoiding leakage of memory data in the memory swap partition and improving the security of memory data under the memory swap technology.
[0107] Processing flow during system upgrade
[0108] Since the terminal needs to use the reserved area in the physical dynamic partition when performing a system upgrade, in order to avoid memory swapping affecting the system upgrade (for example, the memory swap partition stores too much memory data and is unable to store the difference data between the new and old systems), in one possible implementation, in response to a system upgrade instruction, the terminal releases the memory swap partition.
[0109] Releasing the memory swap partition refers to stopping memory swapping and clearing memory data in the memory swap partition to make room in the reserved space for data required for system upgrade.
[0110] In some embodiments, when the memory swap partition is released, the terminal creates a copy-on-write partition and a snapshot, and restarts the terminal after the copy-on-write partition and the snapshot are created. During the terminal restart process, the terminal will perform a system upgrade based on the differential data in the copy-on-write partition and the snapshot.
[0111] Indicatively, in Figure 6 On the basis of Fig. 9 As shown, during the system upgrade process, the terminal releases the memory swap partition 6122A in the reserved space 6122, and creates a COW partition in the reserved space 6122 to store the difference data and snapshots of the system upgrade. When the system upgrade is completed and the boot is successful, the terminal releases the COW partition 6122B and reallocates the memory swap partition 6122A in the reserved space 6122.
[0112] It should be noted that, when the terminal is powered off normally by shutting down or restarting, the terminal can also release the memory swap partition to avoid leakage of memory data in the memory swap partition, which will not be described in detail in this embodiment.
[0113] In this embodiment, when there is a need for system upgrade, the terminal releases the memory swap partition in the reserved space to make room for the system upgrade, avoids the generation of the memory swap function system, and ensures the normal execution of the system upgrade.
[0114] In combination with the above embodiments, Fig.10 As shown, the process of performing memory exchange and system upgrade using the memory exchange solution provided in the embodiment of the present application may include the following steps:
[0115] Step 1001, the terminal is turned on.
[0116] Step 1002, the system boots up successfully.
[0117] Step 1003, determine whether it is a virtual A / B system upgrade startup. If it is a virtual A / B system upgrade startup, execute steps 1004 and 1005; if it is not a virtual A / B system upgrade startup, execute step 1006.
[0118] Step 1004, perform snapshot merging.
[0119] Step 1005, releasing the COW partition.
[0120] The specific implementation of steps 1003 to 1005 may refer to the relevant content of “timing of allocating memory swap partition” in the above embodiment, which will not be described in detail in this embodiment.
[0121] Step 1006, determine whether the available capacity of the reserved space of the physical dynamic partition is greater than the target capacity. If the available capacity is greater than the target capacity, execute step 1007; if the available capacity is greater than the target capacity, end.
[0122] The specific implementation of this step may refer to the relevant content of “capacity of memory swap partition” in the above embodiment, which will not be elaborated in this embodiment.
[0123] Step 1007, allocate a memory swap partition of the target capacity from the reserved space, and clear the data.
[0124] Step 1008, creating a virtual encryption device for the memory swap partition.
[0125] Step 1009, configure the virtual encryption device to the memory swap configuration and activate it.
[0126] The specific implementation of steps 1007 to 1009 may refer to the relevant content of “memory swap process between memory swap partition and memory” in the above embodiment, which will not be described in detail in this embodiment.
[0127] Step 1010: In response to the system upgrade instruction, close the memory swap.
[0128] Step 1011, destroy the virtual encryption device.
[0129] Step 1012, release the memory swap partition in the reserved space.
[0130] Step 1013, create a COW partition.
[0131] Step 1014, create a snapshot.
[0132] Step 1015, restart the terminal.
[0133] The specific implementation of steps 1010 to 1015 may refer to the relevant content of "processing flow during system upgrade" in the above embodiment, which will not be described in detail in this embodiment.
[0134] Please refer to Fig.11, which shows a structural block diagram of a memory exchange device provided by an exemplary embodiment of the present application. The device includes:
[0135] An allocation module 1101 is used to allocate a memory swap partition from a reserved space of a physical dynamic partition, where the reserved space is a space reserved for system upgrade in the physical dynamic partition;
[0136] The memory exchange module 1102 is used to perform memory exchange between the memory and the memory exchange partition when there is a memory exchange demand.
[0137] Optionally, the allocation module 1101 is used to:
[0138] In a case where the available capacity of the reserved space of the physical dynamic partition is greater than or equal to the target capacity, the memory swap partition of the target capacity is allocated from the reserved space.
[0139] Optionally, the device further includes a configuration module, configured to:
[0140] In response to a capacity configuration operation in the memory exchange configuration interface, determining a pre-configured capacity indicated by the capacity configuration operation;
[0141] In a case where the pre-configured capacity is less than or equal to the available capacity of the reserved space, the pre-configured capacity is determined as the target capacity.
[0142] Optionally, the device further comprises a prompt module, which is used to:
[0143] When the available capacity of the reserved space of the physical dynamic partition is less than the target capacity, a memory swap reconfiguration prompt is displayed, where the memory swap reconfiguration prompt is used to prompt reconfiguration of the target capacity of the memory swap partition.
[0144] Optionally, the allocation module 1101 is used to:
[0145] In the case where the system upgrade is not performed and the system is successfully powered on, allocating the memory swap partition from the reserved space of the physical dynamic partition;
[0146] or,
[0147] When the system is upgraded and the system boots up successfully, snapshot merging and copy-on-write partition release are performed, and the copy-on-write partition is used to store the difference data between the new and old systems during the system upgrade; when the snapshot merging and copy-on-write partition release are completed, the memory swap partition is allocated from the reserved space of the physical dynamic partition.
[0148] Optionally, the data stored in the memory swap partition is plaintext data or ciphertext data.
[0149] Optionally, when the data stored in the memory exchange partition is ciphertext data, the memory exchange module 1102 is used to:
[0150] In the case where there is a need to swap out memory, determining swap-out data in the memory; encrypting the swap-out data to obtain swap-out encrypted data; and writing the swap-out encrypted data into the memory swap partition;
[0151] or,
[0152] In the case where there is a demand for memory swapping, the swapping-in encrypted data in the memory swap partition is determined; the swapping-in encrypted data is decrypted to obtain the swapping-in data; and the swapping-in data is written into the memory.
[0153] Optionally, the allocation module 1101 is further configured to:
[0154] Creating a virtual encryption device corresponding to the memory swap partition;
[0155] Configuring the virtual encryption device to a memory swap configuration and activating the virtual encryption device, wherein the memory swap configuration includes a configuration related to controlling a memory swap process;
[0156] The memory exchange module 1102 is used to:
[0157] Encrypting the swapped-out data by the virtual encryption device in the activated state in the memory swap configuration to obtain the swapped-out encrypted data;
[0158] The swapped-in encrypted data is decrypted by the virtual encryption device in the activated state in the memory swap configuration to obtain the swapped-in data.
[0159] Optionally, the virtual encryption device is destroyed when the terminal is powered off and / or the system is upgraded.
[0160] Optionally, the allocation module 1101 is further configured to:
[0161] In response to the system upgrade instruction, releasing the memory swap partition;
[0162] When the memory swap partition is released, a copy-on-write partition and a snapshot are created, wherein the copy-on-write partition is used to store difference data between the new and old systems during system upgrade;
[0163] After the copy-on-write partition and snapshot creation are complete, restart the terminal.
[0164] Optionally, the allocation module 1101 is further configured to:
[0165] Clear the data in the allocated memory swap partition.
[0166] To sum up, in the solution provided by the embodiment of the present application, since the space reserved for system upgrade in the physical dynamic partition is idle in most cases, allocating memory swap space for memory exchange with the memory from the reserved space of the physical dynamic partition can effectively utilize the idle storage space and avoid wasting storage space; and, a terminal that does not have a dedicated physical partition as a memory swap partition can also adopt the solution provided by the embodiment of the present application to implement memory exchange, which reduces the hardware requirements for implementing memory exchange and expands the terminal application scope of the memory exchange technology.
[0167] It should be noted that the specific implementation methods corresponding to the above modules can refer to the method embodiments, and the above module division is only for example. The memory exchange device can be divided into more or fewer functional modules for implementing the memory exchange method according to actual conditions, and this embodiment does not limit this.
[0168] An embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one computer instruction, and the at least one computer instruction is used to be executed by a processor to implement the memory exchange method as described in the above embodiment.
[0169] On the other hand, an embodiment of the present application provides a computer program product, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; a processor reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to implement the memory exchange method described in the above embodiment.
[0170] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented with hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein the communication media include any media that facilitates the transmission of a computer program from one place to another. The storage medium can be any available medium that a general or special-purpose computer can access.
[0171] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A memory exchange method, characterized in that: The method comprises: Allocating a memory swap partition from a reserved space of a physical dynamic partition, wherein the reserved space is a space in the physical dynamic partition reserved for system upgrade; When there is a memory swap requirement, memory swap is performed between the memory and the memory swap partition.
2. The method according to claim 1, characterized in that The allocating the memory swap partition from the reserved space of the physical dynamic partition includes: In a case where the available capacity of the reserved space of the physical dynamic partition is greater than or equal to the target capacity, the memory swap partition of the target capacity is allocated from the reserved space.
3. The method according to claim 2, characterized in that The method further comprises: In response to a capacity configuration operation in the memory exchange configuration interface, determining a pre-configured capacity indicated by the capacity configuration operation; In a case where the pre-configured capacity is less than or equal to the available capacity of the reserved space, the pre-configured capacity is determined as the target capacity.
4. The method according to claim 2, characterized in that: The method further comprises: When the available capacity of the reserved space of the physical dynamic partition is less than the target capacity, a memory swap reconfiguration prompt is displayed, where the memory swap reconfiguration prompt is used to prompt reconfiguration of the target capacity of the memory swap partition.
5. The method according to claim 1, characterized in that The allocating the memory swap partition from the reserved space of the physical dynamic partition includes: In the case where the system upgrade is not performed and the system is successfully powered on, allocating the memory swap partition from the reserved space of the physical dynamic partition; or, When the system is upgraded and the system boots up successfully, snapshot merging and copy-on-write partition release are performed, and the copy-on-write partition is used to store the difference data between the new and old systems during the system upgrade; when the snapshot merging and copy-on-write partition release are completed, the memory swap partition is allocated from the reserved space of the physical dynamic partition.
6. The method according to any one of claims 1 to 5, characterized in that: The data stored in the memory swap partition is plaintext data or ciphertext data.
7. The method according to claim 6, characterized in that In a case where the data stored in the memory exchange partition is ciphertext data, performing memory exchange between the memory and the memory exchange partition when there is a memory exchange requirement includes: In the case where there is a need to swap out memory, determining swap-out data in the memory; encrypting the swap-out data to obtain swap-out encrypted data; and writing the swap-out encrypted data into the memory swap partition; or, In the case where there is a demand for memory swapping, the swapping-in encrypted data in the memory swap partition is determined; the swapping-in encrypted data is decrypted to obtain the swapping-in data; and the swapping-in data is written into the memory.
8. The method according to claim 7, characterized in that The method further comprises: Creating a virtual encryption device corresponding to the memory swap partition; Configuring the virtual encryption device to a memory swap configuration and activating the virtual encryption device, wherein the memory swap configuration includes a configuration related to controlling a memory swap process; The step of encrypting the swapped-out data to obtain the swapped-out encrypted data includes: Encrypting the swapped-out data by the virtual encryption device in the activated state in the memory swap configuration to obtain the swapped-out encrypted data; The decrypting the input encrypted data to obtain the input data includes: The swapped-in encrypted data is decrypted by the virtual encryption device in the activated state in the memory swap configuration to obtain the swapped-in data.
9. The method according to claim 8, characterized in that The virtual encryption device is destroyed when the terminal is powered off and / or the system is upgraded.
10. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: In response to the system upgrade instruction, releasing the memory swap partition; When the memory swap partition is released, a copy-on-write partition and a snapshot are created, wherein the copy-on-write partition is used to store difference data between the new and old systems during system upgrade; After the copy-on-write partition and snapshot creation are complete, restart the terminal.
11. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Clear the data in the allocated memory swap partition.
12. A memory exchange device, characterized in that: The device comprises: An allocation module, configured to allocate a memory swap partition from a reserved space of a physical dynamic partition, wherein the reserved space is a space reserved for system upgrade in the physical dynamic partition; The memory exchange module is used to perform memory exchange between the memory and the memory exchange partition when there is a memory exchange demand.
13. A terminal, characterized in that: The terminal includes a processor and a memory, wherein the memory stores at least one computer instruction, and the at least one computer instruction is loaded and executed by the processor to implement the memory exchange method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one computer instruction, and the at least one computer instruction is used to be executed by a processor to implement the memory exchange method according to any one of claims 1 to 11.
15. A computer program product, characterized in that The computer program product includes computer instructions, which are stored in a computer-readable storage medium; a processor reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to implement the memory exchange method as described in any one of claims 1 to 11.