Using Linux to improve sleep and resurrection technology

Source: Internet
Author: User
Use Linux to improve sleep and resurrection technology-general Linux technology-Linux programming and kernel information. The following is a detailed description. Huang Yi: Hello, everyone. I'm Huang Yi from Intel's scientific research and technology center in Shanghai. Today I will introduce you to some of my recent work. Today, we will give a brief introduction to the background. Next we will introduce how to enhance sleep, including how to increase memory content, how to jump back to the original kernel from the sleep kernel, and how to restore the status, including writing a memory image, how to Use Kexec to implement the wake-up function. Next we will introduce the simple conclusion.

First, let's briefly introduce Kexec. Its function basically turns the Linux kernel into a capability that can load another kernel in a Linux system that is being executed. Its implementation involves two parts: a loading process, in which the content of the kernel to be loaded will be loaded into the software. This may be different from the final target configuration, because it may be in use and some startup parameters will be set. different operating systems have different requirements. Another part is the actual execution. At this time, it should first prepare the device. Basically, the device preparation method is similar to the shutdown method, that is, to stop all the work of the device.

Next we will switch to the physical mode, turn off the page, and then execute the new kernel. We can see from this figure that whether it is the original kernel or the kernel re-executed with Kexec, they all use the entire memory, that is, all the memory, in this case, the new kernel completely overwrites all the content of the past kernel, but it is no problem to implement Kexec.

Next we will introduce Kdump, which can write the memory content to the disk in Kexec mode when the system crashes, so that it can be analyzed in the future, to analyze the cause of the problem. It is implemented based on Kexec. When it is started in the original kernel, some memory will be retained during the startup, which is designed for the Domp kernel. It is like the blue part in the figure. The started kernel is also different from Kexec. It runs only in the specified memory, without damaging other kernels, this function can be achieved through some startup command line parameter modes of the kernel.
  
In this case, when we perform Kexec and load, we can load the Sotf configuration. And then jump to execute a Kexec to complete such a function. In this way, you can see that because the original kernel does not use this memory, the target kernel only uses this memory. Therefore, the memory content of the original kernel is retained, in this way, we can save the original content in the Damp kernel. To implement this saving function, the kernel provides a virtual file named VMCall to access the content of the original kernel memory.

Next we will introduce sleep. Sleep is a power management method. Its basic content is to save the status of the device and CPU to the memory, then, store the memory content in the kernel to the disk, and then shut down or in the standby status to save power. After the restart, the corresponding content will be restored. The current implementation has some details. First, all processes will be frozen during sleep. This is mainly because the current sleep implementation needs to write this out and write the kernel, the kernel used to write this memory image is the same as the original kernel, so it is to stop all other processes, so that they do not write in this process, write something to the disk, because this will cause inconsistency and disk content inconsistency.

Next, we will prepare some devices, including keeping the devices quiet, saving the status, saving some CPU status, writing them out, and loading it at startup, copy it to the target location and restore it back. This is basically the process. There are some problems with the existing sleep implementation. The first one is to repeat the existing implementation, mainly with the Kexec, we can see that the sleep Implementation contains the process of writing a memory image to the disk. In fact, there is also such a process in sleep, A kernel provides two implementations for similar things.

The other is that when the memory image in the disk is loaded in the wake-up mode, there are actually some duplicates with the KESC load. The second big problem is the dependence on frozen programs. This freezing mainly involves some problems, so many people are dissatisfied. Another problem is the memory image size, because the original sleep implementation is copying the memory used to the idle State. In this way, prepare such a memory image, therefore, the size of the memory image cannot exceed half of the total size, which is a big limitation. Although another implementation solves this problem, many people think this method is not good enough.

Next we will introduce the Kexec-based sleep implementation. It basically uses Kexec and Keepdamp to implement the original sleep part. The basic method of its implementation is first like the existing sleep implementation to meet the requirements of the CPU state storage and recovery functions. Then, when writing the memory image out of the disk, it uses the Keep domp method. The Kexec load function is used to wake up, and then the CPU and device status are restored. Basically, the existing Kexec and Keepdomp are enhanced, and then some sleep implementations are combined. Therefore, it is relatively simple.

Next, let's take a look at what enhancements we have made to implement sleep for Kexec and Keepdomp. First, the first problem is to keep the memory. Keepdomp has such a function, but it must be kept at startup and not used. This is a waste of memory, another is that it is a little more difficult to use and prepare. Let's take a look at how we implement this method. Let's take a look at this figure. First, like Keepdomp, We need to write the kernel and run it within the specified range, it adopts the same method as Kexec. Only Memory in this range is used, and no other memory is used. Another one is similar to the original one. We need to allocate a configuration for the loaded kernel, just like the blue one in the figure. The other one is for those within the target range, however, it is not other loaded pages. We allocate a backup page for each of them, just like the green section. In this case, when we do KESC, we will exchange the content of this target page and X-space, so that the original content will be saved and such a function can be completed in this way.

We will define an entry in the original kernel to complete some functions. This function is very simple. It restores content except the target location, just as the arrows in this figure mean to perform another swap, because we used to back up some memory content such as the target range, in this way, the switch will be restored to the original position, so that the original kernel can run on it again. The specific implementation uses an auxiliary function, or the Kexec method.

Next, let's talk about the SAVE and restore statuses. This is basically the same as the existing sleep implementation, which is to list the States to be saved. It may be easy to ignore. For example, in addition to CPU and device, there may be memory, and we may also need to save the disk status. In addition to OS, there may be others on the PC platform, maybe we need to consider what other statuses are like and how to collaborate with them.

Writing out a memory image is basically done using the Keep domp method. Basically, the interface provided by Keep domp is used to access the memory of the original kernel and write it out, in addition, a Make down free tool is also used, which is used together with the Keep domp tool. It can mainly kill some idle pages.

To restore the memory image, we adopt this method to regard the memory image to be restored as a common method to connect to the kernel, load it into the kernel, just like the previous one, copy it to X-Space first, then turn off the page, and then copy it back to the original location, this is done in this way, so the implementation of this part can be very simple.

There are also some problems based on such an implementation. Now we have a problem related to ACPI. In this way, the kernel does not have full control over the entire system, in this way, there are some problems with the collaboration. First, the Kexec requirement is basically theoretically that Kexec requires ACPI to be reentrant, that is, you have, the ACPI method has been called. In the first kernel, its status has changed. At this time, you start a new kernel, so that you can access the ACPI status in the new kernel, it may modify the status of ACPI again. At this time, the interaction process of these statuses may have some problems. Of course, although we haven't found it in our actual experiments, it is indeed a potential problem. They have considered a possible way, that is, whether they can take the ACPI status, in Kexec, we also save some data and restore the data during the bounce. In this way, we can solve this problem.

In addition, there are some problems with ACPI based on the implementation of Kexec sleep. ACPI requires to execute some ACPI methods before and after sleep. The original kernel is executed in one kernel, now we need to divide it into two kernels for execution, so more tests are required. Now we have a simple conclusion that Kexec and Keep domp are used to implement most of the functions, which is simpler than the previous sleep implementation and solves some repeated problems. For a process, because it uses different kernels to write memory images, this should be removed after the driver problem is solved, of course, this driver is mainly because many drivers are supposed to exist and written on such premise. There may be a lot of work to do in this regard.

The other one is that it easily exceeds half of the system memory size, because it does not need to be copied to create a memory image, it may only require that the size of the system's idle memory be greater than the size of the memory used for writing the kernel. This is basically what I'm talking about. Do you have any questions?

Q: Can I re-Initialize an ACPI before Kexec is added to the new kernel and loaded.

Huang MIAO: our thoughts are close to yours, and they are similar to yours.

Q: Will this memory image be compressed?

Yellow GHOST: This compression process is carried out in the Domp process, because in the original position, we will go to the Domp kernel, where there is a complete system, in addition to the limited memory size, it is no problem to perform all kinds of compression.

Q: Will this method be faster than before?

Huang Yun: theoretically, if we do a complete process, the second kernel has a process. If we do this complete process, it must be slower, but we have also developed some optimization methods to solve this problem, that is, we put the second kernel, that is, the first full restart of the second kernel, after completion, we will also sleep the second kernel. The second time we will not do the complete process, it is equivalent to waking up the written kernel, with such an optimization.

Questioner: I don't understand. How can you solve any write operations during the kernel copy?

Yellow kernel: because it is made in two kernels, when you write data to a disk, it is two kernels with the original kernel. The original kernel content is in the original memory, yes.

Q: But is the content in the original kernel running?

Yellow kernel: all the processes in the original kernel will not run, because the new kernel will no longer run.

Questioner: when you are doing this, it is actually a new kernel.

Huang MIAO: Yes. Now we have some interface problems. We are solving some interface problems, including kernel user interfaces, and how to ensure stability and a very stable interface, I think most of them are complete.

Questioner: So I am very supportive of you in this regard. I hope to congratulate you in this regard, and I also encourage you to make more attempts in this regard in the future.

Huang MIAO: OK. Thank you.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.