From owner-freebsd-bugs@FreeBSD.ORG Wed Nov 30 15:40:06 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 883AA16A41F for ; Wed, 30 Nov 2005 15:40:06 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id B314D43D46 for ; Wed, 30 Nov 2005 15:40:05 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id jAUFe57R005590 for ; Wed, 30 Nov 2005 15:40:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id jAUFe5Hd005587; Wed, 30 Nov 2005 15:40:05 GMT (envelope-from gnats) Resent-Date: Wed, 30 Nov 2005 15:40:05 GMT Resent-Message-Id: <200511301540.jAUFe5Hd005587@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Oliver Brandmueller Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7308716A41F for ; Wed, 30 Nov 2005 15:37:08 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1C7B143D46 for ; Wed, 30 Nov 2005 15:37:08 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jAUFb7no050054 for ; Wed, 30 Nov 2005 15:37:07 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id jAUFb7Jb050053; Wed, 30 Nov 2005 15:37:07 GMT (envelope-from nobody) Message-Id: <200511301537.jAUFb7Jb050053@www.freebsd.org> Date: Wed, 30 Nov 2005 15:37:07 GMT From: Oliver Brandmueller To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: misc/89762: top startup is very slow on system with many users X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Nov 2005 15:40:06 -0000 >Number: 89762 >Category: misc >Synopsis: top startup is very slow on system with many users >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Nov 30 15:40:05 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Oliver Brandmueller >Release: RELENG_6 >Organization: >Environment: FreeBSD waikiki.visp.de 6.0-STABLE FreeBSD 6.0-STABLE #0: Tue Nov 29 18:12:02 CET 2005 root@waikiki.visp.de:/usr/obj/usr/src/sys/APP-32-FBSD6 i386 >Description: My servers have >80k accounts via nss_ldap. Startup of top is very slow, because top read the whole list of system users to find out which is the longest username. This takes several seconds for starting up top on an idle machine of decent speed. My current patch replaces the username advance code if a variable is defined at compile time. I suggest dropping the current behaviour completely, because the routine is for cosmetic changes to top output only while really being a pain in the ass if you have lots of users. >How-To-Repeat: put 80k users on your system (probably use a slow user database like LDAP or NIS) and start top. >Fix: diff -c usr.bin/top.orig/Makefile usr.bin/top/Makefile *** usr.bin/top.orig/Makefile Sat Feb 9 00:07:35 2002 --- usr.bin/top/Makefile Wed Nov 30 00:21:29 2005 *************** *** 7,12 **** --- 7,21 ---- CFLAGS+= -DHAVE_GETOPT -DHAVE_STRERROR -I${.CURDIR} -I${TOPDIR} -I. -DORDER # + # In large setups advancing through the complete usertable to find the + # maximum length of a username means a long startup time. If you define + # TOP_NO_NAMELEN in /etc/make.conf the maximum length is considered to + # be a good value + .if defined(TOP_NO_NAMELEN) + CFLAGS+= -DTOP_NO_NAMELEN + .endif + + # # The table size should be a prime number approximately twice as # large as the number of lines in /etc/passwd. The default number # is 20011, use /etc/make.conf to override this. diff -c usr.bin/top.orig/machine.c usr.bin/top/machine.c *** usr.bin/top.orig/machine.c Wed May 18 15:42:51 2005 --- usr.bin/top/machine.c Wed Nov 30 16:34:02 2005 *************** *** 235,240 **** --- 235,246 ---- modelen != sizeof(smpmode)) smpmode = 0; + #ifdef TOP_NO_NAMELEN + if(smpmode) + namelength = SMPUNAMELEN; + else + namelength = UPUNAMELEN; + #else while ((pw = getpwent()) != NULL) { if (strlen(pw->pw_name) > namelength) namelength = strlen(pw->pw_name); *************** *** 243,248 **** --- 249,255 ---- namelength = SMPUNAMELEN; else if (namelength > UPUNAMELEN) namelength = UPUNAMELEN; + #endif kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open"); if (kd == NULL) >Release-Note: >Audit-Trail: >Unformatted: