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
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;

View file

@ -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)

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);
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);

View file

@ -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);

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);
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);

View file

@ -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;

View file

@ -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;
/*

View file

@ -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

View file

@ -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. */

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
* 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 */

View file

@ -383,13 +383,6 @@ vm_daemon(void)
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);