Skip to content

Commit

Permalink
RECOVER: When we pull databases during recovery, we used to reallocat…
Browse files Browse the repository at this point in the history
…e the databuffer for each entry added. This would normally not be an issue, but for cases where memory is fragmented, this could start to cost significant cpu if we need to reallocate and move to a different region.

Change this to instead preallocate , by default, 10MByte chunks to the data buffer.
This significantly reduces the number of potential reallocate and move  operations that may be required.

Create a tunable to override/change how much preallocation should be used.

(This used to be ctdb commit 1f262deaad0818f159f9c68330f7fec121679023)
  • Loading branch information
sahlberg committed May 25, 2012
1 parent 7d9acae commit e7d2183
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions ctdb/include/ctdb_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ struct ctdb_tunable {
uint32_t db_record_count_warn;
uint32_t db_record_size_warn;
uint32_t db_size_warn;
uint32_t pulldb_preallocation_size;
};

/*
Expand Down
7 changes: 6 additions & 1 deletion ctdb/server/ctdb_recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ struct pulldb_data {
struct ctdb_db_context *ctdb_db;
struct ctdb_marshall_buffer *pulldata;
uint32_t len;
uint32_t allocated_len;
bool failed;
};

Expand All @@ -364,7 +365,10 @@ static int traverse_pulldb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
params->failed = true;
return -1;
}
params->pulldata = talloc_realloc_size(NULL, params->pulldata, rec->length + params->len);
if (params->len + rec->length >= params->allocated_len) {
params->allocated_len = rec->length + params->len + ctdb->tunable.pulldb_preallocation_size;
params->pulldata = talloc_realloc_size(NULL, params->pulldata, params->allocated_len);
}
if (params->pulldata == NULL) {
DEBUG(DEBUG_CRIT,(__location__ " Failed to expand pulldb_data to %u\n", rec->length + params->len));
ctdb_fatal(params->ctdb, "failed to allocate memory for recovery. shutting down\n");
Expand Down Expand Up @@ -414,6 +418,7 @@ int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DAT
params.ctdb_db = ctdb_db;
params.pulldata = reply;
params.len = offsetof(struct ctdb_marshall_buffer, data);
params.allocated_len = params.len;
params.failed = false;

if (ctdb_db->unhealthy_reason) {
Expand Down
7 changes: 6 additions & 1 deletion ctdb/server/ctdb_recoverd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ struct recdb_data {
struct ctdb_context *ctdb;
struct ctdb_marshall_buffer *recdata;
uint32_t len;
uint32_t allocated_len;
bool failed;
bool persistent;
};
Expand Down Expand Up @@ -1206,7 +1207,10 @@ static int traverse_recdb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
params->failed = true;
return -1;
}
params->recdata = talloc_realloc_size(NULL, params->recdata, rec->length + params->len);
if (params->len + rec->length >= params->allocated_len) {
params->allocated_len = rec->length + params->len + params->ctdb->tunable.pulldb_preallocation_size;
params->recdata = talloc_realloc_size(NULL, params->recdata, params->allocated_len);
}
if (params->recdata == NULL) {
DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u (%u records)\n",
rec->length + params->len, params->recdata->count));
Expand Down Expand Up @@ -1245,6 +1249,7 @@ static int push_recdb_database(struct ctdb_context *ctdb, uint32_t dbid,
params.ctdb = ctdb;
params.recdata = recdata;
params.len = offsetof(struct ctdb_marshall_buffer, data);
params.allocated_len = params.len;
params.failed = false;
params.persistent = persistent;

Expand Down
3 changes: 2 additions & 1 deletion ctdb/server/ctdb_tunables.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ static const struct {
{ "NoIPTakeover", 0, offsetof(struct ctdb_tunable, no_ip_takeover), false },
{ "DBRecordCountWarn", 100000, offsetof(struct ctdb_tunable, db_record_count_warn), false },
{ "DBRecordSizeWarn", 10000000, offsetof(struct ctdb_tunable, db_record_size_warn), false },
{ "DBSizeWarn", 100000000, offsetof(struct ctdb_tunable, db_size_warn), false }
{ "DBSizeWarn", 100000000, offsetof(struct ctdb_tunable, db_size_warn), false },
{ "PullDBPreallocation", 10*1024*10240, offsetof(struct ctdb_tunable, pulldb_preallocation_size), false }
};

/*
Expand Down

0 comments on commit e7d2183

Please sign in to comment.