Available Physical Memory



A few weeks ago I posted here asking how an application could
determine the available memory on a machine running some variety of
UNIX. There were basically two types of responses:

1. Those who scoffed at the very idea, saying that "available memory"
was too vague of a term and that no application should ever need to
know that anyway because it's exclusively the kernel's business.

2. Those who disagreed saying that there are some situations where a
program legitimately needs to know the available memory.

I'd agree with the 2nd category, but I'd rephrase the question to say:
"is there a way to determine the available physical memory on a UNIX
system?"

Apparently there is, at least on Linux. You can do something like:

size_t av_phys_mem = sysconf(_SC_AVPHYS_PAGES) *
sysconf(_SC_PAGESIZE);

I would also argue that there are legitimate reasons an application
may need to know the available memory.

1. Firstly, if the program itself is *designed* to report the
available system memory to the user, like top or atop. (granted this
is a rare scenario)

2. If the program runs on a dedicated server/work-station and is
designed to perform a specific task, like sort massive amounts of
data.

To expand on number 2, suppose you need to periodically merge-sort
files that exceed 1 terabyte in size. In order to do this, you'd want
the computer to use *ALL* the memory it can. Therefore you have two
options: either hard code the amount of memory it uses, or somehow get
the available physical memory. It seems obvious to me that the latter
option is more desirable and more practical.

Am I wrong? If so, why?

.



Relevant Pages

  • UNIX garbage collection (was Details on delivering and managing application)
    ... > Is it just me or is the Unix process model very strange... ... Here's how modern UNIX garbage collectors work: ... Processes create new memory pools by forking copies ... request, it forks, so all of the code and configuration data is shared ...
    (comp.lang.lisp)
  • Re: Ram Card Design Help
    ... write-protect the common memory, or generate an interrupt on write to the ... management, kernel does it all for you. ... Again unix... ... It's a small system model not an attempt ot make a Z80 into a VAX. ...
    (comp.os.cpm)
  • Re: Another idea from pick goes mainstream...
    ... technologies that comes out tends to be something that pick had for 30+ ... I can remember when UNIX folks talked about how neat the new "demand" paged ... The UNIX concept of demand paged memory was only vaguely related to the ... Then, XML came out. ...
    (comp.databases.pick)
  • Re: Snow Leopard: A 64-bit Observation
    ... I admit to not knowing how Mach is different from other Unix ... until my *inactive* memory gets real full... ... I have been looking for Adobe's statement of their plans for 64-bit Cocoa Photoshop, and it does not appear to actually exist. ... changing their story on 64 bit Carbon. ...
    (comp.sys.mac.advocacy)
  • Re: OT:Gloat now Apple Snobs
    ... John LaCroix wrote: ... years old - 512MHz Pentium III with 256M of memory, running winXP pro. ... on a PC with 256 might make me go berzerk, running it on a PC with 512 of memory might just drive me nutz. ... basically it is just Unix - the fancy MAC OS is just a shell ...
    (rec.music.classical.guitar)