forked from bitcoin/bitcoin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add io priority to reduce impact of ActivateChain on IBD and impact o…
…f historical block serving. Based on bitcoin#9245
- Loading branch information
Showing
7 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2016 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#if defined(HAVE_CONFIG_H) | ||
#include "config/bitcoin-config.h" | ||
#endif | ||
|
||
#include "utilioprio.h" | ||
|
||
#ifdef HAVE_IOPRIO_SYSCALL | ||
|
||
#ifndef _GNU_SOURCE | ||
#define _GNU_SOURCE | ||
#endif | ||
#include <unistd.h> | ||
#include <sys/syscall.h> | ||
|
||
#ifndef IOPRIO_WHO_PROCESS | ||
#define IOPRIO_WHO_PROCESS 1 | ||
#endif | ||
#ifndef IOPRIO_CLASS_IDLE | ||
#define IOPRIO_CLASS_IDLE 3 | ||
#endif | ||
#ifndef IOPRIO_CLASS_SHIFT | ||
#define IOPRIO_CLASS_SHIFT 13 | ||
#endif | ||
|
||
int ioprio_get() { | ||
return syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, 0); | ||
} | ||
|
||
int ioprio_set(const int ioprio) { | ||
return syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, 0, ioprio); | ||
} | ||
|
||
int ioprio_set_idle() { | ||
return ioprio_set(7 | (IOPRIO_CLASS_IDLE << IOPRIO_CLASS_SHIFT)); | ||
} | ||
|
||
#elif HAVE_IOPOLICY | ||
|
||
#include <sys/resource.h> | ||
|
||
int ioprio_get() { | ||
return getiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD); | ||
} | ||
|
||
int ioprio_set(const int ioprio) { | ||
return setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD, ioprio); | ||
} | ||
|
||
int ioprio_set_idle() { | ||
return ioprio_set(IOPOL_UTILITY); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2016 Satoshi Nakamoto | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_UTIL_IOPRIO_H | ||
#define BITCOIN_UTIL_IOPRIO_H | ||
|
||
#if defined(HAVE_CONFIG_H) | ||
#include "config/bitcoin-config.h" | ||
#endif | ||
|
||
#include "util.h" | ||
|
||
#if defined(HAVE_IOPRIO_SYSCALL) || defined(HAVE_IOPOLICY) | ||
int ioprio_get(); | ||
int ioprio_set(int ioprio); | ||
int ioprio_set_idle(); | ||
|
||
class ioprio_idler { | ||
private: | ||
int orig; | ||
|
||
public: | ||
ioprio_idler(const bool actually_idle) { | ||
if (!actually_idle) { | ||
orig = -1; | ||
return; | ||
} | ||
|
||
orig = ioprio_get(); | ||
if (orig == -1) { | ||
return; | ||
} | ||
if (ioprio_set_idle() == -1) { | ||
orig = -1; | ||
} | ||
} | ||
|
||
~ioprio_idler() { | ||
if (orig == -1) { | ||
return; | ||
} | ||
if (ioprio_set(orig) == -1) { | ||
LogPrintf("failed to restore ioprio\n"); | ||
} | ||
} | ||
}; | ||
#define IOPRIO_IDLER(actually_idle) ioprio_idler ioprio_idler_(actually_idle) | ||
|
||
#else | ||
#define ioprio_get() ((void)-1) | ||
#define ioprio_set(ioprio) ((void)-1) | ||
#define ioprio_set_idle() ((void)-1) | ||
#define IOPRIO_IDLER(actually_idle) (void)actually_idle; | ||
#endif | ||
|
||
#endif // BITCOIN_UTIL_IOPRIO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters