473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Swap space size in C

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
Nov 14 '05 #1
14 4373
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.

Nov 14 '05 #2
In <cd**************************@posting.google.com > cw*******@hotmail.com (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: Da*****@ifh.de
Nov 14 '05 #3
In <br**********@news-rocq.inria.fr> Grumble <in*****@kma.eu.org> 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: Da*****@ifh.de
Nov 14 '05 #4
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 (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #5
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 ;-)

Nov 14 '05 #6
cw*******@hotmail.com (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) ks***@mib.org <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)
Nov 14 '05 #7
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-8)) 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

Nov 14 '05 #8
In <tOBCb.102332$_M.539115@attbi_s54> glen herrmannsfeldt <ga*@ugcs.caltech.edu> 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-8)) 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: Da*****@ifh.de
Nov 14 '05 #9
Dan Pop wrote:

(snip on determining swap space)
for(i=0;j=0x40000000;j>8;j>>=1) if(malloc(i-8)) 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

Nov 14 '05 #10
glen herrmannsfeldt <ga*@ugcs.caltech.edu> wrote in message news:<C0sDb.401963$ao4.1321249@attbi_s51>...
Dan Pop wrote:

(snip on determining swap space)
for(i=0;j=0x40000000;j>8;j>>=1) if(malloc(i-8)) 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

Okay everyone,

thanks for some of the pointers, I'm not there yet but getting closer.

Let me first tell you why I wanted this information in the first place.
Our application uses very large files (100G +) and these have to be
procesed in the fastest possible way. We do this my placing a lot of
data in memory and then run our tricks on it. However there are a number
of restrictions that stops us of allocation more and more memory.
We think the following:

1) Address Space of the CPU. (32 bit only allows for 4G range).
2) Process limits.
3) Size of the available swap/page file.

When a malloc fails I would like to print an apropriate error message
why it fails. So we can give the user a meaningfull sugestion how to
improve the job.

Now 1 and 2 are fairly easy to check. Bit 3 is as you already know
quite tricky. So just allocating some memory is not a good option
because we are talking about big systems here and allocates can take
quite some time. Also at the time I need the info there is none left
anyway.

Anway thanks for the info sofar.
Otto
Nov 14 '05 #11
In <C0sDb.401963$ao4.1321249@attbi_s51> glen herrmannsfeldt <ga*@ugcs.caltech.edu> writes:
Dan Pop wrote:

(snip on determining swap space)
for(i=0;j=0x40000000;j>8;j>>=1) if(malloc(i-8)) 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.


Nonsense. Such a system would be irremediably broken and perfectly
useless. Once you write a value to a memory location, that memory
location must be mapped into your program's address space. If this is
not possible (it can happen in a system with lazy swap space allocation,
due to lack of physical swap space), the behaviour is system specific.
Typical examples are sending a signal to the program or killing *other*
programs, chosen more or less randomly, to obtain the missing swap space.

Although such behaviour may sound crazy, the redeeming merits of lazy
swap space allocation make it the preferred choice of many people.

Back when using a system with only 128 MB of swap space (eager swap
allocation would have rendered it next to useless), I knew that it was
time to kill netscape when I was starting to lose xterms ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #12
Dan Pop wrote:
glen herrmannsfeldt <ga*@ugcs.caltech.edu> writes:
Dan Pop wrote:

(snip on determining swap space)
for(i=0;j=0x40000000;j>8;j>>=1) if(malloc(i-8)) 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.


Nonsense. Such a system would be irremediably broken and perfectly
useless. Once you write a value to a memory location, that memory
location must be mapped into your program's address space. If this is
not possible (it can happen in a system with lazy swap space allocation,
due to lack of physical swap space), the behaviour is system specific.
Typical examples are sending a signal to the program or killing *other*
programs, chosen more or less randomly, to obtain the missing swap space.

Although such behaviour may sound crazy, the redeeming merits of lazy
swap space allocation make it the preferred choice of many people.


That system may have built some hidden assumptions in, such as
freshly allocated space contains zeroes, copying zeroes to lazy
allocations does not constitute dirtying, etc. This could result
in some blinding speeds. :-)

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #13
cw*******@hotmail.com (Otto Meijer) writes:
glen herrmannsfeldt <ga*@ugcs.caltech.edu> wrote in message
news:<C0sDb.401963$ao4.1321249@attbi_s51>... [...] Let me first tell you why I wanted this information in the first place.
Our application uses very large files (100G +) and these have to be
procesed in the fastest possible way. We do this my placing a lot of
data in memory and then run our tricks on it. However there are a number
of restrictions that stops us of allocation more and more memory.
We think the following:

1) Address Space of the CPU. (32 bit only allows for 4G range).
2) Process limits.
3) Size of the available swap/page file.

When a malloc fails I would like to print an apropriate error message
why it fails. So we can give the user a meaningfull sugestion how to
improve the job.


Just a thought: as long as you can't read the whole thing into memory
at once, you'll probably get the best performance by reading only as
much as will fit into real memory, avoiding the swap file. It
probably depends on your access patterns and half a dozen other things
that are off-topic here.

<OT>Something like mmap() might be a possibility, apart from the
address space limitation (though it might be worth migrating to a
64-bit CPU).</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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)
Nov 14 '05 #14
Dan Pop wrote:
In <C0sDb.401963$ao4.1321249@attbi_s51> glen herrmannsfeldt writes:
(snip)
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.

Nonsense. Such a system would be irremediably broken and perfectly
useless. Once you write a value to a memory location, that memory
location must be mapped into your program's address space. If this is
not possible (it can happen in a system with lazy swap space allocation,
due to lack of physical swap space), the behaviour is system specific.
Typical examples are sending a signal to the program or killing *other*
programs, chosen more or less randomly, to obtain the missing swap space. Although such behaviour may sound crazy, the redeeming merits of lazy
swap space allocation make it the preferred choice of many people. Back when using a system with only 128 MB of swap space (eager swap
allocation would have rendered it next to useless), I knew that it was
time to kill netscape when I was starting to lose xterms ;-)


Note that the above program does not write anything to b.

I may not have remembered the actual example right, though.
This one would have to actually allocate a, but it doesn't
ever need to allocate memory for b.

I don't know if they actually overcommit, or just don't bother
actually clearing the memory (usually required for security),
and setting up the tables to describe it.

-- glen

Nov 14 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news.onet.pl | last post by:
I've launched some perfomance test for some program measuring number of operations, net messages processed per second, etc. Why is my point, is the question how Java initial and maximal heap is...
3
by: Kevin Bartz | last post by:
I'm de-duping a 45-million-row table (about 4 gigs) by creating a new table with the unique rows of the first table (should be about 3 gigs). I'm on a 64-bit SuSE Linux with 2 gigs of memory and...
0
by: Kevin Bartz | last post by:
-----Original Message----- From: Kevin Bartz Sent: Monday, August 09, 2004 10:37 AM To: 'mike@thegodshalls.com' Subject: RE: Out of swap space & memory Thanks for your reply, Mike!...
18
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra...
8
by: Jason Heyes | last post by:
Does the STL have a function like this one? template <typename T> void remove(std::vector<T> &v, std::vector<T>::size_type index) { std::swap(v, v.back()); v.resize(index); } Unlike...
9
by: ma740988 | last post by:
Consider: # include <vector> # include <iostream> # include <cstdlib> # include <ctime> bool ispow2i ( double n ) {
19
by: Krishanu Debnath | last post by:
Hello, I have a call to hash_map::clear() function which takes long time. someClass::someFunction() { // typedef hash_map<name_id, uintMp; // Mp p; // assuming proper namespace, hash...
1
by: aaron | last post by:
Output of "top" prior to initiation of mysql: load averages: 0.60, 0.97, 1.05 19:03:45 44 processes: 43 sleeping, 1 on cpu CPU states: 97.1% idle, 0.0% user, 0.8% kernel, 2.1% iowait, ...
11
by: Dennis Jones | last post by:
Hi all, 1) Let's say you have two char 's of the same size. How would you write a no-fail swap method for them? For example: class Test { char s; void swap( Test &rhs ) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.