[PATCH 3/5] Use sysconf(_SC_PAGESIZE) to determine PAGE_SIZE

Denys Vlasenko vda.linux at googlemail.com
Fri Jun 3 18:41:12 UTC 2011


On Wednesday 01 June 2011 22:35, Dan Fandrich wrote:
> This seems to be the most portable way to determine page size,
> and the only portable way on systems where it is dynamic.
> 
> Signed-off-by: Dan Fandrich <dan at coneharvesters.com>
> ---
>  libbb/appletlib.c |   17 ++++-------------
>  1 files changed, 4 insertions(+), 13 deletions(-)
> 
> diff --git a/libbb/appletlib.c b/libbb/appletlib.c
> index 0dac0ba..955f680 100644
> --- a/libbb/appletlib.c
> +++ b/libbb/appletlib.c
> @@ -34,17 +34,8 @@
>  # include <malloc.h> /* for mallopt */
>  #endif
>  
> -/* Try to pull in PAGE_SIZE */
> -#ifdef __linux__
> -# include <sys/user.h>
> -#endif
> -#ifdef __GNU__ /* Hurd */
> -# include <mach/vm_param.h>
> -#endif
> -#ifndef PAGE_SIZE
> -# define PAGE_SIZE (4*1024) /* guess */
> -#endif
> -
> +/* Use 4096 if page size can't be otherwise determined */
> +#define CURRENT_PAGE_SIZE ({long ps = sysconf(_SC_PAGESIZE); ps > 0 ? ps : 4*1024;})
>  
>  /* Declare <applet>_main() */
>  #define PROTOTYPES
> @@ -788,13 +779,13 @@ int main(int argc UNUSED_PARAM, char **argv)
>  	 * to keep before releasing to the OS
>  	 * Default is way too big: 256k
>  	 */
> -	mallopt(M_TRIM_THRESHOLD, 2 * PAGE_SIZE);
> +	mallopt(M_TRIM_THRESHOLD, 2 * CURRENT_PAGE_SIZE);
>  #endif
>  #ifdef M_MMAP_THRESHOLD
>  	/* M_MMAP_THRESHOLD is the request size threshold for using mmap()
>  	 * Default is too big: 256k
>  	 */
> -	mallopt(M_MMAP_THRESHOLD, 8 * PAGE_SIZE - 256);
> +	mallopt(M_MMAP_THRESHOLD, 8 * CURRENT_PAGE_SIZE - 256);
>  #endif
>  
>  #if !BB_MMU


I think this is not necessary: old code works too, right?

-- 
vda


More information about the busybox mailing list