![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| UNIX memory problems | eddiej | HP-UX | 3 | 12-12-2007 12:41 PM |
| UNIX memory problems w/Progress DB | eddiej | UNIX and Linux Applications | 0 | 12-12-2007 09:06 AM |
| ftp account locking | morgadoa | SUN Solaris | 5 | 10-19-2007 06:47 AM |
| System Locking Up | mcrawfo4 | SCO | 1 | 02-21-2005 12:31 PM |
| Program/ Memory Problems | dbrundrett | UNIX for Advanced & Expert Users | 1 | 07-28-2004 03:19 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
plock() memory locking problems
I'm experiencing some strangeness when using plock().
I'm on a Solaris 5.7/SPARC machine with 64MB of memory. I can show that plock() works by successfully locking down 10 MB of memory. Then, I ask for 40 MB, and I get a failure notice because there is "Not enough memory" available. I then try to get 10 MB again, and get the same "Not enough memory" failure. Why doesn't the 10 MB lock down the second time? I have freed everything, the memory should be available again. Here's a link to the source code... any ideas? http://www.wegotitall.com/user_space/troccola/plock.c Thanks! |
| Forum Sponsor | ||
|
|
|
|||
|
OK, I see exactly what you mean. I think you are correct.
However, I'm not out of the woods just yet. From the sbrk man page, I found that... sbrk adds incr bytes to the break value and changes the allocated space accordingly. incr can be negative, in which case the amount of allocated space is decreased. So, with intentions of "shrinking" the process size, I've added sbrk(-1 * MB_to_lock * MEGABYTE); to my code immediately following the plock call that fails. Unfortunately, with the sbrk call, the very next malloc now causes a SEGV. I don't understand why. Assuming my process size is N bytes to start, shouldn't it change like this? Start up : N bytes After lock(10) : N + 10 MB After free(10) : N + 10 MB ( free doesn't shrink process size ) After lock(40) : N + 40 MB After free(40) : N + 40 MB ( free doesn't shrink process size ) After sbrk(-40 MB ) : N ( sbrk -40MB should shrink process sz) Am I missing something? Thanks in advance, T |
|
||||
|
Like I said malloc/free will never shrink the process. But also, they aren't prepared for you to sneak in and do it for them. So malloc() is assuming that the process is still the same size it left it. And when it tries to reference the now non-existant space that it previously allocated, you get a SIGSEGV.
|
|
||||
|
Quote:
Also, you can call sbrk() directly. There is a nasty can of worms here. The direction in which the heap grows is undefined. It may grow in the same direction as the stack. Or it may grow in the reverse direction. So when you allocate a buffer you may need to return a pointer to the first new byte or the last new byte. This can change from system to system. So you will want your own routine that sits on top of sbrk to hide the idiosyncrasies of pointer arithmetic from the application. And be aware that this routine cannot be written portably. And using the stack is another way processes grow and then shrink. Automatic variables spring into existence when a function is called and vanish when it returns. |
||||
| Google UNIX.COM |