The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rebuild the Dev of a non UNIX kernel... DevSer2279 High Level Programming 0 04-20-2008 09:23 PM
Unix Kernel Switching? jjinno UNIX for Dummies Questions & Answers 3 08-04-2007 03:22 PM
Unix Distribution and Kernel Dipset UNIX for Dummies Questions & Answers 1 04-24-2007 12:18 PM
How To Shrink /Tmp unclefab SUN Solaris 2 01-11-2005 07:43 PM
Mac OS X - UNIX kernel based. Neo OS X (Apple) 0 06-06-2001 12:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-12-2006
dillidamunda dillidamunda is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 3
Why does UNIX kernel does not shrink?

Hello this is a book problem of chapter 8 william stallings's operating systems..can anyone tells me the accurate solution of it??

The Unix kernel will dynamicaly grow a process’s stack in virtual memory as needed, but it willnever try to shrink it. Consider the case in which a program calls a C function that allocates a local arrayon the stack that consumes 10KB. The kernel will expand the stack segment to accommodate it. When thesubroutine returns, the stack pointer is adjusted and this space could be released by the kernel, but it is notreleased. Explain why it would be possible to shrink the stack at this point, and why the Unix kernel does not shrink it.
  #2 (permalink)  
Old 10-13-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
for {i=0, i<10000; i++} function_that_needs_a_lot_of_stack();

Do you really want to allocate and deallocate several stack pages 10000 times? Well I sure don't. So I disagree with the premise of the question. As a process reaches deeper into a stack it eventually tries to access unallocated pages. This causes a page fault and the page fault causes the kernel to allocate more space or terminate the process if the stack is exceeding a max. There is no coresponding mechanism to notify the kernel when a frame is removed from the stack. If the stack space is needed by the process again, you don't want to deallocate and reallocate the space repeatedly. If the stack space is not needed by the process and physical memory is tight, the unused stack pages will be paged out. If there is plenty of physical memory, they will sit harmlessly in memory. Shrinking a stack, while possible, would not be easy or desirable.
  #3 (permalink)  
Old 10-13-2006
apoorvasharma80 apoorvasharma80 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 69
Usualy the stack allocation is not shrinked to keep track of things when a process behaves unexpectdly. So the remaining stack can provide some valueabel information for debugging!!
  #4 (permalink)  
Old 10-13-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
Another thing is that, in a system where memory is backed by disk, it doesn't have to shrink the stack to get it out of memory. It can swap extra pages to disk instead.

Another issue is how the stack is expanded. Detecting when something uses memory after the end of the current stack is easy -- detect page faults. But how are they supposed to detect when something is not using memory?
  #5 (permalink)  
Old 10-13-2006
dillidamunda dillidamunda is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 3
i am really getting confused with the points..
lets answer this question by taking any assumption..

So,

1. What can be the assumption.

2.Explain why it would be possible to shrink the stack at this point

3. and why the Unix kernel does not shrink it.

I think answering these questions will simplify the problem.
  #6 (permalink)  
Old 10-13-2006
dillidamunda dillidamunda is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 3
assumption?

i am really getting confused with the points..
lets answer this question by taking any assumption..

So,

1. What can be the assumption.

2.Explain why it would be possible to shrink the stack at this point

3. and why the Unix kernel does not shrink it.

I think answering these questions will simplify the problem.
  #7 (permalink)  
Old 10-13-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
1) What?

2) Explain why it is? I don't think it is. Not efficiently, anyway.

3) It doesn't because that's not an efficient way to do it. I don't think Windows shrinks it either.

Like Per said, allocating and freeing memory 10,000 times is expensive. UNIX assumes that memory a process has used once, will probably be used again, so lets it keep it instead of slowing things down by trying to free it all the time.

There's a different strategy for paring down unused memory. The operating just looks for memory that hasn't been used recently. It might grab the end of the stack, or it might bite a page out of a shared library you've loaded, or pull page out of your global variables -- then save its contents to disk and give the memory to someone else. The operating system will remember what pieces it's taken from your process, and give them back if you try to use them.

Last edited by Corona688; 10-13-2006 at 05:23 PM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On




All times are GMT -4. The time now is 07:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0