From owner-dev-commits-src-main@freebsd.org Fri Jan 1 00:04:00 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 639A34D5914; Fri, 1 Jan 2021 00:04:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D6QH427ymz4Z7b; Fri, 1 Jan 2021 00:04:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 20878196D4; Fri, 1 Jan 2021 00:04:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 101040v7093799; Fri, 1 Jan 2021 00:04:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 101040HO093798; Fri, 1 Jan 2021 00:04:00 GMT (envelope-from git) Date: Fri, 1 Jan 2021 00:04:00 GMT Message-Id: <202101010004.101040HO093798@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 47877889f2b8 - main - ddb ps: Use the pidhash to enumerate processes not in allproc. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 47877889f2b823f4c2fa135f5f3955ce0b3bdca1 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jan 2021 00:04:00 -0000 The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=47877889f2b823f4c2fa135f5f3955ce0b3bdca1 commit 47877889f2b823f4c2fa135f5f3955ce0b3bdca1 Author: John Baldwin AuthorDate: 2021-01-01 00:00:05 +0000 Commit: John Baldwin CommitDate: 2021-01-01 00:00:05 +0000 ddb ps: Use the pidhash to enumerate processes not in allproc. Exiting processes that have been removed from allproc but are still executing are not yet marked PRS_ZOMBIE, so they were not listed (for example, if a thread panics during exit1()). To detect these processes, clear p_list.le_prev to NULL explicitly after removing a process from the allproc list and check for this sentinel rather than PRS_ZOMBIE when walking the pidhash. While here, simplify the pidhash walk to use a single outer loop. Reviewed by: kib Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D27824 --- sys/ddb/db_ps.c | 14 ++++++-------- sys/kern/kern_exit.c | 9 +++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/sys/ddb/db_ps.c b/sys/ddb/db_ps.c index df2db88e97a1..da655d11da02 100644 --- a/sys/ddb/db_ps.c +++ b/sys/ddb/db_ps.c @@ -107,7 +107,7 @@ void db_ps(db_expr_t addr, bool hasaddr, db_expr_t count, char *modif) { struct proc *p; - int i, j; + int i; ps_mode = modif[0] == 'a' ? PRINT_ARGS : PRINT_NONE; @@ -125,14 +125,12 @@ db_ps(db_expr_t addr, bool hasaddr, db_expr_t count, char *modif) db_ps_proc(p); /* - * Do zombies. + * Processes such as zombies not in allproc. */ - for (i = 0; i < pidhashlock + 1 && !db_pager_quit; i++) { - for (j = i; j <= pidhash && !db_pager_quit; j += pidhashlock + 1) { - LIST_FOREACH(p, &pidhashtbl[j], p_hash) { - if (p->p_state == PRS_ZOMBIE) - db_ps_proc(p); - } + for (i = 0; i <= pidhash && !db_pager_quit; i++) { + LIST_FOREACH(p, &pidhashtbl[i], p_hash) { + if (p->p_list.le_prev == NULL) + db_ps_proc(p); } } } diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 0e748751d019..e1b40a171345 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -39,6 +39,7 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_ddb.h" #include "opt_ktrace.h" #include @@ -436,6 +437,14 @@ exit1(struct thread *td, int rval, int signo) */ sx_xlock(&allproc_lock); LIST_REMOVE(p, p_list); + +#ifdef DDB + /* + * Used by ddb's 'ps' command to find this process via the + * pidhash. + */ + p->p_list.le_prev = NULL; +#endif sx_xunlock(&allproc_lock); sx_xlock(&proctree_lock);