mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-30 06:43:28 +01:00
Only show a single mlock() error, to avoid flooding the log
This commit is contained in:
parent
84dd674cd0
commit
1132436f97
@ -38,6 +38,12 @@
|
|||||||
#include "syncobj.h"
|
#include "syncobj.h"
|
||||||
#include "mlocker.h"
|
#include "mlocker.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
// did an mlock operation previously fail? we only
|
||||||
|
// want to log an error once and be done with it
|
||||||
|
static std::atomic<bool> previously_failed{ false };
|
||||||
|
|
||||||
static size_t query_page_size()
|
static size_t query_page_size()
|
||||||
{
|
{
|
||||||
#if defined HAVE_MLOCK
|
#if defined HAVE_MLOCK
|
||||||
@ -59,8 +65,8 @@ static void do_lock(void *ptr, size_t len)
|
|||||||
{
|
{
|
||||||
#if defined HAVE_MLOCK
|
#if defined HAVE_MLOCK
|
||||||
int ret = mlock(ptr, len);
|
int ret = mlock(ptr, len);
|
||||||
if (ret < 0)
|
if (ret < 0 && !previously_failed.exchange(true))
|
||||||
MERROR("Error locking page at " << ptr << ": " << strerror(errno));
|
MERROR("Error locking page at " << ptr << ": " << strerror(errno) << ", subsequent mlock errors will be silenced");
|
||||||
#else
|
#else
|
||||||
#warning Missing do_lock implementation
|
#warning Missing do_lock implementation
|
||||||
#endif
|
#endif
|
||||||
@ -70,7 +76,10 @@ static void do_unlock(void *ptr, size_t len)
|
|||||||
{
|
{
|
||||||
#if defined HAVE_MLOCK
|
#if defined HAVE_MLOCK
|
||||||
int ret = munlock(ptr, len);
|
int ret = munlock(ptr, len);
|
||||||
if (ret < 0)
|
// check whether we previously failed, but don't set it, this is just
|
||||||
|
// to pacify the errors of mlock()ing failed, in which case unlocking
|
||||||
|
// is also not going to work of course
|
||||||
|
if (ret < 0 && !previously_failed.load())
|
||||||
MERROR("Error unlocking page at " << ptr << ": " << strerror(errno));
|
MERROR("Error unlocking page at " << ptr << ": " << strerror(errno));
|
||||||
#else
|
#else
|
||||||
#warning Missing implementation of page size detection
|
#warning Missing implementation of page size detection
|
||||||
|
Loading…
Reference in New Issue
Block a user