criu
criu copied to clipboard
Don't dump pages which only contain zero bytes
I want to propose a new command line option zero-pages
which, if enabled, detects pages which only contain zero bytes and skip their dumping to the image file. At restore, such pages will be replaced by the kernels zero page automatically.This can be useful for runtimes like Java, which often allocate large memory regions without fully using them (e.g. for the heap). For a simple Helloworld Java program, this new feature shrinks the image size be about 20% from 13mb to 11mb.
I've enabled GitHub Actions on my fork and all the test are green except the Alpine test which I see failing on upstream as well and the Code Linter test where I can't understand what he's objecting.
I'm a first time contributor to this project so please let me know if I've missed something.
This can be useful for runtimes like Java, which often allocate large memory regions without fully using them (e.g. for the heap). For a simple Helloworld Java program, this new feature shrinks the image size be about 20% from 13mb to 11mb.
@simonis It might be more effective to address this problem using compression for memory pages, similar to the approach used in CRaC.
This can be useful for runtimes like Java, which often allocate large memory regions without fully using them (e.g. for the heap). For a simple Helloworld Java program, this new feature shrinks the image size be about 20% from 13mb to 11mb.
@simonis It might be more effective to address this problem using compression for memory pages, similar to the approach used in CRaC.
I think compressing the image as done criu-crac is somewhat orthogonal. It decreases the image size which is nice if you have to transfer it to another host. But before restore, it decompresses the image again and loads all its content (even the pages containing just zeros) into memory. The zeros are mmaped into the target process which takes time and also increases the initial RSS of the target process.
With the solution proposed here, fewer memory has to be mmaped to the target process. The zero pages will be COWed gradually as they are needed from fresh pages and don't have to be read from the image on the disc which is faster.
I think the code linter wants a \n at the end of the warning.
Without looking too closely, the idea of this PR sounds like a good one.
I think the code linter wants a \n at the end of the warning.
Thanks, I've fixed that now.
Without looking too closely, the idea of this PR sounds like a good one.
Thanks.
Code Linter test where I can't understand what he's objecting
@simonis Would it be possible to run make indent
before committing your changes? This should fix the code style problems such as missing spaces. In addition, it would be great if you can add a commit message with a description that explains what changes are introduced and why. The following blog post describes how to write good commit messages: https://cbea.ms/git-commit/
Code Linter test where I can't understand what he's objecting
@simonis Would it be possible to run
make indent
before committing your changes? This should fix the code style problems such as missing spaces. In addition, it would be great if you can add a commit message with a description that explains what changes are introduced and why. The following blog post describes how to write good commit messages: https://cbea.ms/git-commit/
Done (had to install a newer version of clang-format
).
I believe we need a zdtm test, which can reproduce such a zero page without PAGE_IS_PFNZERO but with zero data.
I've now added a new zdtm test which verifies that the --skip-zero-pages
option does indeed optimize pages which only contain zero bytes.
\On Thu, Feb 1, 2024 at 9:47 PM Andrei Vagin @.***> wrote:
@avagin commented on this pull request.
In criu/mem.c:
vaddr = vma->e->start + *off + pfn * PAGE_SIZE;
- /*
- If should_dump_page() returns true, it means the page is in the dumpees resident memory
- (i.e. bit 63 of the page frame number 'at[pfn]' is set) but it is not the zero-page.
- */
- if (should_dump_page(vma->e, at[pfn])) {
- if (opts.skip_zero_pages) {
- remote[0].iov_base = (void*)vaddr;
- nread = process_vm_readv(item->pid->real, local, 1, remote, 1, 0);
@simonis FOSDEM was my favorite conference when I lived close by. btw @mihalicyn are there too, he is one of criu maintainers. He will be happy to help with any questions.
Both @mihalicyn and @rst0git are in the Containers devroom
-- Sincerely yours, Mike.
A friendly reminder that this PR had no activity for 30 days.
Still on my ToDo list, so post this to avoid auto-closing..