From dec517e3497df25cff70f99bd6888739d410d771 Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Thu, 18 Apr 2013 14:31:58 -0400 Subject: [PATCH] Drop cache after fsync Drop the cache (fadvise) after calling fsync to avoid redundant work in the kernel visiting pages that are dirty. By dropping cache after fsync(), the pages will be clean so can be easily removed from the cache. Change-Id: I3013d2ac1e27bbe43e58a81638d04805f5e2ae6e Signed-off-by: Peter Portante --- swift/obj/server.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/swift/obj/server.py b/swift/obj/server.py index 03fdcff53d..58a1fb756f 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -315,11 +315,21 @@ class DiskFile(object): assert self.tmppath is not None metadata['name'] = self.name timestamp = normalize_timestamp(metadata['X-Timestamp']) + # Write the metadata before calling fsync() so that both data and + # metadata are flushed to disk. write_metadata(fd, metadata) - if 'Content-Length' in metadata: - self.drop_cache(fd, 0, int(metadata['Content-Length'])) + # We call fsync() before calling drop_cache() to lower the amount of + # redundant work the drop cache code will perform on the pages (now + # that after fsync the pages will be all clean). tpool.execute(fsync, fd) + if 'Content-Length' in metadata: + # From the Department of the Redundancy Department, make sure we + # call drop_cache() after fsync() to avoid redundant work (pages + # all clean). + self.drop_cache(fd, 0, int(metadata['Content-Length'])) invalidate_hash(os.path.dirname(self.datadir)) + # After the rename completes, this object will be available for other + # requests to reference. renamer(self.tmppath, os.path.join(self.datadir, timestamp + extension)) self.metadata = metadata