crit: Add madvise flags decoding

Submitted by Víctor González Prieto on April 8, 2019, 9:37 p.m.

Details

Message ID 20190408213717.5009-1-victor.gonzalez.prieto@est.fib.upc.edu
State New
Series "crit: Add madvise flags decoding"
Headers show

Commit Message

Víctor González Prieto April 8, 2019, 9:37 p.m.
Closes: checkpoint-restore/criu#342

Only added support for the subset of advises that CRIU encodes in its
mm images, as defined in criu/proc_parse.c, macro _vmflag_match().

As for the hardcoded advise constants, I crosschecked a number of
mman.h headers available on the Internet, including criu's.

Signed-off-by: Víctor González Prieto <victor.gonzalez.prieto@est.fib.upc.edu>
---
How did I test this:
I ran the Simple Loop demo (https://criu.org/Simple_loop), before
and after the patch. In the mm checkpoint file for the first process,
there's a line for one of the VMAs that, with crit show, reads
"madv": "0x10000"
After applying the patch, the line reads
"madv": "MADV_DONTDUMP"

I guess this happens because of criu/mem.c#L1094, which is the only
use of advises I have seen in the codebase aside from logging and tests.

I also ensured that I'm not breaking any ZDTM tests. Would that mean
that the CRIT tools could use some testing?

 images/vma.proto         |  2 +-
 lib/py/images/pb2dict.py | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/images/vma.proto b/images/vma.proto
index 7085f423..16747882 100644
--- a/images/vma.proto
+++ b/images/vma.proto
@@ -18,7 +18,7 @@  message vma_entry {
 	required sint64		fd	= 8;
 
 	/* madvise flags bitmap */
-	optional uint64		madv	= 9 [(criu).hex = true];
+	optional uint64		madv	= 9 [(criu).flags = "madvise.advice" ];
 
 	/* file status flags */
 	optional uint32		fdflags	= 10 [(criu).hex = true];
diff --git a/lib/py/images/pb2dict.py b/lib/py/images/pb2dict.py
index 18d4c68e..4a2516c4 100644
--- a/lib/py/images/pb2dict.py
+++ b/lib/py/images/pb2dict.py
@@ -98,6 +98,16 @@  mmap_status_map = [
 	('VMA_UNSUPP',		1 << 31),
 ]
 
+madvise_advice_map = [
+	('MADV_RANDOM',	1 << 1),
+	('MADV_SEQUENTIAL',	1 << 2),
+	('MADV_DONTFORK',	1 << 10),
+	('MADV_MERGEABLE',	1 << 12),
+	('MADV_HUGEPAGE',	1 << 14),
+	('MADV_NOHUGEPAGE',	1 << 15),
+	('MADV_DONTDUMP',	1 << 16),
+]
+
 rfile_flags_map = [
 	('O_WRONLY',	0o1),
 	('O_RDWR',	0o2),
@@ -116,6 +126,7 @@  flags_maps = {
 	'mmap.prot' : mmap_prot_map,
 	'mmap.flags' : mmap_flags_map,
 	'mmap.status' : mmap_status_map,
+	'madvise.advice' : madvise_advice_map,
 	'rfile.flags' : rfile_flags_map,
 	'pmap.flags' : pmap_flags_map,
 }

Comments

Cyrill Gorcunov April 13, 2019, 7:46 a.m.
On Mon, Apr 08, 2019 at 11:37:17PM +0200, Víctor González Prieto wrote:
> Closes: checkpoint-restore/criu#342
> 
> Only added support for the subset of advises that CRIU encodes in its
> mm images, as defined in criu/proc_parse.c, macro _vmflag_match().
> 
> As for the hardcoded advise constants, I crosschecked a number of
> mman.h headers available on the Internet, including criu's.
> 
> Signed-off-by: Víctor González Prieto <victor.gonzalez.prieto@est.fib.upc.edu>

Looks ok to me.

Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>