Skip to content

Commit

Permalink
Merge pull request ceph#11834 from liewegas/wip-bluestore-mempool
Browse files Browse the repository at this point in the history
os/bluestore: move bluefs into its own mempool

Reviewed-by: Allen Samuels <[email protected]>
  • Loading branch information
liewegas authored Nov 11, 2016
2 parents 53fb099 + f7d0bc9 commit 27a2d13
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/include/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ inline typename std::enable_if<!traits::supported>::type
{
__u32 n = (__u32)(v.size());
encode(n, bl);
for (typename std::vector<T>::const_iterator p = v.begin(); p != v.end(); ++p)
for (auto p = v.begin(); p != v.end(); ++p)
encode(*p, bl, features);
}
template<class T, class Alloc, typename traits=denc_traits<T>>
Expand All @@ -561,7 +561,7 @@ inline typename std::enable_if<!traits::supported>::type
{
__u32 n = (__u32)(v.size());
encode(n, bl);
for (typename std::vector<T>::const_iterator p = v.begin(); p != v.end(); ++p)
for (auto p = v.begin(); p != v.end(); ++p)
encode(*p, bl);
}
template<class T, class Alloc, typename traits=denc_traits<T>>
Expand Down
3 changes: 2 additions & 1 deletion src/include/mempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ namespace mempool {
f(unittest_1) \
f(unittest_2) \
f(bluestore_meta_onode) \
f(bluestore_meta_other)
f(bluestore_meta_other) \
f(bluefs)

// give them integer ids
#define P(x) mempool_##x,
Expand Down
14 changes: 7 additions & 7 deletions src/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ inline ostream& operator<<(ostream& out, const pair<A,B>& v) {
template<class A, class Alloc>
inline ostream& operator<<(ostream& out, const vector<A,Alloc>& v) {
out << "[";
for (typename vector<A>::const_iterator p = v.begin(); p != v.end(); ++p) {
for (auto p = v.begin(); p != v.end(); ++p) {
if (p != v.begin()) out << ",";
out << *p;
}
Expand All @@ -108,7 +108,7 @@ inline ostream& operator<<(ostream& out, const vector<A,Alloc>& v) {
template<class A, class Alloc>
inline ostream& operator<<(ostream& out, const deque<A,Alloc>& v) {
out << "<";
for (typename deque<A>::const_iterator p = v.begin(); p != v.end(); ++p) {
for (auto p = v.begin(); p != v.end(); ++p) {
if (p != v.begin()) out << ",";
out << *p;
}
Expand All @@ -124,7 +124,7 @@ inline ostream& operator<<(ostream&out, const boost::tuple<A, B, C> &t) {

template<class A, class Alloc>
inline ostream& operator<<(ostream& out, const list<A,Alloc>& ilist) {
for (typename list<A>::const_iterator it = ilist.begin();
for (auto it = ilist.begin();
it != ilist.end();
++it) {
if (it != ilist.begin()) out << ",";
Expand All @@ -135,7 +135,7 @@ inline ostream& operator<<(ostream& out, const list<A,Alloc>& ilist) {

template<class A, class Comp, class Alloc>
inline ostream& operator<<(ostream& out, const set<A, Comp, Alloc>& iset) {
for (typename set<A, Comp>::const_iterator it = iset.begin();
for (auto it = iset.begin();
it != iset.end();
++it) {
if (it != iset.begin()) out << ",";
Expand All @@ -146,7 +146,7 @@ inline ostream& operator<<(ostream& out, const set<A, Comp, Alloc>& iset) {

template<class A, class Comp, class Alloc>
inline ostream& operator<<(ostream& out, const multiset<A,Comp,Alloc>& iset) {
for (typename multiset<A,Comp>::const_iterator it = iset.begin();
for (auto it = iset.begin();
it != iset.end();
++it) {
if (it != iset.begin()) out << ",";
Expand All @@ -159,7 +159,7 @@ template<class A, class B, class Comp, class Alloc>
inline ostream& operator<<(ostream& out, const map<A,B,Comp,Alloc>& m)
{
out << "{";
for (typename map<A,B,Comp>::const_iterator it = m.begin();
for (auto it = m.begin();
it != m.end();
++it) {
if (it != m.begin()) out << ",";
Expand All @@ -173,7 +173,7 @@ template<class A, class B, class Comp, class Alloc>
inline ostream& operator<<(ostream& out, const multimap<A,B,Comp,Alloc>& m)
{
out << "{{";
for (typename multimap<A,B,Comp>::const_iterator it = m.begin();
for (auto it = m.begin();
it != m.end();
++it) {
if (it != m.begin()) out << ",";
Expand Down
25 changes: 17 additions & 8 deletions src/os/bluestore/BlueFS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
#undef dout_prefix
#define dout_prefix *_dout << "bluefs "

MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::File, bluefs_file, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::Dir, bluefs_dir, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileWriter, bluefs_file_writer, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileReaderBuffer,
bluefs_file_reader_buffer, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileReader, bluefs_file_reader, bluefs);
MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileLock, bluefs_file_lock, bluefs);


BlueFS::BlueFS()
: bdev(MAX_BDEV),
ioc(MAX_BDEV),
Expand Down Expand Up @@ -842,7 +851,7 @@ int BlueFS::_read_random(
int ret = 0;
while (len > 0) {
uint64_t x_off = 0;
vector<bluefs_extent_t>::iterator p = h->file->fnode.seek(off, &x_off);
auto p = h->file->fnode.seek(off, &x_off);
uint64_t l = MIN(p->length - x_off, len);
dout(20) << __func__ << " read buffered 0x"
<< std::hex << x_off << "~" << l << std::dec
Expand Down Expand Up @@ -894,8 +903,7 @@ int BlueFS::_read(
buf->bl.clear();
buf->bl_off = off & super.block_mask();
uint64_t x_off = 0;
vector<bluefs_extent_t>::iterator p =
h->file->fnode.seek(buf->bl_off, &x_off);
auto p = h->file->fnode.seek(buf->bl_off, &x_off);
uint64_t want = ROUND_UP_TO(len + (off & ~super.block_mask()),
super.block_size);
want = MAX(want, buf->max_prefetch);
Expand Down Expand Up @@ -957,7 +965,7 @@ void BlueFS::_invalidate_cache(FileRef f, uint64_t offset, uint64_t length)
length = ROUND_UP_TO(length, super.block_size);
}
uint64_t x_off = 0;
vector<bluefs_extent_t>::iterator p = f->fnode.seek(offset, &x_off);
auto p = f->fnode.seek(offset, &x_off);
while (length > 0 && p != f->fnode.extents.end()) {
uint64_t x_len = MIN(p->length - x_off, length);
bdev[p->bdev]->invalidate_cache(p->offset + x_off, x_len);
Expand Down Expand Up @@ -1064,7 +1072,7 @@ void BlueFS::_compact_log_sync()
uint64_t need = bl.length() + g_conf->bluefs_max_log_runway;
dout(20) << __func__ << " need " << need << dendl;

vector<bluefs_extent_t> old_extents;
mempool::bluefs::vector<bluefs_extent_t> old_extents;
old_extents.swap(log_file->fnode.extents);
while (log_file->fnode.get_allocated() < need) {
int r = _allocate(log_file->fnode.prefer_bdev,
Expand Down Expand Up @@ -1186,7 +1194,7 @@ void BlueFS::_compact_log_async(std::unique_lock<std::mutex>& l)
dout(10) << __func__ << " remove 0x" << std::hex << old_log_jump_to << std::dec
<< " of " << log_file->fnode.extents << dendl;
uint64_t discarded = 0;
vector<bluefs_extent_t> old_extents;
mempool::bluefs::vector<bluefs_extent_t> old_extents;
while (discarded < old_log_jump_to) {
assert(!log_file->fnode.extents.empty());
bluefs_extent_t& e = log_file->fnode.extents.front();
Expand Down Expand Up @@ -1473,7 +1481,7 @@ int BlueFS::_flush_range(FileWriter *h, uint64_t offset, uint64_t length)
dout(20) << __func__ << " file now " << h->file->fnode << dendl;

uint64_t x_off = 0;
vector<bluefs_extent_t>::iterator p = h->file->fnode.seek(offset, &x_off);
auto p = h->file->fnode.seek(offset, &x_off);
assert(p != h->file->fnode.extents.end());
dout(20) << __func__ << " in " << *p << " x_off 0x"
<< std::hex << x_off << std::dec << dendl;
Expand Down Expand Up @@ -1700,7 +1708,8 @@ void BlueFS::flush_bdev()
}
}

int BlueFS::_allocate(uint8_t id, uint64_t len, vector<bluefs_extent_t> *ev)
int BlueFS::_allocate(uint8_t id, uint64_t len,
mempool::bluefs::vector<bluefs_extent_t> *ev)
{
dout(10) << __func__ << " len 0x" << std::hex << len << std::dec
<< " from " << (int)id << dendl;
Expand Down
21 changes: 17 additions & 4 deletions src/os/bluestore/BlueFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class BlueFS {
};

struct File : public RefCountedObject {
MEMPOOL_CLASS_HELPERS();

bluefs_fnode_t fnode;
int refs;
uint64_t dirty_seq;
Expand Down Expand Up @@ -96,7 +98,9 @@ class BlueFS {
&File::dirty_item> > dirty_file_list_t;

struct Dir : public RefCountedObject {
map<string,FileRef> file_map;
MEMPOOL_CLASS_HELPERS();

mempool::bluefs::map<string,FileRef> file_map;

Dir() : RefCountedObject(NULL, 0) {}

Expand All @@ -110,6 +114,8 @@ class BlueFS {
typedef boost::intrusive_ptr<Dir> DirRef;

struct FileWriter {
MEMPOOL_CLASS_HELPERS();

FileRef file;
uint64_t pos; ///< start offset for buffer
bufferlist buffer; ///< new data to write (at end of file)
Expand Down Expand Up @@ -150,6 +156,8 @@ class BlueFS {
};

struct FileReaderBuffer {
MEMPOOL_CLASS_HELPERS();

uint64_t bl_off; ///< prefetch buffer logical offset
bufferlist bl; ///< prefetch buffer
uint64_t pos; ///< current logical offset
Expand Down Expand Up @@ -178,6 +186,8 @@ class BlueFS {
};

struct FileReader {
MEMPOOL_CLASS_HELPERS();

FileRef file;
FileReaderBuffer buf;
bool random;
Expand All @@ -196,6 +206,8 @@ class BlueFS {
};

struct FileLock {
MEMPOOL_CLASS_HELPERS();

FileRef file;
explicit FileLock(FileRef f) : file(f) {}
};
Expand All @@ -206,8 +218,8 @@ class BlueFS {
PerfCounters *logger = nullptr;

// cache
map<string, DirRef> dir_map; ///< dirname -> Dir
ceph::unordered_map<uint64_t,FileRef> file_map; ///< ino -> File
mempool::bluefs::map<string, DirRef> dir_map; ///< dirname -> Dir
mempool::bluefs::unordered_map<uint64_t,FileRef> file_map; ///< ino -> File

// map of dirty files, files of same dirty_seq are grouped into list.
map<uint64_t, dirty_file_list_t> dirty_files;
Expand Down Expand Up @@ -251,7 +263,8 @@ class BlueFS {
FileRef _get_file(uint64_t ino);
void _drop_link(FileRef f);

int _allocate(uint8_t bdev, uint64_t len, vector<bluefs_extent_t> *ev);
int _allocate(uint8_t bdev, uint64_t len,
mempool::bluefs::vector<bluefs_extent_t> *ev);
int _flush_range(FileWriter *h, uint64_t offset, uint64_t length);
int _flush(FileWriter *h, bool force);
int _fsync(FileWriter *h, std::unique_lock<std::mutex>& l);
Expand Down
4 changes: 2 additions & 2 deletions src/os/bluestore/bluefs_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ ostream& operator<<(ostream& out, const bluefs_super_t& s)

// bluefs_fnode_t

vector<bluefs_extent_t>::iterator bluefs_fnode_t::seek(
mempool::bluefs::vector<bluefs_extent_t>::iterator bluefs_fnode_t::seek(
uint64_t offset, uint64_t *x_off)
{
vector<bluefs_extent_t>::iterator p = extents.begin();
auto p = extents.begin();
while (p != extents.end()) {
if ((int64_t) offset >= p->length) {
offset -= p->length;
Expand Down
5 changes: 3 additions & 2 deletions src/os/bluestore/bluefs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct bluefs_fnode_t {
uint64_t size;
utime_t mtime;
uint8_t prefer_bdev;
vector<bluefs_extent_t> extents;
mempool::bluefs::vector<bluefs_extent_t> extents;

bluefs_fnode_t() : ino(0), size(0), prefer_bdev(0) {}

Expand All @@ -40,7 +40,8 @@ struct bluefs_fnode_t {
return r;
}

vector<bluefs_extent_t>::iterator seek(uint64_t off, uint64_t *x_off);
mempool::bluefs::vector<bluefs_extent_t>::iterator seek(
uint64_t off, uint64_t *x_off);

void encode(bufferlist& bl) const;
void decode(bufferlist::iterator& p);
Expand Down

0 comments on commit 27a2d13

Please sign in to comment.