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

Maxim Dounin mdounin at mdounin.ru
Thu Dec 3 18:21:29 UTC 2015


Hello!

On Wed, Dec 02, 2015 at 07:18:39PM -0800, Piotr Sikora wrote:

> # 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().

Any practical reasons for the change?

While getpagesize() isn't required by the current issue of POSIX, 
it is easier to use and used to be more widely available than 
sysconf(_SC_PAGESIZE).

> 
> 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;

The cast looks unneeded.

>      ngx_cacheline_size = NGX_CPU_CACHE_LINE;
>  
>      for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }
> 
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list