LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 09-29-2016, 12:40 PM   #1
ataur038
LQ Newbie
 
Registered: Sep 2016
Posts: 2

Rep: Reputation: Disabled
Thumbs up Retrying page fault


Hello All:

I am trying to retry a page fault more than twice (currently allowed in x86_64). This is the code in concern;(arch/x86/mm/fault.c).


Code:
 
 1132         if (unlikely(!down_read_trylock(&mm->mmap_sem))) {
1133                 if ((error_code & PF_USER) == 0 &&
1134                     !search_exception_tables(regs->ip)) {
1135                         bad_area_nosemaphore(regs, error_code, address);
1136                         return;
1137                 }
1138 retry:
1139                 down_read(&mm->mmap_sem);
1140         } else {
1141                 /*
1142                  * The above down_read_trylock() might have succeeded in
1143                  * which case we'll have missed the might_sleep() from
1144                  * down_read():
1145                  */
1146                 might_sleep();
1147         }

....

1214                 if (fault & VM_FAULT_RETRY) {
1215                         /* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
1216                          * of starvation. */
1217                         flags &= ~FAULT_FLAG_ALLOW_RETRY;
1218                         flags |= FAULT_FLAG_TRIED;
1219                         goto retry;
1220                 }
1221         }
1222 
1223         check_v8086_mode(regs, address, tsk);
1224 
1225         up_read(&mm->mmap_sem);
1226 }
You can see that the last line of code releases the semaphore.
My question is, if we go to retry after a VM_FAULT_RETRY, and try to down_write mmap_sem, what happens if the semaphore is already acquired by the current thread? Why isn't the system going to a deadlock?

Last edited by ataur038; 09-29-2016 at 04:23 PM. Reason: EDIT 1: correct spelling.
 
Old 09-30-2016, 08:23 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,599
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
You'll have to look at the kernel code to see exactly how down_read() is implemented ... there could potentially be problems doing it again if you've already done it once ... but the semantics here are what's known as a reader/writer lock. Such a lock allows multiple readers to proceed simultaneously while allowing only one writer to proceed at a time. These semantics are used when many readers merely need to ensure that no one is writing to a shared data structure, but they don't need to delay one another.

Prithee, why are you "retrying a page fault," anyway? (Just curious ...)
 
1 members found this post helpful.
Old 09-30-2016, 11:24 AM   #3
ataur038
LQ Newbie
 
Registered: Sep 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi, Thanks for replying.

You are right, I have to dig into the down_read implementation in kernel. I know about the reader-writer lock semantics, but I was looking if someone has more insights on the down_read kernel implementation.

The reason behind "trying to retrying" is slightly complicated. It's a research problem. To simplify, a group of physical pages are mapped to kernel virtual address, and the pages may be later mapped and shared by different processes. While doing certain operation on the group of pages, I write protect those pages mapped by all the processes and follow with some pointer manipulations in the kernel. I need to make sure no change happens to the pages until I am done with what I need to do . One way to achieve this would be to down_write all the mmap_sem for all the processes; the other way would be retrying the page faults.

Appreciate your suggestions.
 
  


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
Page fault kanis Linux - Server 1 03-04-2010 11:52 AM
Can page fault happen during ISR? shreshtha Linux - Newbie 4 10-30-2009 12:10 AM
kprobe-fault handler(how to generate page fault) hnshashi Linux - Newbie 0 11-13-2008 12:25 AM
Page Fault in Nonpaged Area XPediTioN Slackware 0 09-30-2003 07:57 AM
RedHat 8.0 ---> W2k - Page Fault Abrid Linux - Newbie 1 09-18-2003 10:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 10:31 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
Open Source Consulting | Domain Registration