Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Swap space size in C

Reply
Thread Tools

Swap space size in C

 
 
Otto Meijer
Guest
Posts: n/a
 
      12-12-2003
Hi everyone,

for one of my projects I need to figure out the size of the
swap file(s) of a certain system. The problem is I need to do this
on a host of platforms like: HP_UX, Solaris, Linux, AIX, OSF,
OpenVMS and Windows.

This seems much more difficult than I thought origionaly.
Some platforms don't seem to have any API to query this information.

Any hints how to tack this would be very welcome

Otto
 
Reply With Quote
 
 
 
 
Grumble
Guest
Posts: n/a
 
      12-12-2003
Otto Meijer wrote:
> for one of my projects I need to figure out the size of the
> swap file(s) of a certain system. The problem is I need to do this
> on a host of platforms like: HP_UX, Solaris, Linux, AIX, OSF,
> OpenVMS and Windows.
>
> This seems much more difficult than I thought origionaly.
> Some platforms don't seem to have any API to query this information.
>
> Any hints how to tack this would be very welcome


AFAICT, your best bet is the Portable Operating System Interface for
UNIX, aka POSIX.

 
Reply With Quote
 
 
 
 
Dan Pop
Guest
Posts: n/a
 
      12-12-2003
In <(E-Mail Removed) > http://www.velocityreviews.com/forums/(E-Mail Removed) (Otto Meijer) writes:

>for one of my projects I need to figure out the size of the
>swap file(s) of a certain system. The problem is I need to do this
>on a host of platforms like: HP_UX, Solaris, Linux, AIX, OSF,
>OpenVMS and Windows.
>
>This seems much more difficult than I thought origionaly.
>Some platforms don't seem to have any API to query this information.
>
>Any hints how to tack this would be very welcome


On a platform by platform basis. Post the question to newsgroups
dedicated to programming on each of the platforms of interest to you.
If you get the desired information, write a function for each platform.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      12-12-2003
In <brc3oe$a89$(E-Mail Removed)> Grumble <(E-Mail Removed)> writes:

>Otto Meijer wrote:
>> for one of my projects I need to figure out the size of the
>> swap file(s) of a certain system. The problem is I need to do this
>> on a host of platforms like: HP_UX, Solaris, Linux, AIX, OSF,
>> OpenVMS and Windows.
>>
>> This seems much more difficult than I thought origionaly.
>> Some platforms don't seem to have any API to query this information.
>>
>> Any hints how to tack this would be very welcome

>
>AFAICT, your best bet is the Portable Operating System Interface for
>UNIX, aka POSIX.


Which, AFAICT, blissfully ignores the issue.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      12-12-2003
Otto Meijer wrote:
>
> for one of my projects I need to figure out the size of the
> swap file(s) of a certain system. The problem is I need to do
> this on a host of platforms like: HP_UX, Solaris, Linux, AIX,
> OSF, OpenVMS and Windows.
>
> This seems much more difficult than I thought origionaly. Some
> platforms don't seem to have any API to query this information.
>
> Any hints how to tack this would be very welcome


Yes. Ask on newsgroups that deal with HP_UX, Solaris, Linux, AIX,
OSF, OpenVMS, and Windows. This group deals with ISO standard
portable C only. If it isn't in the C standard, it doesn't exist
(here).

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
Grumble
Guest
Posts: n/a
 
      12-12-2003
Dan Pop wrote:

> Grumble wrote:
>
>> AFAICT, your best bet is the Portable Operating System Interface
>> for UNIX, aka POSIX.

>
> Which, AFAICT, blissfully ignores the issue.


Then, it seems, I could not tell far enough

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-12-2003
(E-Mail Removed) (Otto Meijer) writes:
> Hi everyone,
>
> for one of my projects I need to figure out the size of the
> swap file(s) of a certain system. The problem is I need to do this
> on a host of platforms like: HP_UX, Solaris, Linux, AIX, OSF,
> OpenVMS and Windows.
>
> This seems much more difficult than I thought origionaly.
> Some platforms don't seem to have any API to query this information.
>
> Any hints how to tack this would be very welcome
>
> Otto


As others have mentioned, this is extremely platform-specific. It may
not even be possible on some platforms. Some platforms may not have a
concept of a "swap file" (it could be a swap partition, for example);
others could have a "swap file" whose size can vary over time, or that
doesn't have a well-defined size at all.

You might want to reconsider whether knowing the "size" of the "swap
file" is even useful. What are you going to do with the information?
(That's a rhetorical question; any answer is probably off-topic here.)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      12-13-2003
Otto Meijer wrote:


> for one of my projects I need to figure out the size of the
> swap file(s) of a certain system. The problem is I need to do this
> on a host of platforms like: HP_UX, Solaris, Linux, AIX, OSF,
> OpenVMS and Windows.


I have done it with an exponentially decreasing malloc() loop,

for(i=0;j=0x40000000;j>8;j>>=1) if(malloc(i-) i += j;

There is no guarantee that it gives meaningful results
on any system, and may crash the system.

I did once crash a unix system with a malloc() loop, but
not with this one.

The i-8 is a guess of the malloc() overhead, which may or may
not be related to any real malloc() overhead.

-- glen

 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      12-15-2003
In <tOBCb.102332$_M.539115@attbi_s54> glen herrmannsfeldt <(E-Mail Removed)> writes:

>Otto Meijer wrote:
>
>
>> for one of my projects I need to figure out the size of the
>> swap file(s) of a certain system. The problem is I need to do this
>> on a host of platforms like: HP_UX, Solaris, Linux, AIX, OSF,
>> OpenVMS and Windows.

>
>I have done it with an exponentially decreasing malloc() loop,
>
>for(i=0;j=0x40000000;j>8;j>>=1) if(malloc(i-) i += j;
>
>There is no guarantee that it gives meaningful results
>on any system, and may crash the system.


In particular, it's useless on systems with lazy swap space allocation.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      12-16-2003
Dan Pop wrote:

(snip on determining swap space)

>>for(i=0;j=0x40000000;j>8;j>>=1) if(malloc(i-) i += j;


>>There is no guarantee that it gives meaningful results
>>on any system, and may crash the system.


> In particular, it's useless on systems with lazy swap space allocation.


It might still tell you the maximum for one task...

My favorite lazy swap story was someone trying to determine how fast the
memory system was, something like:

int i;
char *a,*b;
a=malloc(SIZE);
b=malloc(SIZE);
for(i=0;i<1000000;i++) memcpy(a,b,SIZE);

assuming that SIZE was enough bigger than the cache, so that it would
have to go out to memory.

It turned out that in a lazy swap allocation, all the allocated pages
referenced the same physical page, which was smaller than the cache,
so that it only tested the cache.

-- glen

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What swap is called when using std::swap? Niels Dekker (no reply address) C++ 4 07-20-2006 08:44 PM
Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok?? Christian Seberino Python 21 10-27-2003 04:20 PM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-24-2003 11:15 AM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-23-2003 07:07 AM
Stack space, global space, heap space Shuo Xiang C Programming 10 07-11-2003 07:30 PM



Advertisments