Skip to content

Commit

Permalink
Merge pull request #6354: librbd: reads larger than cache size hang
Browse files Browse the repository at this point in the history
Reviewed-by: Loic Dachary <ldachary@redhat.com>
  • Loading branch information
Loic Dachary committed Nov 16, 2015
2 parents a790c2a + 3f33ce6 commit 67c9e8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/osdc/ObjectCacher.cc
Expand Up @@ -1158,7 +1158,7 @@ int ObjectCacher::_readx(OSDRead *rd, ObjectSet *oset, Context *onfinish,
uint64_t rx_bytes = static_cast<uint64_t>(
stat_rx + bh_it->second->length());
bytes_not_in_cache += bh_it->second->length();
if (!waitfor_read.empty() || rx_bytes > max_size) {
if (!waitfor_read.empty() || (stat_rx > 0 && rx_bytes > max_size)) {
// cache is full with concurrent reads -- wait for rx's to complete
// to constrain memory growth (especially during copy-ups)
if (success) {
Expand Down
24 changes: 11 additions & 13 deletions src/test/librbd/test_librbd.cc
Expand Up @@ -2400,7 +2400,7 @@ TEST_F(TestLibRBD, LargeCacheRead)
rados_ioctx_t ioctx;
rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx);

uint32_t new_cache_size = 16777216;
uint32_t new_cache_size = 1 << 20;
std::string orig_cache_size;
ASSERT_EQ(0, _rados.conf_get("rbd_cache_size", orig_cache_size));
ASSERT_EQ(0, _rados.conf_set("rbd_cache_size",
Expand All @@ -2412,24 +2412,22 @@ TEST_F(TestLibRBD, LargeCacheRead)
} BOOST_SCOPE_EXIT_END;

rbd_image_t image;
int order = 0;
const char *name = "testimg";
uint64_t size = new_cache_size + 1;
int order = 21;
std::string name = get_temp_image_name();
uint64_t size = 1 << order;

ASSERT_EQ(0, create_image(ioctx, name, size, &order));
ASSERT_EQ(0, rbd_open(ioctx, name, &image, NULL));
ASSERT_EQ(0, create_image(ioctx, name.c_str(), size, &order));
ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL));

std::string buffer(1 << order, '1');
for (size_t offs = 0; offs < size; offs += buffer.size()) {
size_t len = std::min<uint64_t>(buffer.size(), size - offs);
ASSERT_EQ(static_cast<ssize_t>(len),
rbd_write(image, offs, len, buffer.c_str()));
}

ASSERT_EQ(static_cast<ssize_t>(buffer.size()),
rbd_write(image, 0, buffer.size(), buffer.c_str()));

ASSERT_EQ(0, rbd_invalidate_cache(image));

buffer.resize(size);
ASSERT_EQ(static_cast<ssize_t>(size-1024), rbd_read(image, 1024, size, &buffer[0]));
ASSERT_EQ(static_cast<ssize_t>(buffer.size()),
rbd_read(image, 0, buffer.size(), &buffer[0]));

ASSERT_EQ(0, rbd_close(image));

Expand Down

0 comments on commit 67c9e8e

Please sign in to comment.