]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
allocator alloc_extents min_alloc
authorRamesh Chander <Ramesh.Chander@sandisk.com>
Tue, 13 Dec 2016 14:50:59 +0000 (06:50 -0800)
committerRamesh Chander <Ramesh.Chander@sandisk.com>
Sun, 18 Dec 2016 18:40:40 +0000 (10:40 -0800)
Signed-off-by: Ramesh Chander <Ramesh.Chander@sandisk.com>
src/os/bluestore/BitAllocator.cc
src/os/bluestore/BitAllocator.h

index 1c20b1187b012f3687bd51393d774fb1c5c17b00..02a3147628e9f9c51e1af6c4f7197525b099c01a 100644 (file)
@@ -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 <BmapEntry> iter = BitMapEntityIter<BmapEntry>(
+          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;
index 1c9c2bdc4bc6b6a9f314dc334852593b8ee76cad..c9b4e5acc26d5d51add32c5db43a7738d233a202 100644 (file)
@@ -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);