linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	Nick Piggin <npiggin@gmail.com>,
	linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/10] tmpfs: optimize clearing when writing
Date: Sat, 12 May 2012 05:04:12 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LSU.2.00.1205120502370.28861@eggly.anvils> (raw)
In-Reply-To: <alpine.LSU.2.00.1205120447380.28861@eggly.anvils>

Nick proposed years ago that tmpfs should avoid clearing its pages where
write will overwrite them with new data, as ramfs has long done.  But I
messed it up and just got bad data.  Tried again recently, it works fine.

Here's time output for writing 4GiB 16 times on this Core i5 laptop:

before: real	0m21.169s user	0m0.028s sys	0m21.057s
        real	0m21.382s user	0m0.016s sys	0m21.289s
        real	0m21.311s user	0m0.020s sys	0m21.217s

after:  real	0m18.273s user	0m0.032s sys	0m18.165s 
        real	0m18.354s user	0m0.020s sys	0m18.265s 
        real	0m18.440s user	0m0.032s sys	0m18.337s 

ramfs:  real	0m16.860s user	0m0.028s sys	0m16.765s
        real	0m17.382s user	0m0.040s sys	0m17.273s
        real	0m17.133s user	0m0.044s sys	0m17.021s

Yes, I have done perf reports, but they need more explanation than they
deserve: in summary, clear_page vanishes, its cache loading shifts into
copy_user_generic_unrolled; shmem_getpage_gfp goes down, and surprisingly
mark_page_accessed goes way up - I think because they are respectively
where the cache gets to be reloaded after being purged by clear or copy.

Suggested-by: Nick Piggin <npiggin@gmail.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
---
 mm/shmem.c |   20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

--- 3045N.orig/mm/shmem.c	2012-05-05 10:46:05.732062006 -0700
+++ 3045N/mm/shmem.c	2012-05-05 10:46:12.316062172 -0700
@@ -1095,9 +1095,14 @@ repeat:
 		shmem_recalc_inode(inode);
 		spin_unlock(&info->lock);
 
-		clear_highpage(page);
-		flush_dcache_page(page);
-		SetPageUptodate(page);
+		/*
+		 * Let SGP_WRITE caller clear ends if write does not fill page
+		 */
+		if (sgp != SGP_WRITE) {
+			clear_highpage(page);
+			flush_dcache_page(page);
+			SetPageUptodate(page);
+		}
 		if (sgp == SGP_DIRTY)
 			set_page_dirty(page);
 	}
@@ -1307,6 +1312,14 @@ shmem_write_end(struct file *file, struc
 	if (pos + copied > inode->i_size)
 		i_size_write(inode, pos + copied);
 
+	if (!PageUptodate(page)) {
+		if (copied < PAGE_CACHE_SIZE) {
+			unsigned from = pos & (PAGE_CACHE_SIZE - 1);
+			zero_user_segments(page, 0, from,
+					from + copied, PAGE_CACHE_SIZE);
+		}
+		SetPageUptodate(page);
+	}
 	set_page_dirty(page);
 	unlock_page(page);
 	page_cache_release(page);
@@ -1768,6 +1781,7 @@ static int shmem_symlink(struct inode *d
 		kaddr = kmap_atomic(page);
 		memcpy(kaddr, symname, len);
 		kunmap_atomic(kaddr);
+		SetPageUptodate(page);
 		set_page_dirty(page);
 		unlock_page(page);
 		page_cache_release(page);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2012-05-12 12:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-12 11:52 [PATCH 0/10] shmem/tmpfs: misc and fallocate Hugh Dickins
2012-05-12 11:59 ` [PATCH 1/10] shmem: replace page if mapping excludes its zone Hugh Dickins
2012-05-14  8:55   ` Cong Wang
2012-05-14 19:42     ` Hugh Dickins
2012-05-15  9:44       ` Cong Wang
2012-05-14  9:06   ` KAMEZAWA Hiroyuki
2012-05-14 23:13   ` Andrew Morton
2012-05-15  4:07     ` Hugh Dickins
2012-05-19  1:41       ` Hugh Dickins
2012-05-19  1:44         ` [PATCH v2 1/10] shmem: substitute " Hugh Dickins
2012-05-12 12:02 ` [PATCH 2/10] tmpfs: enable NOSEC optimization Hugh Dickins
2012-05-14  9:35   ` Cong Wang
2012-05-14 19:48     ` Hugh Dickins
2012-05-12 12:04 ` Hugh Dickins [this message]
2012-05-15  8:51   ` [PATCH 3/10] tmpfs: optimize clearing when writing Nick Piggin
2012-05-12 12:05 ` [PATCH 4/10] tmpfs: support fallocate FALLOC_FL_PUNCH_HOLE Hugh Dickins
2012-05-12 12:13 ` [PATCH 5/10] mm/fs: route MADV_REMOVE to FALLOC_FL_PUNCH_HOLE Hugh Dickins
2012-05-22  0:08   ` john stultz
2012-05-22 15:11     ` Hugh Dickins
2012-05-12 12:15 ` [PATCH 6/10] mm/fs: remove truncate_range Hugh Dickins
2012-05-12 12:17 ` [PATCH 7/10] tmpfs: support fallocate preallocation Hugh Dickins
2012-05-12 12:19 ` [PATCH 8/10] tmpfs: undo fallocation on failure Hugh Dickins
2012-05-12 12:21 ` [PATCH 9/10] tmpfs: quit when fallocate fills memory Hugh Dickins
2012-05-12 12:27 ` [PATCH 10/10] tmpfs: support SEEK_DATA and SEEK_HOLE Hugh Dickins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.00.1205120502370.28861@eggly.anvils \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npiggin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox