Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 253773
b: refs/heads/master
c: eee2acb
h: refs/heads/master
i:
  253771: 81e24d6
v: v3
  • Loading branch information
Peter Zijlstra authored and Linus Torvalds committed Jun 18, 2011
1 parent cabb94d commit 3be71af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: bb4aa39676f73b4657b3edd893ae83881c430c0c
refs/heads/master: eee2acbae95555006307395d8a6c91452d62851d
49 changes: 28 additions & 21 deletions trunk/mm/rmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,36 +324,43 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
return -ENOMEM;
}

static void anon_vma_unlink(struct anon_vma_chain *anon_vma_chain)
{
struct anon_vma *anon_vma = anon_vma_chain->anon_vma;
int empty;

/* If anon_vma_fork fails, we can get an empty anon_vma_chain. */
if (!anon_vma)
return;

anon_vma_lock(anon_vma);
list_del(&anon_vma_chain->same_anon_vma);

/* We must garbage collect the anon_vma if it's empty */
empty = list_empty(&anon_vma->head);
anon_vma_unlock(anon_vma);

if (empty)
put_anon_vma(anon_vma);
}

void unlink_anon_vmas(struct vm_area_struct *vma)
{
struct anon_vma_chain *avc, *next;
struct anon_vma *root = NULL;

/*
* Unlink each anon_vma chained to the VMA. This list is ordered
* from newest to oldest, ensuring the root anon_vma gets freed last.
*/
list_for_each_entry_safe(avc, next, &vma->anon_vma_chain, same_vma) {
anon_vma_unlink(avc);
struct anon_vma *anon_vma = avc->anon_vma;

root = lock_anon_vma_root(root, anon_vma);
list_del(&avc->same_anon_vma);

/*
* Leave empty anon_vmas on the list - we'll need
* to free them outside the lock.
*/
if (list_empty(&anon_vma->head))
continue;

list_del(&avc->same_vma);
anon_vma_chain_free(avc);
}
unlock_anon_vma_root(root);

/*
* Iterate the list once more, it now only contains empty and unlinked
* anon_vmas, destroy them. Could not do before due to __put_anon_vma()
* needing to acquire the anon_vma->root->mutex.
*/
list_for_each_entry_safe(avc, next, &vma->anon_vma_chain, same_vma) {
struct anon_vma *anon_vma = avc->anon_vma;

put_anon_vma(anon_vma);

list_del(&avc->same_vma);
anon_vma_chain_free(avc);
}
Expand Down

0 comments on commit 3be71af

Please sign in to comment.