From: Sage Weil Date: Fri, 10 Apr 2015 23:49:07 +0000 (-0700) Subject: os/newstore: use O_DIRECT is write is page-aligned X-Git-Tag: v9.1.0~242^2~75 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c67c9a2bee177183bdff1cc9ef56d13f438a2efe;p=ceph.git os/newstore: use O_DIRECT is write is page-aligned Signed-off-by: Sage Weil --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index abb7a7a000fd..2c3d8ee52a6e 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -803,6 +803,7 @@ OPTION(newstore_nid_prealloc, OPT_INT, 1024) OPTION(newstore_overlay_max_length, OPT_INT, 65536) OPTION(newstore_overlay_max, OPT_INT, 32) OPTION(newstore_open_by_handle, OPT_BOOL, true) +OPTION(newstore_o_direct, OPT_BOOL, true) OPTION(filestore_omap_backend, OPT_STR, "leveldb") diff --git a/src/os/newstore/NewStore.cc b/src/os/newstore/NewStore.cc index 81dd130b2920..8515eb5d0111 100644 --- a/src/os/newstore/NewStore.cc +++ b/src/os/newstore/NewStore.cc @@ -2277,7 +2277,14 @@ int NewStore::_do_wal_transaction(wal_transaction_t& wt) { dout(20) << __func__ << " write " << p->fid << " " << p->offset << "~" << p->length << dendl; - int fd = _open_fid(p->fid, O_RDWR); + unsigned flags = O_RDWR; + if (g_conf->newstore_o_direct && + (p->offset & ~CEPH_PAGE_MASK) == 0 && + (p->length & ~CEPH_PAGE_MASK) == 0) { + dout(20) << __func__ << " page-aligned, using O_DIRECT" << dendl; + flags |= O_DIRECT; + } + int fd = _open_fid(p->fid, flags); if (fd < 0) return fd; int r = ::lseek64(fd, p->offset, SEEK_SET); @@ -3022,12 +3029,19 @@ int NewStore::_do_write(TransContext *txc, o->onode.size == 0 || o->onode.data_map.empty()) { _do_overlay_clear(txc, o); + unsigned flags = O_RDWR; + if (g_conf->newstore_o_direct && + (offset & ~CEPH_PAGE_MASK) == 0 && + (length & ~CEPH_PAGE_MASK) == 0) { + dout(20) << __func__ << " page-aligned, using O_DIRECT" << dendl; + flags |= O_DIRECT; + } if (o->onode.data_map.empty()) { // create fragment_t &f = o->onode.data_map[0]; f.offset = 0; f.length = MAX(offset + length, o->onode.size); - fd = _create_fid(txc, &f.fid, O_RDWR); + fd = _create_fid(txc, &f.fid, flags); if (fd < 0) { r = fd; goto out; @@ -3039,7 +3053,7 @@ int NewStore::_do_write(TransContext *txc, // append (possibly with gap) assert(o->onode.data_map.size() == 1); fragment_t &f = o->onode.data_map.rbegin()->second; - fd = _open_fid(f.fid, O_RDWR); + fd = _open_fid(f.fid, flags); if (fd < 0) { r = fd; goto out;