All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: enh <enh@google.com>
Cc: linux-man <linux-man@vger.kernel.org>,
	"Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
Subject: Re: getpagesize.2
Date: Wed, 27 Mar 2024 00:20:32 +0100	[thread overview]
Message-ID: <ZgNYTXW4qHm7fBxi@debian> (raw)
In-Reply-To: <CAJgzZooCY7EV5LZSom08k0wVB2SW3KAk-HL9VMsioxivQB=MeQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2821 bytes --]

Hi Elliott!

On Tue, Mar 26, 2024 at 03:27:27PM -0700, enh wrote:
> i'm not sure a lot of the text in getpagesize.2 is very helpful? for
> example:
> 
>        Portable applications should employ sysconf(_SC_PAGESIZE) instead
>        of getpagesize():
> 
>            #include <unistd.h>
>            long sz = sysconf(_SC_PAGESIZE);
> 
>        (Most systems allow the synonym _SC_PAGE_SIZE for _SC_PAGESIZE.)
> 
> is this a good recommendation _unless_ you've found yourself on a system
> that doesn't have getpagesize()? on Android i'm advising getpagesize()
> because it's (a) attribute const and (b) inherently cheaper than sysconf().
> (though obviously, "if it really matters, stick it in a static".)
> 
> afaict the only motivation for the "portable applications" advice is that
> HP-UX removed getpagesize() at some point? but given that HP-UX has been
> kept "alive" in an artificial coma since 2007... does anyone writing code
> in 2024 need to worry about that enough for this to be good advice?

I hope not.  It's dead, AFAIC.

> getpagesize() is available on Android, *BSD, iOS/macOS, glibc/musl, and
> even mingw!
> 
>        Whether getpagesize() is present as a Linux system call depends
>        on the architecture.  If it is, it returns the kernel symbol
>        PAGE_SIZE, whose value depends on the architecture and machine
>        model.  Generally, one uses binaries that are dependent on the
>        architecture but not on the machine model, in order to have a
>        single binary distribution per architecture.  This means that a
>        user program should not find PAGE_SIZE at compile time from a
>        header file, but use an actual system call, at least for those
>        architectures (like sun4) where this dependency exists.
> 
> should this just say alpha, sparc32, and sparc64 instead of being vague? (i

Yep, I'd appreciate that, after the current text (not replacing it).

> suspect anyone who doesn't default to searching the kernel source would
> turn to the man pages to answer the "which architectures?" question :-)
> though i'm not sure why anyone who doesn't read the kernel source would
> care whether getpagesize() should really be in man2 or man3...)
> 
>        glibc 2.0 fails because its getpagesize() returns a statically
>        derived value, and does not use a system call.  Things are OK in
>        glibc 2.1.
> 
> 1997 called, and wondered whether we're helping anyone by documenting a bug
> that's been fixed longer than several folks on my team have been alive? :-)

Agree.

Do you intend to send patches?  Otherwise, let me know, and I'll prepare
something.

Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es/>
Looking for a remote C programming job at the moment.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

       reply	other threads:[~2024-03-26 23:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAJgzZooCY7EV5LZSom08k0wVB2SW3KAk-HL9VMsioxivQB=MeQ@mail.gmail.com>
2024-03-26 23:20 ` Alejandro Colomar [this message]
2024-03-28  0:20   ` getpagesize.2 enh
2024-03-28  9:11     ` getpagesize.2 Alejandro Colomar
2024-03-30  0:17       ` getpagesize.2 enh
2024-03-30 23:24         ` getpagesize.2 Alejandro Colomar
2024-03-31 21:35           ` getpagesize.2 Alejandro Colomar
2024-03-26 22:55 getpagesize.2 enh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZgNYTXW4qHm7fBxi@debian \
    --to=alx@kernel.org \
    --cc=alx.manpages@gmail.com \
    --cc=enh@google.com \
    --cc=linux-man@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.