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)
uint32_t db_record_count_warn;
uint32_t db_record_size_warn;
uint32_t db_size_warn;
+ uint32_t pulldb_preallocation_size;
};
/*
struct ctdb_db_context *ctdb_db;
struct ctdb_marshall_buffer *pulldata;
uint32_t len;
+ uint32_t allocated_len;
bool failed;
};
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");
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) {
struct ctdb_context *ctdb;
struct ctdb_marshall_buffer *recdata;
uint32_t len;
+ uint32_t allocated_len;
bool failed;
bool persistent;
};
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));
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;
{ "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 }
};
/*