thread: Remove kernel stack swapping support, part 4

- Remove the IS_SWAPPED thread inhibitor state.
- Remove all uses of TD_IS_SWAPPED() in the kernel.
- Remove the TDF_CANSWAP flag.
- Remove the P_SWAPPINGOUT and P_SWAPPINGIN flags.

Tested by:	pho
Reviewed by:	alc, imp, kib
Differential Revision:	https://reviews.freebsd.org/D46115
This commit is contained in:
Mark Johnston 2024-07-29 01:40:22 +00:00
parent 8370e9dfa1
commit e24a655283
17 changed files with 20 additions and 90 deletions

View file

@ -69,8 +69,6 @@ stack_save_td(struct stack *st, struct thread *td)
struct unwind_state state;
THREAD_LOCK_ASSERT(td, MA_OWNED);
KASSERT(!TD_IS_SWAPPED(td),
("stack_save_td: thread %p is swapped", td));
if (TD_IS_RUNNING(td))
return (EOPNOTSUPP);

View file

@ -59,8 +59,6 @@ stack_save_td(struct stack *st, struct thread *td)
struct unwind_state frame;
THREAD_LOCK_ASSERT(td, MA_OWNED);
KASSERT(!TD_IS_SWAPPED(td),
("stack_save_td: thread %p is swapped", td));
if (TD_IS_RUNNING(td))
return (EOPNOTSUPP);

View file

@ -290,8 +290,6 @@ dumpthread(volatile struct proc *p, volatile struct thread *td, int all)
else
strlcat(state, "D", sizeof(state));
}
if (TD_IS_SWAPPED(td))
strlcat(state, "W", sizeof(state));
if (TD_AWAITING_INTR(td))
strlcat(state, "I", sizeof(state));
if (TD_IS_SUSPENDED(td))
@ -393,12 +391,6 @@ DB_SHOW_COMMAND(thread, db_show_thread)
db_printf("SUSPENDED");
comma = true;
}
if (TD_IS_SWAPPED(td)) {
if (comma)
db_printf(", ");
db_printf("SWAPPED");
comma = true;
}
if (TD_ON_LOCK(td)) {
if (comma)
db_printf(", ");

View file

@ -522,8 +522,6 @@ do_qXfer_threads_read(void)
sbuf_cat(&ctx.qXfer.sb, "Blocked");
else if (TD_IS_SLEEPING(ctx.iter))
sbuf_cat(&ctx.qXfer.sb, "Sleeping");
else if (TD_IS_SWAPPED(ctx.iter))
sbuf_cat(&ctx.qXfer.sb, "Swapped");
else if (TD_AWAITING_INTR(ctx.iter))
sbuf_cat(&ctx.qXfer.sb, "IthreadWait");
else if (TD_IS_SUSPENDED(ctx.iter))

View file

@ -1140,10 +1140,8 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
kp->ki_size = vm->vm_map.size;
kp->ki_rssize = vmspace_resident_count(vm); /*XXX*/
FOREACH_THREAD_IN_PROC(p, td0) {
if (!TD_IS_SWAPPED(td0))
kp->ki_rssize += td0->td_kstack_pages;
}
FOREACH_THREAD_IN_PROC(p, td0)
kp->ki_rssize += td0->td_kstack_pages;
kp->ki_swrss = vm->vm_swrss;
kp->ki_tsize = vm->vm_tsize;
kp->ki_dsize = vm->vm_dsize;
@ -2869,9 +2867,7 @@ sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)
sizeof(kkstp->kkst_trace), SBUF_FIXEDLEN);
thread_lock(td);
kkstp->kkst_tid = td->td_tid;
if (TD_IS_SWAPPED(td))
kkstp->kkst_state = KKST_STATE_SWAPPED;
else if (stack_save_td(st, td) == 0)
if (stack_save_td(st, td) == 0)
kkstp->kkst_state = KKST_STATE_STACKOK;
else
kkstp->kkst_state = KKST_STATE_RUNNING;

View file

@ -2791,8 +2791,7 @@ sig_suspend_threads(struct thread *td, struct proc *p)
FOREACH_THREAD_IN_PROC(p, td2) {
thread_lock(td2);
ast_sched_locked(td2, TDA_SUSPEND);
if ((TD_IS_SLEEPING(td2) || TD_IS_SWAPPED(td2)) &&
(td2->td_flags & TDF_SINTR)) {
if (TD_IS_SLEEPING(td2) && (td2->td_flags & TDF_SINTR) != 0) {
if (td2->td_flags & TDF_SBDRY) {
/*
* Once a thread is asleep with
@ -3579,16 +3578,8 @@ proc_wkilled(struct proc *p)
{
PROC_LOCK_ASSERT(p, MA_OWNED);
if ((p->p_flag & P_WKILLED) == 0) {
if ((p->p_flag & P_WKILLED) == 0)
p->p_flag |= P_WKILLED;
/*
* Notify swapper that there is a process to swap in.
* The notification is racy, at worst it would take 10
* seconds for the swapper process to notice.
*/
if ((p->p_flag & (P_INMEM | P_SWAPPINGIN)) == 0)
wakeup(&proc0);
}
}
/*

View file

@ -558,25 +558,23 @@ mi_switch(int flags)
}
/*
* Change thread state to be runnable, placing it on the run queue if
* it is in memory. If it is swapped out, return true so our caller
* will know to awaken the swapper.
* Change thread state to be runnable, placing it on the run queue.
*
* Requires the thread lock on entry, drops on exit.
*/
int
setrunnable(struct thread *td, int srqflags)
{
int swapin;
THREAD_LOCK_ASSERT(td, MA_OWNED);
KASSERT(td->td_proc->p_state != PRS_ZOMBIE,
("setrunnable: pid %d is a zombie", td->td_proc->p_pid));
swapin = 0;
switch (TD_GET_STATE(td)) {
case TDS_RUNNING:
case TDS_RUNQ:
case TDS_INHIBITED:
if ((srqflags & (SRQ_HOLD | SRQ_HOLDTD)) == 0)
thread_unlock(td);
break;
case TDS_CAN_RUN:
KASSERT((td->td_flags & TDF_INMEM) != 0,
@ -584,25 +582,12 @@ setrunnable(struct thread *td, int srqflags)
td, td->td_flags, td->td_inhibitors));
/* unlocks thread lock according to flags */
sched_wakeup(td, srqflags);
return (0);
case TDS_INHIBITED:
/*
* If we are only inhibited because we are swapped out
* arrange to swap in this process.
*/
if (td->td_inhibitors == TDI_SWAPPED &&
(td->td_flags & TDF_SWAPINREQ) == 0) {
td->td_flags |= TDF_SWAPINREQ;
swapin = 1;
}
break;
default:
panic("setrunnable: state 0x%x", TD_GET_STATE(td));
}
if ((srqflags & (SRQ_HOLD | SRQ_HOLDTD)) == 0)
thread_unlock(td);
return (swapin);
return (0);
}
/*

View file

@ -998,8 +998,6 @@ sched_sleep(struct thread *td, int pri)
td_get_sched(td)->ts_slptime = 0;
if (pri != 0 && PRI_BASE(td->td_pri_class) == PRI_TIMESHARE)
sched_prio(td, pri);
if (TD_IS_SUSPENDED(td) || pri >= PSOCK)
td->td_flags |= TDF_CANSWAP;
}
void
@ -1137,7 +1135,6 @@ sched_wakeup(struct thread *td, int srqflags)
THREAD_LOCK_ASSERT(td, MA_OWNED);
ts = td_get_sched(td);
td->td_flags &= ~TDF_CANSWAP;
if (ts->ts_slptime > 1) {
updatepri(td);
resetpriority(td);

View file

@ -2334,8 +2334,6 @@ sched_sleep(struct thread *td, int prio)
THREAD_LOCK_ASSERT(td, MA_OWNED);
td->td_slptick = ticks;
if (TD_IS_SUSPENDED(td) || prio >= PSOCK)
td->td_flags |= TDF_CANSWAP;
if (PRI_BASE(td->td_pri_class) != PRI_TIMESHARE)
return;
if (static_boost == 1 && prio)
@ -2358,7 +2356,6 @@ sched_wakeup(struct thread *td, int srqflags)
THREAD_LOCK_ASSERT(td, MA_OWNED);
ts = td_get_sched(td);
td->td_flags &= ~TDF_CANSWAP;
/*
* If we slept for more than a tick update our interactivity and

View file

@ -369,12 +369,8 @@ tty_info(struct tty *tp)
kstacks_val = atomic_load_int(&tty_info_kstacks);
print_kstacks = (kstacks_val != STACK_SBUF_FMT_NONE);
if (print_kstacks) {
if (TD_IS_SWAPPED(td))
sterr = ENOENT;
else
sterr = stack_save_td(&stack, td);
}
if (print_kstacks)
sterr = stack_save_td(&stack, td);
#endif
thread_unlock(td);
if (p->p_state == PRS_NEW || p->p_state == PRS_ZOMBIE)

View file

@ -91,8 +91,6 @@ stack_save_td(struct stack *st, struct thread *td)
vm_offset_t frame;
THREAD_LOCK_ASSERT(td, MA_OWNED);
KASSERT(!TD_IS_SWAPPED(td),
("stack_save_td: thread %p is swapped", td));
if (TD_IS_RUNNING(td))
return (EOPNOTSUPP);

View file

@ -65,8 +65,6 @@ stack_save_td(struct stack *st, struct thread *td)
struct unwind_state frame;
THREAD_LOCK_ASSERT(td, MA_OWNED);
KASSERT(!TD_IS_SWAPPED(td),
("stack_save_td: thread %p is swapped", td));
if (TD_IS_RUNNING(td))
return (EOPNOTSUPP);

View file

@ -452,7 +452,7 @@ do { \
#define TDF_SINTR 0x00000008 /* Sleep is interruptible. */
#define TDF_TIMEOUT 0x00000010 /* Timing out during sleep. */
#define TDF_IDLETD 0x00000020 /* This is a per-CPU idle thread. */
#define TDF_CANSWAP 0x00000040 /* Thread can be swapped. */
#define TDF_UNUSED11 0x00000040 /* Available */
#define TDF_SIGWAIT 0x00000080 /* Ignore ignored signals */
#define TDF_KTH_SUSP 0x00000100 /* kthread is suspended */
#define TDF_ALLPROCSUSP 0x00000200 /* suspended by SINGLE_ALLPROC */
@ -468,7 +468,7 @@ do { \
#define TDF_SERESTART 0x00080000 /* ERESTART on stop attempts. */
#define TDF_THRWAKEUP 0x00100000 /* Libthr thread must not suspend itself. */
#define TDF_SEINTR 0x00200000 /* EINTR on stop attempts. */
#define TDF_SWAPINREQ 0x00400000 /* Swapin request due to wakeup. */
#define TDF_UNUSED12 0x00400000 /* Available */
#define TDF_UNUSED6 0x00800000 /* Available */
#define TDF_SCHED0 0x01000000 /* Reserved for scheduler private use */
#define TDF_SCHED1 0x02000000 /* Reserved for scheduler private use */
@ -574,14 +574,12 @@ enum {
*/
#define TDI_SUSPENDED 0x0001 /* On suspension queue. */
#define TDI_SLEEPING 0x0002 /* Actually asleep! (tricky). */
#define TDI_SWAPPED 0x0004 /* Stack not in mem. Bad juju if run. */
#define TDI_LOCK 0x0008 /* Stopped on a lock. */
#define TDI_IWAIT 0x0010 /* Awaiting interrupt. */
#define TD_IS_SLEEPING(td) ((td)->td_inhibitors & TDI_SLEEPING)
#define TD_ON_SLEEPQ(td) ((td)->td_wchan != NULL)
#define TD_IS_SUSPENDED(td) ((td)->td_inhibitors & TDI_SUSPENDED)
#define TD_IS_SWAPPED(td) ((td)->td_inhibitors & TDI_SWAPPED)
#define TD_ON_LOCK(td) ((td)->td_inhibitors & TDI_LOCK)
#define TD_AWAITING_INTR(td) ((td)->td_inhibitors & TDI_IWAIT)
#ifdef _KERNEL
@ -602,7 +600,6 @@ enum {
#define KTDSTATE(td) \
(((td)->td_inhibitors & TDI_SLEEPING) != 0 ? "sleep" : \
((td)->td_inhibitors & TDI_SUSPENDED) != 0 ? "suspended" : \
((td)->td_inhibitors & TDI_SWAPPED) != 0 ? "swapped" : \
((td)->td_inhibitors & TDI_LOCK) != 0 ? "blocked" : \
((td)->td_inhibitors & TDI_IWAIT) != 0 ? "iwait" : "yielding")
@ -618,14 +615,12 @@ enum {
} while (0)
#define TD_SET_SLEEPING(td) TD_SET_INHIB((td), TDI_SLEEPING)
#define TD_SET_SWAPPED(td) TD_SET_INHIB((td), TDI_SWAPPED)
#define TD_SET_LOCK(td) TD_SET_INHIB((td), TDI_LOCK)
#define TD_SET_SUSPENDED(td) TD_SET_INHIB((td), TDI_SUSPENDED)
#define TD_SET_IWAIT(td) TD_SET_INHIB((td), TDI_IWAIT)
#define TD_SET_EXITING(td) TD_SET_INHIB((td), TDI_EXITING)
#define TD_CLR_SLEEPING(td) TD_CLR_INHIB((td), TDI_SLEEPING)
#define TD_CLR_SWAPPED(td) TD_CLR_INHIB((td), TDI_SWAPPED)
#define TD_CLR_LOCK(td) TD_CLR_INHIB((td), TDI_LOCK)
#define TD_CLR_SUSPENDED(td) TD_CLR_INHIB((td), TDI_SUSPENDED)
#define TD_CLR_IWAIT(td) TD_CLR_INHIB((td), TDI_IWAIT)
@ -816,8 +811,7 @@ struct proc {
shortcuts) */
#define P_SUGID 0x00000100 /* Had set id privileges since last
exec. */
#define P_SYSTEM 0x00000200 /* System proc: no sigs, stats or
swapping. */
#define P_SYSTEM 0x00000200 /* System proc: no sigs or stats. */
#define P_SINGLE_EXIT 0x00000400 /* Threads suspending should exit,
not wait. */
#define P_TRACED 0x00000800 /* Debugged process being traced. */
@ -842,8 +836,8 @@ struct 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_SWAPPINGOUT 0x20000000 /* Process is being swapped out. */
#define P_SWAPPINGIN 0x40000000 /* Process is being swapped in. */
#define P_UNUSED1 0x20000000 /* --available-- */
#define P_UNUSED2 0x40000000 /* --available-- */
#define P_PPTRACE 0x80000000 /* PT_TRACEME by vforked child. */
#define P_STOPPED (P_STOPPED_SIG|P_STOPPED_SINGLE|P_STOPPED_TRACE)
@ -1038,9 +1032,6 @@ extern pid_t pid_max;
_p->p_cowgen - _td->td_cowgen; \
})
/* Check whether a thread is safe to be swapped out. */
#define thread_safetoswapout(td) ((td)->td_flags & TDF_CANSWAP)
/* Control whether or not it is safe for curthread to sleep. */
#define THREAD_NO_SLEEPING() do { \
curthread->td_no_sleeping++; \

View file

@ -613,7 +613,7 @@ struct kinfo_vmobject {
#define KKST_MAXLEN 1024
#define KKST_STATE_STACKOK 0 /* Stack is valid. */
#define KKST_STATE_SWAPPED 1 /* Stack swapped out. */
#define KKST_STATE_SWAPPED 1 /* Stack swapped out, obsolete. */
#define KKST_STATE_RUNNING 2 /* Stack ephemeral. */
#if defined(__amd64__) || defined(__i386__)

View file

@ -189,9 +189,7 @@ vmtotal(SYSCTL_HANDLER_ARGS)
thread_lock(td);
switch (TD_GET_STATE(td)) {
case TDS_INHIBITED:
if (TD_IS_SWAPPED(td))
total.t_sw++;
else if (TD_IS_SLEEPING(td)) {
if (TD_IS_SLEEPING(td)) {
if (td->td_priority <= PZERO)
total.t_dw++;
else

View file

@ -1960,8 +1960,7 @@ vm_pageout_oom(int shortage)
if (!TD_ON_RUNQ(td) &&
!TD_IS_RUNNING(td) &&
!TD_IS_SLEEPING(td) &&
!TD_IS_SUSPENDED(td) &&
!TD_IS_SWAPPED(td)) {
!TD_IS_SUSPENDED(td)) {
thread_unlock(td);
breakout = true;
break;

View file

@ -109,8 +109,6 @@ stack_save_td(struct stack *st, struct thread *td)
bool done;
THREAD_LOCK_ASSERT(td, MA_OWNED);
KASSERT(!TD_IS_SWAPPED(td),
("stack_save_td: thread %p is swapped", td));
if (TD_IS_RUNNING(td) && td != curthread)
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);