Skip to content

Commit fb313e8

Browse files
authored
Merge pull request #17 from WukLab/integration/tfork-perf-tune-filecow-pidns
Integration/tfork perf tune filecow pidns
2 parents df5a4cd + 85d1f7c commit fb313e8

50 files changed

Lines changed: 4000 additions & 276 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ check [agent-s README](agents/agent-s/README.md)
178178
- btrfs only
179179
- rootful only
180180
- amd64 only
181-
- linux page-cache CoW currently has a memory leak that will be fixed
181+
- Filecow layers are reclaimed with their cached inode/mapping owners rather
182+
than eagerly when a child is deleted. Repeated unchanged forks reuse the
183+
current layer, so retained layers are bounded by changed generations instead
184+
of the total fork count.
182185

183186
## License
184187

criu/build.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,25 @@ for mod in "${ACTIVE_MODULES[@]}"; do
9393
fi
9494

9595
if lsmod | awk '{print $1}' | grep -qx "${mod}"; then
96-
echo " -- ${mod}: already loaded, rmmod then insmod"
97-
rmmod "${mod}" 2>/dev/null || true
98-
else
99-
echo " -- ${mod}: insmod"
96+
echo " -- ${mod}: already loaded, trying reload"
97+
if ! rmmod "${mod}"; then
98+
echo "build.sh: failed to unload loaded module ${mod}; aborting to avoid stale module" >&2
99+
echo "build.sh: stop running tfork/podman containers that may still hold ${mod}, then retry" >&2
100+
exit 1
101+
fi
102+
if lsmod | awk '{print $1}' | grep -qx "${mod}"; then
103+
echo "build.sh: module ${mod} is still loaded after rmmod; aborting to avoid stale module" >&2
104+
echo "build.sh: stop running tfork/podman containers that may still hold ${mod}, then retry" >&2
105+
exit 1
106+
fi
107+
fi
108+
109+
echo " -- ${mod}: insmod"
110+
if ! insmod "${ko_path}"; then
111+
echo "build.sh: failed to insert rebuilt module ${mod} from ${ko_path}" >&2
112+
echo "build.sh: if the old module is still active, stop running tfork/podman containers and rerun this script" >&2
113+
exit 1
100114
fi
101-
insmod "${ko_path}"
102115
done
103116

104117
echo " -- verify all modules loaded"

criu/criu/action-scripts.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ static const char *action_names[ACT_MAX] = {
3232
[ACT_ORPHAN_PTS_MASTER] = "orphan-pts-master",
3333
[ACT_STATUS_READY] = "status-ready",
3434
[ACT_QUERY_EXT_FILES] = "query-ext-files",
35+
[ACT_POST_TFORK_FREEZE] = "post-tfork-freeze",
36+
[ACT_PRE_TFORK_RESTORE] = "pre-tfork-restore",
37+
[ACT_TFORK_SOURCE_DETACHED] = "tfork-source-detached",
3538
};
3639

3740
struct script {

criu/criu/clone-noasan.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ int clone3_with_pid_noasan(int (*fn)(void *), void *arg, int flags, int exit_sig
7878
c_args.flags = flags;
7979
c_args.set_tid = ptr_to_u64(&pid);
8080
c_args.set_tid_size = 1;
81+
pr_info("clone3 set_tid pid=%d flags=0x%x size=1\n", pid, flags);
8182
pid = syscall(__NR_clone3, &c_args, sizeof(c_args));
83+
if (pid < 0)
84+
pr_perror("clone3 set_tid failed flags=0x%x size=1", flags);
8285
if (pid == 0)
8386
exit(fn(arg));
8487
return pid;
@@ -99,6 +102,12 @@ int clone3_with_nested_pid_noasan(int (*fn)(void *), void *arg, int flags, int e
99102
BUG_ON(pid->ns_level > MAX_PID_NS_LEVEL || pid->ns_level <= 1);
100103
for (i = 0; i < pid->ns_level; i++)
101104
tids[i] = pid->ns[i].ns_pid;
105+
pr_info("clone3 nested set_tid flags=0x%x size=%d tids=%d/%d/%d/%d\n",
106+
flags, pid->ns_level,
107+
tids[0],
108+
pid->ns_level > 1 ? tids[1] : -1,
109+
pid->ns_level > 2 ? tids[2] : -1,
110+
pid->ns_level > 3 ? tids[3] : -1);
102111

103112
if (!(flags & CLONE_PARENT)) {
104113
if (exit_signal != SIGCHLD) {
@@ -112,6 +121,13 @@ int clone3_with_nested_pid_noasan(int (*fn)(void *), void *arg, int flags, int e
112121
c_args.set_tid = ptr_to_u64(tids);
113122
c_args.set_tid_size = pid->ns_level;
114123
pid_ret = syscall(__NR_clone3, &c_args, sizeof(c_args));
124+
if (pid_ret < 0)
125+
pr_perror("clone3 nested set_tid failed flags=0x%x size=%d tids=%d/%d/%d/%d",
126+
flags, pid->ns_level,
127+
tids[0],
128+
pid->ns_level > 1 ? tids[1] : -1,
129+
pid->ns_level > 2 ? tids[2] : -1,
130+
pid->ns_level > 3 ? tids[3] : -1);
115131
if (pid_ret == 0)
116132
exit(fn(arg));
117133
return pid_ret;

0 commit comments

Comments
 (0)