From owner-freebsd-ports@FreeBSD.ORG Tue Jan 24 20:58:47 2006 Return-Path: X-Original-To: ports@freebsd.org Delivered-To: freebsd-ports@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2A23216A41F for ; Tue, 24 Jan 2006 20:58:47 +0000 (GMT) (envelope-from garyj@jennejohn.org) Received: from mail08a.verio.de (mail08a.verio.de [213.198.55.73]) by mx1.FreeBSD.org (Postfix) with SMTP id 0782943D70 for ; Tue, 24 Jan 2006 20:58:39 +0000 (GMT) (envelope-from garyj@jennejohn.org) Received: from mx14.stngva01.us.mxservers.net (204.202.242.37) by mail08a.verio.de (RS ver 1.0.95vs) with SMTP id 2-0442456307; Tue, 24 Jan 2006 21:58:38 +0100 (CET) Received: from www.jennejohn.org [213.198.5.174] (EHLO peedub.jennejohn.org) by mx14.stngva01.us.mxservers.net (mxl_mta-1.3.8-10p4) with ESMTP id 6f496d34.30892.054.mx14.stngva01.us.mxservers.net; Tue, 24 Jan 2006 15:58:30 -0500 (EST) Received: from jennejohn.org (localhost [127.0.0.1]) by peedub.jennejohn.org (8.13.4/8.11.6) with ESMTP id k0OKwH2i016170; Tue, 24 Jan 2006 21:58:17 +0100 (CET) (envelope-from garyj@jennejohn.org) Message-Id: <200601242058.k0OKwH2i016170@peedub.jennejohn.org> X-Mailer: exmh version 2.7.2 01/07/2005 with nmh-1.0.4 To: FreeBSD Ports In-Reply-To: Message from Fernan Aguero of "Tue, 24 Jan 2006 14:23:17 -0300." <20060124172317.GF72149@iib.unsam.edu.ar> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 24 Jan 2006 21:58:17 +0100 From: Gary Jennejohn X-Spam: [F=0.0100000000; heur=0.500(-19800); stat=0.010; spamtraq-heur=0.500(2006012408)] X-MAIL-FROM: X-SOURCE-IP: [213.198.5.174] X-Loop-Detect: 1 X-DistLoop-Detect: 1 Cc: Subject: Re: porting an app that checks /proc/meminfo X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jan 2006 20:58:47 -0000 Fernan Aguero writes: > I've got a port ready for muscle > > WWW: http://www.drive5.com/muscle/ > Port: http://genoma.unsam.edu.ar/~fernan/freebsd/muscle.shar > > The program builds fine, but because it uses /proc/meminfo > to check for available memory, when you run it, it will > complain about the lack of /proc/meminfo and won't let you > do anything. > > The author, has suggested a hack (see globalslinux.cpp > and patch-globalslinux.cpp in the port) that disables the > function that returns the amount of memory used by muscle > and the amount of RAM available in the computer. With this > patch muscle runs fine but i) the progress messages will > give incorrect values for current memory use & fraction of > available RAM and ii) muscle may fail to fail gracefully > when it runs out of memory, it may just crash. > > I'm not a C programmer, and the author is not familiar with > BSD internals ... I'm trying to help by pointing him in the > right direction. So my question can be summarized as: > > How does one gets the values of i) memory used by the > program/process and ii) amount of RAM available in the > computer without using /proc/meminfo in FreeBSD? > > Suggestion of places to look (man pages) and/or examples in > C are welcomed. The functions that need to be modified are > GetMemUseMB and GetRAMSizeMB in globalslinux.cpp. > > OTOH, I know we have linprocfs ... but AFAIK it will mount under > /compat/linux/proc ... and given that the muscle executable > is FreeBSD native it will not check there ... am I right? > A good place to look at is /usr/src/usr.bin/top/machine.c. This is FreeBSD specific and grabs the memory and process information from the kernel. top uses sysctlbyname(3) to get the memory info and kvm_getprocs(3) to get the process-specific stuff. There seem to be 3 sysctl's of interest: hw.physmem, hw.usermem and hw.realmem. Here's output on my machine: hw.physmem: 2138202112 hw.usermem: 1953370112 hw.realmem: 2147155968 realmem > physmem > usermem. --- Gary Jennejohn / garyjATjennejohnDOTorg gjATfreebsdDOTorg garyjATdenxDOTde