From nobody@FreeBSD.org  Fri Feb 13 02:30:22 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 29D4A16A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Feb 2004 02:30:22 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0F76443D2F
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Feb 2004 02:30:22 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.10/8.12.10) with ESMTP id i1DAUL72098938
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Feb 2004 02:30:21 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.10/8.12.10/Submit) id i1DAULwP098937;
	Fri, 13 Feb 2004 02:30:21 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200402131030.i1DAULwP098937@www.freebsd.org>
Date: Fri, 13 Feb 2004 02:30:21 -0800 (PST)
From: chc <chc@mail2000.com.tw>
To: freebsd-gnats-submit@FreeBSD.org
Subject: strlcpy performance problem
X-Send-Pr-Version: www-2.0

>Number:         62782
>Category:       gnu
>Synopsis:       strlcpy performance problem
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 13 02:40:25 PST 2004
>Closed-Date:    Fri Feb 13 14:53:12 PST 2004
>Last-Modified:  Sat Mar 27 11:40:09 PST 2004
>Originator:     chc
>Release:        4.8
>Organization:
>Environment:
>Description:
strlcpy.c
line 71:
     while (*s++);            /* performance problem when src is mmap pointer */

Mmap a big file which is above 500M and use strlcpy. I found it was very slow.        

>How-To-Repeat:
mmap a big file and use strlcpy() to copy some data.

>Fix:
It seems no way to solve it.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: das 
State-Changed-When: Fri Feb 13 14:52:41 PST 2004 
State-Changed-Why:  
chc <chc@mail2000.com.tw> wrote: 
> It seems no way to solve it. 

Bingo.  You need to use something else (e.g. strncpy()) if this is a 
problem for you. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=62782 

From: Valentin Nechayev <netch@ivb.nn.kiev.ua>
To: chc <chc@mail2000.com.tw>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: gnu/62782: strlcpy performance problem
Date: Sat, 27 Mar 2004 21:26:10 +0200

  Fri, Feb 13, 2004 at 02:30:21, chc (chc) wrote about "gnu/62782: strlcpy performance problem": 
 
 c>      while (*s++);            /* performance problem when src is mmap pointer */
 c> Mmap a big file which is above 500M and use strlcpy. I found it was very slow.        
 
 As mapping is on per-page basis, any implementation of per-char scanning
 (as required by C-styled string copy) will be much faster than page fault
 interrupt. So your problem isn't strlcpy slowness, but bad program design:
 you should not use nul-terminated strings for this task.
 
 PR is already closed, but I want add my $0.05 to clarify that it isn't
 one function problem, but conceptual problem (and strncpy() can't fix it,
 but can only aggravate). Redesign your program.
 
 
 -netch-
>Unformatted:
