LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2010, 10:39 AM   #1
daudiam
Member
 
Registered: Mar 2010
Posts: 68

Rep: Reputation: 15
When page's retrieved from swap, how does its application know new virtual address ?


During runtime when a program asks for a memory block (say, by malloc()), its provided with a block of virtual addresses, say 0x10000000 to 0x1000A00 (for 32 bit). During the execution, other processes are incorporated into the main memory and pages 0x10000000-0x100000A0 are paged out. After some time, the program requests the page 0x10000000. Its incorporated back into the main memory (at the cost of some other page) but its assigned a new virtual address, but the program is oblivious of the new virtual address assigned to it and references the it using 0x10000000. How is this problem resolved ? Does it proceed in any other way ?
 
Old 06-16-2010, 11:24 AM   #2
xweb
Member
 
Registered: Dec 2005
Location: norfolk, va
Distribution: kubuntu, debian
Posts: 36

Rep: Reputation: 16
The application has a virtual address to begin with. so when the page is swaped into memory the os associates the phycial location the page is swapped into with the appropropriate virtual address. the app continues to access the virtual address it had from the begining and is completely oblivious of the swap/paging process.

This is basiclly a form of virtualization. The os present the memory resource ( physical and virtual) as a single storage resource.
 
Old 06-17-2010, 01:25 AM   #3
daudiam
Member
 
Registered: Mar 2010
Posts: 68

Original Poster
Rep: Reputation: 15
Thanks, by I wanted to ask this:

Suppose the contents of page 0 are swapped out and are replaced by some other data, when the process references page 0 by the virtual address 0x00000000, it'll not be knowing that the original contents of page 0 have been swapped out. Since it uses virtual addresses (since virtual addresses don't disappear, how can the process know that its a page fault), how can it know that the value at that virtual address is the original one or has been replaced.
 
Old 06-17-2010, 02:12 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,959

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
The userspace process neither knows nor cares about page fault. It references virtual addresses - if a fault occurs, the process is interrupted until the fault is resolved, then it is re-dispatched. As far as the process is concerned all the addresses it references are always (instantly) available - it doesn't even know it was interrupted.
Have a read of this
 
Old 06-17-2010, 06:13 AM   #5
daudiam
Member
 
Registered: Mar 2010
Posts: 68

Original Poster
Rep: Reputation: 15
Isn't virtual memory infinite.

Thanks. All this time, by page I was understanding the pages in the virtual memory table, though the pages in the memory were meant.

So, I get these things :

1. Any process larger than 2GiB can't be accommodated since each process is given only 2GiB virtual addresses.

2. If the swap space as well as the main memory gets filled up, the kernel gives an error saying "Virtual memory is low" (Actually, shouldn't it say that "swap is too small" as virtual memory is infinite)

3. The reason swap space is maintained is that if a page fault occurs, the page is first located in the swap space as compared to searching the entire hard disk. If its not found there, then the remaining hard disk is checked. This checking, though occurs just for the first time when the process is being loaded, because otherwise, the only reason for the page to be not present in either the swap or the main memory is that it has ended or the process has been killed.

4. Even when a process swaps out of the memory, the page table for that process does keep some info about where that page is in the swap

5. I take it that "increasing virtual memory" is actually a misnomer because virtual memory is infinite. What is meant is increasing the swap space.

Am I right?
 
Old 06-17-2010, 07:35 AM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190
Quote:
Originally Posted by daudiam View Post
Its incorporated back into the main memory (at the cost of some other page) but its assigned a new virtual address
No. It keeps its original virtual address.

Quote:
Originally Posted by daudiam View Post
how can the process know that its a page fault
When the page is taken out of that process's resident set (prior to being physically swapped out) the kernel sets the page table entry for that virtual page of that process to fault. But that fault is handled later by the kernel, so the user code in the process doesn't know about it.

Quote:
Originally Posted by daudiam View Post
1. Any process larger than 2GiB can't be accommodated since each process is given only 2GiB virtual addresses.
Depends on the OS, the architecture, and maybe the program.

2GiB is the default limit for 32 bit Windows. 3GiB is the default limit for 32 bit Linux. Each can be changed.

Quote:
2. If the swap space as well as the main memory gets filled up, the kernel gives an error saying "Virtual memory is low"
What OS does that? Some version of Windows?

Quote:
3. The reason swap space is maintained is that if a page fault occurs, the page is first located in the swap space as compared to searching the entire hard disk. If its not found there, then the remaining hard disk is checked.
Nonsense.

Swap space is maintained because there are "anonymous" pages, meaning pages that do not correspond directly to a properly sized and aligned chunk of some file.

When a page is out of physical memory, the page table data keeps track of where the page actually is (which part of which file or which slot in the swap file). There is no search and there is no checking one place then another. When it is time to load the page into memory, the kernel knows where to get it.

Quote:
the only reason for the page to be not present in either the swap or the main memory is that it has ended or the process has been killed.
More nonsense. See above explanation.

Quote:
5. I take it that "increasing virtual memory" is actually a misnomer because virtual memory is infinite.
Virtual memory is not infinite. There are several different related meanings of the phrase "virtual memory" but none of them are infinite and most of them can be increased up to some limit.

Quote:
What is meant is increasing the swap space.
What's hard to understand about that? Windows defaults to increasing swap space automatically when it thinks it should (I always turn that feature off and select a good swap size myself). Linux does not increase swap space automatically, but the root user can increase swap space in various ways even on a running system.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Application Virtual address space memory allocation - memory does not get free chamara82 Linux - General 4 01-01-2011 09:19 PM
how to translate virtual address to physical address in linux application saurin Programming 1 11-18-2009 10:05 PM
Does user stack have a fixed address location in its virtual address? lqu Linux - Kernel 1 09-11-2009 02:28 PM
Outgoing local trafic over virtual interface has not virtual ip address :-( tkmbe Linux - Networking 3 08-25-2009 09:03 PM
Page's Source Code Ciccio LQ Suggestions & Feedback 6 01-16-2003 01:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration