Oddness in i_shared_lock and page_table_lock nesting hierarchies ?
The vma list lock can nest with i_shared_lock, as per Kanoj Sarcar's
note on mem-mgmt locks (Documentation/vm/locking), and currently vma list lock == mm->page_table_lock.
But there appears to be some inconsistency in the hierarchy of these 2 locks. (By vma list lock I mean vmlist_access/modify_lock(s) )
Looking at mmap code, it appears that the vma list lock i.e. page_table_lock right now, is to be acquired first (e.g insert_vm_struct which acquires i_shared_lock internally, is called under the page_table_lock/vma list lock). Elsewhere in madvise too, I see a similar hierarchy. In the unmap code, care has been taken not to have these locks acquired simultaneously.
However, in the vmtruncate code, it looks like the hierarchy is
reversed.
There, the i_shared_lock is acquired, in order to traverse the i_mmap
list
and inside the loop it calls zap_page_range, which aquires the page_table_lock.
This is odd. Isn't there a possibility of a deadlock if mmap and
truncation
for the same file happen simultaneously (on an SMP) ?
I'm wondering if this could be a side effect of the doubling up of the page_table_lock as a vma list lock ?
Or have I missed something ?
[I have checked upto 2.4-test10-pre5 ]
I had put this query up on linux-mm, as part of a much larger mail, but didn't get any response yet, so I thought of putting up a more focussed query this time.
Regards
Suparna
Suparna Bhattacharya
Systems Software Group, IBM Global Services, India E-mail : [email protected]
Phone : 91-80-5267117, Extn : 2525
Quoted 11 lines
List: linux-mm Subject: Re: Updated Linux 2.4 Status/TODO List (from the ALS show) From: Kanoj Sarcar <[email protected]> Date: 2000-10-13 18:19:06[Download message RAW]
Quoted 5 lines · David S. Miller
Quoted 2 lines
page_table_lockis supposed to protect normal page table activity
(like
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
what's done in page fault handler) from swapping out. However, grabbing this lock in swap-out code is completely missing!
Audrey, vmlist_access_{un,}lock == unlocking/locking
page_table_lock.Yeah, it's an easy mistake to make.
I've made it myself - grepping for
page_table_lockand coming up empty
in
Quoted 3 lines
Quoted 3 lines
places where I expected it to be.
In fact, if somebody sends me patches to remove the
"vmlist_access_lock()"
Quoted 3 lines
Quoted 3 lines
stuff completely, and replace them with explicit
page_table_lockthings, I'll apply it pretty much immediately. I don't like information hiding, and right now that's the only thing that thevmlist_access_lock()stuff
is
Quoted 17 lines
Quoted 1 line
doing.
Linus,
I came up with the vmlist_access_lock/vmlist_modify_lock names early in 2.3. The reasoning behind that was that in most places where the "vmlist lock" was being taken was to protect the vmlist chain,
vma_tfields ormm_structfields. The fact that implementation wise this lock could be the same aspage_table_lockwas a good idea that you suggested.Nevertheless, the name was chosen to indicate what type of things it was guarding. For example, in the future, you might actually have a different (possibly sleeping) lock to guard the vmachain etc, but still have a spin lock for the
page_table_lock(No, I don't want to be drawn into a discussion of why this might be needed right now). Some of this is mentioned inDocumentation/vm/locking.
Quoted 5 lines
Just thought I would mention, in case you don't recollect some of this history. Of course, I understand the "information hiding" part.
Kanoj
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
From: [email protected]
Date: Sun, 5 Nov 2000 11:21:05 +0530
However, in the vmtruncate code, it looks like the hierarchy is reversed.
It is a well known bug amongst gurus :-) I sent a linux24 bug addition to Ted Ty'tso a week or so ago but he dropped it aparently.
Ted, I'm resending this below, please add it to the linux24 list thanks.
X-Coding-System: undecided-unix
Date: Fri, 13 Oct 2000 17:36:04 -0700
From: "David S. Miller" <[email protected]>
To: [email protected]
Subject: New BUG for todo list
This bug will essentially hard-hang an SMP system if triggered. Linus and myself both know about it already for some time now, the fix is straight forward, just nobody has coded it up and tested it yet.
The problem basically is that mm/memory.c:vmtruncate() violates the lock acquisition ordering rules when both mm->page_table_lock and mapping->i_shared_lock must both be acquired. All other instances (in the mmap/munmap syscalls for example) acuire the page_table_lock then the i_shared_lock. vmtruncate() on the other hand acquires the locks i_shared_lock first then page_table_lock.
Essentially I would describe this in the TODO list as:
vmtruncate() violates page_table_lock/i_shared_lock acquisition ordering rules leading to deadlock
The fix is to actually keep vmtruncate() how it is, and change the ordering rules for the rest of the kernel to follow vmtruncate()'s lock ordering. Linus agreed with me on this because the more natural data inspection flow is to go from the object to mappings of that object.
I'm going to try and work on this change this weekend, but I want it to be in the bug list so that it _is_ accounted for.
Later,
David S. Miller
[email protected]
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
Date: Sun, 5 Nov 2000 19:14:29 -0800
From: "David S. Miller" <[email protected]>
It is a well known bug amongst gurus :-) I sent a linux24 bug addition to Ted Ty'tso a week or so ago but he dropped it aparently.
I got it, but I thought it was fixed before I had a chance to add it to the bug list. I got confused by one of Linus's descriptions of fixes to the test10-pre* series.
Sorry; my bad. I'll get it added to the list.
- Ted
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/