From owner-freebsd-questions@FreeBSD.ORG Mon Jul 5 15:18:37 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 816CB1065673 for ; Mon, 5 Jul 2010 15:18:37 +0000 (UTC) (envelope-from Vikash.Badal@is.co.za) Received: from phobytor.is.co.za (phobytor.is.co.za [196.4.160.171]) by mx1.freebsd.org (Postfix) with ESMTP id CFA298FC21 for ; Mon, 5 Jul 2010 15:18:36 +0000 (UTC) Received: from phobytor.is.co.za (localhost [127.0.0.1]) by phobytor.is.co.za (Postfix) with ESMTP id C725A3BBF15 for ; Mon, 5 Jul 2010 17:18:33 +0200 (SAST) Received: from rs-aplha.mfw.is.co.za (rs-alpha.mfw.is.co.za [196.26.2.112]) by phobytor.is.co.za (Postfix) with ESMTP id 71C663BBF00 for ; Mon, 5 Jul 2010 17:18:33 +0200 (SAST) Received: from root by rs-aplha.mfw.is.co.za with local (Exim 4.71) (envelope-from ) id 1OVnR9-000NwY-Pm for freebsd-questions@freebsd.org; Mon, 05 Jul 2010 17:18:23 +0200 Received: from exim by rs-aplha.mfw.is.co.za with split (Exim 4.71) (envelope-from ) id 1OVnQz-000Nvi-SI for freebsd-questions@freebsd.org; Mon, 05 Jul 2010 17:18:13 +0200 Received: from [196.26.2.110] (helo=ZABRYSVISMFW3) by rs-aplha.mfw.is.co.za with esmtp (Exim 4.71) (envelope-from ) id 1OVnQz-000Nvf-PN for freebsd-questions@freebsd.org; Mon, 05 Jul 2010 17:18:13 +0200 Received: from zabrysvisexhub2.af.didata.local (Not Verified[10.1.8.39]) by ZABRYSVISMFW3 with MailMarshal (v6,7,2,8378) id ; Mon, 05 Jul 2010 17:17:32 +0200 Received: from ZABRYSVISEXMBX1.af.didata.local ([fe80::914a:a14c:13c1:d279]) by zabrysvisexhub2.af.didata.local ([fe80::486:fd5b:97f4:6b92%10]) with mapi; Mon, 5 Jul 2010 17:18:38 +0200 From: Vikash Badal To: "freebsd-questions@freebsd.org" Date: Mon, 5 Jul 2010 17:18:18 +0200 Thread-Topic: syslog strangeness on freebsd 8.0 and 8.1-RC Thread-Index: AcscVUwUgFjM35LBSLueGudXz3ZdTg== Message-ID: <9B425C841283E0418B1825D40CBCFA613D9E4C75CE@ZABRYSVISEXMBX1.af.didata.local> Accept-Language: en-US, en-ZA Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US, en-ZA Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Recipient-Count: 1 X-Virus-Scanned: ClamAV using ClamSMTP Subject: syslog strangeness on freebsd 8.0 and 8.1-RC X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jul 2010 15:18:37 -0000 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 ? #include #include #include #include #include #include #include #include #include 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); } 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.