Skip to content

Commit

Permalink
ovsdb-server: Fix excessive memory usage on DB open.
Browse files Browse the repository at this point in the history
During initial read of a database file all the file transactions are
added to the transaction history.  The history run with the history
size checks is only executed after the whole file is processed.
If, for some reason, the file contains way too many transactions,
this behavior may result in excessive memory consumption up to
hundreds of GBs.  For example, here is a log entry about memory usage
after reading a file with 100K+ OVN NbDB transactions:

  |00004|memory|INFO|95650400 kB peak resident set size after 96.9 seconds
  |00005|memory|INFO|atoms:3083346 cells:1838767 monitors:0
        raft-log:123309 txn-history:123307 txn-history-atoms:1647022868

In this particular case ovsdb-server allocated 95 GB of RAM in order
to accommodate 1.6 billion ovsdb atoms in the history, while only 3
million atoms are in the actual database.

Fix that by running history size checks after applying each file
transaction.  This way the memory usage while reading the database
from the example stays at about 1 GB mark.  History size checks are
cheap in comparison with transaction replay, so the additional calls
do not reduce performance.

We could've just moved the history run into ovsdb_txn_replay_commit(),
but it seems more organic to call it externally, since we have init()
and destroy() functions called externally as well.

Since the history run will be executed shortly after reading the
database and actual memory consumption peak is not always logged,
there seem to be no reliable way to unit test for the issue without
adding extra testing infrastructure into the code.

Fixes: 695e815 ("ovsdb-server: Transaction history tracking.")
Reported-at: https://bugzilla.redhat.com/2228464
Acked-by: Dumitru Ceara <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
igsilya committed Aug 3, 2023
1 parent 369daff commit d4d068f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ovsdb/ovsdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ main_loop(struct server_config *config,

SHASH_FOR_EACH_SAFE (node, all_dbs) {
struct db *db = node->data;
ovsdb_txn_history_run(db->db);

ovsdb_storage_run(db->db->storage);
read_db(config, db);
/* Run triggers after storage_run and read_db to make sure new raft
Expand Down Expand Up @@ -663,6 +663,7 @@ parse_txn(struct server_config *config, struct db *db,
if (!error && !uuid_is_zero(txnid)) {
db->db->prereq = *txnid;
}
ovsdb_txn_history_run(db->db);
}
return error;
}
Expand Down
1 change: 1 addition & 0 deletions ovsdb/relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ ovsdb_relay_run(void)
}
ovsdb_cs_event_destroy(event);
}
ovsdb_txn_history_run(ctx->db);
}
}

Expand Down

0 comments on commit d4d068f

Please sign in to comment.