🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #20385

INN and realloc()

#20385
From: Marc Slemko
Date: Mon, 11 Aug 1997 00:00
39 lines
2536 bytes
Has anyone looked into just how much INN calls realloc()?  While
adding some code for debugging something else (INN deciding it
wanted to grab all the vm in the system), I noticed things like
(in 1.5.1+patches):

Aug 10 18:01:51 scanner innd: RENEW: site.c:387: trying to realloc 78080 bytes
Aug 10 18:01:51 scanner innd: RENEW: site.c:431: trying to realloc 51456 bytes
Aug 10 18:01:51 scanner innd: RENEW: site.c:387: trying to realloc 79104 bytes
Aug 10 18:01:51 scanner innd: RENEW: site.c:387: trying to realloc 80128 bytes
Aug 10 18:01:52 scanner innd: RENEW: site.c:387: trying to realloc 81152 bytes
Aug 10 18:01:52 scanner innd: RENEW: site.c:387: trying to realloc 82176 bytes
Aug 10 18:01:52 scanner innd: RENEW: site.c:431: trying to realloc 52480 bytes
Aug 10 18:01:52 scanner innd: RENEW: site.c:387: trying to realloc 83200 bytes
Aug 10 18:01:52 scanner innd: RENEW: site.c:387: trying to realloc 84224 bytes
Aug 10 18:01:52 scanner innd: RENEW: site.c:392: trying to realloc 17664 bytes
Aug 10 18:01:52 scanner innd: RENEW: site.c:387: trying to realloc 85248 bytes
Aug 10 18:01:52 scanner innd: RENEW: site.c:431: trying to realloc 53504 bytes

Depending on your malloc implementation, this can be quite painful.
Some realloc()s simply copy the whole bit of memory each time and
don't even try to expand the given space... some buffers grow to
be hundreds of K in size, 1k at a time.  Most of them are coming
from the BUFFappend macro:

            if (i_ + l_ > bp_->Size) { \
                /* Round size up to next 1K. */ \
                bp_->Size += (l_ + 0x3FF) & ~0x3FF; \
                RENEW(bp_->Data, char, bp_->Size); \
            } \

Bumping the 1k up to 16k helped nicely.  A more complicated algorithm
that picked the new size based on the old one could reduce the number
of calls even further without resulting in a huge waste of memory.

Couldn't say if it actually has any real-world impact on performance;
I would doubt it would be a measurable difference.

Technical Details
Message-ID: <5sm582$nv9$1@scanner.worldgate.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <5sm582$nv9$1@scanner.worldgate.com>
Subject: INN and realloc()
Date: Mon, 11 Aug 1997 00:00:00 +0000
From: Marc Slemko <marcs@znep.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 263414806
Organization: WorldGate Inc. http://www.worldgate.com/
Newsgroups: news.software.nntp