[PATCH] Core: use sysconf(_SC_PAGESIZE) instead of getpagesize()

Piotr Sikora piotrsikora at google.com
Thu Dec 3 03:18:39 UTC 2015


# HG changeset patch
# User Piotr Sikora <piotrsikora at google.com>
# Date 1449112639 28800
#      Wed Dec 02 19:17:19 2015 -0800
# Branch patch1
# Node ID 60321d69523e74791e541430ecf61ae404760dde
# Parent  be3aed17689c0edd36c2025ff5c36fe493b68bd7
Core: use sysconf(_SC_PAGESIZE) instead of getpagesize().

Signed-off-by: Piotr Sikora <piotrsikora at google.com>

diff -r be3aed17689c -r 60321d69523e src/os/unix/ngx_posix_init.c
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -32,6 +32,7 @@ ngx_os_io_t ngx_os_io = {
 ngx_int_t
 ngx_os_init(ngx_log_t *log)
 {
+    long        value;
     ngx_uint_t  n;
 
 #if (NGX_HAVE_OS_SPECIFIC_INIT)
@@ -44,7 +45,14 @@ ngx_os_init(ngx_log_t *log)
         return NGX_ERROR;
     }
 
-    ngx_pagesize = getpagesize();
+    value = sysconf(_SC_PAGESIZE);
+    if (value == -1) {
+        ngx_log_error(NGX_LOG_ALERT, log, errno,
+                      "sysconf(_SC_PAGESIZE) failed");
+        return NGX_ERROR;
+    }
+
+    ngx_pagesize = (ngx_uint_t) value;
     ngx_cacheline_size = NGX_CPU_CACHE_LINE;
 
     for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }



More information about the nginx-devel mailing list