[Openais] [PATCH 1/2] flight recorder: switch from int to bytes for requested allocation

Steven Dake sdake at redhat.com
Thu Jun 18 08:24:18 PDT 2009


Looks good

"roundup" should be caps (ie: ROUNDUP) since its a macro.

Regards
-steve

On Thu, 2009-06-18 at 15:14 +0200, Fabio M. Di Nitto wrote:
> The flight recoder buffer size as specified in LOGSYS_DECLARE_SYSTEM
> or _logsys_rec_init was expressed in number of ints. A developer asking
> to allocate 512K would get a 2M allocation on a machine with sizeof(int) = 4.
> 
> This is confusing and the patch addresses it:
> 
> - rename rec_size to fltsize for external API (no type change),
>   because rec_size is used many times internally for other reasons
>   and it can be confusing.
> 
> - rename size to fltsize in _logsys_rec_init.
> 
> - document what we allocate and why.
> 
> - swap comments around to match the code.
> 
> - introduce a simple macro to perform rounding (stolen from linux-2.6.git).
> 
> Signed-off-by: Fabio M. Di Nitto <fdinitto at redhat.com>
> ---
> :100644 100644 90efdf8... 904e631... M	exec/logsys.c
> :100644 100644 b34b327... 19e5dae... M	include/corosync/engine/logsys.h
> :100644 100644 e19836e... 6017f10... M	man/logsys_overview.8
>  exec/logsys.c                    |   31 ++++++++++++++++++++++++++-----
>  include/corosync/engine/logsys.h |    4 ++--
>  man/logsys_overview.8            |    5 +++--
>  3 files changed, 31 insertions(+), 9 deletions(-)
> 
> diff --git a/exec/logsys.c b/exec/logsys.c
> index 90efdf8..904e631 100644
> --- a/exec/logsys.c
> +++ b/exec/logsys.c
> @@ -66,6 +66,8 @@
>  
>  #define MIN(x,y) ((x) < (y) ? (x) : (y))
>  
> +#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
> +
>  /*
>   * syslog prioritynames, facility names to value mapping
>   * Some C libraries build this in to their headers, but it is non-portable
> @@ -1044,17 +1046,36 @@ int _logsys_wthread_create (void)
>  	return (0);
>  }
>  
> -int _logsys_rec_init (unsigned int size)
> +int _logsys_rec_init (unsigned int fltsize)
>  {
>  	/*
> -	 * First record starts at zero
> -	 * Last record ends at zero
> +	 * we need to allocate:
> +	 * - requested size +
> +	 *   2 extra unsigned ints for HEAD/TAIL tracking
> +	 *
> +	 * then round it up to the next PAGESIZE
>  	 */
> -	flt_data = malloc ((size + 2) * sizeof (unsigned int));
> +	size_t flt_real_size;
> +
> +	flt_real_size = roundup(
> +			(fltsize + (2 * sizeof (unsigned int))),
> +			sysconf(_SC_PAGESIZE));
> +
> +	flt_data = malloc (flt_real_size);
>  	if (flt_data == NULL) {
>  		return (-1);
>  	}
> -	flt_data_size = size;
> +
> +	/*
> +	 * flt_data_size tracks data by ints and not bytes/chars.
> +	 */
> +
> +	flt_data_size = (flt_real_size / sizeof (unsigned int));
> +
> +	/*
> +	 * First record starts at zero
> +	 * Last record ends at zero
> +	 */
>  	flt_data[FDHEAD_INDEX] = 0;
>  	flt_data[FDTAIL_INDEX] = 0;
>  
> diff --git a/include/corosync/engine/logsys.h b/include/corosync/engine/logsys.h
> index b34b327..19e5dae 100644
> --- a/include/corosync/engine/logsys.h
> +++ b/include/corosync/engine/logsys.h
> @@ -305,7 +305,7 @@ extern void *logsys_rec_end;
>  #define LOGSYS_REC_END (&logsys_rec_end)
>  
>  #define LOGSYS_DECLARE_SYSTEM(name,mode,debug,file,file_priority,	\
> -		syslog_facility,syslog_priority,format,rec_size)	\
> +		syslog_facility,syslog_priority,format,fltsize)		\
>  __attribute__ ((constructor))						\
>  static void logsys_system_init (void)					\
>  {									\
> @@ -322,7 +322,7 @@ static void logsys_system_init (void)					\
>  		exit (-1);						\
>  	}								\
>  									\
> -	if (_logsys_rec_init (rec_size) < 0) {				\
> +	if (_logsys_rec_init (fltsize) < 0) {				\
>  		fprintf (stderr,					\
>  			"Unable to initialize log flight recorder.\n");	\
>  		exit (-1);						\
> diff --git a/man/logsys_overview.8 b/man/logsys_overview.8
> index e19836e..6017f10 100644
> --- a/man/logsys_overview.8
> +++ b/man/logsys_overview.8
> @@ -62,7 +62,7 @@ require it and enables full logging capabilities before any application code is
>  executed.
>  
>  #define LOGSYS_DECLARE_SYSTEM (name, mode, debug, file, file_priority,
> -syslog_facility, syslog_priority, format, rec_size)
> +syslog_facility, syslog_priority, format, fltsize)
>  
>  The name parameter is the name of the application or system.
>  
> @@ -99,7 +99,8 @@ syslog.
>  The format parameter allows to set custom output format.
>  Set to NULL to use built-in default.
>  
> -The rec_size parameter specifies the flight recorder buffer size.
> +The fltsize parameter specifies the flight recorder buffer size in bytes. The requested value
> +is increased by the size of 2 unsigned ints and rounded to the next PAGE_SIZE.
>  
>  An example declaration would be:
>  



More information about the Openais mailing list