Tunable Base Page Size

6
Appendices
Application programming for tunable base pages
The standards-based interfaces needed to obtain the base page size of the underlying system have
long existed in HP-UX. Most portable application code already uses these interfaces. Some
applications, however, may still rely on hard-coded notions of the system base page size. This
document provides example code that can replace many legacy idioms in a page size independent
manner.
The getconf(1) command provides this capability for use in scripting. The sysconf(2) and
getpagesize(2) system calls provide this ability for compiled code. Using these interfaces enables
application developers write page size independent code in user space.
In the kernel, the macros NBPG and PGSHIFT are the basis for a whole set of macros that do page-
oriented operations. In HP-UX 11i v3, these macros were modified in a way that is mostly source-
compatible, but there are some subtle (and not so subtle) syntactic and semantic differences. For
example, it is no longer be possible to dimension an array at compile time using NBPG, because the
value is not known until run time. These changes have been present in 11i v3 since first customer
shipment, so existing 11i v3 kernel-intrusive code will not see a change when the Tunable Base Page
Size enhancement is installed.
Obsolete programming constructs
HP-UX releases prior to 11i v3 included a manifest constant called NBPG in some kernel header files.
This constant corresponded to the number of bytes in a base page. While not intended for
application use, it was nonetheless visible in the application-visible namespace under some
circumstances. The constant is obsolete, was removed from 11i v3 header files, and should not be
used by applications.
In 11i v3, the NBPG macro was retracted into the _KERNEL namespace within the HP-UX header files,
so it is now no longer visible to user space. On Integrity systems, NBPG is no longer a constant, but
now returns the current base page size of the running kernel.
Proper programming practices
HP-UX provides two system calls that are capable of returning the base page size of the running
kernel: sysconf(2) and getpagesize(2). These calls can be used in any user space code that
need to have knowledge of the underlying base page size.
A brief summary of each is provided below. Note that the principal difference between them is that
sysconf(2) returns a signed long, while getpagesize(2) returns a signed int.
getpagesize(2) is in fact a wrapper routine for sysconf(_SC_PAGE_SIZE).
See the sysconf(2) and getpagesize(2) man pages on any HP-UX 11i release for full details.
System calls that create and operate on memory-mapped objects generally require that addresses and
file offsets used for these objects be “aligned and sized according to the value
returned by sysconf() when passed _SC_PAGESIZE or _SC_PAGE_SIZE.” These calls
include, but are not necessarily limited to mmap(2), munmap(2), mprotect(2), msync(2),
and madvise(2).
The system configurable variable „PAGESIZE‟ mentioned in the pthread(3T) manual pages is
affected by the setting of the base_pagesize tunable. A call to sysconf(_SC_PAGE_SIZE)
should be made at program startup time to obtain the page size currently in effect.