Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use memory purge redis command when initializing new kb #452

Merged
merged 5 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add v3 handling to get_cvss_score_from_base_metrics. [#411](https://github.com/greenbone/gvm-libs/pull/411)
- Add severity_date tag in epoch time format. [#412](https://github.com/greenbone/gvm-libs/pull/412)
- Make more scanner preferences available to openvas-nasl. [#413](https://github.com/greenbone/gvm-libs/pull/413)
- Use memory purge redis command when initializing new kb. [#452](https://github.com/greenbone/gvm-libs/pull/452)

### Changed
- Add separators for a new (ip address) field in ERRMSG and DEADHOST messages. [#376](https://github.com/greenbone/gvm-libs/pull/376)
Expand Down
32 changes: 32 additions & 0 deletions util/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,33 @@ redis_get_kb_index (kb_t kb)
return -1;
}

/**
* @brief Attempt to purge dirty pages.
*
* Attempt to purge dirty pages so these can be reclaimed by the allocator.
* This command only works when using jemalloc as an allocator, and evaluates
* to a benign NOOP for all others. Command is applied to complete redis
* instance and not only single db.
*
* @param[in] kb KB handle where to run the command.
*
* @return 0 on success, non-null on error.
*/
static int
redis_memory_purge (kb_t kb)
{
redisReply *rep;
int rc = 0;

rep = redis_cmd (redis_kb (kb), "MEMORY PURGE");
if (!rep || rep->type == REDIS_REPLY_ERROR)
rc = -1;
if (rep)
freeReplyObject (rep);

return rc;
}

/**
* @brief Initialize a new Knowledge Base object.
*
Expand Down Expand Up @@ -413,6 +440,11 @@ redis_new (kb_t *kb, const char *kb_path)
}

*kb = (kb_t) kbr;

/* Try to make unused memory available for the OS again. */
if (redis_memory_purge (*kb))
g_warning ("%s: Memory purge was not successfull", __func__);

return rc;
}

Expand Down