4
4
#include <fcntl.h> // For open()
5
5
#include <sys/types.h>
6
6
#include <criu/criu.h>
7
+ #include <string.h> // For memset()
8
+ #include <time.h>
9
+ #include <sys/time.h>
7
10
8
- #define CHECKPOINT_ITER 5
9
- #define TOTAL_ITER 10
11
+ #define CHECKPOINT_ITER 3
12
+ #define TOTAL_ITER 5
10
13
11
14
int fd = -1 ;
12
15
@@ -28,35 +31,43 @@ void set_criu() {
28
31
criu_set_pid (getpid ()); // Set PID of the process to checkpoint
29
32
criu_set_leave_running (1 ); // Keep the process running after dump
30
33
criu_set_service_address ("/tmp/criu_service.socket" );
34
+ criu_set_track_mem (0 ); // Track memory pages
31
35
}
32
36
33
37
int main () {
34
38
set_criu ();
35
39
36
- if (access ("./criu_images" , F_OK ) == 0 ) {
37
- printf ("Restoring from checkpoint...\n" );
38
- criu_restore ();
39
- perror ("CRIU restore failed" );
40
- exit (EXIT_FAILURE );
41
- }
40
+ // if (access("./criu_images", F_OK) == 0) {
41
+ // printf("Restoring from checkpoint...\n");
42
+ // criu_restore();
43
+ // perror("CRIU restore failed");
44
+ // exit(EXIT_FAILURE);
45
+ // }
46
+
42
47
for (int i = 1 ; i <= TOTAL_ITER ; i ++ ) {
48
+ struct timeval start ;
49
+ gettimeofday (& start , NULL );
43
50
printf ("Iteration: %d\n" , i );
44
51
sleep (1 ); // Simulate long-running work
45
-
52
+ void * x = malloc (1025 * 1024 * 1024 ); // Allocate 1MB memory
53
+ memset (x , 1 , 1024 * 1024 * 1024 ); // Write to the memory
54
+ printf ("address: %p\n" , x );
46
55
// Create a checkpoint after a certain number of iterations
47
56
if (i == CHECKPOINT_ITER ) {
48
57
printf ("Creating checkpoint...\n" );
49
58
50
59
// Perform the checkpoint
51
- if (criu_dump () < 0 ) {
52
- perror ("CRIU checkpoint failed" );
53
- exit (EXIT_FAILURE );
54
- }
60
+ criu_dump ();
55
61
56
62
printf ("Checkpoint created successfully!\n" );
57
- printf ("Exiting after creating a checkpoint, run again to restore from it.\n" );
58
- exit (EXIT_SUCCESS );
63
+ // printf("Exiting after creating a checkpoint, run again to restore from it.\n");
64
+ // exit(EXIT_SUCCESS);
59
65
}
66
+ free (x );
67
+
68
+ struct timeval end ;
69
+ gettimeofday (& end , NULL );
70
+ printf ("took %lu us\n" , (end .tv_sec - start .tv_sec ) * 1000000 + end .tv_usec - start .tv_usec );
60
71
}
61
72
62
73
printf ("Loop finished.\n" );
0 commit comments