[v3,29/29] Optimize various ways to obtain the page size using <bits/pagesize.h>

Message ID 52aa57f9ba1971262b8aaa5c705b2a260e6c09eb.1727624528.git.fweimer@redhat.com
State Under Review
Delegated to: Adhemerval Zanella Netto
Headers
Series Teach glibc about possible page sizes and handle gaps in ld.so |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
redhat-pt-bot/TryBot-32bit fail Patch caused testsuite regressions
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm fail Test failed

Commit Message

Florian Weimer Sept. 29, 2024, 4:45 p.m. UTC
  Create inline definitions of getpagesize and __getpagesize if they
are constant.  Expand sysconf (_SC_PAGE_SIZE) inline if possible.
---
 bits/shm.h     |  9 +++++++++
 posix/unistd.h | 21 +++++++++++++++++++++
 2 files changed, 30 insertions(+)
  

Patch

diff --git a/bits/shm.h b/bits/shm.h
index ab0864cb9c..c6a235e33d 100644
--- a/bits/shm.h
+++ b/bits/shm.h
@@ -20,6 +20,7 @@ 
 #endif
 
 #include <bits/types.h>
+#include <bits/pagesize.h>
 
 /* Flags for `shmat'.  */
 #define SHM_RDONLY	010000		/* attach read-only else read-write */
@@ -35,6 +36,14 @@  __BEGIN_DECLS
 /* Segment low boundary address multiple.  */
 #define SHMLBA		(__getpagesize ())
 extern int __getpagesize (void) __THROW __attribute__ ((__const__));
+#if defined __USE_EXTERN_INLINES && defined __REDIRECT_NTH \
+  && __GLIBC_PAGE_SHIFT_MIN == __GLIBC_PAGE_SHIFT_MAX
+__extern_inline int
+__NTH (__getpagesize (void))
+{
+  return 1 << __GLIBC_PAGE_SHIFT_MIN;
+}
+#endif
 
 
 /* Type to count number of attaches.  */
diff --git a/posix/unistd.h b/posix/unistd.h
index 54d7d7527e..a5fa6768c9 100644
--- a/posix/unistd.h
+++ b/posix/unistd.h
@@ -639,6 +639,19 @@  extern long int fpathconf (int __fd, int __name) __THROW;
 /* Get the value of the system variable NAME.  */
 extern long int sysconf (int __name) __THROW;
 
+#include <bits/pagesize.h>
+#if defined __USE_EXTERN_INLINES && defined __REDIRECT_NTH \
+  && __GLIBC_PAGE_SHIFT_MIN == __GLIBC_PAGE_SHIFT_MAX
+__extern_inline long int
+__NTH (sysconf (int __name))
+{
+  if (__builtin_constant_p (__name) && __name == _SC_PAGESIZE)
+    return 1L << __GLIBC_PAGE_SHIFT_MIN;
+  extern long int __REDIRECT_NTH (__sysconf_alias, (int), sysconf);
+  return __sysconf_alias (__name);
+}
+#endif /* __USE_EXTERN_INLINES */
+
 #ifdef	__USE_POSIX2
 /* Get the value of the string-valued system variable NAME.  */
 extern size_t confstr (int __name, char *__buf, size_t __len) __THROW
@@ -1010,6 +1023,14 @@  extern void sync (void) __THROW;
    which is not necessarily the same as the hardware page size.  */
 extern int getpagesize (void)  __THROW __attribute__ ((__const__));
 
+# if defined __USE_EXTERN_INLINES && defined __REDIRECT_NTH \
+  && __GLIBC_PAGE_SHIFT_MIN == __GLIBC_PAGE_SHIFT_MAX
+__extern_inline int
+__NTH (getpagesize (void))
+{
+  return 1 << __GLIBC_PAGE_SHIFT_MIN;
+}
+# endif
 
 /* Return the maximum number of file descriptors
    the current process could possibly have.  */