Skip to contentSkip to conversation

Understanding page faults code in mm/memory.c

DISCUSSION Eugene Teo 3 participants 6 messages Jul 31, 2003 Memory management

lore
Share & tools
lore

Eugene Teo

author
#0 lore raw

Hi there,

With reference to 2.4.20, I have a few questions:

[1] I was looking at mm/memory.c. I noticed that there is a difference between minor, and major faults. My guess is that when a major fault occurs, the mm performs a page-in from the swap to the memory, whilst a minor fault doesn't? No?

[2] I understand that for the handle_pte_fault routine, the if structure basically handles page-in. I am trying to figure out where I can find the code for page-out which I understand it can be involved the swap, etc. Can someone give me some pointers as to where I can look for:

- what causes page-outs,
- where in the kernel can i look for them?

[3] in mm/memory.c, in do_wp_page, I am not sure what the portion of code is about:

// If old_page bit is not set, set it, and test.
if (!TryLockPage(old_page) {

    // [QN:] I don't understand what can_share_swap_page() do
    // I tried tracing, but i still don't quite get it.
    int reuse = can_share_swap_page(old_page);    
    unlock_page(old_page);
    if (reuse) {
        // flush the old mapping out of the tlb.
        fluse_cache_page(vma, address);
        
        // creates a new mapping with entry in the page table        
        // [QN:] What is pte_mkyoung?
        establish_pte(vma, address, page_table, pte_mkyoung(...
        
        spin_unlock(&mm->page_table_lock);

        // [QN:] why didn't the mm->rss increased since it is
        // a minor fault? hmm, i am not sure what minor
        // fault is though.
        return 1; /* minor fault */
    }
}    

Hear from you guys. Thank you so much.

Cheers,
Eugene
(posted this in another mailing list before)

#1 lore raw
Quoted 5 lines · Eugene Teo

[1] I was looking at mm/memory.c. I noticed that there is a difference between minor, and major faults. My guess is that when a major fault occurs, the mm performs a page-in from the swap to the memory, whilst a minor fault doesn't?

Close enough. A major fault requires disk IO of some sort, it could be either to a file or to swap.

Quoted 4 lines

[2] <snip>
- what causes page-outs,
- where in the kernel can i look for them?

vmscan.c:shrink_cache() is a decent place to start.

Quoted 9 lines

[3] in mm/memory.c, in do_wp_page, I am not sure what the portion of code is about:

// If old_page bit is not set, set it, and test.
if (!TryLockPage(old_page) {

    // [QN:] I don't understand what can_share_swap_page() do
    // I tried tracing, but i still don't quite get it.
    int reuse = can_share_swap_page(old_page);

Basically it'll determine if you are the only user of that swap page. If it returns true, it means that you are the last process to break COW on that page so just use it. Otherwise it'll fall through and a new page will be allocated.

Quoted 2 lines
        // creates a new mapping with entry in the page table
        // [QN:] What is pte_mkyoung?

Sets the accessed bit in the PTE to show it has been recently used

Quoted 3 lines
        // [QN:] why didn't the mm->rss increased since it is
        // a minor fault? hmm, i am not sure what minor
        // fault is though.

Because you are using the same page that was there before. No new page is being used by the process so no need to rss++

Signature · 6 lines
Mel Gorman
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 8 lines
Quoted 8 lines

[3] in mm/memory.c, in do_wp_page, I am not sure what the portion of code is about:

// If old_page bit is not set, set it, and test.
if (!TryLockPage(old_page) {

Quoted 8 lines
Quoted 3 lines
    // [QN:] I don't understand what can_share_swap_page() do
    // I tried tracing, but i still don't quite get it.
    int reuse = can_share_swap_page(old_page);

Basically it'll determine if you are the only user of that swap page. If it returns true, it means that you are the last process to break COW on that page so just use it. Otherwise it'll fall through and a new page will be allocated.

But when you put a page on to the swap cache will not the rss of the
address spage decrease. if not then when will the rss value of the address space change.

thanks,
Raghu
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 4 lines · Raghu R. Arur

But when you put a page on to the swap cache will not the rss of the
address spage decrease. if not then when will the rss value of the address space change.

vmscan.c:try_to_swap_out() will decrement the rss before adding it to the swap cache with add_to_swap_cache()

Signature · 6 lines
Mel Gorman
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw

No, what i meant was, if the rss value gets decremented when a page is
put into swap cache, then why is it not incremented in do_wp_page when you fault for a page inside swap cache. if you fault, then you add it establish the pte to the page in the swap cache. dont you need to increment the rss value too ?? I know i am missing something over here. Please help me in understanding it correctly.

Thanks,
Raghu

Quoted 7 lines · Mel Gorman
Quoted 4 lines · Raghu R. Arur

But when you put a page on to the swap cache will not the rss of the
address spage decrease. if not then when will the rss value of the address space change.

Quoted 6 lines

vmscan.c:try_to_swap_out() will decrement the rss before adding it to the swap cache with add_to_swap_cache()

--
Mel Gorman

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 4 lines · Raghu R. Arur

No, what i meant was, if the rss value gets decremented when a page is
put into swap cache, then why is it not incremented in do_wp_page when you fault for a page inside swap cache.

Because paging in from the swap cache is handled by do_swap_page() which does increment rss, not do_wp_page().

Signature · 6 lines
Mel Gorman
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>