mm: PageUptodate memorder problem?
Subsystems (5)
RFC 1/1 mm: PageUptodate memorder problem?
Hi,
I think there might be a problem, but don't take this as a final patch because I can make it nicer if we are agreed there is a problem.
One thing I like about it is that it ties in the anonymous page handling with the rest of the page management, by marking anon pages as uptodate when they _are_ uptodate, rather than when our implementation requires that they be marked as such. Doing this let me get rid of the smp_wmb's in the page copying functions, which always vaguely troubled me.
Any comments?
include/linux/highmem.h +0 -4
@@ -57,8 +57,6 @@ static inline void clear_user_highpage(svoid *addr =kmap_atomic (page,KM_USER0 );clear_user_page (addr, vaddr, page);kunmap_atomic (addr,KM_USER0 ); -/* Make sure this page is cleared on other CPU's too before using it */ -smp_wmb (); }#ifndef __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
@@ -108,8 +106,6 @@ static inline void copy_user_highpage(stcopy_user_page (vto, vfrom, vaddr, to);kunmap_atomic (vfrom,KM_USER0 ); kunmap_atomic(vto, KM_USER1); -/* Make sure this page is cleared on other CPU's too before using it */ - smp_wmb(); }#endif
include/linux/page-flags.h +15 -3
@@ -127,15 +127,27 @@#define TestClearPageReferenced (page) test_and_clear_bit(PG_referenced, &(page)->flags)#define PageUptodate (page) test_bit(PG_uptodate, &(page)->flags) -#ifdef CONFIG_S390 static inline void SetPageUptodate (struct page *page) { +#ifdef CONFIG_S390 if (!test_and_set_bit (PG_uptodate, &page->flags))page_test_and_clear_dirty (page); -}#else -#define SetPageUptodate (page) set_bit(PG_uptodate, &(page)->flags) +/* +* Memory barrier must be issued before setting the PG_uptodate bit, +* so all previous writes that served to bring the page uptodate are +* visible before PageUptodate becomes true. +* +* S390 is guaranteed to have a barrier in the test_and_set operation +* (see Documentation/atomic_ops.txt). +* +* XXX: does this memory barrier need to be anything special to +* handle things like DMA writes into the page? +*/ +smp_wmb (); +set_bit (PG_uptodate, &(page)->flags);#endif +}#define ClearPageUptodate (page) clear_bit(PG_uptodate, &(page)->flags)#define PageDirty (page) test_bit(PG_dirty, &(page)->flags)
mm/hugetlb.c +2 -0
@@ -443,6 +443,7 @@ static int hugetlb_cow(struct mm_structspin_unlock (&mm->page_table_lock);copy_huge_page (new_page, old_page, address, vma); +SetPageUptodate (new_page);spin_lock (&mm->page_table_lock); ptep =huge_pte_offset (mm, address &HPAGE_MASK );
@@ -506,6 +507,7 @@ retry: }else lock_page (page); } +SetPageUptodate (page);spin_lock (&mm->page_table_lock); size =i_size_read (mapping->host) >>HPAGE_SHIFT ;
mm/memory.c +5 -4
@@ -1463,10 +1463,8 @@ static inline void cow_user_page(structmemset (kaddr,0 ,PAGE_SIZE );kunmap_atomic (kaddr,KM_USER0 );flush_dcache_page (dst); -return ; - - } -copy_user_highpage (dst, src, va, vma); + }else +copy_user_highpage (dst, src, va, vma); }/*
@@ -1579,6 +1577,7 @@ gotten: goto oom;cow_user_page (new_page, old_page, address, vma); } +SetPageUptodate (new_page);/* * Re-check the pte - we dropped the lock
@@ -2097,6 +2096,7 @@ static int do_anonymous_page(struct mm_s page =alloc_zeroed_user_highpage (vma, address);if (!page) goto oom; +SetPageUptodate (page); entry =mk_pte (page, vma->vm_page_prot); entry =maybe_mkwrite (pte_mkdirty (entry), vma);
@@ -2203,6 +2203,7 @@ retry:copy_user_highpage (page, new_page, address, vma);page_cache_release (new_page); new_page = page; +SetPageUptodate (new_page); anon =1 ; }else {
mm/filemap.c +17 -0
@@ -935,6 +935,13 @@ find_page:if (!PageUptodate (page)) goto page_not_up_to_date; page_ok: +/* +* Must ensure that the data we read out of the page is loaded +* _after_ we've loaded page->flags to check for PageUptodate. +* See include/linux/page-flags.h:SetPageUptodate() for the +* other side of the story. +*/ +smp_rmb ();/* If users can be writing to this page using arbitrary * virtual addresses, take care about potential aliasing
@@ -1422,6 +1429,11 @@ retry_find: success:/* +* Must order memory for the same reason as do_generic_mapping_read +*/ +smp_rmb (); + +/* * Found the page and have a reference on it. */ mark_page_accessed (page);
@@ -1564,6 +1576,11 @@ retry_find: success:/* +* Must order memory for the same reason as do_generic_mapping_read +*/ +smp_rmb (); + +/* * Found the page and have a reference on it. */ mark_page_accessed (page);
mm/page_io.c +1 -1
@@ -134,7 +134,7 @@ int swap_readpage(struct file *file, strint ret =0 ;BUG_ON (!PageLocked (page)); -ClearPageUptodate (page); +BUG_ON (PageUptodate (page)); bio =get_swap_bio (GFP_KERNEL ,page_private (page), page, end_swap_bio_read);if (bio ==NULL ) {
mm/swap_state.c +1 -1
@@ -149,6 +149,7 @@ int add_to_swap(struct page * page, gfp_int err;BUG_ON (!PageLocked (page)); +BUG_ON (!PageUptodate (page));for (;;) { entry =get_swap_page ();
@@ -171,7 +172,6 @@ int add_to_swap(struct page * page, gfp_switch (err) {case 0 :/* Success */ -SetPageUptodate (page);SetPageDirty (page);INC_CACHE_INFO (add_total);return 1 ;
--
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>