Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Jul 2010 17:18:18 +0200
From:      Vikash Badal <Vikash.Badal@is.co.za>
To:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   syslog strangeness on freebsd 8.0 and 8.1-RC
Message-ID:  <9B425C841283E0418B1825D40CBCFA613D9E4C75CE@ZABRYSVISEXMBX1.af.didata.local>

next in thread | raw e-mail | index | archive | help

Can someone please assist me with some strangeness on FreeBSD 8.0 and 8.1=
-RC2

using a threaded test code code, I see the that freebsd 8.x seems to be u=
sing more memory when using the syslog() call from a c program:


Results:

7.2
without syslog
=20 PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME   WCPU COMMA=
ND
26872 vikashb    1001   8    0   128M 14236K RUN      0:00  0.00% a.out

with syslog
=20 PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME   WCPU COMMA=
ND
26881 vikashb    1001  44    0   128M 26236K RUN      0:00  0.00% a.out

8.0-RELEASE-p3
without syslog
=20 PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME   WCPU COMMA=
ND
61529 vikashb    1001  44    0   129M 14840K RUN      0:01  0.00% a.out

with syslog
=20 PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME   WCPU COMMA=
ND
61507 vikashb    1001  44    0   257M 42708K RUN      0:30  0.00% a.out

8.1-RC2
without syslog
=20 PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME   WCPU COMMA=
ND
33062 vikashb    1001  44    0   129M 14804K RUN      0:00  0.00% a.out

with syslog
=20 PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME   WCPU COMMA=
ND
33056 vikashb    1001  44    0   257M 42708K RUN      0:03  0.00% a.out


I have not been able to find any reasonable information via google.

Why does syslog result in more memory being consumed on 8.x as opposed to=
=207.2 ?



<CODE>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <stdarg.h>
#include <errno.h>
#include <syslog.h>
#include <signal.h>
#include <pthread.h>

char *ProgramName =3D "WTF";

int loop =3D 0;
int LogToSTDOUT =3D 1;

void LogMessage(int debug, const char *fmt,...)
{
=20  extern int LogToSTDOUT;

=20  char message[8192];

=20  memset(message, 0, sizeof(message));

=20  va_list args;

=20  va_start(args, fmt);
=20  vsnprintf(message, sizeof(message), fmt, args);
=20  va_end(args);

=20  if ( LogToSTDOUT )
=20  {
=20     printf("%s\n", message);
=20  }

=20  syslog(LOG_NOTICE, "%s", message);

}

unsigned long int getTimeNow()
{
=20  struct timeval tv;

=20  if ( gettimeofday(&tv, NULL) =3D=3D -1 )
=20  {
=20     LogMessage(0, "ERROR(%d) %s\n", errno, strerror(errno));
=20     tv.tv_sec =3D 0;
=20  }

=20  return tv.tv_sec;
}

void HandleSignal(int sig)
{
=20  loop =3D 0;
=20  LogMessage(0, "loop  =3D %d\n", loop);
=20  signal(sig, SIG_IGN);
=20  usleep(1000);
}

void *worker(int n)
{
=20  while ( loop )
=20  {
=20     LogMessage(0, "worker #%d logging", n);
=20     usleep(1000);
=20  }

=20  pthread_exit(0);
}

int main(int argc, char* argv[])
{
=20  pthread_t* tpool;

=20  int workers =3D 1000, i, rc;

=20  openlog(ProgramName, LOG_PID, LOG_MAIL);

=20  unsigned long int duration =3D 120, StartTime, TimeNow;

=20  signal(SIGINT, HandleSignal);
=20  signal(SIGTERM, HandleSignal);
=20  signal(SIGHUP, HandleSignal);
=20  signal(SIGQUIT, HandleSignal);

=20  StartTime =3D getTimeNow();

=20  tpool =3D (pthread_t*)malloc(workers * sizeof(pthread_t));

=20  if ( tpool =3D=3D NULL )
=20  {
=20     LogMessage(0, "malloc failed \n");
=20     closelog();
=20     exit(-1);
=20  }

=20  memset(tpool, 0, sizeof(pthread_t) * workers);

=20  loop =3D 1;

=20  for ( i =3D 0; i < workers; i++ )
=20  {
=20     rc =3D pthread_create(&tpool[i], NULL, (void *(*)(void*))&worker,=
=20(void*)i);

=20     if ( rc !=3D 0 )
=20     {
=20        LogMessage(0, "pthread_create #%d failed\n", i );
=20        pthread_cancel(tpool[i]);
=20     }
=20     else
=20     {
=20        pthread_detach(tpool[i]);
=20     }
=20  }

=20  LogMessage(0, "loop  =3D %d\n", loop);

=20  while ( loop )
=20  {
=20     TimeNow =3D getTimeNow();

=20     if ( ( TimeNow - StartTime )  > duration )
=20     {
=20         loop =3D 0;
=20     }

=20     usleep(1000);
=20  }

=20  for ( i =3D 0; i < workers; i++ )
=20  {
=20     pthread_cancel(tpool[i]);
=20  }

=20  for ( i =3D 0; i < workers; i++ )
=20  {
=20     pthread_join(tpool[i], NULL);
=20  }

=20  free(tpool);
=20  closelog();
=20  exit(0);
}

</CODE>
Please note: This email and its content are subject to the disclaimer as =
displayed at the following link http://www.is.co.za/legal/E-mail+Confiden=
tiality+Notice+and+Disclaimer.htm. Should you not have Web access, send a=
=20mail to disclaimers@is.co.za and a copy will be emailed to you.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9B425C841283E0418B1825D40CBCFA613D9E4C75CE>