Skip to content

Commit

Permalink
buffer: size append_buffer so that it fits into page-multiple allocat…
Browse files Browse the repository at this point in the history
…ions

We drop some unittest assertions about alloc buffer size.  Sorry!

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas committed Mar 1, 2016
1 parent f2c0d5c commit b6ed4d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include <ostream>
namespace ceph {

#define CEPH_BUFFER_ALLOC_UNIT (MIN(CEPH_PAGE_SIZE, 4096))
#define CEPH_BUFFER_APPEND_SIZE (CEPH_BUFFER_ALLOC_UNIT - sizeof(raw_combined))

#ifdef BUFFER_DEBUG
static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
# define bdout { simple_spin_lock(&buffer_debug_lock); std::cout
Expand Down Expand Up @@ -1657,7 +1660,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
unsigned gap = append_buffer.unused_tail_length();
if (!gap) {
// make a new append_buffer!
append_buffer = create_aligned(CEPH_BUFFER_APPEND_SIZE, CEPH_BUFFER_APPEND_SIZE);
append_buffer = create_combined(CEPH_BUFFER_APPEND_SIZE);
append_buffer.set_length(0); // unused, so far.
}
append(append_buffer, append_buffer.append(c) - 1, 1); // add segment to the list
Expand All @@ -1679,9 +1682,12 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
if (len == 0)
break; // done!

// make a new append_buffer!
unsigned alen = CEPH_BUFFER_APPEND_SIZE * (((len-1) / CEPH_BUFFER_APPEND_SIZE) + 1);
append_buffer = create_aligned(alen, CEPH_BUFFER_APPEND_SIZE);
// make a new append_buffer. fill out a complete page, factoring in the
// raw_combined overhead.
size_t need = ROUND_UP_TO(len, sizeof(size_t)) + sizeof(raw_combined);
size_t alen = ROUND_UP_TO(need, CEPH_BUFFER_ALLOC_UNIT) -
sizeof(raw_combined);
append_buffer = create_combined(alen);
append_buffer.set_length(0); // unused, so far.
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class XioDispatchHook;

namespace ceph {

const static int CEPH_BUFFER_APPEND_SIZE(4096);

namespace buffer CEPH_BUFFER_API {
/*
* exceptions
Expand Down
6 changes: 3 additions & 3 deletions src/test/bufferlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ TEST(BufferList, rebuild) {
bl.append(str.c_str(), str.size());
bl.append(str.c_str(), str.size());
EXPECT_EQ((unsigned)2, bl.get_num_buffers());
EXPECT_TRUE(bl.is_aligned(CEPH_BUFFER_APPEND_SIZE));
//EXPECT_TRUE(bl.is_aligned(CEPH_BUFFER_APPEND_SIZE));
bl.rebuild();
EXPECT_TRUE(bl.is_page_aligned());
EXPECT_EQ((unsigned)1, bl.get_num_buffers());
Expand Down Expand Up @@ -1981,7 +1981,7 @@ TEST(BufferList, append) {
EXPECT_EQ((unsigned)0, bl.get_num_buffers());
bl.append('A');
EXPECT_EQ((unsigned)1, bl.get_num_buffers());
EXPECT_TRUE(bl.is_aligned(CEPH_BUFFER_APPEND_SIZE));
//EXPECT_TRUE(bl.is_aligned(CEPH_BUFFER_APPEND_SIZE));
}
//
// void append(const char *data, unsigned len);
Expand Down Expand Up @@ -2269,7 +2269,7 @@ TEST(BufferList, read_fd) {
EXPECT_EQ(-EBADF, bl.read_fd(fd, len));
fd = ::open(FILENAME, O_RDONLY);
EXPECT_EQ(len, (unsigned)bl.read_fd(fd, len));
EXPECT_EQ(CEPH_BUFFER_APPEND_SIZE - len, bl.front().unused_tail_length());
//EXPECT_EQ(CEPH_BUFFER_APPEND_SIZE - len, bl.front().unused_tail_length());
EXPECT_EQ(len, bl.length());
::close(fd);
::unlink(FILENAME);
Expand Down

0 comments on commit b6ed4d3

Please sign in to comment.