Skip to contentSkip to conversation

mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible.patch removed from -mm tree

merged [email protected] 1 participant 1 message Jun 5, 2014

Subsystems (12)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

Subject: [merged] mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible.patch removed from -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Thu, 05 Jun 2014 12:52:49 -0700

The patch titled
Subject: mm: non-atomically mark page accessed during page cache allocation where possible
has been removed from the -mm tree. Its filename was
mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Mel Gorman <[email protected]>
Subject: mm: non-atomically mark page accessed during page cache allocation where possible

aops->write_begin may allocate a new page and make it visible only to have mark_page_accessed called almost immediately after. Once the page is visible the atomic operations are necessary which is noticable overhead when writing to an in-memory filesystem like tmpfs but should also be noticable with fast storage. The objective of the patch is to initialse the accessed information with non-atomic operations before the page is visible.

The bulk of filesystems directly or indirectly use grab_cache_page_write_begin or find_or_create_page for the initial allocation of a page cache page. This patch adds an init_page_accessed() helper which behaves like the first call to mark_page_accessed() but may called before the page is visible and can be done non-atomically.

The primary APIs of concern in this care are the following and are used by most filesystems.

find_get_page
find_lock_page
find_or_create_page
grab_cache_page_nowait
grab_cache_page_write_begin

All of them are very similar in detail to the patch creates a core helper pagecache_get_page() which takes a flags parameter that affects its behavior such as whether the page should be marked accessed or not. Then old API is preserved but is basically a thin wrapper around this core function.

Each of the filesystems are then updated to avoid calling mark_page_accessed when it is known that the VM interfaces have already done the job. There is a slight snag in that the timing of the mark_page_accessed() has now changed so in rare cases it's possible a page gets to the end of the LRU as PageReferenced where as previously it might have been repromoted. This is expected to be rare but it's worth the filesystem people thinking about it in case they see a problem with the timing change. It is also the case that some filesystems may be marking pages accessed that previously did not but it makes sense that filesystems have consistent behaviour in this regard.

The test case used to evaulate this is a simple dd of a large file done multiple times with the file deleted on each iterations. The size of the file is 1/10th physical memory to avoid dirty page balancing. In the async case it will be possible that the workload completes without even hitting the disk and will have variable results but highlight the impact of mark_page_accessed for async IO. The sync results are expected to be more stable. The exception is tmpfs where the normal case is for the "IO" to not hit the disk.

The test machine was single socket and UMA to avoid any scheduling or NUMA artifacts. Throughput and wall times are presented for sync IO, only wall times are shown for async as the granularity reported by dd and the variability is unsuitable for comparison. As async results were variable do to writback timings, I'm only reporting the maximum figures. The sync results were stable enough to make the mean and stddev uninteresting.

The performance results are reported based on a run with no profiling. Profile data is based on a separate run with oprofile running.

async dd

                                    3.15.0-rc3            3.15.0-rc3
                                       vanilla           accessed-v2

ext3 Max elapsed 13.9900 ( 0.00%) 11.5900 ( 17.16%)
tmpfs Max elapsed 0.5100 ( 0.00%) 0.4900 ( 3.92%)
btrfs Max elapsed 12.8100 ( 0.00%) 12.7800 ( 0.23%)
ext4 Max elapsed 18.6000 ( 0.00%) 13.3400 ( 28.28%)
xfs Max elapsed 12.5600 ( 0.00%) 2.0900 ( 83.36%)

The XFS figure is a bit strange as it managed to avoid a worst case by sheer luck but the average figures looked reasonable.

samples percentage

ext3       86107    0.9783  vmlinux-3.15.0-rc4-vanilla        mark_page_accessed
ext3       23833    0.2710  vmlinux-3.15.0-rc4-accessed-v3r25 mark_page_accessed
ext3        5036    0.0573  vmlinux-3.15.0-rc4-accessed-v3r25 init_page_accessed
ext4       64566    0.8961  vmlinux-3.15.0-rc4-vanilla        mark_page_accessed
ext4        5322    0.0713  vmlinux-3.15.0-rc4-accessed-v3r25 mark_page_accessed
ext4        2869    0.0384  vmlinux-3.15.0-rc4-accessed-v3r25 init_page_accessed
xfs        62126    1.7675  vmlinux-3.15.0-rc4-vanilla        mark_page_accessed
xfs         1904    0.0554  vmlinux-3.15.0-rc4-accessed-v3r25 init_page_accessed
xfs          103    0.0030  vmlinux-3.15.0-rc4-accessed-v3r25 mark_page_accessed
btrfs      10655    0.1338  vmlinux-3.15.0-rc4-vanilla        mark_page_accessed
btrfs       2020    0.0273  vmlinux-3.15.0-rc4-accessed-v3r25 init_page_accessed
btrfs        587    0.0079  vmlinux-3.15.0-rc4-accessed-v3r25 mark_page_accessed
tmpfs      59562    3.2628  vmlinux-3.15.0-rc4-vanilla        mark_page_accessed
tmpfs       1210    0.0696  vmlinux-3.15.0-rc4-accessed-v3r25 init_page_accessed
tmpfs         94    0.0054  vmlinux-3.15.0-rc4-accessed-v3r25 mark_page_accessed
[[email protected]: don't run init_page_accessed() against an uninitialised pointer]
Cc Johannes Weiner <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Jan Kara <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Theodore Ts'o <[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

 fs/btrfs/extent_io.c       |   11 +
 fs/btrfs/file.c            |    5 
 fs/buffer.c                |    7 -
 fs/ext4/mballoc.c          |   14 +-
 fs/f2fs/checkpoint.c       |    3 
 fs/f2fs/node.c             |    2 
 fs/fuse/file.c             |    2 
 fs/gfs2/aops.c             |    1 
 fs/gfs2/meta_io.c          |    4 
 fs/ntfs/attrib.c           |    1 
 fs/ntfs/file.c             |    1 
 include/linux/page-flags.h |    1 
 include/linux/pagemap.h    |  107 +++++++++++++++++-
 include/linux/swap.h       |    1 
 mm/filemap.c               |  202 ++++++++++++-----------------------
 mm/shmem.c                 |    6 -
 mm/swap.c                  |   11 +
 17 files changed, 217 insertions(+), 162 deletions(-)
fs/btrfs/extent_io.c renamed from fs/btrfs/extent_io.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +6 -5
diff -puN fs/btrfs/extent_io.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/btrfs/extent_io.c
@@ -4510,7 +4510,8 @@ static void check_buffer_tree_ref(struct
 	spin_unlock(&eb->refs_lock);
 }
 
-static void mark_extent_buffer_accessed(struct extent_buffer *eb)
+static void mark_extent_buffer_accessed(struct extent_buffer *eb,
+		struct page *accessed)
 {
 	unsigned long num_pages, i;
 
@@ -4519,7 +4520,8 @@ static void mark_extent_buffer_accessed(
 	num_pages = num_extent_pages(eb->start, eb->len);
 	for (i = 0; i < num_pages; i++) {
 		struct page *p = extent_buffer_page(eb, i);
-		mark_page_accessed(p);
+		if (p != accessed)
+			mark_page_accessed(p);
 	}
 }
 
@@ -4533,7 +4535,7 @@ struct extent_buffer *find_extent_buffer
 			       start >> PAGE_CACHE_SHIFT);
 	if (eb && atomic_inc_not_zero(&eb->refs)) {
 		rcu_read_unlock();
-		mark_extent_buffer_accessed(eb);
+		mark_extent_buffer_accessed(eb, NULL);
 		return eb;
 	}
 	rcu_read_unlock();
@@ -4581,7 +4583,7 @@ struct extent_buffer *alloc_extent_buffe
 				spin_unlock(&mapping->private_lock);
 				unlock_page(p);
 				page_cache_release(p);
-				mark_extent_buffer_accessed(exists);
+				mark_extent_buffer_accessed(exists, p);
 				goto free_eb;
 			}
 
@@ -4596,7 +4598,6 @@ struct extent_buffer *alloc_extent_buffe
 		attach_extent_buffer_page(eb, p);
 		spin_unlock(&mapping->private_lock);
 		WARN_ON(PageDirty(p));
-		mark_page_accessed(p);
 		eb->pages[i] = p;
 		if (!PageUptodate(p))
 			uptodate = 0;
fs/btrfs/file.c renamed from fs/btrfs/file.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +3 -2
diff -puN fs/btrfs/file.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/btrfs/file.c
@@ -470,11 +470,12 @@ static void btrfs_drop_pages(struct page
 	for (i = 0; i < num_pages; i++) {
 		/* page checked is some magic around finding pages that
 		 * have been modified without going through btrfs_set_page_dirty
-		 * clear it here
+		 * clear it here. There should be no need to mark the pages
+		 * accessed as prepare_pages should have marked them accessed
+		 * in prepare_pages via find_or_create_page()
 		 */
 		ClearPageChecked(pages[i]);
 		unlock_page(pages[i]);
-		mark_page_accessed(pages[i]);
 		page_cache_release(pages[i]);
 	}
 }
fs/buffer.c renamed from fs/buffer.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +4 -3
diff -puN fs/buffer.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/buffer.c
@@ -227,7 +227,7 @@ __find_get_block_slow(struct block_devic
 	int all_mapped = 1;
 
 	index = block >> (PAGE_CACHE_SHIFT - bd_inode->i_blkbits);
-	page = find_get_page(bd_mapping, index);
+	page = find_get_page_flags(bd_mapping, index, FGP_ACCESSED);
 	if (!page)
 		goto out;
 
@@ -1366,12 +1366,13 @@ __find_get_block(struct block_device *bd
 	struct buffer_head *bh = lookup_bh_lru(bdev, block, size);
 
 	if (bh == NULL) {
+		/* __find_get_block_slow will mark the page accessed */
 		bh = __find_get_block_slow(bdev, block);
 		if (bh)
 			bh_lru_install(bh);
-	}
-	if (bh)
+	} else
 		touch_buffer(bh);
+
 	return bh;
 }
 EXPORT_SYMBOL(__find_get_block);
fs/ext4/mballoc.c renamed from fs/ext4/mballoc.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +8 -6
diff -puN fs/ext4/mballoc.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/ext4/mballoc.c
@@ -1044,6 +1044,8 @@ int ext4_mb_init_group(struct super_bloc
 	 * allocating. If we are looking at the buddy cache we would
 	 * have taken a reference using ext4_mb_load_buddy and that
 	 * would have pinned buddy page to page cache.
+	 * The call to ext4_mb_get_buddy_page_lock will mark the
+	 * page accessed.
 	 */
 	ret = ext4_mb_get_buddy_page_lock(sb, group, &e4b);
 	if (ret || !EXT4_MB_GRP_NEED_INIT(this_grp)) {
@@ -1062,7 +1064,6 @@ int ext4_mb_init_group(struct super_bloc
 		ret = -EIO;
 		goto err;
 	}
-	mark_page_accessed(page);
 
 	if (e4b.bd_buddy_page == NULL) {
 		/*
@@ -1082,7 +1083,6 @@ int ext4_mb_init_group(struct super_bloc
 		ret = -EIO;
 		goto err;
 	}
-	mark_page_accessed(page);
 err:
 	ext4_mb_put_buddy_page_lock(&e4b);
 	return ret;
@@ -1141,7 +1141,7 @@ ext4_mb_load_buddy(struct super_block *s
 
 	/* we could use find_or_create_page(), but it locks page
 	 * what we'd like to avoid in fast path ... */
-	page = find_get_page(inode->i_mapping, pnum);
+	page = find_get_page_flags(inode->i_mapping, pnum, FGP_ACCESSED);
 	if (page == NULL || !PageUptodate(page)) {
 		if (page)
 			/*
@@ -1176,15 +1176,16 @@ ext4_mb_load_buddy(struct super_block *s
 		ret = -EIO;
 		goto err;
 	}
+
+	/* Pages marked accessed already */
 	e4b->bd_bitmap_page = page;
 	e4b->bd_bitmap = page_address(page) + (poff * sb->s_blocksize);
-	mark_page_accessed(page);
 
 	block++;
 	pnum = block / blocks_per_page;
 	poff = block % blocks_per_page;
 
-	page = find_get_page(inode->i_mapping, pnum);
+	page = find_get_page_flags(inode->i_mapping, pnum, FGP_ACCESSED);
 	if (page == NULL || !PageUptodate(page)) {
 		if (page)
 			page_cache_release(page);
@@ -1209,9 +1210,10 @@ ext4_mb_load_buddy(struct super_block *s
 		ret = -EIO;
 		goto err;
 	}
+
+	/* Pages marked accessed already */
 	e4b->bd_buddy_page = page;
 	e4b->bd_buddy = page_address(page) + (poff * sb->s_blocksize);
-	mark_page_accessed(page);
 
 	BUG_ON(e4b->bd_bitmap_page == NULL);
 	BUG_ON(e4b->bd_buddy_page == NULL);
fs/f2fs/checkpoint.c renamed from fs/f2fs/checkpoint.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +0 -3
diff -puN fs/f2fs/checkpoint.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/f2fs/checkpoint.c
@@ -69,7 +69,6 @@ repeat:
 		goto repeat;
 	}
 out:
-	mark_page_accessed(page);
 	return page;
 }
 
@@ -137,13 +136,11 @@ int ra_meta_pages(struct f2fs_sb_info *s
 		if (!page)
 			continue;
 		if (PageUptodate(page)) {
-			mark_page_accessed(page);
 			f2fs_put_page(page, 1);
 			continue;
 		}
 
 		f2fs_submit_page_mbio(sbi, page, blk_addr, &fio);
-		mark_page_accessed(page);
 		f2fs_put_page(page, 0);
 	}
 out:
fs/f2fs/node.c renamed from fs/f2fs/node.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +0 -2
diff -puN fs/f2fs/node.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/f2fs/node.c
@@ -967,7 +967,6 @@ repeat:
 		goto repeat;
 	}
 got_it:
-	mark_page_accessed(page);
 	return page;
 }
 
@@ -1022,7 +1021,6 @@ page_hit:
 		f2fs_put_page(page, 1);
 		return ERR_PTR(-EIO);
 	}
-	mark_page_accessed(page);
 	return page;
 }
 
fs/fuse/file.c renamed from fs/fuse/file.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +0 -2
diff -puN fs/fuse/file.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/fuse/file.c
@@ -1089,8 +1089,6 @@ static ssize_t fuse_fill_write_pages(str
 		tmp = iov_iter_copy_from_user_atomic(page, ii, offset, bytes);
 		flush_dcache_page(page);
 
-		mark_page_accessed(page);
-
 		if (!tmp) {
 			unlock_page(page);
 			page_cache_release(page);
fs/gfs2/aops.c renamed from fs/gfs2/aops.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +0 -1
diff -puN fs/gfs2/aops.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/gfs2/aops.c
@@ -577,7 +577,6 @@ int gfs2_internal_read(struct gfs2_inode
 		p = kmap_atomic(page);
 		memcpy(buf + copied, p + offset, amt);
 		kunmap_atomic(p);
-		mark_page_accessed(page);
 		page_cache_release(page);
 		copied += amt;
 		index++;
fs/gfs2/meta_io.c renamed from fs/gfs2/meta_io.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +2 -2
diff -puN fs/gfs2/meta_io.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/gfs2/meta_io.c
@@ -136,7 +136,8 @@ struct buffer_head *gfs2_getbuf(struct g
 			yield();
 		}
 	} else {
-		page = find_lock_page(mapping, index);
+		page = find_get_page_flags(mapping, index,
+						FGP_LOCK|FGP_ACCESSED);
 		if (!page)
 			return NULL;
 	}
@@ -153,7 +154,6 @@ struct buffer_head *gfs2_getbuf(struct g
 		map_bh(bh, sdp->sd_vfs, blkno);
 
 	unlock_page(page);
-	mark_page_accessed(page);
 	page_cache_release(page);
 
 	return bh;
fs/ntfs/attrib.c renamed from fs/ntfs/attrib.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +0 -1
diff -puN fs/ntfs/attrib.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/ntfs/attrib.c
@@ -1748,7 +1748,6 @@ int ntfs_attr_make_non_resident(ntfs_ino
 	if (page) {
 		set_page_dirty(page);
 		unlock_page(page);
-		mark_page_accessed(page);
 		page_cache_release(page);
 	}
 	ntfs_debug("Done.");
fs/ntfs/file.c renamed from fs/ntfs/file.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +0 -1
diff -puN fs/ntfs/file.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible fs/ntfs/file.c
@@ -2060,7 +2060,6 @@ static ssize_t ntfs_file_buffered_write(
 		}
 		do {
 			unlock_page(pages[--do_pages]);
-			mark_page_accessed(pages[do_pages]);
 			page_cache_release(pages[do_pages]);
 		} while (do_pages);
 		if (unlikely(status))
include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +1 -0
diff -puN include/linux/page-flags.h~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible include/linux/page-flags.h
@@ -198,6 +198,7 @@ struct page;	/* forward declaration */
 TESTPAGEFLAG(Locked, locked)
 PAGEFLAG(Error, error) TESTCLEARFLAG(Error, error)
 PAGEFLAG(Referenced, referenced) TESTCLEARFLAG(Referenced, referenced)
+	__SETPAGEFLAG(Referenced, referenced)
 PAGEFLAG(Dirty, dirty) TESTSCFLAG(Dirty, dirty) __CLEARPAGEFLAG(Dirty, dirty)
 PAGEFLAG(LRU, lru) __CLEARPAGEFLAG(LRU, lru)
 PAGEFLAG(Active, active) __CLEARPAGEFLAG(Active, active)
include/linux/pagemap.h renamed from include/linux/pagemap.h~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +101 -6

121 lines not on this page · raw message

include/linux/swap.h renamed from include/linux/swap.h~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +1 -0
diff -puN include/linux/swap.h~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible include/linux/swap.h
@@ -311,6 +311,7 @@ extern void lru_add_page_tail(struct pag
 			 struct lruvec *lruvec, struct list_head *head);
 extern void activate_page(struct page *);
 extern void mark_page_accessed(struct page *);
+extern void init_page_accessed(struct page *page);
 extern void lru_add_drain(void);
 extern void lru_add_drain_cpu(int cpu);
 extern void lru_add_drain_all(void);
mm/filemap.c renamed from mm/filemap.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +75 -127

270 lines not on this page · raw message

mm/shmem.c renamed from mm/shmem.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +5 -1
diff -puN mm/shmem.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible mm/shmem.c
@@ -1372,9 +1372,13 @@ shmem_write_begin(struct file *file, str
 			loff_t pos, unsigned len, unsigned flags,
 			struct page **pagep, void **fsdata)
 {
+	int ret;
 	struct inode *inode = mapping->host;
 	pgoff_t index = pos >> PAGE_CACHE_SHIFT;
-	return shmem_getpage(inode, index, pagep, SGP_WRITE, NULL);
+	ret = shmem_getpage(inode, index, pagep, SGP_WRITE, NULL);
+	if (ret == 0 && *pagep)
+		init_page_accessed(*pagep);
+	return ret;
 }
 
 static int
mm/swap.c renamed from mm/swap.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible +11 -0
diff -puN mm/swap.c~mm-non-atomically-mark-page-accessed-during-page-cache-allocation-where-possible mm/swap.c
@@ -614,6 +614,17 @@ void mark_page_accessed(struct page *pag
 }
 EXPORT_SYMBOL(mark_page_accessed);
 
+/*
+ * Used to mark_page_accessed(page) that is not visible yet and when it is
+ * still safe to use non-atomic ops
+ */
+void init_page_accessed(struct page *page)
+{
+	if (!PageReferenced(page))
+		__SetPageReferenced(page);
+}
+EXPORT_SYMBOL(init_page_accessed);
+
 static void __lru_cache_add(struct page *page)
 {
 	struct pagevec *pvec = &get_cpu_var(lru_add_pvec);

_

Patches currently in -mm which might be from [email protected] are

origin.patch mm-introduce-do_shared_fault-and-drop-do_fault-fix-fix.patch mm-compactionc-isolate_freepages_block-small-tuneup.patch do_shared_fault-check-that-mmap_sem-is-held.patch smp-print-more-useful-debug-info-upon-receiving-ipi-on-an-offline-cpu.patch smp-print-more-useful-debug-info-upon-receiving-ipi-on-an-offline-cpu-fix.patch smp-print-more-useful-debug-info-upon-receiving-ipi-on-an-offline-cpu-v5.patch cpu-hotplug-smp-flush-any-pending-ipi-callbacks-before-cpu-offline.patch linux-next.patch