Re: getpagesize.2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Elliott,

On Fri, Mar 29, 2024 at 05:17:18PM -0700, enh wrote:
> On Thu, Mar 28, 2024 at 2:11 AM Alejandro Colomar <alx@xxxxxxxxxx> wrote:
> >
> > Hi Elliott,
> >
> > On Wed, Mar 27, 2024 at 05:20:18PM -0700, enh wrote:
> > > > Do you intend to send patches?  Otherwise, let me know, and I'll prepare
> > > > something.
> > >
> > > i can do, but it also sounds like enough of a bikeshed that i imagine
> > > you'd only want to rewrite it again anyway :-)
> >
> > Actually, I tried to write something, and felt like you'll definitely do
> > better; I didn't like my text.  Please send a patch.  (I can do the
> > bikeshed when applying it, if you don't feel like entertaining it.)  :-}
> 
> heh, i didn't even write mine out and had the same worry. oh well,
> i've attached something so at least we have something concrete to talk
> about!

:-)

> > > (i was actually surprised how many references to glibc 2.0 there are
> > > in various man pages, and even more amused by references to "ancient
> > > versions of glibc" being defined as "before glibc 2.0", as  if 1997
> > > isn't ancient :-) )
> >
> > You can move anything like that to HISTORY sections in any page you see
> > it.  In some cases, it might make sense to remove it, but only if it was
> > a small bug.
> >
> > Have a lovely day!
> > Alex
> >
> > --
> > <https://www.alejandro-colomar.es/>
> > Looking for a remote C programming job at the moment.

> From e4e24a6a7ef66016edcd735f3cebc7f6583e716a Mon Sep 17 00:00:00 2001
> From: Elliott Hughes <enh@xxxxxxxxxx>
> Date: Fri, 29 Mar 2024 17:10:26 -0700
> Subject: [PATCH] getpagesize.2/syscalls.2: modernization.
> 
> Remove the HP-UX portability advice, since getpagesize() is a slightly
> better option than sysconf() for Linux systems.
> 
> Explain why this function exists, and why this man page is in the wrong
> section. (The previous text tried to do both at the same, which was
> confusing.) Also explain how the vast majority of architectures that
> don't have a syscall (but do support multiple page sizes) actually work.
> 
> Also de-emphasize the glibc 2.0 bug, since most people don't need to
> worry about compatibility with versions of glibc from 1997.
> 
> Finally, change "not on x86" in syscalls.2 to say where there _is_ a
> syscall.
> ---
>  man2/getpagesize.2 | 47 ++++++++++------------------------------------
>  man2/syscalls.2    |  4 +++-
>  2 files changed, 13 insertions(+), 38 deletions(-)
> 
> diff --git a/man2/getpagesize.2 b/man2/getpagesize.2
> index b82586f36..5d0006f04 100644
> --- a/man2/getpagesize.2
> +++ b/man2/getpagesize.2
> @@ -44,46 +44,19 @@ This call first appeared in 4.2BSD.
>  SVr4, 4.4BSD, SUSv2.
>  In SUSv2 the
>  .BR getpagesize ()
> -call is labeled LEGACY, and in POSIX.1-2001
> -it has been dropped;
> -HP-UX does not have this call.
> +call was labeled LEGACY, and it was removed in POSIX.1-2001.

LGTM

>  .SH NOTES
> -Portable applications should employ
> -.I sysconf(_SC_PAGESIZE)
> -instead of
> -.BR getpagesize ():
> -.P
> -.in +4n
> -.EX
> -#include <unistd.h>
> -long sz = sysconf(_SC_PAGESIZE);
> -.EE
> -.in
> -.P
> -(Most systems allow the synonym
> -.B _SC_PAGE_SIZE
> -for
> -.BR _SC_PAGESIZE .)
> -.P
> -Whether
> -.BR getpagesize ()
> -is present as a Linux system call depends on the architecture.
> -If it is, it returns the kernel symbol
> -.BR 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
> +A user program should not hard-code a page size,
> +neither as a literal nor using the
>  .B 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.
> -Here glibc 2.0 fails because its
> +macro, because some architectures support multiple page sizes.
> +.P
> +This manual page is in section 2 because Alpha, SPARC, and SPARC64
> +all have a Linux system call
>  .BR getpagesize ()
> -returns a statically derived value, and does not use a system call.
> -Things are OK in glibc 2.1.
> +though other architectures do not, and use the ELF auxiliary vector

Remember to use semantic newlines.  :)

$ MANWIDTH=72 man man-pages | sed -n '/Use semantic newlines/,/^$/p';
   Use semantic newlines
     In  the  source of a manual page, new sentences should be started
     on new lines, long sentences should be split into lines at clause
     breaks (commas, semicolons, colons, and so on), and long  clauses
     should be split at phrase boundaries.  This convention, sometimes
     known  as  "semantic newlines", makes it easier to see the effect
     of patches, which often operate at the level of  individual  sen‐
     tences, clauses, or phrases.

> +instead. glibc 2.0 returned a constant even on architectures with mutliple
> +page sizes.

I would maybe move the glibc 2.0 comment to HISTORY.  Someone interested
in these NOTES probably doesn't care about that detail, unless they care
about HISTORY.  The fact that HISTORY goes before NOTES is a bit bad for
this, but I was thinking that the new text fits well a VERSIONS section,
so we could move it before HISTORY in a new VERSIONS section.  Here's
what I'm thinking of:

VERSIONS
     A  user  program  should  not hard‐code a page size, neither as a
     literal nor using the PAGE_SIZE macro, because some architectures
     support multiple page sizes.

     This manual page is  in  section  2  because  Alpha,  SPARC,  and
     SPARC64  all  have a Linux system call getpagesize() though other
     architectures do not, and use the ELF auxiliary  vector  instead.

HISTORY
     This  call  first  appeared  in 4.2BSD.  SVr4, 4.4BSD, SUSv2.  In
     SUSv2 the getpagesize() call was labeled LEGACY, and it  was  re‐
     moved in POSIX.1‐2001.

     glibc 2.0 returned a constant even on architectures with mutliple
     page sizes.

This order reinforces the sense that this function is preferred, being
documented first, and that POSIX removed it is unimportant to us, and
lower in the page.

>  .SH SEE ALSO
>  .BR mmap (2),
>  .BR sysconf (3)
> diff --git a/man2/syscalls.2 b/man2/syscalls.2
> index 6c2313506..69f24ef29 100644
> --- a/man2/syscalls.2
> +++ b/man2/syscalls.2
> @@ -324,7 +324,9 @@ T}
>  \fBgetpeername\fP(2)	2.0	T{
>  See notes on \fBsocketcall\fP(2)
>  T}
> -\fBgetpagesize\fP(2)	2.0	Not on x86
> +\fBgetpagesize\fP(2)	2.0	T{
> +Alpha, SPARC/SPARC64 only
> +T}

LGTM

Have a lovely night!
Alex

>  \fBgetpgid\fP(2)	1.0
>  \fBgetpgrp\fP(2)	1.0
>  \fBgetpid\fP(2)	1.0
> -- 
> 2.44.0.478.gd926399ef9-goog
> 


-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux