]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/segment_cleaner: cleanup, track available space in open segments
authorYingxin Cheng <yingxin.cheng@intel.com>
Thu, 5 May 2022 02:36:36 +0000 (10:36 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Fri, 13 May 2022 07:51:20 +0000 (15:51 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/segment_cleaner.cc
src/crimson/os/seastore/segment_cleaner.h

index 9d8b2b54957ae6c96a6d5d70cd204997c60e632e..edd21b1f5b977273bab4902041070c975b27a339 100644 (file)
@@ -91,7 +91,7 @@ void segments_info_t::reset()
   count_close = 0;
 
   total_bytes = 0;
-  avail_bytes = 0;
+  avail_bytes_in_open = 0;
 }
 
 void segments_info_t::add_segment_manager(
@@ -123,7 +123,6 @@ void segments_info_t::add_segment_manager(
   num_empty += nsegments;
 
   total_bytes += sm_size;
-  avail_bytes += sm_size;
 }
 
 void segments_info_t::init_closed(
@@ -144,8 +143,6 @@ void segments_info_t::init_closed(
     ceph_assert(get_journal_head() == JOURNAL_SEQ_NULL);
     ++num_in_journal;
   }
-  ceph_assert(avail_bytes >= get_segment_size());
-  avail_bytes -= get_segment_size();
   // do not increment count_close;
 }
 
@@ -172,6 +169,8 @@ void segments_info_t::mark_open(
     journal_segment_id = segment;
     ++num_in_journal;
   }
+  ceph_assert(segment_info.written_to == 0);
+  avail_bytes_in_open += get_segment_size();
   ++count_open;
 }
 
@@ -194,7 +193,6 @@ void segments_info_t::mark_empty(
     ceph_assert(num_in_journal > 0);
     --num_in_journal;
   }
-  avail_bytes += get_segment_size();
   ++count_release;
 }
 
@@ -213,8 +211,8 @@ void segments_info_t::mark_closed(
   ++num_closed;
   ceph_assert(get_segment_size() >= segment_info.written_to);
   auto seg_avail_bytes = get_segment_size() - segment_info.written_to;
-  ceph_assert(avail_bytes >= seg_avail_bytes);
-  avail_bytes -= seg_avail_bytes;
+  ceph_assert(avail_bytes_in_open >= seg_avail_bytes);
+  avail_bytes_in_open -= seg_avail_bytes;
   ++count_close;
 }
 
@@ -242,8 +240,8 @@ void segments_info_t::update_written_to(
   DEBUG("type={}, offset={}, {}", type, offset, segment_info);
   ceph_assert(type == segment_info.type);
   auto avail_deduction = new_written_to - segment_info.written_to;
-  ceph_assert(avail_bytes >= avail_deduction);
-  avail_bytes -= avail_deduction;
+  ceph_assert(avail_bytes_in_open >= avail_deduction);
+  avail_bytes_in_open -= avail_deduction;
   segment_info.written_to = new_written_to;
 }
 
index 5b3f617fd6725c242ebdb15d0fbdd8882c0f9a2f..edf64097d6290cc05e6cb7f81f3a9d9fc576a569 100644 (file)
@@ -139,7 +139,11 @@ public:
     return total_bytes;
   }
   std::size_t get_available_bytes() const {
-    return avail_bytes;
+    return num_empty * get_segment_size() + avail_bytes_in_open;
+  }
+  std::size_t get_unavailable_bytes() const {
+    assert(total_bytes >= get_available_bytes());
+    return total_bytes - get_available_bytes();
   }
   journal_seq_t get_journal_head() const {
     if (unlikely(journal_segment_id == NULL_SEG_ID)) {
@@ -195,7 +199,7 @@ private:
   std::size_t count_close;
 
   std::size_t total_bytes;
-  std::size_t avail_bytes;
+  std::size_t avail_bytes_in_open;
 };
 
 /**