The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=472888018ce141227f8b019b6663739c36bc608c

commit 472888018ce141227f8b019b6663739c36bc608c
Author:     Mark Johnston <ma...@freebsd.org>
AuthorDate: 2024-07-29 01:40:48 +0000
Commit:     Mark Johnston <ma...@freebsd.org>
CommitDate: 2024-07-29 01:43:18 +0000

    proc: Remove kernel stack swapping support, part 6
    
    - Remove most checks of the P_INMEM flag.
    - Some uses remain since a few userspace tools, e.g., ps(1) and top(1)
      expect the flag to be set.  These can be cleaned up but the code has
      most likely been copy-pasted elsewhere and while linger for a long
      time.
    
    Tested by:      pho
    Reviewed by:    alc, imp, kib
    Differential Revision:  https://reviews.freebsd.org/D46117
---
 sys/ddb/db_command.c                  | 10 ++----
 sys/ddb/db_ps.c                       |  2 --
 sys/ddb/db_thread.c                   |  7 ++--
 sys/fs/procfs/procfs_status.c         | 26 ++++++--------
 sys/i386/linux/linux_ptrace_machdep.c |  4 +--
 sys/kern/kern_proc.c                  |  5 +--
 sys/kern/kern_racct.c                 |  6 ----
 sys/kern/sys_process.c                | 65 +++++++++++++++--------------------
 sys/sys/proc.h                        |  2 +-
 sys/sys/user.h                        |  2 +-
 sys/vm/vm_swapout.c                   |  7 ----
 11 files changed, 47 insertions(+), 89 deletions(-)

diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c
index 1043f7091085..bdc8a707970c 100644
--- a/sys/ddb/db_command.c
+++ b/sys/ddb/db_command.c
@@ -871,10 +871,7 @@ db_stack_trace(db_expr_t tid, bool hastid, db_expr_t 
count, char *modif)
        else
                pid = -1;
        db_printf("Tracing pid %d tid %ld td %p\n", pid, (long)td->td_tid, td);
-       if (td->td_proc != NULL && (td->td_proc->p_flag & P_INMEM) == 0)
-               db_printf("--- swapped out\n");
-       else
-               db_trace_thread(td, count);
+       db_trace_thread(td, count);
 }
 
 static void
@@ -898,10 +895,7 @@ _db_stack_trace_all(bool active_only)
                                db_printf("\nTracing command %s pid %d"
                                    " tid %ld td %p\n", td->td_proc->p_comm,
                                    td->td_proc->p_pid, (long)td->td_tid, td);
-                       if (td->td_proc->p_flag & P_INMEM)
-                               db_trace_thread(td, -1);
-                       else
-                               db_printf("--- swapped out\n");
+                       db_trace_thread(td, -1);
                        if (db_pager_quit) {
                                kdb_jmpbuf(prev_jb);
                                return;
diff --git a/sys/ddb/db_ps.c b/sys/ddb/db_ps.c
index 9bccb46f989c..733c440f5ee3 100644
--- a/sys/ddb/db_ps.c
+++ b/sys/ddb/db_ps.c
@@ -215,8 +215,6 @@ db_ps_proc(struct proc *p)
        state[1] = '\0';
 
        /* Additional process state flags. */
-       if (!(p->p_flag & P_INMEM))
-               strlcat(state, "W", sizeof(state));
        if (p->p_flag & P_TRACED)
                strlcat(state, "X", sizeof(state));
        if (p->p_flag & P_WEXIT && p->p_state != PRS_ZOMBIE)
diff --git a/sys/ddb/db_thread.c b/sys/ddb/db_thread.c
index e34d7356eb30..38ca9fa84f64 100644
--- a/sys/ddb/db_thread.c
+++ b/sys/ddb/db_thread.c
@@ -87,11 +87,8 @@ db_show_threads(db_expr_t addr, bool hasaddr, db_expr_t cnt, 
char *mod)
                    (void *)thr->td_kstack);
                prev_jb = kdb_jmpbuf(jb);
                if (setjmp(jb) == 0) {
-                       if (thr->td_proc->p_flag & P_INMEM) {
-                               if (db_trace_thread(thr, 1) != 0)
-                                       db_printf("***\n");
-                       } else
-                               db_printf("*** swapped out\n");
+                       if (db_trace_thread(thr, 1) != 0)
+                               db_printf("***\n");
                }
                kdb_jmpbuf(prev_jb);
                thr = kdb_thr_next(thr);
diff --git a/sys/fs/procfs/procfs_status.c b/sys/fs/procfs/procfs_status.c
index 9c2f42a45102..38070e0946bb 100644
--- a/sys/fs/procfs/procfs_status.c
+++ b/sys/fs/procfs/procfs_status.c
@@ -61,6 +61,7 @@
 int
 procfs_doprocstatus(PFS_FILL_ARGS)
 {
+       struct timeval start, ut, st;
        struct session *sess;
        struct thread *tdfirst;
        struct tty *tp;
@@ -121,21 +122,16 @@ procfs_doprocstatus(PFS_FILL_ARGS)
                wmesg = "nochan";
        thread_unlock(tdfirst);
 
-       if (p->p_flag & P_INMEM) {
-               struct timeval start, ut, st;
-
-               PROC_STATLOCK(p);
-               calcru(p, &ut, &st);
-               PROC_STATUNLOCK(p);
-               start = p->p_stats->p_start;
-               getboottime(&boottime);
-               timevaladd(&start, &boottime);
-               sbuf_printf(sb, " %jd,%ld %jd,%ld %jd,%ld",
-                   (intmax_t)start.tv_sec, start.tv_usec,
-                   (intmax_t)ut.tv_sec, ut.tv_usec,
-                   (intmax_t)st.tv_sec, st.tv_usec);
-       } else
-               sbuf_printf(sb, " -1,-1 -1,-1 -1,-1");
+       PROC_STATLOCK(p);
+       calcru(p, &ut, &st);
+       PROC_STATUNLOCK(p);
+       start = p->p_stats->p_start;
+       getboottime(&boottime);
+       timevaladd(&start, &boottime);
+       sbuf_printf(sb, " %jd,%ld %jd,%ld %jd,%ld",
+           (intmax_t)start.tv_sec, start.tv_usec,
+           (intmax_t)ut.tv_sec, ut.tv_usec,
+           (intmax_t)st.tv_sec, st.tv_usec);
 
        sbuf_printf(sb, " %s", wmesg);
 
diff --git a/sys/i386/linux/linux_ptrace_machdep.c 
b/sys/i386/linux/linux_ptrace_machdep.c
index a815b42ca024..8d88f8540fd5 100644
--- a/sys/i386/linux/linux_ptrace_machdep.c
+++ b/sys/i386/linux/linux_ptrace_machdep.c
@@ -213,7 +213,7 @@ linux_proc_read_fpxregs(struct thread *td, struct 
linux_pt_fpxreg *fpxregs)
 {
 
        PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
-       if (cpu_fxsr == 0 || (td->td_proc->p_flag & P_INMEM) == 0)
+       if (cpu_fxsr == 0)
                return (EIO);
        bcopy(&get_pcb_user_save_td(td)->sv_xmm, fpxregs, sizeof(*fpxregs));
        return (0);
@@ -224,7 +224,7 @@ linux_proc_write_fpxregs(struct thread *td, struct 
linux_pt_fpxreg *fpxregs)
 {
 
        PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
-       if (cpu_fxsr == 0 || (td->td_proc->p_flag & P_INMEM) == 0)
+       if (cpu_fxsr == 0)
                return (EIO);
        bcopy(fpxregs, &get_pcb_user_save_td(td)->sv_xmm, sizeof(*fpxregs));
        return (0);
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 280ad3facd3a..c47f5a15f252 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1148,10 +1148,7 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc 
*kp)
                kp->ki_ssize = vm->vm_ssize;
        } else if (p->p_state == PRS_ZOMBIE)
                kp->ki_stat = SZOMB;
-       if (kp->ki_flag & P_INMEM)
-               kp->ki_sflag = PS_INMEM;
-       else
-               kp->ki_sflag = 0;
+       kp->ki_sflag = PS_INMEM;
        /* Calculate legacy swtime as seconds since 'swtick'. */
        kp->ki_swtime = (ticks - p->p_swtick) / hz;
        kp->ki_pid = p->p_pid;
diff --git a/sys/kern/kern_racct.c b/sys/kern/kern_racct.c
index 43c3da0c2320..d900078fe5e2 100644
--- a/sys/kern/kern_racct.c
+++ b/sys/kern/kern_racct.c
@@ -332,12 +332,6 @@ racct_getpcpu(struct proc *p, u_int pcpu)
 
        ASSERT_RACCT_ENABLED();
 
-       /*
-        * If the process is swapped out, we count its %cpu usage as zero.
-        * This behaviour is consistent with the userland ps(1) tool.
-        */
-       if ((p->p_flag & P_INMEM) == 0)
-               return (0);
        swtime = (ticks - p->p_swtick) / hz;
 
        /*
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index 6df8e694e91a..8ce4ea01fe6f 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -71,7 +71,7 @@
 #define        PROC_ASSERT_TRACEREQ(p) MPASS(((p)->p_flag2 & P2_PTRACEREQ) != 
0)
 
 /*
- * Functions implemented using PROC_ACTION():
+ * Functions implemented below:
  *
  * proc_read_regs(proc, regs)
  *     Get the current user-visible register set from the process
@@ -96,43 +96,32 @@
  *     Arrange for the process to trap after executing a single instruction.
  */
 
-#define        PROC_ACTION(action) do {                                        
\
-       int error;                                                      \
-                                                                       \
-       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);                        \
-       if ((td->td_proc->p_flag & P_INMEM) == 0)                       \
-               error = EIO;                                            \
-       else                                                            \
-               error = (action);                                       \
-       return (error);                                                 \
-} while (0)
-
 int
 proc_read_regs(struct thread *td, struct reg *regs)
 {
-
-       PROC_ACTION(fill_regs(td, regs));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (fill_regs(td, regs));
 }
 
 int
 proc_write_regs(struct thread *td, struct reg *regs)
 {
-
-       PROC_ACTION(set_regs(td, regs));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (set_regs(td, regs));
 }
 
 int
 proc_read_dbregs(struct thread *td, struct dbreg *dbregs)
 {
-
-       PROC_ACTION(fill_dbregs(td, dbregs));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (fill_dbregs(td, dbregs));
 }
 
 int
 proc_write_dbregs(struct thread *td, struct dbreg *dbregs)
 {
-
-       PROC_ACTION(set_dbregs(td, dbregs));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (set_dbregs(td, dbregs));
 }
 
 /*
@@ -142,15 +131,15 @@ proc_write_dbregs(struct thread *td, struct dbreg *dbregs)
 int
 proc_read_fpregs(struct thread *td, struct fpreg *fpregs)
 {
-
-       PROC_ACTION(fill_fpregs(td, fpregs));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (fill_fpregs(td, fpregs));
 }
 
 int
 proc_write_fpregs(struct thread *td, struct fpreg *fpregs)
 {
-
-       PROC_ACTION(set_fpregs(td, fpregs));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (set_fpregs(td, fpregs));
 }
 
 static struct regset *
@@ -295,51 +284,51 @@ proc_write_regset(struct thread *td, int note, struct 
iovec *iov)
 int
 proc_read_regs32(struct thread *td, struct reg32 *regs32)
 {
-
-       PROC_ACTION(fill_regs32(td, regs32));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (fill_regs32(td, regs32));
 }
 
 int
 proc_write_regs32(struct thread *td, struct reg32 *regs32)
 {
-
-       PROC_ACTION(set_regs32(td, regs32));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (set_regs32(td, regs32));
 }
 
 int
 proc_read_dbregs32(struct thread *td, struct dbreg32 *dbregs32)
 {
-
-       PROC_ACTION(fill_dbregs32(td, dbregs32));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (fill_dbregs32(td, dbregs32));
 }
 
 int
 proc_write_dbregs32(struct thread *td, struct dbreg32 *dbregs32)
 {
-
-       PROC_ACTION(set_dbregs32(td, dbregs32));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (set_dbregs32(td, dbregs32));
 }
 
 int
 proc_read_fpregs32(struct thread *td, struct fpreg32 *fpregs32)
 {
-
-       PROC_ACTION(fill_fpregs32(td, fpregs32));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (fill_fpregs32(td, fpregs32));
 }
 
 int
 proc_write_fpregs32(struct thread *td, struct fpreg32 *fpregs32)
 {
-
-       PROC_ACTION(set_fpregs32(td, fpregs32));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (set_fpregs32(td, fpregs32));
 }
 #endif
 
 int
 proc_sstep(struct thread *td)
 {
-
-       PROC_ACTION(ptrace_single_step(td));
+       PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
+       return (ptrace_single_step(td));
 }
 
 int
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 2c8b0dc041c4..d7d4b4c7450e 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -835,7 +835,7 @@ struct proc {
 #define        P_TOTAL_STOP    0x02000000      /* Stopped in stop_all_proc. */
 #define        P_INEXEC        0x04000000      /* Process is in execve(). */
 #define        P_STATCHILD     0x08000000      /* Child process stopped or 
exited. */
-#define        P_INMEM         0x10000000      /* Loaded into memory. */
+#define        P_INMEM         0x10000000      /* Loaded into memory, always 
set. */
 #define        P_UNUSED1       0x20000000      /* --available-- */
 #define        P_UNUSED2       0x40000000      /* --available-- */
 #define        P_PPTRACE       0x80000000      /* PT_TRACEME by vforked child. 
*/
diff --git a/sys/sys/user.h b/sys/sys/user.h
index 96f17bffff8c..cd0535f0d765 100644
--- a/sys/sys/user.h
+++ b/sys/sys/user.h
@@ -225,7 +225,7 @@ void fill_kinfo_proc(struct proc *, struct kinfo_proc *);
  *  Legacy PS_ flag.  This moved to p_flag but is maintained for
  *  compatibility.
  */
-#define        PS_INMEM        0x00001         /* Loaded into memory. */
+#define        PS_INMEM        0x00001         /* Loaded into memory, always 
true. */
 
 /* ki_sessflag values */
 #define        KI_CTTY         0x00000001      /* controlling tty vnode active 
*/
diff --git a/sys/vm/vm_swapout.c b/sys/vm/vm_swapout.c
index 1f3b3a8532f1..cb5dab7cacdd 100644
--- a/sys/vm/vm_swapout.c
+++ b/sys/vm/vm_swapout.c
@@ -383,13 +383,6 @@ again:
                        limit = OFF_TO_IDX(
                            qmin(rsslim.rlim_cur, rsslim.rlim_max));
 
-                       /*
-                        * let processes that are swapped out really be
-                        * swapped out set the limit to nothing (will force a
-                        * swap-out.)
-                        */
-                       if ((p->p_flag & P_INMEM) == 0)
-                               limit = 0;      /* XXX */
                        vm = vmspace_acquire_ref(p);
                        _PHOLD(p);
                        PROC_UNLOCK(p);

Reply via email to