mm: concurrent page-cache
Subsystems (9)
RFC PATCH 1/1 mm: concurrent page-cache
Hi,
here my current attempts at a concurrent page-cache. It applies on top if Nick's latest lockless page-cache patch. It is very much a work-in-progress. It may eat your data. I post with the hopes of getting some feedback.
I've ran it on a SMP qemu and found that it currently live-locks in find_get_pages_tag(). It seems to be the case that a concurrent radix_tree_tag_clear()/radix_tree_delete() removed the 'last' entry for a gang lookup, which makes find_get_pages_tag() loop forever since it requires progress.
If this is indeed the case, it seems to me the lockless page-cache patch might be susceptible to this same problem.
I still have to investigate fully, but I might not have time to look into it until after Ottawa.
--- fs/buffer.c | 4 include/linux/page-flags.h | 2 include/linux/pagemap.h | 21 +-- include/linux/radix-tree.h | 6 lib/radix-tree.c | 314 +++++++++++++++++++++++++++++++++------------ mm/filemap.c | 41 +++-- mm/migrate.c | 27 ++- mm/page-writeback.c | 22 +-- mm/swap_state.c | 17 +- mm/swapfile.c | 5 mm/truncate.c | 7 - mm/vmscan.c | 10 - 12 files changed, 323 insertions(+), 153 deletions(-)
include/linux/radix-tree.h +5 -1
@@ -25,6 +25,7 @@#include <linux/types.h> #include <linux/kernel.h> #include <linux/rcupdate.h> +#include <linux/spinlock.h> /*** radix-tree API starts here ***/
@@ -32,12 +33,14 @@ struct radix_tree_root {unsigned int height;gfp_t gfp_mask;struct radix_tree_node *rnode; +spinlock_t lock; };#define RADIX_TREE_INIT (mask) { \ .height = 0, \ .gfp_mask = (mask), \ .rnode = NULL, \ + .lock = SPIN_LOCK_UNLOCKED, \ }#define RADIX_TREE (name, mask) \
@@ -48,6 +51,7 @@ do { \ (root)->height =0 ; \ (root)->gfp_mask = (mask); \ (root)->rnode =NULL ; \ +spin_lock_init (&(root)->lock); \ } while (0)#define RADIX_TREE_MAX_TAGS 2
@@ -116,7 +120,7 @@ static inline void radix_tree_replace_slint radix_tree_insert (struct radix_tree_root *,unsigned long ,void *);void *radix_tree_lookup (struct radix_tree_root *,unsigned long ); -void **radix_tree_lookup_slot (struct radix_tree_root *,unsigned long ); +void **radix_tree_lookup_slot (struct radix_tree_root *,unsigned long ,spinlock_t **);void *radix_tree_delete (struct radix_tree_root *,unsigned long ); unsigned int radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
lib/radix-tree.c +232 -82
512 lines not on this page · raw message
fs/buffer.c +2 -2
@@ -851,7 +851,7 @@ int __set_page_dirty_buffers(struct pagespin_unlock (&mapping->private_lock);if (!TestSetPageDirty (page)) { -spin_lock_irq (&mapping->tree_lock); +LockPageNoNewRefs (page);if (page->mapping) {/* Race with truncate? */ if (mapping_cap_account_dirty (mapping))inc_page_state (nr_dirty);
@@ -859,7 +859,7 @@ int __set_page_dirty_buffers(struct pagepage_index (page), PAGECACHE_TAG_DIRTY); } -spin_unlock_irq (&mapping->tree_lock); +UnlockPageNoNewRefs (page);__mark_inode_dirty (mapping->host,I_DIRTY_PAGES );return 1 ; }
include/linux/page-flags.h +2 -0
@@ -363,6 +363,8 @@ extern void __mod_page_state_offset(unsi#define SetPageNoNewRefs (page) set_bit(PG_nonewrefs, &(page)->flags)#define ClearPageNoNewRefs (page) clear_bit(PG_nonewrefs, &(page)->flags)#define __ClearPageNoNewRefs (page) __clear_bit(PG_nonewrefs, &(page)->flags) +#define LockPageNoNewRefs (page) bit_spin_lock(PG_nonewrefs, &(page)->flags) +#define UnlockPageNoNewRefs (page) bit_spin_unlock(PG_nonewrefs, &(page)->flags)struct page ;/* forward declaration */
mm/filemap.c +26 -15
103 lines not on this page · raw message
mm/migrate.c +16 -11
@@ -25,6 +25,8 @@#include <linux/cpuset.h> #include <linux/swapops.h> +#include "internal.h" +/* The maximum number of pages to take off the LRU for migration */ #define MIGRATE_CHUNK_SIZE 256
@@ -181,6 +183,7 @@ int migrate_page_remove_references(struc {struct address_space *mapping =page_mapping (page);struct page **radix_pointer; +spinlock_t *lock;/* * Avoid doing any of the following work if the page count
@@ -196,7 +199,7 @@ int migrate_page_remove_references(struc* * In order to reestablish file backed mappings the fault handlers * will take the radix tree_lock which may then be used to stop -* processses from accessing this page until the new page is ready. +* processes from accessing this page until the new page is ready. * * A process accessing via a swap pte (an anonymous page) will take a * page_lock on the old page which will block the process until the
@@ -219,18 +222,20 @@ int migrate_page_remove_references(strucif (page_mapcount (page))return -EAGAIN ; -SetPageNoNewRefs (page); +LockPageNoNewRefs (page);smp_wmb (); -spin_lock_irq (&mapping->tree_lock); +local_irq_disable (); radix_pointer = (struct page **)radix_tree_lookup_slot ( &mapping->page_tree, -page_index (page)); +page_index (page), &lock);if (!page_mapping (page) ||page_count (page) != nr_refs ||radix_tree_deref_slot (radix_pointer) != page) { -spin_unlock_irq (&mapping->tree_lock); -ClearPageNoNewRefs (page); +if (lock) +spin_unlock (lock); +local_irq_enable (); +UnlockPageNoNewRefs (page);return -EAGAIN ; }
@@ -250,15 +255,15 @@ int migrate_page_remove_references(strucset_page_private (newpage,page_private (page)); } -SetPageNoNewRefs (newpage); +LockPageNoNewRefs (newpage);radix_tree_replace_slot (radix_pointer, newpage); page->mapping =NULL ; -spin_unlock_irq (&mapping->tree_lock); -__put_page (page); +spin_unlock_irq (lock);smp_wmb (); -ClearPageNoNewRefs (page); -ClearPageNoNewRefs (newpage); +UnlockPageNoNewRefs (page); +UnlockPageNoNewRefs (newpage); +__put_page (page);return 0 ; }
mm/page-writeback.c +10 -12
@@ -29,6 +29,7 @@#include <linux/sysctl.h> #include <linux/cpu.h> #include <linux/syscalls.h> +#include <linux/bit_spinlock.h> /* * The maximum number of pages to writeout in a single bdflush/kupdate
@@ -632,7 +633,7 @@ int __set_page_dirty_nobuffers(struct pastruct address_space *mapping2;if (mapping) { -spin_lock_irq (&mapping->tree_lock); +LockPageNoNewRefs (page); mapping2 =page_mapping (page);if (mapping2) {/* Race with truncate? */ BUG_ON (mapping2 != mapping);
@@ -641,7 +642,7 @@ int __set_page_dirty_nobuffers(struct paradix_tree_tag_set (&mapping->page_tree,page_index (page),PAGECACHE_TAG_DIRTY ); } -spin_unlock_irq (&mapping->tree_lock); +UnlockPageNoNewRefs (page);if (mapping->host) {/* !PageAnon && !swapper_space */ __mark_inode_dirty(mapping->host,
@@ -716,20 +717,19 @@ EXPORT_SYMBOL(set_page_dirty_lock);int test_clear_page_dirty (struct page *page) {struct address_space *mapping =page_mapping (page); -unsigned long flags;if (mapping) { -spin_lock_irqsave (&mapping->tree_lock, flags); +LockPageNoNewRefs (page);if (TestClearPageDirty (page)) {radix_tree_tag_clear (&mapping->page_tree,page_index (page),PAGECACHE_TAG_DIRTY ); -spin_unlock_irqrestore (&mapping->tree_lock, flags); +UnlockPageNoNewRefs (page);if (mapping_cap_account_dirty (mapping))dec_page_state (nr_dirty);return 1 ; } -spin_unlock_irqrestore (&mapping->tree_lock, flags); +UnlockPageNoNewRefs (page);return 0 ; }return TestClearPageDirty (page);
@@ -771,16 +771,15 @@ int test_clear_page_writeback(struct pagstruct address_space *mapping =page_mapping (page);if (mapping) { -unsigned long flags;int ret; -spin_lock_irqsave (&mapping->tree_lock, flags); +LockPageNoNewRefs (page); ret =TestClearPageWriteback (page);if (ret)radix_tree_tag_clear (&mapping->page_tree,page_index (page),PAGECACHE_TAG_WRITEBACK ); -spin_unlock_irqrestore (&mapping->tree_lock, flags); +UnlockPageNoNewRefs (page);return ret; }return TestClearPageWriteback (page);
@@ -791,10 +790,9 @@ int test_set_page_writeback(struct pagestruct address_space *mapping =page_mapping (page);if (mapping) { -unsigned long flags;int ret; -spin_lock_irqsave (&mapping->tree_lock, flags); +LockPageNoNewRefs (page); ret =TestSetPageWriteback (page);if (!ret) radix_tree_tag_set(&mapping->page_tree,
@@ -804,7 +802,7 @@ int test_set_page_writeback(struct pageradix_tree_tag_clear (&mapping->page_tree,page_index (page),PAGECACHE_TAG_DIRTY ); -spin_unlock_irqrestore (&mapping->tree_lock, flags); +UnlockPageNoNewRefs (page);return ret; }return TestSetPageWriteback (page);
mm/swap_state.c +11 -6
@@ -16,6 +16,7 @@#include <linux/backing-dev.h> #include <linux/pagevec.h> #include <linux/migrate.h> +#include <linux/bit_spinlock.h> #include <asm/pgtable.h>
@@ -78,9 +79,8 @@ static int __add_to_swap_cache(struct paBUG_ON (PagePrivate (page)); error =radix_tree_preload (gfp_mask);if (!error) { -SetPageNoNewRefs (page); +LockPageNoNewRefs (page);smp_wmb (); -spin_lock_irq (&swapper_space.tree_lock); error =radix_tree_insert (&swapper_space.page_tree, entry.val, page);if (!error) {
@@ -88,12 +88,14 @@ static int __add_to_swap_cache(struct paSetPageLocked (page);SetPageSwapCache (page);set_page_private (page, entry.val); + +spin_lock_irq (&swapper_space.tree_lock); total_swapcache_pages++;pagecache_acct (1 ); +spin_unlock_irq (&swapper_space.tree_lock); } -spin_unlock_irq (&swapper_space.tree_lock);smp_wmb (); -ClearPageNoNewRefs (page); +UnlockPageNoNewRefs (page);radix_tree_preload_end (); }return error;
@@ -135,9 +137,12 @@ void __delete_from_swap_cache(struct pagradix_tree_delete (&swapper_space.page_tree,page_private (page));set_page_private (page,0 );ClearPageSwapCache (page); + +spin_lock_irq (&swapper_space.tree_lock); total_swapcache_pages--;pagecache_acct (-1 );INC_CACHE_INFO (del_total); +spin_unlock_irq (&swapper_space.tree_lock); }/**
@@ -204,9 +209,9 @@ void delete_from_swap_cache(struct page entry.val =page_private (page); -spin_lock_irq (&swapper_space.tree_lock); +LockPageNoNewRefs (page);__delete_from_swap_cache (page); -spin_unlock_irq (&swapper_space.tree_lock); +UnlockPageNoNewRefs (page);swap_free (entry);page_cache_release (page);
mm/swapfile.c +3 -2
@@ -28,6 +28,7 @@#include <linux/mutex.h> #include <linux/capability.h> #include <linux/syscalls.h> +#include <linux/bit_spinlock.h> #include <asm/pgtable.h> #include <asm/tlbflush.h>
@@ -368,13 +369,13 @@ int remove_exclusive_swap_page(struct pa retval =0 ;if (p->swap_map[swp_offset (entry)] ==1 ) {/* Recheck the page count with the swapcache lock held.. */ -spin_lock_irq (&swapper_space.tree_lock); +LockPageNoNewRefs (page);if ((page_count (page) ==2 ) && !PageWriteback (page)) {__delete_from_swap_cache (page);SetPageDirty (page); retval =1 ; } -spin_unlock_irq (&swapper_space.tree_lock); +UnlockPageNoNewRefs (page); }spin_unlock (&swap_lock);
mm/truncate.c +4 -3
@@ -14,6 +14,7 @@#include <linux/pagevec.h> #include <linux/buffer_head.h> /* grr. try_to_release_page, do_invalidatepage */ +#include <linux/bit_spinlock.h> static inline void truncate_partial_page (struct page *page,unsigned partial)
@@ -67,15 +68,15 @@ invalidate_complete_page(struct address_if (PagePrivate (page) && !try_to_release_page (page,0 ))return 0 ; -spin_lock_irq (&mapping->tree_lock); +LockPageNoNewRefs (page);if (PageDirty (page)) { -spin_unlock_irq (&mapping->tree_lock); +UnlockPageNoNewRefs (page);return 0 ; }BUG_ON (PagePrivate (page));__remove_from_page_cache (page); -spin_unlock_irq (&mapping->tree_lock); +UnlockPageNoNewRefs (page);ClearPageUptodate (page);page_cache_release (page);/* pagecache ref */ return 1 ;
mm/vmscan.c +4 -6
@@ -34,6 +34,7 @@#include <linux/notifier.h> #include <linux/rwsem.h> #include <linux/delay.h> +#include <linux/bit_spinlock.h> #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -365,9 +366,8 @@ int remove_mapping(struct address_spaceif (!mapping)return 0 ;/* truncate got there first */ -SetPageNoNewRefs (page); +LockPageNoNewRefs (page);smp_wmb (); -spin_lock_irq (&mapping->tree_lock);/* * The non-racy check for busy page. It is critical to check
@@ -383,13 +383,12 @@ int remove_mapping(struct address_spaceif (PageSwapCache (page)) {swp_entry_t swap = { .val =page_private (page) };__delete_from_swap_cache (page); -spin_unlock_irq (&mapping->tree_lock);swap_free (swap); goto free_it; }__remove_from_page_cache (page); -spin_unlock_irq (&mapping->tree_lock); +UnlockPageNoNewRefs (page); free_it:smp_wmb ();
@@ -398,8 +397,7 @@ free_it:return 1 ; cannot_free: -spin_unlock_irq (&mapping->tree_lock); -ClearPageNoNewRefs (page); +UnlockPageNoNewRefs (page);return 0 ; }
include/linux/pagemap.h +8 -13
@@ -13,6 +13,7 @@#include <linux/gfp.h> #include <linux/page-flags.h> #include <linux/hardirq.h> /* for in_interrupt() */ +#include <linux/bit_spinlock.h> /* * Bits in mapping->flags. The lower __GFP_BITS_SHIFT bits are the page
@@ -74,23 +75,17 @@ static inline struct page *page_cache_geatomic_inc (&page->_count);#else -if (unlikely (!get_page_unless_zero (page))) -return NULL ;/* page has been freed */ - -/* -* Note that get_page_unless_zero provides a memory barrier. -* This is needed to ensure PageNoNewRefs is evaluated after the -* page refcount has been raised. See below comment. -*/ -/* * PageNoNewRefs is set in order to prevent new references to the * page (eg. before it gets removed from pagecache). Wait until it -* becomes clear (and checks below will ensure we still have the -* correct one). +* becomes clear. */ -while (unlikely (PageNoNewRefs (page))) -cpu_relax (); +LockPageNoNewRefs (page); +if (unlikely (!get_page_unless_zero (page))) { +UnlockPageNoNewRefs (page); +return NULL ;/* page has been freed */ + } +UnlockPageNoNewRefs (page);/* * smp_rmb is to ensure the load of page->flags (for PageNoNewRefs())
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>