Skip to content

Commit b93b016

Browse files
Matthew Wilcoxtorvalds
authored andcommitted
page cache: use xa_lock
Remove the address_space ->tree_lock and use the xa_lock newly added to the radix_tree_root. Rename the address_space ->page_tree to ->i_pages, since we don't really care that it's a tree. [willy@infradead.org: fix nds32, fs/dax.c] Link: http://lkml.kernel.org/r/20180406145415.GB20605@bombadil.infradead.orgLink: http://lkml.kernel.org/r/20180313132639.17387-9-willy@infradead.org Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com> Acked-by: Jeff Layton <jlayton@redhat.com> Cc: Darrick J. Wong <darrick.wong@oracle.com> Cc: Dave Chinner <david@fromorbit.com> Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f6bb2a2 commit b93b016

39 files changed

Lines changed: 345 additions & 366 deletions

File tree

Documentation/cgroup-v1/memory.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ When oom event notifier is registered, event will be delivered.
262262
2.6 Locking
263263

264264
lock_page_cgroup()/unlock_page_cgroup() should not be called under
265-
mapping->tree_lock.
265+
the i_pages lock.
266266

267267
Other lock order is following:
268268
PG_locked.

Documentation/vm/page_migration

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Steps:
9090

9191
1. Lock the page to be migrated
9292

93-
2. Insure that writeback is complete.
93+
2. Ensure that writeback is complete.
9494

9595
3. Lock the new page that we want to move to. It is locked so that accesses to
9696
this (not yet uptodate) page immediately lock while the move is in progress.
@@ -100,8 +100,8 @@ Steps:
100100
mapcount is not zero then we do not migrate the page. All user space
101101
processes that attempt to access the page will now wait on the page lock.
102102

103-
5. The radix tree lock is taken. This will cause all processes trying
104-
to access the page via the mapping to block on the radix tree spinlock.
103+
5. The i_pages lock is taken. This will cause all processes trying
104+
to access the page via the mapping to block on the spinlock.
105105

106106
6. The refcount of the page is examined and we back out if references remain
107107
otherwise we know that we are the only one referencing this page.
@@ -114,12 +114,12 @@ Steps:
114114

115115
9. The radix tree is changed to point to the new page.
116116

117-
10. The reference count of the old page is dropped because the radix tree
117+
10. The reference count of the old page is dropped because the address space
118118
reference is gone. A reference to the new page is established because
119-
the new page is referenced to by the radix tree.
119+
the new page is referenced by the address space.
120120

121-
11. The radix tree lock is dropped. With that lookups in the mapping
122-
become possible again. Processes will move from spinning on the tree_lock
121+
11. The i_pages lock is dropped. With that lookups in the mapping
122+
become possible again. Processes will move from spinning on the lock
123123
to sleeping on the locked new page.
124124

125125
12. The page contents are copied to the new page.

arch/arm/include/asm/cacheflush.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,8 @@ static inline void flush_anon_page(struct vm_area_struct *vma,
318318
#define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
319319
extern void flush_kernel_dcache_page(struct page *);
320320

321-
#define flush_dcache_mmap_lock(mapping) \
322-
spin_lock_irq(&(mapping)->tree_lock)
323-
#define flush_dcache_mmap_unlock(mapping) \
324-
spin_unlock_irq(&(mapping)->tree_lock)
321+
#define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages)
322+
#define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages)
325323

326324
#define flush_icache_user_range(vma,page,addr,len) \
327325
flush_dcache_page(page)

arch/nds32/include/asm/cacheflush.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void flush_anon_page(struct vm_area_struct *vma,
3434
void flush_kernel_dcache_page(struct page *page);
3535
void flush_icache_range(unsigned long start, unsigned long end);
3636
void flush_icache_page(struct vm_area_struct *vma, struct page *page);
37-
#define flush_dcache_mmap_lock(mapping) spin_lock_irq(&(mapping)->tree_lock)
38-
#define flush_dcache_mmap_unlock(mapping) spin_unlock_irq(&(mapping)->tree_lock)
37+
#define flush_dcache_mmap_lock(mapping) xa_lock_irq(&(mapping)->i_pages)
38+
#define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&(mapping)->i_pages)
3939

4040
#else
4141
#include <asm-generic/cacheflush.h>

arch/nios2/include/asm/cacheflush.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ extern void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
4646
extern void flush_dcache_range(unsigned long start, unsigned long end);
4747
extern void invalidate_dcache_range(unsigned long start, unsigned long end);
4848

49-
#define flush_dcache_mmap_lock(mapping) \
50-
spin_lock_irq(&(mapping)->tree_lock)
51-
#define flush_dcache_mmap_unlock(mapping) \
52-
spin_unlock_irq(&(mapping)->tree_lock)
49+
#define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages)
50+
#define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages)
5351

5452
#endif /* _ASM_NIOS2_CACHEFLUSH_H */

arch/parisc/include/asm/cacheflush.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ void invalidate_kernel_vmap_range(void *vaddr, int size);
5555
#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
5656
extern void flush_dcache_page(struct page *page);
5757

58-
#define flush_dcache_mmap_lock(mapping) \
59-
spin_lock_irq(&(mapping)->tree_lock)
60-
#define flush_dcache_mmap_unlock(mapping) \
61-
spin_unlock_irq(&(mapping)->tree_lock)
58+
#define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages)
59+
#define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages)
6260

6361
#define flush_icache_page(vma,page) do { \
6462
flush_kernel_dcache_page(page); \

drivers/staging/lustre/lustre/llite/glimpse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ blkcnt_t dirty_cnt(struct inode *inode)
6969
void *results[1];
7070

7171
if (inode->i_mapping)
72-
cnt += radix_tree_gang_lookup_tag(&inode->i_mapping->page_tree,
72+
cnt += radix_tree_gang_lookup_tag(&inode->i_mapping->i_pages,
7373
results, 0, 1,
7474
PAGECACHE_TAG_DIRTY);
7575
if (cnt == 0 && atomic_read(&vob->vob_mmap_cnt) > 0)

drivers/staging/lustre/lustre/mdc/mdc_request.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,14 @@ static struct page *mdc_page_locate(struct address_space *mapping, __u64 *hash,
934934
struct page *page;
935935
int found;
936936

937-
spin_lock_irq(&mapping->tree_lock);
938-
found = radix_tree_gang_lookup(&mapping->page_tree,
937+
xa_lock_irq(&mapping->i_pages);
938+
found = radix_tree_gang_lookup(&mapping->i_pages,
939939
(void **)&page, offset, 1);
940940
if (found > 0 && !radix_tree_exceptional_entry(page)) {
941941
struct lu_dirpage *dp;
942942

943943
get_page(page);
944-
spin_unlock_irq(&mapping->tree_lock);
944+
xa_unlock_irq(&mapping->i_pages);
945945
/*
946946
* In contrast to find_lock_page() we are sure that directory
947947
* page cannot be truncated (while DLM lock is held) and,
@@ -989,7 +989,7 @@ static struct page *mdc_page_locate(struct address_space *mapping, __u64 *hash,
989989
page = ERR_PTR(-EIO);
990990
}
991991
} else {
992-
spin_unlock_irq(&mapping->tree_lock);
992+
xa_unlock_irq(&mapping->i_pages);
993993
page = NULL;
994994
}
995995
return page;

fs/afs/write.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,11 @@ static int afs_writepages_region(struct address_space *mapping,
570570

571571
_debug("wback %lx", page->index);
572572

573-
/* at this point we hold neither mapping->tree_lock nor lock on
574-
* the page itself: the page may be truncated or invalidated
575-
* (changing page->mapping to NULL), or even swizzled back from
576-
* swapper_space to tmpfs file mapping
573+
/*
574+
* at this point we hold neither the i_pages lock nor the
575+
* page lock: the page may be truncated or invalidated
576+
* (changing page->mapping to NULL), or even swizzled
577+
* back from swapper_space to tmpfs file mapping
577578
*/
578579
ret = lock_page_killable(page);
579580
if (ret < 0) {

fs/btrfs/compression.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
458458
break;
459459

460460
rcu_read_lock();
461-
page = radix_tree_lookup(&mapping->page_tree, pg_index);
461+
page = radix_tree_lookup(&mapping->i_pages, pg_index);
462462
rcu_read_unlock();
463463
if (page && !radix_tree_exceptional_entry(page)) {
464464
misses++;

0 commit comments

Comments
 (0)