Method, device and storage medium for recovering image abnormality during sleep process
By reading and restarting the kernel multiple times during the hibernation wake-up phase of the Linux system to deal with the problem of mirror recovery exceptions, the user data loss caused by hardware memory is solved, and data security and user experience are improved.
Patent Information
- Application Number
- CN202411794554.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2044-12-09
AI Technical Summary
During the hibernation wake-up stage, the Linux system is not able to recover the image abnormality due to hardware memory, causing user data loss.
When the system wake-up sleep signal is received, the sleep image reading function is started to read the mirror data from the exchange partition; when the received return result is an abnormal result, the current partition buffer is released and the mirror data is read again; the read number variable is used to accumulate the number of reads; when the number of reads exceeds the preset threshold, the kernel is restarted and the mirror data is read again.
By loading the image data multiple times and initializing the memory in the kernel restart process, the UEFI will reduce the occasional wake-up exception caused by memory instability, improve the probability of normal loading of the image, avoid user data loss, and improve data security and user experience.
Smart Images

Figure CN119248360B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Linux system hibernation, and in particular to a method, device and storage medium for recovering image abnormality in a hibernation process. Background Art
[0002] With the development of computer systems, system stability and data security are becoming more and more important. S4 sleep mode is a low-power state defined in the ACPI specification. In this mode, the system can be completely powered off and the current system state can be saved to a non-volatile storage device.
[0003] When the hardware system memory is unstable, image data anomalies may occur during the wake-up process from sleep mode, such as illegal image data decompression length, image data decompression failure, image data verification anomalies, etc., resulting in the system being unable to recover normally and causing user data loss.
[0004] When using the Linux operating system, it is common to experience sleep and wake-up failures caused by unstable hardware memory. However, the current kernel processing method is to directly discard the image data, resulting in user data loss, which seriously affects data security and user experience. Summary of the invention
[0005] The embodiment of the present invention provides a method, device and storage medium for recovering an image abnormality in a sleep process, so as to solve the technical problem in the prior art that in a sleep wake-up phase of a Linux system, an image recovery abnormality causes user data loss due to memory instability.
[0006] In a first aspect, an embodiment of the present invention provides a method for recovering from image abnormality in a sleep process, comprising:
[0007] When receiving the system wake-up hibernation signal, start the hibernation image reading function to read the image data from the swap partition;
[0008] When the return result of the received dormant image reading function is an abnormal result, the current partition buffer is released, and the dormant image reading function is started to re-read the image data from the exchange partition;
[0009] The read count variable is used to accumulate the number of times the dormant image read function is started during the wake-up phase;
[0010] When the read count variable is greater than a preset first threshold, the kernel is restarted, and after the kernel is restarted, the dormant image reading function is started again to read the image data from the swap partition.
[0011] In a second aspect, an embodiment of the present invention further provides a device for recovering image abnormality in a dormancy process, comprising:
[0012] A startup module, used for starting the sleep image reading function to read the image data from the swap partition when receiving a system wake-up sleep signal;
[0013] A release module is used to release the current partition buffer when the return result of the received dormant image reading function is an abnormal result, and start the dormant image reading function to re-read the image data from the exchange partition;
[0014] The accumulation module is used to accumulate the number of startup times of the dormant image reading function in the wake-up phase by using the reading number variable;
[0015] The restart module is used to restart the kernel when the read count variable is greater than a preset first threshold value, and after restarting the kernel, restart the dormant image reading function to read the image data from the swap partition.
[0016] In a third aspect, an embodiment of the present invention further provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute the method for recovering from an abnormal image in a hibernation process as provided in the above embodiment.
[0017] The method, device and storage medium for recovering image abnormality in the dormancy process provided by the embodiment of the present invention start the dormancy image reading function to read the image data from the exchange partition when receiving the system wake-up dormancy signal; when the return result of the received dormancy image reading function is an abnormal result, release the current partition buffer, start the dormancy image reading function to read the image data from the exchange partition again; use the reading number variable to accumulate the number of times the dormancy image reading function is started in the wake-up phase; when the reading number variable is greater than the preset first threshold, restart the kernel, and after restarting the kernel, start the dormancy image reading function again to read the image data from the exchange partition. The method of loading image data multiple times can be used to reduce the sporadic occurrence of wake-up abnormalities caused by memory instability, and the UEFI in the kernel restart process can be used to re-initialize the memory to correct the memory instability, further improving the probability that the image can be loaded normally. Avoid the loss of user data, improve the security of data and the user experience of the dormancy wake-up process. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0019] Figure 1 It is a flowchart of a method for recovering an abnormal image in a dormancy process provided by the first embodiment of the present invention;
[0020] Figure 2It is a flowchart of a method for recovering an abnormal image in a dormant process provided by Embodiment 2 of the present invention;
[0021] Figure 3 It is a structural schematic diagram of a device for recovering an abnormal image in a dormant process provided by Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0022] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0023] Embodiment 1
[0024] Figure 1 : is a flowchart of a method for recovering an image abnormality in a sleep process provided by the first embodiment of the present invention. This embodiment is applicable to a situation where an image recovery abnormality is handled when a Linux system is in a system wake-up sleep phase. The method can be executed by a device for recovering an image abnormality in a sleep process, and specifically includes the following steps:
[0025] Step 110: when a system sleep wake-up signal is received, a sleep image reading function is started to read image data from the swap partition.
[0026] Read image data.
[0027] System hibernation states include S1, S3, S4, etc. They are implemented through the Advanced Configuration and Power Interface (ACPI). S4 stands for Suspend-to-disk, which means suspend to hard disk, also known as hibernation. Simply put, the current memory image is saved and stored on the hard disk, and then all devices are powered off. When the power is turned on again, the system will restore the image data saved in the hard disk to the memory, thereby restoring the scene before sleep.
[0028] When waking up from hibernation, the image data needs to be read from the swap partition in the hard disk and restored to the memory. During this process, the image restoration may be abnormal due to memory abnormalities.
[0029] In this embodiment, when receiving the sleep awakening signal sent by the system, firstly, an attempt is made to restore the image normally, that is, the image is read from the swap partition and written into the memory.
[0030] Exemplarily, the image data in the swap partition may be exchanged using the hibernation image reading function swsusp_read().
[0031] Step 120: when the return result of the received dormant image reading function is an abnormal result, the current partition buffer is released, and the dormant image reading function is started to re-read the image data from the swap partition.
[0032] By attempting to restore the image through the previous step, it is possible to judge whether the image is read normally based on the return result of the dormant image reading function. For example, generally speaking, the function return value is 0, which means that there is no abnormality during the operation of the dormant image reading function. If the return value is not 0, it may indicate that an image recovery abnormality has occurred. This abnormality may be caused by memory instability, so it is necessary to release the partition buffer in the memory and clear the content therein. Restart the dormant image reading function to re-read the image data from the swap partition.
[0033] Step 130 , using the read count variable to accumulate the number of times the sleep mirror read function is started during the wake-up phase.
[0034] Accordingly, in this embodiment, a new variable reload_cnt can be created to record the current swsusp_read() function loading times, and each time the swsusp_read() function is executed, the reload_cnt variable value is increased by 1. The above method is used to count the times of reading the dormant image in the wake-up phase.
[0035] Step 140, when the read count variable is greater than a preset first threshold, restart the kernel, and after restarting the kernel, start the dormant image reading function again to read the image data from the swap partition.
[0036] If the image cannot be restored normally after releasing the current partition buffer multiple times and then starting the hibernation image reading function to re-read the image data from the swap partition, it means that the current processing method, that is, releasing the partition buffer, cannot solve the image recovery abnormality caused by memory instability. Therefore, it is necessary to further process the memory and try to solve the image abnormality problem in the hibernation process through further processing.
[0037] Exemplarily, the memory can be further processed by restarting the kernel, and after restarting the kernel, the dormant image reading function is started again to read the image data from the swap partition. Try again to see if the image recovery can be achieved. The first threshold can be set based on experience.
[0038] This embodiment starts the sleep image reading function to read the image data from the swap partition when receiving the system wake-up sleep signal; when the return result of the received sleep image reading function is an abnormal result, releases the current partition buffer, starts the sleep image reading function to read the image data from the swap partition again; uses the read count variable to accumulate the number of times the sleep image reading function is started in the wake-up phase; when the read count variable is greater than the preset first threshold, restarts the kernel, and after restarting the kernel, starts the sleep image reading function again to read the image data from the swap partition. The method of loading the image data multiple times can be used to reduce the sporadic occurrence of wake-up anomalies caused by memory instability, and the UEFI in the kernel restart process can be used to re-initialize the memory to correct the memory instability, further improving the probability that the image can be loaded normally. Avoiding the loss of user data improves the security of data and the user experience of the sleep wake-up process.
[0039] In a preferred implementation of this embodiment, before receiving the system wake-up sleep signal, the method may further add the following steps: upon receiving the sleep request sent by the processor platform, all data in the current memory and the system state are saved to the swap partition, all hardware devices are shut down and the power is cut off, and the sleep state is entered. The sleep process can be executed in a standardized manner by using the above method, and the probability of abnormal sleep wake-up image recovery caused by image problems is reduced.
[0040] Embodiment 2
[0041] Figure 2 It is a flow chart of the method for recovering an abnormal image in the hibernation process provided by the second embodiment of the present invention. This embodiment is optimized based on the above embodiment, and the kernel is restarted, and after the kernel is restarted, the hibernation image reading function is started again to read the image data from the swap partition. The specific optimization is: a cumulative variable for accumulating the number of kernel restarts is created at the head of the swap partition; after the kernel is restarted, the hibernation image reading function is started again to read the image data from the swap partition. If the return result of the hibernation image reading function received is an abnormal result, the cumulative variable is read to determine whether the value of the cumulative variable is less than a second threshold; when it is less than the second threshold, the kernel is restarted.
[0042] See also Figure 2 , the image abnormality recovery method in the sleep process includes:
[0043] Step 210: When a system sleep wake-up signal is received, a sleep image reading function is started to read image data from the swap partition.
[0044] Step 220: when the received return result of the dormant image reading function is an abnormal result, the current partition buffer is released, and the dormant image reading function is started to re-read the image data from the swap partition.
[0045] Step 230: Count the number of times the sleep mirror read function is started during the wake-up phase using the read count variable.
[0046] Step 240: When the read count variable is greater than a preset first threshold, create a cumulative variable for accumulating kernel restart times at the head of the swap partition.
[0047] In this embodiment, a cumulative variable for accumulating the number of kernel restarts can be created at the head of the swap partition. Setting the variable at the head of the swap partition can make the cumulative variable persistent, avoiding the situation where the data is lost due to kernel restart.
[0048] Step 250, after restarting the kernel, start the sleep image reading function again to read the image data from the swap partition. If the return result of the sleep image reading function is an abnormal result, read the accumulated variable to determine whether the value of the accumulated variable is less than the second threshold.
[0049] After restarting the kernel, the hibernation image reading function is still started to read the image data from the swap partition. If the return result of the hibernation image reading function is a normal result, the kernel is used to restore the image data to the memory and exit the hibernation state. The above can prove that by restarting the kernel, UEFI will reinitialize the memory (memory training) to avoid memory instability. On the contrary, if the return result is an abnormal result, it is necessary to read the accumulated variable to determine whether the value of the accumulated variable is less than the second threshold.
[0050] Step 260: When the value is less than the second threshold, return to restart the kernel.
[0051] When it is less than the second threshold, the memory can still be initialized by restarting the kernel. And when the value of the accumulated variable is not less than the preset second threshold, and the return result of the received hibernation image reading function is an abnormal result, the data in the swap partition is cleared, the hibernation is abnormally exited, and the system is restored in a data loss manner. If the problem cannot be solved by restarting the kernel multiple times, it means that restarting the kernel to initialize the memory still cannot solve the problem of abnormal image recovery. This may indicate that the problem is more serious and cannot be solved by the above means. Therefore, the system is restored by losing data.
[0052] Exemplarily, restarting the kernel may include: setting the swap partition header flag (swsusp_header->sig) to a dormant state; after setting the dormant state, restarting the kernel again. Setting the swap partition header flag back allows developers to quickly relocate the last dormant data. This is to determine whether the recovery exception is caused by an image file problem.
[0053] This embodiment is optimized based on the above embodiment. The kernel is restarted, and after the kernel is restarted, the dormant image reading function is started again to read the image data from the swap partition. The specific optimization is as follows: a cumulative variable for accumulating the number of kernel restarts is created at the head of the swap partition; after the kernel is restarted, the dormant image reading function is started again to read the image data from the swap partition. If the return result of the dormant image reading function received is an abnormal result, the cumulative variable is read to determine whether the value of the cumulative variable is less than the second threshold; when it is less than the second threshold, the kernel is restarted. The UEFI in the kernel restart process can be used to reinitialize the memory, correct the memory instability, and further increase the probability that the image can be loaded normally. Avoid the loss of user data, improve data security and user experience during the dormant wake-up process.
[0054] In this embodiment, the method can also add the following steps: creating a variable for recording the number of times the dormant image is read in the swap partition; averaging the number of times the dormant image is read in each wake-up state; and updating the variable for recording the number of times the dormant image is read using the average calculation result. The above method is convenient for recording the specific situation of each abnormal recovery of the image, which is convenient for developers to collect statistics, understand the details of each abnormal recovery of the image, and determine the possible cause of the fault.
[0055] Embodiment 3
[0056] Figure 3 is a schematic diagram of the structure of the image abnormality recovery device in the dormancy process provided by the third embodiment of the present invention, see Figure 3 , the image abnormality recovery device in the dormancy process includes:
[0057] The start module 310 is used to start the sleep image reading function to read the image data from the swap partition when receiving the system wake-up sleep signal;
[0058] The release module 320 is used to release the current partition buffer and start the dormant image reading function to re-read the image data from the exchange partition when the return result of the received dormant image reading function is an abnormal result;
[0059] The accumulation module 330 is used to accumulate the number of startup times of the dormant image reading function in the wake-up phase by using the reading number variable;
[0060] The restart module 340 is used to restart the kernel when the read count variable is greater than a preset first threshold, and after restarting the kernel, restart the dormant image reading function to read the image data from the swap partition.
[0061] The image abnormality recovery device in the sleep process provided by this embodiment starts the sleep image reading function to read the image data from the exchange partition when receiving the system wake-up sleep signal; when the return result of the received sleep image reading function is an abnormal result, the current partition buffer is released, and the sleep image reading function is started to read the image data from the exchange partition again; the number of times the sleep image reading function is started in the wake-up phase is accumulated by using the read count variable; when the read count variable is greater than the preset first threshold, the kernel is restarted, and after the kernel is restarted, the sleep image reading function is started again to read the image data from the exchange partition. The image data can be loaded multiple times to reduce the sporadic occurrence of wake-up abnormalities caused by memory instability, and the UEFI in the kernel restart process can be used to re-initialize the memory to correct the memory instability, further improving the probability that the image can be loaded normally. Avoid the loss of user data, improve data security and user experience in the sleep wake-up process.
[0062] Based on the above embodiments, the restart module includes:
[0063] Create a unit for creating a cumulative variable for accumulating the number of kernel restarts at the head of the swap partition;
[0064] A judging unit, configured to restart the kernel, restart the dormant image reading function to read the image data from the swap partition, and if the return result of the dormant image reading function is an abnormal result, read the accumulated variable to judge whether the value of the accumulated variable is less than a second threshold;
[0065] The returning unit is used to return and restart the kernel when the value is less than a second threshold.
[0066] Based on the above embodiments, the restart module uses the kernel_restart() function to restart the kernel.
[0067] Based on the above embodiments, the restart module further includes:
[0068] Use kernel_restart() function to restart the kernel.
[0069] Set as a unit to set the swap partition header flag to a dormant state;
[0070] The restart unit is used to restart the kernel again after being put into sleep state.
[0071] Based on the above embodiments, the device further includes:
[0072] The clearing module is used to clear the data in the swap partition, exit the sleep state abnormally, and restore the system in a data loss mode when the value of the accumulated variable is not less than a preset second threshold and the return result of the received sleep image reading function is an abnormal result.
[0073] Based on the above embodiments, the device further includes:
[0074] The exit module is used to use the kernel to restore the image data to the memory and exit the dormant state when the value is less than the second threshold and the return result of the dormant image reading function is a normal result.
[0075] Based on the above embodiments, the device further includes:
[0076] The sleep state entry module is used to save all data and system status in the current memory to the swap partition, shut down all hardware devices and cut off the power supply to enter the sleep state when receiving the sleep request sent by the processor platform.
[0077] Based on the above embodiments, the device further includes:
[0078] A recording module is used to create a variable in the swap partition for recording the number of times the dormant image is read;
[0079] A calculation module, used for averaging the number of times the dormant image is read in each wake-up state;
[0080] The updating module is used to update the variable used to record the number of times the dormant image is read using the result of the average calculation.
[0081] The device for recovering from an abnormal image during a sleep process provided by an embodiment of the present invention can execute the method for recovering from an abnormal image during a sleep process provided by any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution method.
[0082] Embodiment 4
[0083] Embodiment 4 of the present invention further provides a storage medium containing computer executable instructions, and when the computer executable instructions are executed by a computer processor, the computer executable instructions are used to execute the method for recovering from an abnormal image in a dormant process as described in any of the above embodiments.
[0084] The computer storage medium of the embodiment of the present invention may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, device or device.
[0085] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0086] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0087] Computer program code for performing the operation of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0088] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for recovering image abnormality during a dormancy process, characterized in that: include: When receiving the system wake-up hibernation signal, start the hibernation image reading function to read the image data from the swap partition; When the return result of the received dormant image reading function is an abnormal result, the current partition buffer in the memory is released, and the dormant image reading function is started to re-read the image data from the exchange partition; The read count variable is used to accumulate the number of times the dormant image read function is started during the wake-up phase; When the read count variable is greater than a preset first threshold, restarting the kernel, and after restarting the kernel, starting the dormant image reading function again to read the image data from the swap partition; The restarting of the kernel and, after restarting the kernel, restarting the dormant image reading function to read the image data from the swap partition comprises: Create a cumulative variable at the head of the swap partition to accumulate the number of kernel restarts; After restarting the kernel, the dormant image reading function is started again to read the image data from the swap partition. If the return result of the dormant image reading function is an abnormal result, the accumulated variable is read to determine whether the value of the accumulated variable is less than a second threshold value. When the value is less than the second threshold, the kernel is restarted.
2. The method according to claim 1, characterized in that The restart kernel utilizes kernel_restart() function to restart the kernel.
3. The method according to claim 1, characterized in that: The restarting kernel comprises: Set the swap partition header flag to dormant state; After putting it into hibernation, restart the kernel again.
4. The method according to claim 1, characterized in that: The method further comprises: When the value of the accumulated variable is not less than a preset second threshold value and the received return result of the hibernation image reading function is an abnormal result, the data in the swap partition is cleared, hibernation is abnormally exited, and the system is restored in a data loss manner.
5. The method according to claim 1, characterized in that The method further comprises: When the value is less than the second threshold and the return result of the dormant image reading function is a normal result, the kernel is used to restore the image data to the memory and the dormant state is exited.
6. The method according to claim 1, characterized in that The method further comprises: When a sleep request is received from the processor platform, all data and system status in the current memory are saved to the swap partition.
7. The method according to claim 1, characterized in that The method further comprises: Create a variable in the swap partition to record the number of times the dormant image is read; The average number of times the dormant image is read in each wake-up state is calculated; The variable for recording the number of times the dormant image is read is updated using the result of the average calculation.
8. A device for recovering image abnormality during a dormancy process, characterized in that: include: A startup module, used for starting the sleep image reading function to read the image data from the swap partition when receiving a system wake-up sleep signal; A release module is used to release the current partition buffer in the memory when the return result of the received dormant image reading function is an abnormal result, and start the dormant image reading function to re-read the image data from the exchange partition; The accumulation module is used to accumulate the number of startup times of the dormant image reading function in the wake-up phase by using the reading number variable; A restart module, used for restarting the kernel when the read count variable is greater than a preset first threshold value, and after restarting the kernel, restarting the dormant image reading function to read the image data from the swap partition; The restart module comprises: Create a unit for creating a cumulative variable for accumulating the number of kernel restarts at the head of the swap partition; A judging unit, configured to restart the kernel, restart the dormant image reading function to read the image data from the swap partition, and if the return result of the dormant image reading function is an abnormal result, read the accumulated variable to judge whether the value of the accumulated variable is less than a second threshold; The returning unit is used to return and restart the kernel when the value is less than a second threshold.
9. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the image abnormality recovery method in the hibernation process as described in any one of claims 1-7 when executed by a computer processor.
Citation Information
Patent Citations
Computer restart testing system and method
CN102375767A
Linux operating system sleep quick starting method based on NVDIMM
CN107589969A