From: Lu Shi Date: Thu, 24 Sep 2015 08:02:41 +0000 (+0800) Subject: librbd:reads larger than cache size hang. X-Git-Tag: v9.1.0~80^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F6031%2Fhead;p=ceph.git librbd:reads larger than cache size hang. Fixes:#13164 Signed-off-by: Lu Shi --- diff --git a/src/osdc/ObjectCacher.cc b/src/osdc/ObjectCacher.cc index daff1052020..d1f80209c79 100644 --- a/src/osdc/ObjectCacher.cc +++ b/src/osdc/ObjectCacher.cc @@ -1163,7 +1163,7 @@ int ObjectCacher::_readx(OSDRead *rd, ObjectSet *oset, Context *onfinish, uint64_t rx_bytes = static_cast( 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) { diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index 99d272a0d3d..5dc5c66da47 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -2570,7 +2570,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", @@ -2582,24 +2582,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(buffer.size(), size - offs); - ASSERT_EQ(static_cast(len), - rbd_write(image, offs, len, buffer.c_str())); - } + + ASSERT_EQ(static_cast(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(size-1024), rbd_read(image, 1024, size, &buffer[0])); + ASSERT_EQ(static_cast(buffer.size()), + rbd_read(image, 0, buffer.size(), &buffer[0])); ASSERT_EQ(0, rbd_close(image));