Re: snprintf.c hammering memset() - Mailing list pgsql-hackers

From Tom Lane
Subject Re: snprintf.c hammering memset()
Date
Msg-id 4353.1538437960@sss.pgh.pa.us
Whole thread Raw
In response to snprintf.c hammering memset()  (Thomas Munro <thomas.munro@enterprisedb.com>)
Responses Re: snprintf.c hammering memset()  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Thomas Munro <thomas.munro@enterprisedb.com> writes:
> Mateusz Guzik was benchmarking PostgreSQL on FreeBSD investigating the
> kqueue thread and complained off-list about a lot of calls to memset()
> of size 256KB from dopr() in our snprintf.c code.

> Yeah, that says:
>     PrintfArgType argtypes[NL_ARGMAX + 2];
> ...
>     MemSet(argtypes, 0, sizeof(argtypes));

> PrintfArgType is an enum, and we define NL_ARGMAX as 16 if the OS
> didn't already define it.  On FreeBSD 11, NL_ARGMAX was defined as 99
> in <limits.h>.  On FreeBSD 12, it is defined as 65536... ouch.  On a
> Debian box I see it is 4096.

> Is there any reason to use the OS definition here?

Ouch indeed.  Quite aside from cycles wasted, that's way more stack than
we want this to consume.  I'm good with forcing this to 16 or so ...
any objections?

(For reference, POSIX doesn't require NL_ARGMAX to be more than 9.)

(I wonder if this has anything to do with Andres' performance gripes.)

            regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: has_column_privilege behavior (was Re: Assert failed in snprintf.c)
Next
From: Andres Freund
Date:
Subject: Re: snprintf.c hammering memset()