summaryrefslogtreecommitdiff
path: root/include/linux/rmap-locking.h
blob: 302a58f54ca303727f40a48f37cfa0f5f506436c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * include/linux/rmap-locking.h
 *
 * Locking primitives for exclusive access to a page's reverse-mapping
 * pte chain.
 */

static inline void pte_chain_lock(struct page *page)
{
	/*
	 * Assuming the lock is uncontended, this never enters
	 * the body of the outer loop. If it is contended, then
	 * within the inner loop a non-atomic test is used to
	 * busywait with less bus contention for a good time to
	 * attempt to acquire the lock bit.
	 */
	preempt_disable();
#ifdef CONFIG_SMP
	while (test_and_set_bit(PG_chainlock, &page->flags)) {
		while (test_bit(PG_chainlock, &page->flags))
			cpu_relax();
	}
#endif
}

static inline void pte_chain_unlock(struct page *page)
{
#ifdef CONFIG_SMP
	smp_mb__before_clear_bit();
	clear_bit(PG_chainlock, &page->flags);
#endif
	preempt_enable();
}