This is an automated email from the ASF dual-hosted git repository.
jvanderzee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 12793241cd Deduplicate `StripeSM` evacuate hit window computation
(#11919)
12793241cd is described below
commit 12793241cd3225db38621061a8b5ea41be5c7fa1
Author: JosiahWI <[email protected]>
AuthorDate: Mon Jan 6 11:25:03 2025 -0600
Deduplicate `StripeSM` evacuate hit window computation (#11919)
The same expression is duplicated in 3 places, and 2 of them have a comment
which I borrowed the name from. This allows us to make `Stripe::data_blocks`
protected.
---
src/iocore/cache/CacheDir.cc | 3 +--
src/iocore/cache/Stripe.h | 2 +-
src/iocore/cache/StripeSM.cc | 11 ++++++++---
src/iocore/cache/StripeSM.h | 6 +++++-
4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc
index efacf0c206..1c4029d9ea 100644
--- a/src/iocore/cache/CacheDir.cc
+++ b/src/iocore/cache/CacheDir.cc
@@ -980,8 +980,7 @@ Lrestart:
start_time = ink_get_hrtime();
}
- // recompute hit_evacuate_window
- stripe->hit_evacuate_window = (stripe->data_blocks *
cache_config_hit_evacuate_percent) / 100;
+ stripe->recompute_hit_evacuate_window();
if (DISK_BAD(stripe->disk)) {
goto Ldone;
diff --git a/src/iocore/cache/Stripe.h b/src/iocore/cache/Stripe.h
index 1231810d6a..633354993a 100644
--- a/src/iocore/cache/Stripe.h
+++ b/src/iocore/cache/Stripe.h
@@ -97,7 +97,6 @@ public:
off_t skip{}; // start of headers
off_t start{}; // start of data
off_t len{};
- off_t data_blocks{};
uint32_t sector_size{};
@@ -168,6 +167,7 @@ public:
bool copy_from_aggregate_write_buffer(char *dest, Dir const &dir, size_t
nbytes) const;
protected:
+ off_t data_blocks{};
AggregateWriteBuffer _write_buffer;
void _clear_init(std::uint32_t hw_sector_size);
diff --git a/src/iocore/cache/StripeSM.cc b/src/iocore/cache/StripeSM.cc
index f01a8ab603..665995f0b6 100644
--- a/src/iocore/cache/StripeSM.cc
+++ b/src/iocore/cache/StripeSM.cc
@@ -170,7 +170,7 @@ StripeSM::init(bool clear)
CryptoContext().hash_immediate(hash_id, hash_text, strlen(hash_text));
// Evacuation
- this->hit_evacuate_window = (this->data_blocks *
cache_config_hit_evacuate_percent) / 100;
+ this->recompute_hit_evacuate_window();
// AIO
if (clear) {
@@ -1332,8 +1332,7 @@ StripeSM::shutdown(EThread *shutdown_thread)
Dbg(dbg_ctl_cache_dir_sync, "Dir %s: ignoring -- not dirty",
this->hash_text.get());
return;
}
- // recompute hit_evacuate_window
- this->hit_evacuate_window = (this->data_blocks *
cache_config_hit_evacuate_percent) / 100;
+ this->recompute_hit_evacuate_window();
// check if we have data in the agg buffer
// dont worry about the cachevc s in the agg queue
@@ -1401,3 +1400,9 @@ StripeSM::close_write(CacheVC *cont)
{
return open_dir.close_write(cont);
}
+
+void
+StripeSM::recompute_hit_evacuate_window()
+{
+ this->hit_evacuate_window = (this->data_blocks *
cache_config_hit_evacuate_percent) / 100;
+}
diff --git a/src/iocore/cache/StripeSM.h b/src/iocore/cache/StripeSM.h
index 1863d17380..63fdcac41b 100644
--- a/src/iocore/cache/StripeSM.h
+++ b/src/iocore/cache/StripeSM.h
@@ -158,7 +158,11 @@ public:
int evac_range(off_t start, off_t end, int evac_phase);
- int within_hit_evacuate_window(Dir const *dir) const;
+ /**
+ * Recompute the hit evacuate window after a config change.
+ */
+ void recompute_hit_evacuate_window();
+ int within_hit_evacuate_window(Dir const *dir) const;
/**
* StripeSM constructor.