From nobody Sat Nov 09 17:25:12 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Xm2kd26R1z5cR7F; Sat, 09 Nov 2024 17:25:13 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xm2kc64c7z4M8w; Sat, 9 Nov 2024 17:25:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731173112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lc0i1dMwHo4de86uOJk0yGjkZXDrv7a6W60efNqvRF0=; b=tUci5AllkwYJOhuF2xT8L6K3q0UJ4cgv1KvmHaa4BjmrM7vz5F/eSkDOwxn3iygwvAL833 oqNrJ6FlwGM2pcQNVGXS1qeC+8qK021WWkrqIOwcIkR9RwxmboCp6HImDUek+I6Hxo7wM+ 1V8dCIOJF1l3cLn8R3FEmIqGFubFbAZp57Xj0jAPqJj+mI2T94OhRilX5pQnzmKozs+v6f SNx4SS6lfewMqSVyMI6aMvr+/On8hx4Bs34jU2H7tyVLPLDGJeAaoCK0zc1T3dK/5VY6v4 t/sxLA+kh3TaZWmy6HC2BBTORpE7cswCX7cAfOe0zHydK/6dvFiAfecASNJXaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731173112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lc0i1dMwHo4de86uOJk0yGjkZXDrv7a6W60efNqvRF0=; b=JHoRWXT+hiHfkHaKh7sl1pXw/hb1vex8bHwa0UrneMap0NfAIRw45nLAjyv5VKiO5z5XBj xlD7wmbaqczklNroq9Twc6rPU7t+liYoIyW9R6C+wXI004U9mOIaPRyfl5IniAQZ2KNF4r JAEbDvtdAG+rcVw47OeA08HQjJKJT/kKA9IYcgV+KZOtbNdv9DqUWdG6VD+KiJPecbMKQG AQ0jkg+L/0z1IPSK9qtQpm5r2aOWGAv9cN+/ibxh2li8j2XenzztzPUVPAI3NkIjS9bdQj d/h2WBE96p8V5VASGKa/sMY36q0OzfzDToyd6YhXpBKXAN4GKCsRJ7oLPosfWg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731173112; a=rsa-sha256; cv=none; b=Z/ADdBd25vab5DYoDQJZoQwqSeXpHKAgfXsHh5sYLxvSs+C+8n6ySXIVw3rhn+I07FamzJ kxgdRzL0NSFyeIyz5gFaerQpCZulcvucyShaP52dDcD3emjoC83oSitWNDGRWITuOoxTCH eACzuIvkkjYu07fBSehsUn8ricmmJ9Wt+ErwESqjPbSoBPZS46YyO1pds/OVMqMe0kss5d MzRGV33igrzCVTHXehJjKaeeR46nqOfzMhe9hu2Pd6LULgxmZURCLCHJ3qrImkUXYti/QG nc3I84tKgRtAj8sXtLXaF5rSAHEEY+vDyV6VwJU2cKKHDmBZxq7QyvWUrssfvQ== 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 4Xm2kc5T29z1Lbb; Sat, 9 Nov 2024 17:25:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A9HPCgE015839; Sat, 9 Nov 2024 17:25:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A9HPCHC015836; Sat, 9 Nov 2024 17:25:12 GMT (envelope-from git) Date: Sat, 9 Nov 2024 17:25:12 GMT Message-Id: <202411091725.4A9HPCHC015836@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 62e6ca0f07e4 - main - ps(1): clean up after swapout removal List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 62e6ca0f07e448da27cb2cc8165e749e7fdfcd7e Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=62e6ca0f07e448da27cb2cc8165e749e7fdfcd7e commit 62e6ca0f07e448da27cb2cc8165e749e7fdfcd7e Author: Konstantin Belousov AuthorDate: 2024-11-09 01:37:07 +0000 Commit: Konstantin Belousov CommitDate: 2024-11-09 17:22:42 +0000 ps(1): clean up after swapout removal The process flag P_INMEM is always set. Eliminate all checks for the bit. Also eliminate LAZY_PS define and code covered by it: we do not have an u-area for long time, and it cannot be swapped out. Also eliminate setting controlled by the '-f' switch, but accept it for backward compatibility. The 'W' process secondary state (swapped out) is impossible, stop calculating it. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D47492 --- bin/ps/Makefile | 7 ------- bin/ps/print.c | 6 +----- bin/ps/ps.1 | 9 +-------- bin/ps/ps.c | 41 ++++++++--------------------------------- 4 files changed, 10 insertions(+), 53 deletions(-) diff --git a/bin/ps/Makefile b/bin/ps/Makefile index a25b6a796ed0..71973b34dd24 100644 --- a/bin/ps/Makefile +++ b/bin/ps/Makefile @@ -2,13 +2,6 @@ PACKAGE=runtime PROG= ps SRCS= fmt.c keyword.c nlist.c print.c ps.c -# -# To support "lazy" ps for non root/wheel users -# add -DLAZY_PS to the cflags. This helps -# keep ps from being an unnecessary load -# on large systems. -# -CFLAGS+=-DLAZY_PS LIBADD= m kvm jail xo .include diff --git a/bin/ps/print.c b/bin/ps/print.c index a3423d8b3956..59631fb66a10 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -253,8 +253,6 @@ state(KINFO *k, VARENT *ve __unused) *cp = '?'; } cp++; - if (!(flag & P_INMEM)) - *cp++ = 'W'; if (k->ki_p->ki_nice < NZERO || k->ki_p->ki_pri.pri_class == PRI_REALTIME) *cp++ = '<'; else if (k->ki_p->ki_nice > NZERO || k->ki_p->ki_pri.pri_class == PRI_IDLE) @@ -633,7 +631,7 @@ getpcpu(const KINFO *k) #define fxtofl(fixpt) ((double)(fixpt) / fscale) /* XXX - I don't like this */ - if (k->ki_p->ki_swtime == 0 || (k->ki_p->ki_flag & P_INMEM) == 0) + if (k->ki_p->ki_swtime == 0) return (0.0); if (rawcpu) return (100.0 * fxtofl(k->ki_p->ki_pctcpu)); @@ -661,8 +659,6 @@ getpmem(KINFO *k) if (failure) return (0.0); - if ((k->ki_p->ki_flag & P_INMEM) == 0) - return (0.0); /* XXX want pmap ptpages, segtab, etc. (per architecture) */ /* XXX don't have info about shared */ fracmem = ((double)k->ki_p->ki_rssize) / mempages; diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 828239fd2ba9..8ece5b1bbfad 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -159,9 +159,6 @@ does not imply but works well with it. .It Fl e Display the environment as well. -.It Fl f -Show command-line and environment information about swapped out processes. -This option is honored only if the UID of the user is 0. .It Fl G Display information about processes which are running with the specified real group IDs. @@ -358,9 +355,7 @@ the include file .It Dv "P_TOTAL_STOP" Ta No "0x02000000" Ta "Stopped for system suspend" .It Dv "P_INEXEC" Ta No "0x04000000" Ta Process is in Xr execve 2 .It Dv "P_STATCHILD" Ta No "0x08000000" Ta "Child process stopped or exited" -.It Dv "P_INMEM" Ta No "0x10000000" Ta "Loaded into memory" -.It Dv "P_SWAPPINGOUT" Ta No "0x20000000" Ta "Process is being swapped out" -.It Dv "P_SWAPPINGIN" Ta No "0x40000000" Ta "Process is being swapped in" +.It Dv "P_INMEM" Ta No "0x10000000" Ta "Always set, unused" .It Dv "P_PPTRACE" Ta No "0x80000000" Ta "Vforked child issued ptrace(PT_TRACEME)" .El .It Cm flags2 @@ -491,8 +486,6 @@ The process is a session leader. The process' parent is suspended during a .Xr vfork 2 , waiting for the process to exec or exit. -.It Li W -The process is swapped out. .It Li X The process is being traced or debugged. .El diff --git a/bin/ps/ps.c b/bin/ps/ps.c index b0af2bdf37ca..49c69bb76084 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -68,14 +68,6 @@ #define W_SEP " \t" /* "Whitespace" list separators */ #define T_SEP "," /* "Terminate-element" list separators */ -#ifdef LAZY_PS -#define DEF_UREAD 0 -#define OPT_LAZY_f "f" -#else -#define DEF_UREAD 1 /* Always do the more-expensive read. */ -#define OPT_LAZY_f /* I.e., the `-f' option is not added. */ -#endif - /* * isdigit takes an `int', but expects values in the range of unsigned char. * This wrapper ensures that values from a 'char' end up in the correct range. @@ -92,7 +84,6 @@ int showthreads; /* will threads be shown? */ struct velisthead varlist = STAILQ_HEAD_INITIALIZER(varlist); -static int forceuread = DEF_UREAD; /* Do extra work to get u-area. */ static kvm_t *kd; static int needcomm; /* -o "command" */ static int needenv; /* -e */ @@ -154,7 +145,7 @@ static char vfmt[] = "pid,state,time,sl,re,pagein,vsz,rss,lim,tsiz," "%cpu,%mem,command"; static char Zfmt[] = "label"; -#define PS_ARGS "AaCcD:de" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ" +#define PS_ARGS "AaCcD:defG:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ" int main(int argc, char *argv[]) @@ -272,12 +263,9 @@ main(int argc, char *argv[]) case 'e': /* XXX set ufmt */ needenv = 1; break; -#ifdef LAZY_PS case 'f': - if (getuid() == 0 || getgid() == 0) - forceuread = 1; + /* compat */ break; -#endif case 'G': add_list(&gidlist, optarg); xkeep_implied = 1; @@ -1276,31 +1264,21 @@ fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki, return (s); } -#define UREADOK(ki) (forceuread || (ki->ki_p->ki_flag & P_INMEM)) - static void saveuser(KINFO *ki) { char tdname[COMMLEN + 1]; char *argsp; - if (ki->ki_p->ki_flag & P_INMEM) { - /* - * The u-area might be swapped out, and we can't get - * at it because we have a crashdump and no swap. - * If it's here fill in these fields, otherwise, just - * leave them 0. - */ - ki->ki_valid = 1; - } else - ki->ki_valid = 0; + ki->ki_valid = 1; + /* * save arguments if needed */ if (needcomm) { if (ki->ki_p->ki_stat == SZOMB) { ki->ki_args = strdup(""); - } else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL)) { + } else if (ki->ki_p->ki_args != NULL) { (void)snprintf(tdname, sizeof(tdname), "%s%s", ki->ki_p->ki_tdname, ki->ki_p->ki_moretdname); ki->ki_args = fmt(kvm_getargv, ki, @@ -1315,11 +1293,8 @@ saveuser(KINFO *ki) ki->ki_args = NULL; } if (needenv) { - if (UREADOK(ki)) - ki->ki_env = fmt(kvm_getenvv, ki, - (char *)NULL, (char *)NULL, 0); - else - ki->ki_env = strdup("()"); + ki->ki_env = fmt(kvm_getenvv, ki, (char *)NULL, + (char *)NULL, 0); if (ki->ki_env == NULL) xo_errx(1, "malloc failed"); } else { @@ -1479,7 +1454,7 @@ pidmax_init(void) static void __dead2 usage(void) { -#define SINGLE_OPTS "[-aCcde" OPT_LAZY_f "HhjlmrSTuvwXxZ]" +#define SINGLE_OPTS "[-aCcdeHhjlmrSTuvwXxZ]" xo_error("%s\n%s\n%s\n%s\n%s\n", "usage: ps [--libxo] " SINGLE_OPTS " [-O fmt | -o fmt]",