Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!sgi!shinobu!odin!patton.wpd.sgi.com!jmb From: jmb@patton.wpd.sgi.com (Jim Barton) Newsgroups: comp.sys.sgi Subject: Re: Determining memory availabilty. Message-ID: <1991Feb23.201337.28984@odin.corp.sgi.com> Date: 23 Feb 91 20:13:37 GMT References: <9102211011.AA03206@crow.omni.co> Sender: news@odin.corp.sgi.com (Net News) Reply-To: jmb@patton.wpd.sgi.com (Jim Barton) Organization: Silicon Graphics Inc. Lines: 28 In article <9102211011.AA03206@crow.omni.co>, rpaul@crow.UUCP (Rodian Paul) writes: |> How can I determine at run time how much virtual memory (RAM + swap) |> is available prior to my calling malloc(3C) or malloc(3X)? |> |> Perhaps I want to warn the user that this application ain't gunna run too |> fast 'cos it'll hit swap and suggest the user get rid of some of those |> processes they've got cluttering up the console. |> |> Perhaps I want to make sure that the amount of memory I need is resident |> on this machine. I.e with 32MB RAM and 50MB swap, I can still have |> a valid pointer to 511 MB returned from malloc(3C), or 289 MB from malloc(3X). |> |> Is there a simple way to do this? How does osview/gr_osview handle it? |> |> Suggestions/tips will be appreciated. |> ------------------------------------------------------------------------------- |> crow!rpaul@ccut.cc.u-tokyo.ac.jp phone: +81 (3) 5706-8357 |> ccut.cc.u-tokyo.ac.jp!crow!rpaul FAX: +81 (3) 5706-8437 There are two obvious ways to do this. First, use the sysmp(2) system call to fetch the minfo structure (described in /usr/include/sys/sysinfo.h), which gives the amount of free swap available at any given point in time, and use the MPKA_FREEMEM option to get the free real memory available. Then do the obvious calculation. The second, possibly simpler way is to use the statfs(2) system call on the /debug file system. /debug overall filesystem size is the same as the total amount of virtual memory available, free space is the same as the amount of free virtual space available. The inode count fields give the total number of process slots, and number free. -- Jim Barton Silicon Graphics Computer Systems jmb@sgi.com Brought to you by Super Global Mega Corp .com