git: 43339648088b - main - pwd_altroot(): avoid creating new pwd structure if altroot does not change
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 20 Nov 2026 15:10:44 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=43339648088b5fb71ff5e05c5b2937950f849654
commit 43339648088b5fb71ff5e05c5b2937950f849654
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-09-25 23:48:49 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-20 15:10:26 +0000
pwd_altroot(): avoid creating new pwd structure if altroot does not change
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D60035
---
sys/kern/kern_descrip.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index de49d738c6d0..d7e16db12a05 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -4416,6 +4416,7 @@ pwd_altroot(struct thread *td, struct vnode *altroot_vp)
{
struct pwddesc *pdp;
struct pwd *newpwd, *oldpwd;
+ struct vnode *vp;
if (altroot_vp != NULL && altroot_vp->v_type != VDIR)
return (ENOTDIR);
@@ -4423,25 +4424,21 @@ pwd_altroot(struct thread *td, struct vnode *altroot_vp)
pdp = td->td_proc->p_pd;
PWDDESC_XLOCK(pdp);
oldpwd = PWDDESC_XLOCKED_LOAD_PWD(pdp);
- if (altroot_vp != NULL) {
- /*
- * Native process to a non-native ABI.
- */
-
- vrefact(altroot_vp);
- newpwd->pwd_adir = altroot_vp;
+ vp = altroot_vp != NULL ? altroot_vp : oldpwd->pwd_rdir;
+ if (vp != oldpwd->pwd_adir) {
+ vrefact(vp);
+ newpwd->pwd_adir = vp;
+ pwd_fill(oldpwd, newpwd);
+ pwd_set(pdp, newpwd);
+ newpwd = NULL;
} else {
- /*
- * Non-native process to the native ABI.
- */
-
- vrefact(oldpwd->pwd_rdir);
- newpwd->pwd_adir = oldpwd->pwd_rdir;
+ oldpwd = NULL;
}
- pwd_fill(oldpwd, newpwd);
- pwd_set(pdp, newpwd);
PWDDESC_XUNLOCK(pdp);
- pwd_drop(oldpwd);
+ if (oldpwd != NULL)
+ pwd_drop(oldpwd);
+ if (newpwd != NULL)
+ pwd_drop(newpwd);
return (0);
}