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
This commit is contained in:
Mark Johnston 2024-07-29 01:40:48 +00:00
parent ba682f8b9b
commit 472888018c
11 changed files with 47 additions and 89 deletions

View file

@ -871,10 +871,7 @@ db_stack_trace(db_expr_t tid, bool hastid, db_expr_t count, char *modif)
else else
pid = -1; pid = -1;
db_printf("Tracing pid %d tid %ld td %p\n", pid, (long)td->td_tid, td); 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_trace_thread(td, count);
db_printf("--- swapped out\n");
else
db_trace_thread(td, count);
} }
static void static void
@ -898,10 +895,7 @@ _db_stack_trace_all(bool active_only)
db_printf("\nTracing command %s pid %d" db_printf("\nTracing command %s pid %d"
" tid %ld td %p\n", td->td_proc->p_comm, " tid %ld td %p\n", td->td_proc->p_comm,
td->td_proc->p_pid, (long)td->td_tid, td); td->td_proc->p_pid, (long)td->td_tid, td);
if (td->td_proc->p_flag & P_INMEM) db_trace_thread(td, -1);
db_trace_thread(td, -1);
else
db_printf("--- swapped out\n");
if (db_pager_quit) { if (db_pager_quit) {
kdb_jmpbuf(prev_jb); kdb_jmpbuf(prev_jb);
return; return;

View file

@ -215,8 +215,6 @@ db_ps_proc(struct proc *p)
state[1] = '\0'; state[1] = '\0';
/* Additional process state flags. */ /* Additional process state flags. */
if (!(p->p_flag & P_INMEM))
strlcat(state, "W", sizeof(state));
if (p->p_flag & P_TRACED) if (p->p_flag & P_TRACED)
strlcat(state, "X", sizeof(state)); strlcat(state, "X", sizeof(state));
if (p->p_flag & P_WEXIT && p->p_state != PRS_ZOMBIE) if (p->p_flag & P_WEXIT && p->p_state != PRS_ZOMBIE)

View file

@ -87,11 +87,8 @@ db_show_threads(db_expr_t addr, bool hasaddr, db_expr_t cnt, char *mod)
(void *)thr->td_kstack); (void *)thr->td_kstack);
prev_jb = kdb_jmpbuf(jb); prev_jb = kdb_jmpbuf(jb);
if (setjmp(jb) == 0) { if (setjmp(jb) == 0) {
if (thr->td_proc->p_flag & P_INMEM) { if (db_trace_thread(thr, 1) != 0)
if (db_trace_thread(thr, 1) != 0) db_printf("***\n");
db_printf("***\n");
} else
db_printf("*** swapped out\n");
} }
kdb_jmpbuf(prev_jb); kdb_jmpbuf(prev_jb);
thr = kdb_thr_next(thr); thr = kdb_thr_next(thr);

View file

@ -61,6 +61,7 @@
int int
procfs_doprocstatus(PFS_FILL_ARGS) procfs_doprocstatus(PFS_FILL_ARGS)
{ {
struct timeval start, ut, st;
struct session *sess; struct session *sess;
struct thread *tdfirst; struct thread *tdfirst;
struct tty *tp; struct tty *tp;
@ -121,21 +122,16 @@ procfs_doprocstatus(PFS_FILL_ARGS)
wmesg = "nochan"; wmesg = "nochan";
thread_unlock(tdfirst); thread_unlock(tdfirst);
if (p->p_flag & P_INMEM) { PROC_STATLOCK(p);
struct timeval start, ut, st; calcru(p, &ut, &st);
PROC_STATUNLOCK(p);
PROC_STATLOCK(p); start = p->p_stats->p_start;
calcru(p, &ut, &st); getboottime(&boottime);
PROC_STATUNLOCK(p); timevaladd(&start, &boottime);
start = p->p_stats->p_start; sbuf_printf(sb, " %jd,%ld %jd,%ld %jd,%ld",
getboottime(&boottime); (intmax_t)start.tv_sec, start.tv_usec,
timevaladd(&start, &boottime); (intmax_t)ut.tv_sec, ut.tv_usec,
sbuf_printf(sb, " %jd,%ld %jd,%ld %jd,%ld", (intmax_t)st.tv_sec, st.tv_usec);
(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");
sbuf_printf(sb, " %s", wmesg); sbuf_printf(sb, " %s", wmesg);

View file

@ -213,7 +213,7 @@ linux_proc_read_fpxregs(struct thread *td, struct linux_pt_fpxreg *fpxregs)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED); 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); return (EIO);
bcopy(&get_pcb_user_save_td(td)->sv_xmm, fpxregs, sizeof(*fpxregs)); bcopy(&get_pcb_user_save_td(td)->sv_xmm, fpxregs, sizeof(*fpxregs));
return (0); 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); 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); return (EIO);
bcopy(fpxregs, &get_pcb_user_save_td(td)->sv_xmm, sizeof(*fpxregs)); bcopy(fpxregs, &get_pcb_user_save_td(td)->sv_xmm, sizeof(*fpxregs));
return (0); return (0);

View file

@ -1148,10 +1148,7 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
kp->ki_ssize = vm->vm_ssize; kp->ki_ssize = vm->vm_ssize;
} else if (p->p_state == PRS_ZOMBIE) } else if (p->p_state == PRS_ZOMBIE)
kp->ki_stat = SZOMB; kp->ki_stat = SZOMB;
if (kp->ki_flag & P_INMEM) kp->ki_sflag = PS_INMEM;
kp->ki_sflag = PS_INMEM;
else
kp->ki_sflag = 0;
/* Calculate legacy swtime as seconds since 'swtick'. */ /* Calculate legacy swtime as seconds since 'swtick'. */
kp->ki_swtime = (ticks - p->p_swtick) / hz; kp->ki_swtime = (ticks - p->p_swtick) / hz;
kp->ki_pid = p->p_pid; kp->ki_pid = p->p_pid;

View file

@ -332,12 +332,6 @@ racct_getpcpu(struct proc *p, u_int pcpu)
ASSERT_RACCT_ENABLED(); 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; swtime = (ticks - p->p_swtick) / hz;
/* /*

View file

@ -71,7 +71,7 @@
#define PROC_ASSERT_TRACEREQ(p) MPASS(((p)->p_flag2 & P2_PTRACEREQ) != 0) #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) * proc_read_regs(proc, regs)
* Get the current user-visible register set from the process * 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. * 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 int
proc_read_regs(struct thread *td, struct reg *regs) proc_read_regs(struct thread *td, struct reg *regs)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(fill_regs(td, regs)); return (fill_regs(td, regs));
} }
int int
proc_write_regs(struct thread *td, struct reg *regs) proc_write_regs(struct thread *td, struct reg *regs)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(set_regs(td, regs)); return (set_regs(td, regs));
} }
int int
proc_read_dbregs(struct thread *td, struct dbreg *dbregs) proc_read_dbregs(struct thread *td, struct dbreg *dbregs)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(fill_dbregs(td, dbregs)); return (fill_dbregs(td, dbregs));
} }
int int
proc_write_dbregs(struct thread *td, struct dbreg *dbregs) proc_write_dbregs(struct thread *td, struct dbreg *dbregs)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(set_dbregs(td, dbregs)); return (set_dbregs(td, dbregs));
} }
/* /*
@ -142,15 +131,15 @@ proc_write_dbregs(struct thread *td, struct dbreg *dbregs)
int int
proc_read_fpregs(struct thread *td, struct fpreg *fpregs) proc_read_fpregs(struct thread *td, struct fpreg *fpregs)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(fill_fpregs(td, fpregs)); return (fill_fpregs(td, fpregs));
} }
int int
proc_write_fpregs(struct thread *td, struct fpreg *fpregs) proc_write_fpregs(struct thread *td, struct fpreg *fpregs)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(set_fpregs(td, fpregs)); return (set_fpregs(td, fpregs));
} }
static struct regset * static struct regset *
@ -295,51 +284,51 @@ proc_write_regset(struct thread *td, int note, struct iovec *iov)
int int
proc_read_regs32(struct thread *td, struct reg32 *regs32) proc_read_regs32(struct thread *td, struct reg32 *regs32)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(fill_regs32(td, regs32)); return (fill_regs32(td, regs32));
} }
int int
proc_write_regs32(struct thread *td, struct reg32 *regs32) proc_write_regs32(struct thread *td, struct reg32 *regs32)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(set_regs32(td, regs32)); return (set_regs32(td, regs32));
} }
int int
proc_read_dbregs32(struct thread *td, struct dbreg32 *dbregs32) proc_read_dbregs32(struct thread *td, struct dbreg32 *dbregs32)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(fill_dbregs32(td, dbregs32)); return (fill_dbregs32(td, dbregs32));
} }
int int
proc_write_dbregs32(struct thread *td, struct dbreg32 *dbregs32) proc_write_dbregs32(struct thread *td, struct dbreg32 *dbregs32)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(set_dbregs32(td, dbregs32)); return (set_dbregs32(td, dbregs32));
} }
int int
proc_read_fpregs32(struct thread *td, struct fpreg32 *fpregs32) proc_read_fpregs32(struct thread *td, struct fpreg32 *fpregs32)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(fill_fpregs32(td, fpregs32)); return (fill_fpregs32(td, fpregs32));
} }
int int
proc_write_fpregs32(struct thread *td, struct fpreg32 *fpregs32) proc_write_fpregs32(struct thread *td, struct fpreg32 *fpregs32)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(set_fpregs32(td, fpregs32)); return (set_fpregs32(td, fpregs32));
} }
#endif #endif
int int
proc_sstep(struct thread *td) proc_sstep(struct thread *td)
{ {
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
PROC_ACTION(ptrace_single_step(td)); return (ptrace_single_step(td));
} }
int int

View file

@ -835,7 +835,7 @@ struct proc {
#define P_TOTAL_STOP 0x02000000 /* Stopped in stop_all_proc. */ #define P_TOTAL_STOP 0x02000000 /* Stopped in stop_all_proc. */
#define P_INEXEC 0x04000000 /* Process is in execve(). */ #define P_INEXEC 0x04000000 /* Process is in execve(). */
#define P_STATCHILD 0x08000000 /* Child process stopped or exited. */ #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_UNUSED1 0x20000000 /* --available-- */
#define P_UNUSED2 0x40000000 /* --available-- */ #define P_UNUSED2 0x40000000 /* --available-- */
#define P_PPTRACE 0x80000000 /* PT_TRACEME by vforked child. */ #define P_PPTRACE 0x80000000 /* PT_TRACEME by vforked child. */

View file

@ -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 * Legacy PS_ flag. This moved to p_flag but is maintained for
* compatibility. * compatibility.
*/ */
#define PS_INMEM 0x00001 /* Loaded into memory. */ #define PS_INMEM 0x00001 /* Loaded into memory, always true. */
/* ki_sessflag values */ /* ki_sessflag values */
#define KI_CTTY 0x00000001 /* controlling tty vnode active */ #define KI_CTTY 0x00000001 /* controlling tty vnode active */

View file

@ -383,13 +383,6 @@ vm_daemon(void)
limit = OFF_TO_IDX( limit = OFF_TO_IDX(
qmin(rsslim.rlim_cur, rsslim.rlim_max)); 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); vm = vmspace_acquire_ref(p);
_PHOLD(p); _PHOLD(p);
PROC_UNLOCK(p); PROC_UNLOCK(p);