From owner-freebsd-bugs@FreeBSD.ORG Mon Sep 5 22:50:04 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2F4EC106566C for ; Mon, 5 Sep 2011 22:50:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0516A8FC16 for ; Mon, 5 Sep 2011 22:50:04 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p85Mo3Vs016187 for ; Mon, 5 Sep 2011 22:50:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p85Mo3xt016184; Mon, 5 Sep 2011 22:50:03 GMT (envelope-from gnats) Resent-Date: Mon, 5 Sep 2011 22:50:03 GMT Resent-Message-Id: <201109052250.p85Mo3xt016184@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, Jeremy Chadwick Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1B5101065674 for ; Mon, 5 Sep 2011 22:46:08 +0000 (UTC) (envelope-from jdc@koitsu.dyndns.org) Received: from qmta12.westchester.pa.mail.comcast.net (qmta12.westchester.pa.mail.comcast.net [76.96.59.227]) by mx1.freebsd.org (Postfix) with ESMTP id D094D8FC13 for ; Mon, 5 Sep 2011 22:46:07 +0000 (UTC) Received: from omta18.westchester.pa.mail.comcast.net ([76.96.62.90]) by qmta12.westchester.pa.mail.comcast.net with comcast id VADS1h0021wpRvQ5CAYs9a; Mon, 05 Sep 2011 22:32:52 +0000 Received: from koitsu.dyndns.org ([67.180.84.87]) by omta18.westchester.pa.mail.comcast.net with comcast id VAYq1h00G1t3BNj3eAYrAN; Mon, 05 Sep 2011 22:32:51 +0000 Received: by icarus.home.lan (Postfix, from userid 1000) id E9779102C1B; Mon, 5 Sep 2011 15:32:48 -0700 (PDT) Message-Id: <20110905223248.E9779102C1B@icarus.home.lan> Date: Mon, 5 Sep 2011 15:32:48 -0700 (PDT) From: Jeremy Chadwick To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: sylvio@FreeBSD.org Subject: bin/160494: bsnmpd returns inaccurate data for hrSystemProcesses OID X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jeremy Chadwick List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Sep 2011 22:50:04 -0000 >Number: 160494 >Category: bin >Synopsis: bsnmpd returns inaccurate data for hrSystemProcesses OID >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Sep 05 22:50:03 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Jeremy Chadwick >Release: FreeBSD 8.2-STABLE amd64 >Organization: >Environment: System: FreeBSD icarus.home.lan 8.2-STABLE FreeBSD 8.2-STABLE #0: Tue Aug 23 18:20:42 PDT 2011 root@icarus.home.lan:/usr/obj/usr/src/sys/X7SBA_RELENG_8_amd64 amd64 >Description: (CC'ing maintainer of ports/net-mgmt/net-snmp, since said port has the exact same problem described below. Maintainer may want to report this upstream to the net-snmp folks, since based on my review of the net-snmp code this looks like it affects multiple BSDs (any BSD that implements kvm_getprocs(3), sans Darwin which has its own code)) bsnmpd(8)'s support for HOST-MIB has a "bug" where the hrSystemProcesses OID returns an inaccurate number of system processes. On a machine with ~50 actual processes, hrSystemProcesses.0 reports 240 or so (this will vary per machine configuration/driver/etc. given the nature of the issue). The root cause is use of KERN_PROC_ALL when calling kvm_getprocs(3) in src/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c, function OS_getSystemProcesses. KERN_PROC_ALL, per the kvm_getprocs(3) man page, includes system processes *as well* as visible kernel threads. According to the official HOST-MIB, hrSystemProcesses should be the "number of process contexts currently loaded or running"; the "industry norm" is to return system process counts only: http://www.net-snmp.org/docs/mibs/host.html Comparatively, for hrSystemProcesses, both Linux and Solaris 10 return the actual number of processes running on the box and DO NOT include kernel threads. Use of KERN_PROC_ALL is also in function swrun_OS_get_procs in src/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c, however the comment at the top of the code indicates this is intentional ("Get all visible proceses including the kernel visible threads"). This code is used for the hrSWRun and hrSWRunPert OIDs. I'm of the opinion that code SHOULD NOT be changed; hrSWRun can include things like kernel modules, so kernel thread count seems relevant there. However, the spelling mistake ("proceses") should be corrected. :-) hrSystemProcesses behaviour varies per FreeBSD version. Old RELENG_6 (specifically 6.4-STABLE) returns just the process count; RELENG_7 and newer return the number of system processes in addition to kernel threads. I imagine the explanation is that some kernel innards changed between FreeBSD releases, but there is no mention of that change here: http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html I would need to dig through kernel code to find the actual change that induced this. Finally, I want to point out that existing FreeBSD utilities like pkill have noted this change in the past. See lines 318-319: http://www.freebsd.org/cgi/cvsweb.cgi/src/bin/pkill/pkill.c?annotate=1.4.2.5 >How-To-Repeat: Compare "snmpwalk -v2c -c community some.system.name hrSystemProcesses" count to that of ps -auxwww. >Fix: In usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c, function OS_getSystemProcesses, change KERN_PROC_ALL to KERN_PROC_PROC. >Release-Note: >Audit-Trail: >Unformatted: