Commit cba48b98 authored by Rik van Riel's avatar Rik van Riel Committed by Linus Torvalds

mm: change direct call of spin_lock(anon_vma->lock) to inline function

Subsitute a direct call of spin_lock(anon_vma->lock) with an inline
function doing exactly the same.

This makes it easier to do the substitution to the root anon_vma lock in a
following patch.

We will deal with the handful of special locks (nested, dec_and_lock, etc)
separately.
Signed-off-by: default avatarRik van Riel <riel@redhat.com>
Acked-by: default avatarMel Gorman <mel@csn.ul.ie>
Acked-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Tested-by: default avatarLarry Woodman <lwoodman@redhat.com>
Acked-by: default avatarLarry Woodman <lwoodman@redhat.com>
Reviewed-by: default avatarMinchan Kim <minchan.kim@gmail.com>
Acked-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bb4a340e
...@@ -113,6 +113,16 @@ static inline void vma_unlock_anon_vma(struct vm_area_struct *vma) ...@@ -113,6 +113,16 @@ static inline void vma_unlock_anon_vma(struct vm_area_struct *vma)
spin_unlock(&anon_vma->lock); spin_unlock(&anon_vma->lock);
} }
static inline void anon_vma_lock(struct anon_vma *anon_vma)
{
spin_lock(&anon_vma->lock);
}
static inline void anon_vma_unlock(struct anon_vma *anon_vma)
{
spin_unlock(&anon_vma->lock);
}
/* /*
* anon_vma helper functions. * anon_vma helper functions.
*/ */
......
...@@ -327,7 +327,7 @@ static void drop_anon_vma(struct rmap_item *rmap_item) ...@@ -327,7 +327,7 @@ static void drop_anon_vma(struct rmap_item *rmap_item)
if (atomic_dec_and_lock(&anon_vma->external_refcount, &anon_vma->lock)) { if (atomic_dec_and_lock(&anon_vma->external_refcount, &anon_vma->lock)) {
int empty = list_empty(&anon_vma->head); int empty = list_empty(&anon_vma->head);
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
if (empty) if (empty)
anon_vma_free(anon_vma); anon_vma_free(anon_vma);
} }
...@@ -1566,7 +1566,7 @@ int page_referenced_ksm(struct page *page, struct mem_cgroup *memcg, ...@@ -1566,7 +1566,7 @@ int page_referenced_ksm(struct page *page, struct mem_cgroup *memcg,
struct anon_vma_chain *vmac; struct anon_vma_chain *vmac;
struct vm_area_struct *vma; struct vm_area_struct *vma;
spin_lock(&anon_vma->lock); anon_vma_lock(anon_vma);
list_for_each_entry(vmac, &anon_vma->head, same_anon_vma) { list_for_each_entry(vmac, &anon_vma->head, same_anon_vma) {
vma = vmac->vma; vma = vmac->vma;
if (rmap_item->address < vma->vm_start || if (rmap_item->address < vma->vm_start ||
...@@ -1589,7 +1589,7 @@ int page_referenced_ksm(struct page *page, struct mem_cgroup *memcg, ...@@ -1589,7 +1589,7 @@ int page_referenced_ksm(struct page *page, struct mem_cgroup *memcg,
if (!search_new_forks || !mapcount) if (!search_new_forks || !mapcount)
break; break;
} }
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
if (!mapcount) if (!mapcount)
goto out; goto out;
} }
...@@ -1619,7 +1619,7 @@ int try_to_unmap_ksm(struct page *page, enum ttu_flags flags) ...@@ -1619,7 +1619,7 @@ int try_to_unmap_ksm(struct page *page, enum ttu_flags flags)
struct anon_vma_chain *vmac; struct anon_vma_chain *vmac;
struct vm_area_struct *vma; struct vm_area_struct *vma;
spin_lock(&anon_vma->lock); anon_vma_lock(anon_vma);
list_for_each_entry(vmac, &anon_vma->head, same_anon_vma) { list_for_each_entry(vmac, &anon_vma->head, same_anon_vma) {
vma = vmac->vma; vma = vmac->vma;
if (rmap_item->address < vma->vm_start || if (rmap_item->address < vma->vm_start ||
...@@ -1637,11 +1637,11 @@ int try_to_unmap_ksm(struct page *page, enum ttu_flags flags) ...@@ -1637,11 +1637,11 @@ int try_to_unmap_ksm(struct page *page, enum ttu_flags flags)
ret = try_to_unmap_one(page, vma, ret = try_to_unmap_one(page, vma,
rmap_item->address, flags); rmap_item->address, flags);
if (ret != SWAP_AGAIN || !page_mapped(page)) { if (ret != SWAP_AGAIN || !page_mapped(page)) {
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
goto out; goto out;
} }
} }
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
} }
if (!search_new_forks++) if (!search_new_forks++)
goto again; goto again;
...@@ -1671,7 +1671,7 @@ int rmap_walk_ksm(struct page *page, int (*rmap_one)(struct page *, ...@@ -1671,7 +1671,7 @@ int rmap_walk_ksm(struct page *page, int (*rmap_one)(struct page *,
struct anon_vma_chain *vmac; struct anon_vma_chain *vmac;
struct vm_area_struct *vma; struct vm_area_struct *vma;
spin_lock(&anon_vma->lock); anon_vma_lock(anon_vma);
list_for_each_entry(vmac, &anon_vma->head, same_anon_vma) { list_for_each_entry(vmac, &anon_vma->head, same_anon_vma) {
vma = vmac->vma; vma = vmac->vma;
if (rmap_item->address < vma->vm_start || if (rmap_item->address < vma->vm_start ||
...@@ -1688,11 +1688,11 @@ int rmap_walk_ksm(struct page *page, int (*rmap_one)(struct page *, ...@@ -1688,11 +1688,11 @@ int rmap_walk_ksm(struct page *page, int (*rmap_one)(struct page *,
ret = rmap_one(page, vma, rmap_item->address, arg); ret = rmap_one(page, vma, rmap_item->address, arg);
if (ret != SWAP_AGAIN) { if (ret != SWAP_AGAIN) {
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
goto out; goto out;
} }
} }
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
} }
if (!search_new_forks++) if (!search_new_forks++)
goto again; goto again;
......
...@@ -684,7 +684,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private, ...@@ -684,7 +684,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
/* Drop an anon_vma reference if we took one */ /* Drop an anon_vma reference if we took one */
if (anon_vma && atomic_dec_and_lock(&anon_vma->external_refcount, &anon_vma->lock)) { if (anon_vma && atomic_dec_and_lock(&anon_vma->external_refcount, &anon_vma->lock)) {
int empty = list_empty(&anon_vma->head); int empty = list_empty(&anon_vma->head);
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
if (empty) if (empty)
anon_vma_free(anon_vma); anon_vma_free(anon_vma);
} }
......
...@@ -2593,7 +2593,7 @@ static void vm_unlock_anon_vma(struct anon_vma *anon_vma) ...@@ -2593,7 +2593,7 @@ static void vm_unlock_anon_vma(struct anon_vma *anon_vma)
if (!__test_and_clear_bit(0, (unsigned long *) if (!__test_and_clear_bit(0, (unsigned long *)
&anon_vma->head.next)) &anon_vma->head.next))
BUG(); BUG();
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
} }
} }
......
...@@ -134,7 +134,7 @@ int anon_vma_prepare(struct vm_area_struct *vma) ...@@ -134,7 +134,7 @@ int anon_vma_prepare(struct vm_area_struct *vma)
allocated = anon_vma; allocated = anon_vma;
} }
spin_lock(&anon_vma->lock); anon_vma_lock(anon_vma);
/* page_table_lock to protect against threads */ /* page_table_lock to protect against threads */
spin_lock(&mm->page_table_lock); spin_lock(&mm->page_table_lock);
if (likely(!vma->anon_vma)) { if (likely(!vma->anon_vma)) {
...@@ -147,7 +147,7 @@ int anon_vma_prepare(struct vm_area_struct *vma) ...@@ -147,7 +147,7 @@ int anon_vma_prepare(struct vm_area_struct *vma)
avc = NULL; avc = NULL;
} }
spin_unlock(&mm->page_table_lock); spin_unlock(&mm->page_table_lock);
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
if (unlikely(allocated)) if (unlikely(allocated))
anon_vma_free(allocated); anon_vma_free(allocated);
...@@ -170,9 +170,9 @@ static void anon_vma_chain_link(struct vm_area_struct *vma, ...@@ -170,9 +170,9 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
avc->anon_vma = anon_vma; avc->anon_vma = anon_vma;
list_add(&avc->same_vma, &vma->anon_vma_chain); list_add(&avc->same_vma, &vma->anon_vma_chain);
spin_lock(&anon_vma->lock); anon_vma_lock(anon_vma);
list_add_tail(&avc->same_anon_vma, &anon_vma->head); list_add_tail(&avc->same_anon_vma, &anon_vma->head);
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
} }
/* /*
...@@ -246,12 +246,12 @@ static void anon_vma_unlink(struct anon_vma_chain *anon_vma_chain) ...@@ -246,12 +246,12 @@ static void anon_vma_unlink(struct anon_vma_chain *anon_vma_chain)
if (!anon_vma) if (!anon_vma)
return; return;
spin_lock(&anon_vma->lock); anon_vma_lock(anon_vma);
list_del(&anon_vma_chain->same_anon_vma); list_del(&anon_vma_chain->same_anon_vma);
/* We must garbage collect the anon_vma if it's empty */ /* We must garbage collect the anon_vma if it's empty */
empty = list_empty(&anon_vma->head) && !anonvma_external_refcount(anon_vma); empty = list_empty(&anon_vma->head) && !anonvma_external_refcount(anon_vma);
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
if (empty) if (empty)
anon_vma_free(anon_vma); anon_vma_free(anon_vma);
...@@ -302,7 +302,7 @@ struct anon_vma *page_lock_anon_vma(struct page *page) ...@@ -302,7 +302,7 @@ struct anon_vma *page_lock_anon_vma(struct page *page)
goto out; goto out;
anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON); anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON);
spin_lock(&anon_vma->lock); anon_vma_lock(anon_vma);
return anon_vma; return anon_vma;
out: out:
rcu_read_unlock(); rcu_read_unlock();
...@@ -311,7 +311,7 @@ struct anon_vma *page_lock_anon_vma(struct page *page) ...@@ -311,7 +311,7 @@ struct anon_vma *page_lock_anon_vma(struct page *page)
void page_unlock_anon_vma(struct anon_vma *anon_vma) void page_unlock_anon_vma(struct anon_vma *anon_vma)
{ {
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
rcu_read_unlock(); rcu_read_unlock();
} }
...@@ -1389,7 +1389,7 @@ static int rmap_walk_anon(struct page *page, int (*rmap_one)(struct page *, ...@@ -1389,7 +1389,7 @@ static int rmap_walk_anon(struct page *page, int (*rmap_one)(struct page *,
anon_vma = page_anon_vma(page); anon_vma = page_anon_vma(page);
if (!anon_vma) if (!anon_vma)
return ret; return ret;
spin_lock(&anon_vma->lock); anon_vma_lock(anon_vma);
list_for_each_entry(avc, &anon_vma->head, same_anon_vma) { list_for_each_entry(avc, &anon_vma->head, same_anon_vma) {
struct vm_area_struct *vma = avc->vma; struct vm_area_struct *vma = avc->vma;
unsigned long address = vma_address(page, vma); unsigned long address = vma_address(page, vma);
...@@ -1399,7 +1399,7 @@ static int rmap_walk_anon(struct page *page, int (*rmap_one)(struct page *, ...@@ -1399,7 +1399,7 @@ static int rmap_walk_anon(struct page *page, int (*rmap_one)(struct page *,
if (ret != SWAP_AGAIN) if (ret != SWAP_AGAIN)
break; break;
} }
spin_unlock(&anon_vma->lock); anon_vma_unlock(anon_vma);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment