Mirror von
https://github.com/tkuschel/bees.git
synchronisiert 2026-06-19 15:07:54 +02:00
hash: prevent eleventy-gigabyte core dumps
Add MADV_DONTDUMP to the list of advice flags. There are now three flags which may or may not be supported by the target kernel. Try each one and log its success or failure separately. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
Dieser Commit ist enthalten in:
+14
-6
@@ -635,12 +635,20 @@ BeesHashTable::BeesHashTable(shared_ptr<BeesContext> ctx, string filename, off_t
|
|||||||
THROW_CHECK2(runtime_error, m_void_ptr, m_bucket_ptr, m_void_ptr == m_bucket_ptr);
|
THROW_CHECK2(runtime_error, m_void_ptr, m_bucket_ptr, m_void_ptr == m_bucket_ptr);
|
||||||
THROW_CHECK2(runtime_error, m_void_ptr, m_extent_ptr, m_void_ptr == m_extent_ptr);
|
THROW_CHECK2(runtime_error, m_void_ptr, m_extent_ptr, m_void_ptr == m_extent_ptr);
|
||||||
|
|
||||||
{
|
// Give all the madvise hints that the kernel understands
|
||||||
// It's OK if this fails (e.g. kernel not built with CONFIG_TRANSPARENT_HUGEPAGE)
|
const struct madv_flag {
|
||||||
// We don't fork any more so DONTFORK isn't really needed
|
const char *name;
|
||||||
BEESTOOLONG("madvise(MADV_HUGEPAGE | MADV_DONTFORK)");
|
int value;
|
||||||
if (madvise(m_byte_ptr, m_size, MADV_HUGEPAGE | MADV_DONTFORK)) {
|
} madv_flags[] = {
|
||||||
BEESLOG("mostly harmless: madvise(MADV_HUGEPAGE | MADV_DONTFORK) failed: " << strerror(errno));
|
{ .name = "MADV_HUGEPAGE", .value = MADV_HUGEPAGE },
|
||||||
|
{ .name = "MADV_DONTFORK", .value = MADV_DONTFORK },
|
||||||
|
{ .name = "MADV_DONTDUMP", .value = MADV_DONTDUMP },
|
||||||
|
{ .name = "", .value = 0 },
|
||||||
|
};
|
||||||
|
for (auto fp = madv_flags; fp->value; ++fp) {
|
||||||
|
BEESTOOLONG("madvise(" << fp->name << ")");
|
||||||
|
if (madvise(m_byte_ptr, m_size, fp->value)) {
|
||||||
|
BEESLOG("madvise(..., " << fp->name << "): " << strerror(errno) << " (ignored)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
In neuem Issue referenzieren
Einen Benutzer sperren