f



Available memory

Is there a function call, or a set of calls, that will tell me how much 
physical memory is available to grab with malloc?

I'm sure there is, but I can't find it.
0
Allo
2/28/2004 10:38:16 PM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (349) is leader. Post Follow

11 Replies
409 Views

Similar Articles

[PageSpeed] 31


Allo wrote:

> Is there a function call, or a set of calls, that will tell me how much=
=20
> physical memory is available to grab with malloc?
>=20
> I'm sure there is, but I can't find it.

see if there's an getrlimit(2) function in your
distribution.

man 2 getrlimit

It's a Berkleyism as far as I can tell but may
be in some other kernels as well.

--=20
=D1
"It is impossible to make anything foolproof because fools are so=20
ingenious" - A. Bloch

0
Nick
2/28/2004 10:44:29 PM
In article <hR80c.113749$hR.2200197@bgtnsc05-news.ops.worldnet.att.net>, 
hukolau@NOSPAM.att.net says...
> 
> 
> Allo wrote:
> 
> > Is there a function call, or a set of calls, that will tell me how much=
> =20
> > physical memory is available to grab with malloc?
> >=20
> > I'm sure there is, but I can't find it.
> 
> see if there's an getrlimit(2) function in your
> distribution.
> 
> man 2 getrlimit
> 
> It's a Berkleyism as far as I can tell but may
> be in some other kernels as well.

Yeah, there is.  (I'm using Solaris, by the way.)

And it just occurred to me that I could always look at the source code 
for "top" and see how that prog checks for quantities of available 
memory.  Should've thought of that sooner.
0
Allo
2/28/2004 11:06:41 PM
On Sat, 28 Feb 2004, Allo wrote:

> Is there a function call, or a set of calls, that will tell me how much
> physical memory is available to grab with malloc?

sysconf is a good one - but the amountof physical memory you have
and what's available for use by malloc two entirely different beasts.
All memory allocated to your process comes from a pool of virtual
memory.

-- 
Rich Teer, SCNA, SCSA

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net
0
Rich
2/28/2004 11:07:24 PM
in comp.unix.programmer i read:

>Is there a function call, or a set of calls, that will tell me how much 
>physical memory is available to grab with malloc?

why would you want to do that -- just allocate what you need.  other
programs may need some memory, and if you are hogging it all they may fail.

-- 
a signature
0
those
2/29/2004 3:44:06 AM
"those who know me have no need of my name" <not-a-real-address@usa.net> 
wrote in message news:m1y8qmo8iw.gnus@usa.net...
> in comp.unix.programmer i read:

>>Is there a function call, or a set of calls, that will tell me how much
>>physical memory is available to grab with malloc?


    The 'malloc' function allocates virtual memory, not physical memory, so 
your question makes no sense. A typical UNIX machine has a physical memory 
availability target (usually 2-32Mb) and there is nearly always that amount 
free.

    Free memory is only good for certain very specific things, such as 
handling a sudden burst of incoming network traffic. Other than that, free 
memory is wasted memory and there is no good reason for an operating system 
to waste anything.

> why would you want to do that -- just allocate what you need.  other
> programs may need some memory, and if you are hogging it all they may 
> fail.


    Or ask the real question rather than how to implement a solution that 
won't work. ;)

    DS




0
David
2/29/2004 4:10:43 AM
In article <c1roo3$o75$1@nntp.webmaster.com>, davids@webmaster.com 
says...
> 
> "those who know me have no need of my name" <not-a-real-address@usa.net> 
> wrote in message news:m1y8qmo8iw.gnus@usa.net...
> > in comp.unix.programmer i read:
> 
> >>Is there a function call, or a set of calls, that will tell me how much
> >>physical memory is available to grab with malloc?
> 
> 
>     The 'malloc' function allocates virtual memory, not physical memory, so 
> your question makes no sense.

Physical memory is part of virtual memory, so malloc actually does 
allocate physical memory.  If I determine the amount of unused physical 
memory, then a request for a percentage of that amount should result in 
an allocation that resides entirely within physical RAM.  This should be 
true unless the amount of allocated virtual memory exceeds the machine's 
physical memory capacity (adjusted for whatever amount of physical 
memory has been reserved by the operating system).

> A typical UNIX machine has a physical memory 
> availability target (usually 2-32Mb) and there is nearly always that amount 
> free.
> 
>     Free memory is only good for certain very specific things, such as 
> handling a sudden burst of incoming network traffic. Other than that, free 
> memory is wasted memory and there is no good reason for an operating system 
> to waste anything.

If free memory is wasted memory, then a "physical memory availability 
target" (i.e., an amount of physical memory that's always free) means 
that memory waste is actually part of the system design.
0
Allo
2/29/2004 9:25:11 AM

Allo wrote:
> In article <c1roo3$o75$1@nntp.webmaster.com>, davids@webmaster.com=20
> says...
>=20
>>"those who know me have no need of my name" <not-a-real-address@usa.net=
>=20
>>wrote in message news:m1y8qmo8iw.gnus@usa.net...
>>
>>>in comp.unix.programmer i read:
>>
>>>>Is there a function call, or a set of calls, that will tell me how mu=
ch
>>>>physical memory is available to grab with malloc?
>>
>>
>>    The 'malloc' function allocates virtual memory, not physical memory=
, so=20
>>your question makes no sense.
>=20
>=20
> Physical memory is part of virtual memory, so malloc actually does=20
> allocate physical memory.  If I determine the amount of unused physical=
=20
> memory, then a request for a percentage of that amount should result in=
=20
> an allocation that resides entirely within physical RAM.  This should b=
e=20
> true unless the amount of allocated virtual memory exceeds the machine'=
s=20
> physical memory capacity (adjusted for whatever amount of physical=20
> memory has been reserved by the operating system).
>=20
>=20
>>A typical UNIX machine has a physical memory=20
>>availability target (usually 2-32Mb) and there is nearly always that am=
ount=20
>>free.
>>
>>    Free memory is only good for certain very specific things, such as =

>>handling a sudden burst of incoming network traffic. Other than that, f=
ree=20
>>memory is wasted memory and there is no good reason for an operating sy=
stem=20
>>to waste anything.
>=20
>=20
> If free memory is wasted memory, then a "physical memory availability=20
> target" (i.e., an amount of physical memory that's always free) means=20
> that memory waste is actually part of the system design.

Actually, you're both right.

In the "usual world" of *nix, you often exceed physical
memory as processes get created, live for a few seconds
or a few minuts, then go away.  (Transients).
Every  command typed into a shell command line
is like this.  Paging portions of processes to
th swap device is how the O/S takes care of this
condition.  In theory, if I had only one process,
it could grow to physical memory size plus
swap partition size.  (I said in theory).

This implies that in order to run a process
once it is next in the pecking order, some
or all of the process image has to be
read in from disk again.  On systems with
strict response time requirements this
is considered a "BAD THING" because it leads
to unpredictable response times.  At least
even more unpredictable than just because
of the scheduling algorithm.

Those kinds of systems (and I have worked on
several of the over the years) generally
have long lived processes to do the majority
of the work (a few maintenance tasks are
transients but carefully controlled), and
the size of each process is also carefully
controlled by the design.

e.g. Total Memory: 2 GB
Database memory: 1,570 MB
O/S & Utilities: 100 MB
Communications Subsystem: 60 MB
Application Logic Handlers: 150 MB
Reserve: 120 MB (space for transients in here)

Our statisics indicate that we generally
page on average of only once or twice per second
and most of this happens during the short time
period when transients pop up to monitor the
health and welfare of the syste and to
gather statistics on the operation.

--=20
=D1
"It is impossible to make anything foolproof because fools are so=20
ingenious" - A. Bloch

0
Nick
2/29/2004 1:00:15 PM
Allo wrote:

>>     The 'malloc' function allocates virtual memory, not physical
>>     memory, so your question makes no sense.
> 
> Physical memory is part of virtual memory, so malloc actually does
> allocate physical memory.  If I determine the amount of unused
> physical memory, then a request for a percentage of that amount should
> result in an allocation that resides entirely within physical RAM. 

Actually, it might result in no real allocation at all. Many kernels do
lazy allocation, which means that the actual memory allocation doesn't
happen before you access the memory. Therefore, it can even happen that
you allocate more memory than is physically or virtually available.

>>     Free memory is only good for certain very specific things, such
>>     as handling a sudden burst of incoming network traffic. Other
>>     than that, free memory is wasted memory and there is no good
>>     reason for an operating system to waste anything.
> 
> If free memory is wasted memory, then a "physical memory availability
> target" (i.e., an amount of physical memory that's always free) means
> that memory waste is actually part of the system design.

Under some systems, you often have only few memory free, because the
system tries to use memory for buffers and caches instead of letting it
stay unused. However, as soon as a program needs that memory, it's made
available for it.

0
Rolf
2/29/2004 3:31:04 PM
> The 'malloc' function allocates virtual memory, not physical
> memory, so your question makes no sense. A typical UNIX machine has
> a physical memory availability target (usually 2-32Mb) and there is
> nearly always that amount free.

Most modern UNIX systems are virtual memory systems. When you request a 
large allocation, sometimes you get physical RAM; sometimes you get swap 
space; sometimes both. Also, sometimes you get nothing... by which I mean, 
the kernel delays allocating anything until you actually start using the 
area. Here's a description of copy-on-write, used during fork and calloc
http://en.wikipedia.org/wiki/Copy-on-write

This all makes it very difficult to determine what exactly is available (in 
terms of resources).

-- 
Jem Berkes
http://www.sysdesign.ca/
0
Jem
2/29/2004 6:50:26 PM
On Sat, 28 Feb 2004 17:38:16 -0500
Allo <all@other.s> wrote:

> Is there a function call, or a set of calls, that will tell me how
> much physical memory is available to grab with malloc?
> 
> I'm sure there is, but I can't find it.
To add to what has already been discussed, it is very implementation
specific. Depends if you are on a 32 or 64 bit system, BSD or SysV, and
how the OS manages its own memory. Most Unix systems historically used
brk(2) and sbrk(2) to grow the heap, and when it cannot grow any
more,that becomes your limit unless you have already his the artificial
limit. But, newer mallocs may use mmap(2) to allocate pages as they are
needed. This is more flexible since mmap(2) may allocate pages anywhere
in the process' virtual memory space where sbrk(2) can only allocate in
a contiguous space. And, as I mentioned, memory management is very
implementation specific. Other than that, there are tools (like
getrlimit()) that can give you some information to make a guess. 

-- 
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
0
Jerry
2/29/2004 7:50:03 PM
Jerry Feldman <gaf-noSPAM@blu.org> writes:

> On Sat, 28 Feb 2004 17:38:16 -0500
> Allo <all@other.s> wrote:
> 
> > Is there a function call, or a set of calls, that will tell me how
> > much physical memory is available to grab with malloc?
> > 
> > I'm sure there is, but I can't find it.
> To add to what has already been discussed, it is very implementation
> specific. 

And anyway, you don't grab physical memory, you grab virtual memory:
the OS can swap your process out anytime.

Perhaps there are some  platform specific extensions allowing usercode
to wire a page, but the more wired pages there are the more easy it is
to trash the  system with swaps, to crash the  processes if the system
does  overcommiting, or  even to  panic it  with  resource exhaustion.
Niceties we all need to have some fun in our dull lifes...

-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
0
Pascal
3/1/2004 1:53:39 AM
Reply:

Similar Artilces:

how to get available physical memory on unix
hi, on window we can GlobalMemoryStatusEx() to get the memory status on the system do we have any equivalent function on Unix/linux? can we use BOOST library to memory information on the unix? please help me. pp wrote: > on window we can GlobalMemoryStatusEx() to get the memory status on > the system > do we have any equivalent function on Unix/linux? - wrong newsgroup (try comp.unix.programmer, or some Linux newsgroup), - it is typically possible on a per-system basis but not portably, - normally programs shouldn't care about this unless you know why, from your question, I ...

Programmers, Programmers, Programmers, ...
As Steve Balmer correctly stated, while making his monkey dance, it is applications and hence programmers that make a platform. The fact though is that if you want to do professional programming, then Linux is the platform for you. I know that this statement will get the heckels up on a lot of trolls in C.O.L.A, but I have a recent experience that proves this. I am currently working for a Windows only house producing a system that receives and transmits around 1000 telegrams per second in each direction on a UDP socket, translates them into a different format and creates a log entry for each ...

Memory Management
Hi, 'free' releases the memory. I find that the freed memory is 'not immediately available' on certain systems and on some systems we 'get the released memory immediately' for our use . But, Why do some memory management design return the memory immediately to the OS and some at the later stage. Is there any specific advantage in either of these designs ? Thx in advans, Karthik Balaguru karthikbalaguru said: > Hi, > 'free' releases the memory. I find that the freed memory is 'not > immediately available' on certain systems and on some systems...

Error : memory requirements exceed available memory
Hi, everyone... I was using my Cisco and it was disconnected. But two days later, when I tried to turn it on again, now it shows me the following message : System Bootstrap, Version 11.3(2)XA4, RELEASE SOFTWARE (fc1) Copyright (c) 1999 by cisco Systems, Inc. TAC:Home:SW:IOS:Specials for info C2600 platform with 32768 Kbytes of main memory program load complete, entry point: 0x80008000, size: 0xe62120 Error : memory requirements exceed available memory Memory required : 0x025DD89C *** System received a Software forced crash *** signal= 0x17, code= 0x4, context= 0x8000c08c PC = 0x0, ...

available memory
How do we find out how much system memory is available for allocation of matlab variables? That is, can we avoid 'OUT OF MEMORY' when initializing. What operating system are you using? "Darren Weber" <Darren.Weber@radiology.ucsf.edu> wrote in message news:bFfsc.12798$Fo4.179821@typhoon.sonic.net... > > How do we find out how much system memory is available for allocation of matlab > variables? > > That is, can we avoid 'OUT OF MEMORY' when initializing. > Darren Weber wrote: > > > > How do we find out how much system memory...

Out of memory & Function MEMORY is not available on this platform
well guys is very strange... since: when I type: help memory I am to get response from Matlab as: .... Example 1: Run the MEMORY command on a 32-bit Windows system: .... Example 2: Run the MEMORY command on a 64-bit Windows system: .... Example 3: Run the MEMORY command with two outputs on a 32-bit Windows system: [uV sV] = memory .... but when I type: memory ??? Error using ==> memory Function MEMORY is not available on this platform. Its kind of strange isn't it? btw I use MAC OS X 10.6 (might this be a problem?) Moreover I would like to execute this ...

3620 memory requirements exceed available memory
HI GUYS I loaded a new IOS but i loaded the wrong one by accident and now its exceeding memory. How do i erase it and load the right one? Now i can only stay in ROMMON. i tried to do tftpdnld but its not working :( Any ideas? Thanks experts Sam, I believe 3620 have a Compact Flash slot - just copy correct IOS image into the Flash module (may be in another router, compact flash reader or even photocamera), and boot from that image. Good luck, Mike CCNP, CCDP, CCSP, Cisco Voice, MCSE W2K, MCSE+I, Security+, etc. CCIE R&S (in progress), CCIE Voice (in progress) ------ Headset Adapters f...

Memory available in system memory partition suddenly vanishes
Hi, I am building a system using VxWorks 5.5 with tornado 2.2 on windows. I am booting target via ethernet. When I run my system, suddenly system starts giving arror "block too big to allocate". Now to diagnose this, while system was running on target, I checked the status of memory from shell on host using memShow(). Here is the status shown at various instances. At very beginning just after system comes up on target- -> memShow SUMMARY: status bytes blocks avg block max block ------ ---------- --------- ---------- ---------- current free 56685480 156 ...

Unix Admn. & Unix Programmers required urgently..!!
---------- Forwarded message ---------- From: krishnamohan Kola <krishnamohan.kola@paralogica.com> Date: Jul 1, 2008 10:12 PM Subject: Unix Admn. & Unix Programmers required urgently..!! To: kol.srinu@gmail.com Dear srinivas, Hi, Greetings...!!! Our clientele includes the Top 20 IT companies in India.At present we have Immediate Opening at CMM Level 5 Co. at Mumbai. We have an urgent requirement for following skill set: Open Position : 1) Unix Programmers(3 positions) Exp: 1 + yrs 2) Unix/Solaris Admins (4 positions) Exp: 1+ yrs 3) Solaris Admins (4 positions) Exp: 2-3 year...

hpgcc help on memory allocation, checking available memory
Hi, I have started experimenting with the decNumber library included with the hpgcc. I'm using it for matrix multiplications, it may later be an amendment to my longfloat library, as it's much faster, and it works fine, except for one problem: Sometimes the matrixes may be large, and sometimes when during dynamic memory allocation these arrays exceed the available memory and then the calc freezes. How can I check and abort the program if I have insufficient memory available e.g // how to check if the below memory is // available prior to actually trying to reserve the memory: ...

No More Memory Available??
Hey to all. I'm fairly new to Mathematica, and while doing some arithmatic on large matrices, I came up with the following problem: No more memory available now, when I try the MemoryInUse[] command I get back the number 2001464 (bytes?). The funny thing is that if this is truly bytes, then why is it complaining already? I have 1Gig of Ram running on a XP Pro system. with I believe at least 1 gig of swap space? How can I get around this problem in mathematica? Is there any way to increase the amount of memory allocated to mathematica in mathematica? Thanks for any/all h...

No more memory available
Hi, In a loop I am pushing data on a stack and popping it later. In the first part of the calculation I push more than I pop and it eats up all the physical memory, and eats also up all the virtual memory available for the App. No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. It is with OSX 10.3.5 and Mathematica 5.0.1 on a G4 with 2GB SDRAM. I am wondering what technics are used by others in similar situation. Do you start to write out to the file system your accumulated unprocessed data and read it back late...

No Memory Available
Dear Mathematica Experts, I am using NDSolve to do integration in time for 24 variables. I can choose only to do the integration for a short time range, otherwise I get the error: No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. What frustrates me is that I get this error only after a minute or so although I can accept to carry out the run for a much longer time to reach the steady state solution but this error prevents me from this by killing the whole kernel. I tried to set the Historylength to zero with no improveme...

UNIX Programmer
Title: Data Development Operations Support Analyst Salary: 70k Fulltime role A Reference Data Operations Support Analyst position involves a combination of operations support and development responsibilities in a financial services environment. Responsibilities include loading feeds from vendors into database applications on a predefined schedule. Vendor feeds provide data that must be validated, cross referenced against data already in the applications and then loaded Operations support responsibilities include: Responding to problems communicated via email, telephone call, bee...

Web resources about - Available memory - comp.unix.programmer

Peyton's Place: No Ratings Record for Sloppy Super Bowl 50
Super Bowl 50 was not exactly the glorious golden anniversary celebration for which the NFL had been hoping, but despite the sheer sloppy joylessness ...

Apparently Marco Rubio’s stall is all Joe Scarborough’s fault
Ever since Marco Rubio’s rather repetitive performance at Saturday night’s debate, much of the talk of This Town has been centered on the Marcomentum ...

Mark Zuckerberg is 'disappointed' at India Free Basics ban and vows to fight on
Facebook was dealt a blow today when its Free Basics program was banned in India for contravening net neutrality rules. As you would expect, ...

Survivors found, but dozens still missing after Taiwan quake
CBS News Survivors found, but dozens still missing after Taiwan quake CBS News TAINAN, Taiwan At least four people, including an 8-year-old ...

Is it time to give up on WordPress sites?
It’s being reported by Malwarebytes’ CyberheistNews and other sources that a unexpectedly large wave of hacking has been hitting thousands of ...

Ted Cruz Lives Up to ‘Weasel’ Accusation with Shady Mailer
CNN has called it “astonishing” that Republican Iowa caucus winner Ted Cruz “continues to knowingly mislead” the public when it comes to his ...

Text this number to get a free Chipotle burrito. If you dare.
Free (probably safe) food alert After a string of tumultuous health issues , Chipotle closed its doors Monday during lunch in order to hold ...

Watch: Royal Caribbean Cruise Ship Buffeted By Hurricane-Force Winds
The Anthem of the Seas is headed back to New Jersey after encountering high winds and 40-foot waves.

Marshawn Lynch of Seattle Seahawks posts photo of hanging cleats on Twitter
Seahawks running back Marshawn Lynch tweeted a photo of hanging cleats Sunday, and Lynch's agent confirmed Monday that his client plans to retire. ...

Valentines Day Gift Guide for Geeks and Nerds 2016
The following Valentine's Day gift guide is androgynous and prepared for the nerd in your life. Whether you're in love or just obligated to gift ...

Resources last updated: 2/8/2016 10:46:42 PM