`fork` takes 113 ms while an exited `CLONE_VM` child is unreaped, where it takes 6 ms otherwise
Les mainteneurs répondent en général sous 2 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 65/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- c
- Domaine
- operating-systems
Piste de recherche
Start by reading thread_quiesce_siblings in src/runtime/thread.c, then compare the normal exit path in vm_clone_thread_run with vm_clone_report_bringup_failure in src/runtime/forkipc.c. Run the issue's reproducer to confirm the delay with an exited, unreaped CLONE_VM child. Done means forks no longer wait for the quiesce timeout in that state and the before/after-reap cases still behave normally.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
What happens
While a clone(CLONE_VM | SIGCHLD) child has exited but has not been reaped, every fork() in the parent waits the full 100 ms quiesce timeout in thread_quiesce_siblings (src/runtime/thread.c). Linux forks at its normal speed in the same state.
Evidence
On upstream main a20dfab, the probe below compared with elfuse-probe-diff against Linux 6.18.60 (qemu reference VM):
| state | elfuse | Linux |
|---|---|---|
| before the vm-clone | slowest of 5 forks < 50 ms | < 50 ms |
| vm-clone exited, not reaped | slowest of 5 forks >= 50 ms | < 50 ms |
after waitpid reaps it |
< 50 ms | < 50 ms |
The timing variant of the probe (%.1f ms instead of the 50 ms test), 3 runs under elfuse: 5.7 / 5.3 / 7.3 ms before, 112.8 / 112.9 / 113.6 ms with the unreaped child, 13.1 / 11.7 / 13.6 ms after the reap.
Cause
Checked by reading. thread_quiesce_siblings counts every active thread slot except the caller and sets fork_counted on it. A vm-clone child's slot stays active after it exits until the parent's wait4 frees it in thread_ptrace_wait, so the exited child is counted, and it can never reach thread_fork_barrier_check. The normal exit path in vm_clone_thread_run (src/runtime/forkipc.c) sets vm_exited but does not call thread_fork_release_counted_locked, which the bring-up failure path in vm_clone_report_bringup_failure does call, so nothing hands the count back and the forker waits until the 100 ms deadline.
Reproduce
#include <sched.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
static int child_fn(void *arg) { (void) arg; return 0; }
static double fork_ms(void)
{
struct timespec a, b;
clock_gettime(CLOCK_MONOTONIC, &a);
pid_t pid = fork();
if (pid == 0)
_exit(0);
clock_gettime(CLOCK_MONOTONIC, &b);
waitpid(pid, NULL, 0);
return (b.tv_sec - a.tv_sec) * 1e3 + (b.tv_nsec - a.tv_nsec) / 1e6;
}
static double worst(void)
{
double w = 0;
for (int i = 0; i < 5; i++) {
double t = fork_ms();
if (t > w)
w = t;
}
return w;
}
int main(void)
{
printf("before vm-clone: slowest of 5 forks >= 50 ms: %d\n", worst() >= 50);
size_t sz = 64 * 1024;
char *stack = malloc(sz);
pid_t vc = clone(child_fn, stack + sz, CLONE_VM | SIGCHLD, NULL);
if (vc < 0)
return 1;
usleep(100 * 1000); /* let the vm-clone child exit; do not reap it */
printf("with an unreaped vm-clone: slowest of 5 forks >= 50 ms: %d\n", worst() >= 50);
waitpid(vc, NULL, 0);
printf("after reaping it: slowest of 5 forks >= 50 ms: %d\n", worst() >= 50);
return 0;
}
Possible fix
Call thread_fork_release_counted_locked(t) in vm_clone_thread_run under the same thread_lock section that sets vm_exited, as vm_clone_report_bringup_failure does. Or skip vm_exited slots in the counting loop of thread_quiesce_siblings, since an exited child runs no guest code.
Origin
Follow-up from #525. Related: #511 (the same barrier, bypassed by a running sibling; a different cause).
- Langage dominant
- C
- Étoiles
- 287
- Forks
- 33
- Merge moyen
- 2 j 17 h
- PR mergées (30 j)
- 18
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de sysprog21/elfuse
-
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 80/100
Les mainteneurs répondent en général sous 2 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
Les mainteneurs répondent en général sous 2 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 2 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de sysprog21/elfuse
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
libreswan/libreswan#3185 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
[SDL3pp] update to 0.12.0Ouvertecategory:port-update
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 2 jours
-
[InstCombine] 23.x folds 0.0 * (0.0 / x) to 0.0 when x may be zero (fixed on main by #202482)Ouvertellvm:instcombine
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
llvm/llvm-project#246503 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour