[PATCH v2 08/11] vinyl: do not try to trigger dump in regulator if already in progress
Vladimir Davydov
vdavydov.dev at gmail.com
Fri Sep 28 20:40:06 MSK 2018
This is pointless since trigger_dump_cb callback will return right away
in such a case. Let's wrap trigger_dump_cb in vy_regulator_trigger_dump
method, which will actulally invoke the callback only if the previous
dump has already completed (i.e. vy_regulator_dump_complete was called).
This also gives us a definite place in code where we can adjust the rate
limit so as to guarantee that a triggered memory dump will finish before
we hit the hard memory limit (this will be done later).
Needed for #1862
---
src/box/vinyl.c | 5 +++--
src/box/vy_regulator.c | 20 ++++++++++++++++++--
src/box/vy_regulator.h | 11 +++++++++--
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 25ba92fe..c3d95777 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -2427,7 +2427,7 @@ vy_env_quota_exceeded_cb(struct vy_quota *quota)
vy_regulator_no_memory(&env->regulator);
}
-static void
+static int
vy_env_trigger_dump_cb(struct vy_regulator *regulator)
{
struct vy_env *env = container_of(regulator, struct vy_env, regulator);
@@ -2439,9 +2439,10 @@ vy_env_trigger_dump_cb(struct vy_regulator *regulator)
* quota has been consumed by pending transactions.
* There's nothing we can do about that.
*/
- return;
+ return -1;
}
vy_scheduler_trigger_dump(&env->scheduler);
+ return 0;
}
static void
diff --git a/src/box/vy_regulator.c b/src/box/vy_regulator.c
index 3bd4fee4..5ec5629f 100644
--- a/src/box/vy_regulator.c
+++ b/src/box/vy_regulator.c
@@ -31,6 +31,7 @@
#include "vy_regulator.h"
#include <math.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tarantool_ev.h>
@@ -66,6 +67,18 @@ static const int VY_DUMP_BW_PCT = 10;
static const size_t VY_DUMP_BW_DEFAULT = 10 * 1024 * 1024;
static void
+vy_regulator_trigger_dump(struct vy_regulator *regulator)
+{
+ if (regulator->dump_in_progress)
+ return;
+
+ if (regulator->trigger_dump_cb(regulator) != 0)
+ return;
+
+ regulator->dump_in_progress = true;
+}
+
+static void
vy_regulator_update_write_rate(struct vy_regulator *regulator)
{
size_t used_curr = regulator->quota->used;
@@ -152,6 +165,7 @@ vy_regulator_create(struct vy_regulator *regulator, struct vy_quota *quota,
regulator->watermark = SIZE_MAX;
regulator->write_rate = 0;
regulator->dump_bw = VY_DUMP_BW_DEFAULT;
+ regulator->dump_in_progress = false;
}
void
@@ -170,20 +184,22 @@ vy_regulator_destroy(struct vy_regulator *regulator)
void
vy_regulator_no_memory(struct vy_regulator *regulator)
{
- regulator->trigger_dump_cb(regulator);
+ vy_regulator_trigger_dump(regulator);
}
void
vy_regulator_check_watermark(struct vy_regulator *regulator)
{
if (regulator->quota->used >= regulator->watermark)
- regulator->trigger_dump_cb(regulator);
+ vy_regulator_trigger_dump(regulator);
}
void
vy_regulator_dump_complete(struct vy_regulator *regulator,
size_t mem_dumped, double dump_duration)
{
+ regulator->dump_in_progress = false;
+
if (dump_duration > 0) {
histogram_collect(regulator->dump_bw_hist,
mem_dumped / dump_duration);
diff --git a/src/box/vy_regulator.h b/src/box/vy_regulator.h
index 9336adc9..0ea708d6 100644
--- a/src/box/vy_regulator.h
+++ b/src/box/vy_regulator.h
@@ -31,6 +31,7 @@
* SUCH DAMAGE.
*/
+#include <stdbool.h>
#include <stddef.h>
#include <tarantool_ev.h>
@@ -42,7 +43,7 @@ struct histogram;
struct vy_quota;
struct vy_regulator;
-typedef void
+typedef int
(*vy_trigger_dump_f)(struct vy_regulator *regulator);
/**
@@ -59,7 +60,7 @@ struct vy_regulator {
/**
* Called when the regulator detects that memory usage
* exceeds the computed watermark. Supposed to trigger
- * memory dump.
+ * memory dump and return 0 on success, -1 on failure.
*/
vy_trigger_dump_f trigger_dump_cb;
/**
@@ -100,6 +101,12 @@ struct vy_regulator {
* best result among 10% worst measurements.
*/
struct histogram *dump_bw_hist;
+ /**
+ * Set if the last triggered memory dump hasn't completed
+ * yet, i.e. trigger_dump_cb() was successfully invoked,
+ * but vy_regulator_dump_complete() hasn't been called yet.
+ */
+ bool dump_in_progress;
};
void
--
2.11.0
More information about the Tarantool-patches
mailing list