Why does UNIX kernel does not shrink?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Why does UNIX kernel does not shrink?
# 1  
Old 10-13-2006
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  
Old 10-13-2006
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  
Old 10-13-2006
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  
Old 10-13-2006
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  
Old 10-13-2006
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  
Old 10-13-2006
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  
Old 10-13-2006
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 06:23 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Safe way to shrink lvm vg_*-lv_swap partition and reclaim freed space on Linux?

Hello, # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom sda 8:0 0 38.2G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 ... (2 Replies)
Discussion started by: centosadmin
2 Replies

2. AIX

[ASK] decrease/shrink the size of filesystem

Hello, I would like to reduce the size of filesystem online. We can do online for increase without any problem. So any risk can be occurred with the decrease? This is not an issue, just a discussion for decrease/shrink space with chfs command. My AIX system is version 6.1 and the filesystem... (2 Replies)
Discussion started by: Phat
2 Replies

3. Red Hat

Shrink ext4 filesystem and reduce the size of a Logical Volume in Linux

Hello guys, I would like to ask you kindly if you don't know some quick and safe method how to shrink ext4 filesystem and reduce the size of a Logical Volume in Linux, please? Thank you very much. (2 Replies)
Discussion started by: los_bandidos
2 Replies

4. SCO

Study UNIX Kernel

Hi all, I hope you are fine, I'd like study Os I tried a book like Silberschatz it's a good book but like other books it talks about the concepts abstractly and that's due to it try to encompass many concepts from many operating systems in GENERAL. i am not too much comfortable from these... (20 Replies)
Discussion started by: Abdo_8008
20 Replies

5. UNIX for Advanced & Expert Users

How to shrink root file system (LVM) in Linux Fedora 9?

My root file system is of type LVM. i wanna shrink it but unable to do so. When i give the below command: resize2fs /dev/mapper/VolGroup00-VolLog00 10000M it messages that online shrink can't can't be done as the logical volume is mounted on /. i switched to single user mode by giving command:... (2 Replies)
Discussion started by: ravisingh
2 Replies

6. AIX

Shrink Volume in V7000

When we shrink one of the volume in our IBM Storwize V7000, upto 100GB its shrinks well on storage but the shrink space was not reflected on the volume group, it still shows the same space that it has before shrinking. Should I have to export/import the volume group. (10 Replies)
Discussion started by: m_raheelahmed
10 Replies

7. UNIX for Advanced & Expert Users

Shrink my partition to new disk

I want to backup my partitions by shrinking it my issue is like I want to create a new disk copy from only the used blocks I my current image. How would I redirect the output of resize2fs to new disk and dd the current partition so that I can boot my new image without issues and also without... (3 Replies)
Discussion started by: amol28kulkarni
3 Replies

8. AIX

jfs2 - cannot shrink filesystem

Hi, is anyone aware about filesystem size restrictions on AIX? And does anyone know a solution for below problem? I have 2 boxes attached to EMC Raid5 storage, both have huge /optware/oracle/oradata filesystems - 4.5 and 2.5 TB in size, nothing is striped or in any other way restricted. Due to... (11 Replies)
Discussion started by: zxmaus
11 Replies

9. UNIX for Dummies Questions & Answers

Unix Kernel Switching?

How do I go about switching from one Kernel to another? I figure the process is somewhat like "compile -> remove old boot reference -> add new boot reference -> reboot/restart kernel"... but honestly I have no idea how to do this... I'm trying to test out a piece of software, but it only runs... (3 Replies)
Discussion started by: jjinno
3 Replies

10. Solaris

How To Shrink /Tmp

Hi, Do you know if we can shrink the size of the Swap under Solaris 8 ? 8Gb is already allocated to /TMP but we would like to reduce to 1 GB. Thanks, Fabien. (2 Replies)
Discussion started by: unclefab
2 Replies
Login or Register to Ask a Question