-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't dump pages which only contain zero bytes
Introduces a new command line option '--skip-zero-bytes' which detects pages which only contain zero bytes and prohibits that they get dumped in the processes image file. It is a potentially expensive operation because it checks for every single process page if it contains only zeros, but it can significantly decrease the image size and improve the startup-time if many such pages exist. It effectively replaces such pages which the kernel's zero-page on restore. Signed-off-by: Volker Simonis <[email protected]>
- Loading branch information
Showing
15 changed files
with
185 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ | |
#include <sys/mman.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <string.h> | ||
#include <sys/syscall.h> | ||
#include <sys/prctl.h> | ||
#include <sys/uio.h> | ||
|
||
#include "types.h" | ||
#include "cr_options.h" | ||
|
@@ -31,6 +33,7 @@ | |
#include "prctl.h" | ||
#include "compel/infect-util.h" | ||
#include "pidfd-store.h" | ||
#include "xmalloc.h" | ||
|
||
#include "protobuf.h" | ||
#include "images/pagemap.pb-c.h" | ||
|
@@ -191,11 +194,33 @@ static int generate_iovs(struct pstree_item *item, struct vma_area *vma, struct | |
bool has_parent) | ||
{ | ||
unsigned long nr_scanned; | ||
unsigned long pages[3] = {}; | ||
/* Counters for PAGES_SKIPPED_PARENT, PAGES_LAZY, PAGES_WRITTEN and SKIPPED_ZERO_PAGES */ | ||
unsigned long pages[4] = {}; | ||
unsigned long vaddr; | ||
bool dump_all_pages; | ||
int ret = 0; | ||
|
||
static char *zero_page = NULL; | ||
static char *remote_page = NULL; | ||
int zero = 0; | ||
struct iovec local[2]; | ||
struct iovec remote[1]; | ||
int nread = 0; | ||
if (opts.skip_zero_pages && zero_page == NULL) { | ||
zero_page = xmalloc(PAGE_SIZE); | ||
remote_page = xmalloc(PAGE_SIZE); | ||
if (zero_page == NULL || remote_page == NULL) { | ||
pr_warn("Can't allocate memory - disabling --skip-zero-pages\n"); | ||
opts.skip_zero_pages = 0; | ||
} else { | ||
memzero(zero_page, PAGE_SIZE); | ||
local[0].iov_base = remote_page; | ||
local[0].iov_len = PAGE_SIZE; | ||
remote[0].iov_base = (void *)0x0; | ||
remote[0].iov_len = PAGE_SIZE; | ||
} | ||
} | ||
|
||
dump_all_pages = should_dump_entire_vma(vma->e); | ||
|
||
nr_scanned = 0; | ||
|
@@ -207,10 +232,26 @@ static int generate_iovs(struct pstree_item *item, struct vma_area *vma, struct | |
|
||
/* If dump_all_pages is true, should_dump_page is called to get pme. */ | ||
next = should_dump_page(pmc, vma->e, vaddr, &softdirty); | ||
if (!dump_all_pages && next != vaddr) { | ||
vaddr = next - PAGE_SIZE; | ||
continue; | ||
} | ||
if (!dump_all_pages) { | ||
if (next != vaddr) { | ||
Check warning on line 236 in criu/mem.c GitHub Actions / build
|
||
vaddr = next - PAGE_SIZE; | ||
continue; | ||
} else if (opts.skip_zero_pages) { | ||
remote[0].iov_base = (void *)vaddr; | ||
nread = process_vm_readv(item->pid->real, local, 1, remote, 1, 0); | ||
if (nread == PAGE_SIZE) { | ||
zero = memcmp(zero_page, remote_page, PAGE_SIZE); | ||
/* | ||
* If the page contains just zeros we can treat it like the zero page and skip it. | ||
* At restore it will be replaced by a reference to the zero page and COWed if accessed. | ||
*/ | ||
if (zero == 0) { | ||
pages[3]++; | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (vma_entry_can_be_lazy(vma->e) && !is_stack(item, vaddr)) | ||
ppb_flags |= PPB_LAZY; | ||
|
@@ -247,8 +288,10 @@ static int generate_iovs(struct pstree_item *item, struct vma_area *vma, struct | |
cnt_add(CNT_PAGES_SKIPPED_PARENT, pages[0]); | ||
cnt_add(CNT_PAGES_LAZY, pages[1]); | ||
cnt_add(CNT_PAGES_WRITTEN, pages[2]); | ||
cnt_add(CNT_SKIPPED_ZERO_PAGES, pages[3]); | ||
|
||
pr_info("Pagemap generated: %lu pages (%lu lazy) %lu holes\n", pages[2] + pages[1], pages[1], pages[0]); | ||
pr_info("Pagemap generated: %lu pages (%lu lazy) %lu holes %lu skipped zero\n", | ||
pages[2] + pages[1], pages[1], pages[0], pages[3]); | ||
return ret; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version = "1.0" encoding = "UTF-8"?> | ||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > | ||
|
||
<suite name = "Suite2"> | ||
<parameter name="checkpointOpt" value="--skip-zero-pages"/> | ||
<parameter name="restoreOpt" value=""/> | ||
|
||
<test name = "test1-FileRead"> | ||
<parameter name="testname" value="FileRead"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test2-ReadWrite"> | ||
<parameter name="testname" value="ReadWrite"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test3-MemoryMappings"> | ||
<parameter name="testname" value="MemoryMappings"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test4-MultipleFileRead"> | ||
<parameter name="testname" value="MultipleFileRead"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test5-MultipleFileWrite"> | ||
<parameter name="testname" value="MultipleFileWrite"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test6-Sockets"> | ||
<parameter name="testname" value="Sockets"/> | ||
<parameter name="checkpointOpt" value="--tcp-established --skip-zero-pages"/> | ||
<parameter name="restoreOpt" value="--tcp-established"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test7-SocketsListen"> | ||
<parameter name="testname" value="SocketsListen"/> | ||
<parameter name="checkpointOpt" value="--tcp-established --skip-zero-pages"/> | ||
<parameter name="restoreOpt" value="--tcp-established"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test8-SocketsConnect"> | ||
<parameter name="testname" value="SocketsConnect"/> | ||
<parameter name="checkpointOpt" value="--tcp-established --skip-zero-pages"/> | ||
<parameter name="restoreOpt" value="--tcp-established"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test9-SocketsMultiple"> | ||
<parameter name="testname" value="SocketsMultiple"/> | ||
<parameter name="checkpointOpt" value="--tcp-established --skip-zero-pages"/> | ||
<parameter name="restoreOpt" value="--tcp-established"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
</test> | ||
|
||
<test name = "test10-SocketsData"> | ||
<parameter name="testname" value="SocketsData"/> | ||
<parameter name="checkpointOpt" value="--tcp-established --skip-zero-pages"/> | ||
<parameter name="restoreOpt" value="--tcp-established"/> | ||
<classes> | ||
<class name = "org.criu.java.tests.CheckpointRestore"/> | ||
</classes> | ||
|
||
</test> | ||
|
||
</suite> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters