From: Ramesh Chander Date: Tue, 13 Dec 2016 14:50:59 +0000 (-0800) Subject: allocator alloc_extents min_alloc X-Git-Tag: v11.1.1~21^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f9338b1a1f4b01ceaa2c653e475608ae67737107;p=ceph.git allocator alloc_extents min_alloc Signed-off-by: Ramesh Chander --- diff --git a/src/os/bluestore/BitAllocator.cc b/src/os/bluestore/BitAllocator.cc index 1c20b1187b01..02a3147628e9 100644 --- a/src/os/bluestore/BitAllocator.cc +++ b/src/os/bluestore/BitAllocator.cc @@ -1,4 +1,5 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- + // vim: ts=8 sw=2 smarttab /* * Bitmap based in-memory allocator. @@ -641,6 +642,94 @@ int64_t BitMapZone::alloc_blocks_dis(int64_t num_blocks, return allocated; } +int64_t BitMapZone::alloc_blocks_dis2(int64_t num_blocks, + int64_t min_alloc, + int64_t hint, + int64_t zone_blk_off, + ExtentList *alloc_blocks) +{ + int64_t bmap_idx = hint / BmapEntry::size(); + int bit = hint % BmapEntry::size(); + BmapEntry *bmap = NULL; + int64_t allocated = 0; + int64_t blk_off = 0; + int64_t alloc_cont = 0; + int64_t last_cont = 0; + int64_t last_running_ext = 0; + int search_idx = bit; + int64_t scanned = 0; + int start_off = 0; + + + alloc_assert(check_locked()); + + BitMapEntityIter iter = BitMapEntityIter( + m_bmap_list, bmap_idx); + + while (allocated < num_blocks) { + blk_off = zone_blk_off + bmap_idx * size(); + if (last_cont) { + /* + * We had bits free at end of last bitmap, try to complete required + * min alloc size using that. + */ + alloc_cont = bmap->find_n_cont_bits(0, min_alloc - last_cont); + allocated += alloc_cont; + last_cont += alloc_cont; + + if (!alloc_cont) { + this->free_blocks(last_running_ext, last_cont); + allocated -= last_cont; + last_cont = 0; + } else { + /* + * Got contiguous min_alloc_size across bitmaps. + */ + alloc_blocks->add_extents(last_running_ext, last_cont); + } + last_running_ext = 0; + search_idx = alloc_cont; + } else { + /* + * Try to allocate min_alloc_size bits from given bmap. + */ + alloc_cont = bmap->find_first_set_bits(min_alloc, search_idx, &start_off, &scanned); + search_idx = search_idx + scanned; + if (alloc_cont / min_alloc) { + /* + * Got contiguous min_alloc_size within a bitmap. + */ + alloc_blocks->add_extents(blk_off + start_off, min_alloc); + } + + if (alloc_cont % min_alloc) { + /* + * Got some bits at end of bitmap, carry them to try match with + * start bits from next bitmap. + */ + if (!last_cont) { + last_running_ext = blk_off + start_off; + } + last_cont += alloc_cont % min_alloc; + } + } + + + if (search_idx == BmapEntry::size()) { + search_idx = 0; + if ((bmap = iter.next())) { + this->free_blocks(last_running_ext, last_cont); + allocated -= last_cont; + break; + } + } + } + + return allocated; +} + + + void BitMapZone::dump_state(int& count) { BmapEntry *bmap = NULL; diff --git a/src/os/bluestore/BitAllocator.h b/src/os/bluestore/BitAllocator.h index 1c9c2bdc4bc6..c9b4e5acc26d 100644 --- a/src/os/bluestore/BitAllocator.h +++ b/src/os/bluestore/BitAllocator.h @@ -380,6 +380,8 @@ public: using BitMapArea::alloc_blocks_dis; int64_t alloc_blocks_dis(int64_t num_blocks, int64_t hint, int64_t blk_off, ExtentList *block_list); + int64_t alloc_blocks_dis2(int64_t num_blocks, int64_t min_alloc, int64_t hint, + int64_t blk_off, ExtentList *block_list); void set_blocks_used(int64_t start_block, int64_t num_blocks); void free_blocks(int64_t start_block, int64_t num_blocks);