checkpoint-restore / criu

Checkpoint/Restore tool
criu.org
Other
2.88k stars 583 forks source link

Change criu restore to an on-demand version #1705

Open Yangfisher1 opened 2 years ago

Yangfisher1 commented 2 years ago

Hey, about two months ago I started to use criu as a part of our own project. We noticed that when restore the process, loading process memory from page.img just loads all pages, whose code is in criu/pie/restorer.c, line 1535, r = sys_preadv(args->vma_ios_fd, iovs, nr, rio->off); Considering that our work is related to serverless, we thought this was totally unnecessary to load all pages at once. Instead, we can use an "on-demand" way by changing the sys_preadv to sys_mmap, which has been introduced by a paper Replayable Execution Optimized for Page Sharing for a Managed Runtime Environment, in Section 4, Figure 8. We implemented the algorithm and tested for some simple program to dump and restore, it worked well. So I think it might be a new feature to restore a process using sys_mmap. But when I tested for this, it didn't pass the test zdtm.py. In fact, it failed at the very beginning of the test. I checked the code and found out the reason it failed was the maps check in check_visible_state, which will check the status of a program before and after dump+restore. However, after the restore changed, at this phase, we changed some anonymous memory area which was now mapped to page.img, so the check failed. So I'm wondering that is it possible for this to become a new feature in criu, or you just have tried and it didn't perform well. And I think that I can still use a hybrid way to pass the exam(just still keep the anonymous memory area using pread). But anyway, I want to hear your advice at first. Thanks!

Yangfisher1 commented 2 years ago

Using a hybrid way, as keeping the anonymous memory area with sys_pread passed the test with sudo ./zdtm.py run -a.

avagin commented 2 years ago

Cc: @checkpoint-restore/maintainers

avagin commented 2 years ago

This should not be a default behaviour, but we can think on adding a separate mode for that.

We may need to introduce a new format for page.img, otherwise we can end up with thousands of thousands mappings. // Just thinking aloud .

Yangfisher1 commented 2 years ago

Yes, I believe that adding a parameter like criu restore -D checkpoint/ --on-demand and then using the sys_mmap to restore is properly in some case where you don't need to load all the memory at once.

github-actions[bot] commented 2 years ago

A friendly reminder that this issue had no activity for 30 days.

Snorch commented 2 years ago

Sorry in advance if I'm asking something obvious.

Am I right that this approach with switching from preadv to mmap would make mappings, which were anonymous before c/r, become file mappings after c/r with backing file referring to criu image file?

Yangfisher1 commented 2 years ago

I chose to use a hybrid way to solve this problem, because the zdtm test would check these state. I have already made a pull request #1711 , but there're still few bugs need to fix.