Bug 289717 - getconf: Missing _SC_PHYS_PAGES support
Summary: getconf: Missing _SC_PHYS_PAGES support
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 14.3-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: John Baldwin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-09-20 15:42 UTC by Jason W. Bacon
Modified: 2025-12-19 12:03 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason W. Bacon freebsd_committer freebsd_triage 2025-09-20 15:42:52 UTC
I believe running

    getconf PHYS_PAGES

or

    getconf _PHYS_PAGES

should report sysconf(_SC_PHYS_PAGES), as the latter does on Linux.  Maybe the following would be sufficient to fix it?  Not sure if there's an efficient way to test this, or if I need to do a buildworld.

--- sysconf.gperf.orig  2025-09-20 10:30:22.800063000 -0500
+++ sysconf.gperf       2025-09-20 10:30:59.613519000 -0500
@@ -46,6 +46,7 @@
 OPEN_MAX, _SC_OPEN_MAX
 PAGESIZE, _SC_PAGESIZE
 PAGE_SIZE, _SC_PAGESIZE
+PHYS_PAGES, _SC_PHYS_PAGES
 PASS_MAX, _SC_PASS_MAX
 PTHREAD_DESTRUCTOR_ITERATIONS, _SC_THREAD_DESTRUCTOR_ITERATIONS 
 PTHREAD_KEYS_MAX, _SC_THREAD_KEYS_MAX
Comment 1 Jason W. Bacon freebsd_committer freebsd_triage 2025-09-20 16:53:56 UTC
OK, I figured out that running make in usr.bin/getconf stores results under /usr/obj.  The patch I suggested does the trick:

# /usr/obj/usr/src/amd64.amd64/usr.bin/getconf/getconf PHYS_PAGES
4184686

While we're in here, we should probably make sure that all variables documented in sysconf(3) are properly supported.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html lists the variables required by POSIX.
Comment 2 commit-hook freebsd_committer freebsd_triage 2025-10-03 20:45:36 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=aa9e4fe3c9021d623743e26aef879a0036f87c0f

commit aa9e4fe3c9021d623743e26aef879a0036f87c0f
Author:     Jason W. Bacon <jwb@FreeBSD.org>
AuthorDate: 2025-10-03 20:43:47 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-10-03 20:43:47 +0000

    getconf: Report value of _SC_PHYS_PAGES

    PR:             289717
    Reviewed by:    jhb

 usr.bin/getconf/sysconf.gperf | 1 +
 1 file changed, 1 insertion(+)
Comment 3 John Baldwin freebsd_committer freebsd_triage 2025-10-03 20:46:11 UTC
I've merged the patch to HEAD.  I probably won't audit the list of required variables, but I'll happily merge any further patches you have to getconf (or review them if you want to push them directly).
Comment 4 Jason W. Bacon freebsd_committer freebsd_triage 2025-10-04 11:41:13 UTC
OK, thanks.  I'll review and see if anything else is missing.
Comment 5 Jason W. Bacon freebsd_committer freebsd_triage 2025-12-09 18:11:38 UTC
Extracting column 2 from 
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html to file "vars", and running the following script:

#!/bin/sh -e

for var in $(awk '{ print $1 }' vars); do
    # echo "'$var'"
    if ! fgrep -q $var sysconf.gperf; then
        printf "'$var' is missing.\n"
    fi
done

'_SC_PAGE_SIZE' is missing.
'_SC_ADVISORY_INFO' is missing.
'_SC_RAW_SOCKETS' is missing.
'_SC_SS_REPL_MAX' is missing.
'_SC_THREAD_ROBUST_PRIO_INHERIT' is missing.
'_SC_THREAD_ROBUST_PRIO_PROTECT' is missing.
'_SC_TRACE_EVENT_NAME_MAX' is missing.
'_SC_TRACE_NAME_MAX' is missing.
'_SC_TRACE_SYS_MAX' is missing.
'_SC_TRACE_USER_EVENT_MAX' is missing.
'_SC_V7_ILP32_OFF32' is missing.
'_SC_V7_ILP32_OFFBIG' is missing.
'_SC_V7_LP64_OFF64' is missing.
'_SC_V7_LPBIG_OFFBIG' is missing.
'_SC_2_PBS' is missing.
'_SC_2_PBS_ACCOUNTING' is missing.
'_SC_2_PBS_CHECKPOINT' is missing.
'_SC_2_PBS_LOCATE' is missing.
'_SC_2_PBS_MESSAGE' is missing.
'_SC_2_PBS_TRACK' is missing.
'_SC_XOPEN_STREAMS' is missing.
'_SC_XOPEN_UUCP' is missing.

The missing _SC_PAGE_SIZE looks like a typo in sysconf.gperf:

PAGESIZE, _SC_PAGESIZE
PAGE_SIZE, _SC_PAGESIZE

The rest appear to have no analogs.  Someone who knows more would have to determine how hard they would be to implement.

I'm only a ports committer, so I wouldn't be able to push any changes myself.
Comment 6 commit-hook freebsd_committer freebsd_triage 2025-12-18 19:14:03 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1a9ecead726a73817b3cd641cbdc03c9bb0abbd8

commit 1a9ecead726a73817b3cd641cbdc03c9bb0abbd8
Author:     Jason W. Bacon <jwb@FreeBSD.org>
AuthorDate: 2025-10-03 20:43:47 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-12-18 18:41:18 +0000

    getconf: Report value of _SC_PHYS_PAGES

    PR:             289717
    Reviewed by:    jhb

    (cherry picked from commit aa9e4fe3c9021d623743e26aef879a0036f87c0f)

 usr.bin/getconf/sysconf.gperf | 1 +
 1 file changed, 1 insertion(+)
Comment 7 commit-hook freebsd_committer freebsd_triage 2025-12-18 19:14:04 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=857d3887e66426865ca73fa143b04b3ca7930ef5

commit 857d3887e66426865ca73fa143b04b3ca7930ef5
Author:     Jason W. Bacon <jwb@FreeBSD.org>
AuthorDate: 2025-10-03 20:43:47 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-12-18 18:41:23 +0000

    getconf: Report value of _SC_PHYS_PAGES

    PR:             289717
    Reviewed by:    jhb

    (cherry picked from commit aa9e4fe3c9021d623743e26aef879a0036f87c0f)

 usr.bin/getconf/sysconf.gperf | 1 +
 1 file changed, 1 insertion(+)
Comment 8 Jason W. Bacon freebsd_committer freebsd_triage 2025-12-19 12:03:20 UTC
To clarify, I think maybe it should read

PAGESIZE, _SC_PAGESIZE
PAGE_SIZE, _SC_PAGE_SIZE

instead of

PAGESIZE, _SC_PAGESIZE
PAGE_SIZE, _SC_PAGESIZE

<<<ROOT@moray.acadix>>> /usr/src/usr.bin/getconf 1056 # grep PAGE sysconf.gperf
PAGESIZE, _SC_PAGESIZE
PAGE_SIZE, _SC_PAGE_SIZE

<<<ROOT@moray.acadix>>> /usr/src/usr.bin/getconf 1057 # make 

[snip]

<<<ROOT@moray.acadix>>> /usr/src/usr.bin/getconf 1058 # /usr/obj/usr/src/amd64.amd64/usr.bin/getconf/getconf PAGE_SIZE
4096

<<<ROOT@moray.acadix>>> /usr/src/usr.bin/getconf 1059 # /usr/obj/usr/src/amd64.amd64/usr.bin/getconf/getconf PAGESIZE
4096

However, sysconf(3) states that _SC_PAGESIZE and _SC_PAGE_SIZE are equivalent, so this would only be a cosmetic improvement.