Operating System - Tru64 Unix
1827879 Members
1352 Online
109969 Solutions
New Discussion

Re: Swap space error

 
Balasubramanian S
Frequent Advisor

Swap space error

Hello, I got the following error while
running the following program,
"Unable to obtain requested swap space".

There is no problem with the program;
I have freed the memory before forking
a new process. I would like to know is
this an expected behavior or a bug?

Here is the program which I have used
to get the error message. The swap mode
was set to eager while running the
program.

void main()
{
char *buf;
int pid=0;

buf=(char *)malloc(1024*1024*256);
if(buf)
free(buf);
else
printf("Malloc failed \n");
pid=fork();

printf("Pid is %d \n", pid);
}

Thanks, Bala S
7 REPLIES 7
Mark Poeschl_2
Honored Contributor

Re: Swap space error

What does the output of 'swapon -s' look like immediately before running your program?
Devesh Pant_1
Esteemed Contributor

Re: Swap space error

You might want to go back to lazy mode and test.
In eager mode system preallocates swap ahead of time and depending on the arbitration logic, this might happen.

I suggest lazy mode for most environments unless a lot of performance planning has gone into the setting up.

thanks
DP
Venkatesh BL
Honored Contributor

Re: Swap space error

I think what Bala is trying to address here is a possible bug where in the OS still assumes that the 'freed' heap space is part of the parent process and tries to provide same amount of user address space for the child as well.

I think this is an optimization thing for malloc-n-free such that the program always has the freed memory if it wants to malloc again. But, when it comes to forking, this could be a problem.
Hein van den Heuvel
Honored Contributor

Re: Swap space error

I suspect that Venkatesh is right in his guess about the underlying question.

A much similar question is raised was raised back in 1998.
[HP Internal readers, check the DIGITAL_UNIX.NOTE file topic 2199]

The VM engineer at that time responded:

"fork() will attempt to reserve the required swap space in eager mode.
Since V4.0, vfork(2) supports lazy swap allocation for the child.
The assumption, of course, is that the child will exec immediately. Note that the child will modify (COW) at least the stack page that it is running on. Address space duplication is always done lazily, using COW mechanism."

This is not a bug, just an implementation choice that will be good for some, sub-optimal for others.
If this presents a problem, then the first order of business would seem to be to see whether you can use vfork, and next to allocate more swap space!

hth,
Hein.


Venkatesh BL
Honored Contributor

Re: Swap space error

yeah...it need not be termed as a 'bug'. It would be interesting to see if 'vfork' solves the problem.
Balasubramanian S
Frequent Advisor

Re: Swap space error

Hello, Thank you for all your responses. My intension was to find out is that is behavior of fork or a bug. Your replies ensure that is an expected behavior of fork.

Thanks, Bala S
Balasubramanian S
Frequent Advisor

Re: Swap space error

Thanks for your help.

-Bala S