This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] Allow shrinking of arena heaps using mmap based onovercommit settings when available


> +  static int may_shrink_heap = -1;
> +
> +  if (__builtin_expect (may_shrink_heap < 0, 0))
> +    may_shrink_heap = check_may_shrink_heap ();

Just call check_may_shrink_heap () directly in the use below.
Leave it to the malloc-sysdep.h inline to cache or whatnot.

> --- /dev/null
> +++ b/sysdeps/generic/malloc-sysdep.h
> @@ -0,0 +1,27 @@
> +/* Copyright (C) 2012 Free Software Foundation, Inc.

Top line of a new file should always be a descriptive comment.

> +static inline int
> +check_may_shrink_heap (void)
> +{
> +  return __libc_enable_secure;
> +}

Make it return bool.

> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -9,6 +9,7 @@ endif
>  
>  ifeq ($(subdir),malloc)
>  CFLAGS-malloc.c += -DMORECORE_CLEARS=2
> +sysdep_headers += malloc-sysdep.h
>  endif

sysdep_headers is only for installed headers.  And it's never necessary
for ones that exist in all configurations anyway.

> +static inline int
> +check_may_shrink_heap (void)
> +{
> +  int fd;
> +  int ret = 0;
> +
> +  if (__libc_enable_secure)
> +    return 1;

Use C99-style initialized definitions later in the function.
Here, the if can be the first line of the function body.

Use a static inside this function to cache the /proc result.

> +  fd = open ("/proc/sys/vm/overcommit_memory", O_RDONLY);

Use open_not_cancel and O_CLOEXEC.

> +  if (fd != -1)
> +    {
> +      char val = 0;
> +      int n = read (fd, &val, 1);

Use read_not_cancel.

> +      if (n > 0)
> +	val -= '0';
> +
> +      if (val == 2)
> +	ret = 1;

Simplify to just:
	ret = n > 0 && val == '2';

> +      close (fd);

Use close_not_cancel_no_status.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]