Re: [HACKERS] Another aspect of set_ps_display ()

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: "Strong, David" <david(dot)strong(at)unisys(dot)com>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Another aspect of set_ps_display ()
Date: 2007-02-13 23:17:03
Message-ID: 200702132317.l1DNH3J13283@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


I did some research on this item from October, 2006. I was struck by
the memset of 2344 for every proc title change on popular platforms like
Linux.

The attached patch reduces the memset to only span the length needed
since the last title change. This should significantly reduce the proc
title overhead.

Now that we are using strlcpy(), we still need this code because
strlcpy() doesn't span the entire buffer if not needed, and sometimes
the clobber character is a space, rather than a zero byte.

---------------------------------------------------------------------------

Strong, David wrote:
> We were just analyzing some more OProfile and ltrace data against
> Postgres 8.2Beta1 and we noticed a number of calls as follows:
>
>
> strlen("postgres: tpc tpc 192.168.1.200("...) = 58
> memset(0xbffff6b2, '\000', 2344) = 0xbffff6b2
>
>
> We have tracked this down to the following code in the set_ps_display ()
> function:
>
>
> #ifdef PS_USE_CLOBBER_ARGV
> {
> int buflen;
>
> /* pad unused memory */
> buflen = strlen(ps_buffer);
> MemSet(ps_buffer + buflen, PS_PADDING, ps_buffer_size - buflen);
> }
> #endif /* PS_USE_CLOBBER_ARGV */
>
>
> If set_ps_display () moves to use the strlcpy () function call, this
> code might be redundant. Even if the StrNCpy () call is kept, this code
> may still be redundant as StrNCpy () will zero fill the ps_buffer.
>
> A MemSet () call on the ps_buffer has to be added to the init_ps_display
> () function, if this code is removed to clear the buffer before use.
>
> David
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/pgpatches/proc_title text/x-diff 1.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Rief 2007-02-13 23:22:58 Writing triggers in C++
Previous Message Bruce Momjian 2007-02-13 22:55:11 Re: NULL and plpgsql rows

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Dunstan 2007-02-14 00:03:47 Re: Enums patch v2
Previous Message Tom Lane 2007-02-13 19:42:03 Re: Forbid finishing a prepared transaction from another database