Skip to content

Commit

Permalink
Add plugin to trigger kernel plugin
Browse files Browse the repository at this point in the history
Summary: This plugin triggers kernel panic when executed. This helps capture elusive memory issues which go away after OOM kills.

Reviewed By: masoncl

Differential Revision: D51082682

fbshipit-source-id: 5af584086353ba3fc833dce80dd7959315201af6
  • Loading branch information
lnyng authored and facebook-github-bot committed Nov 7, 2023
1 parent 168fdc2 commit 54bb4db
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/core_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ otherwise.
When `negate` is `true`, if `cgroup` doesn't exist, CONTINUE. STOP
otherwise.

## kernel_panic

### Arguments

No argument

### Description

This plugin triggers kernel panic when executed, which helps capture elusive
memory issues that goes away after OOM kills.

## nr_dying_descendants

### Arguments
Expand Down
48 changes: 48 additions & 0 deletions src/oomd/plugins/KernelPanic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2018-present, Facebook, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "oomd/plugins/KernelPanic.h"

#include "oomd/Log.h"
#include "oomd/PluginRegistry.h"
#include "oomd/util/Fs.h"
#include "oomd/util/Util.h"

namespace Oomd {

REGISTER_PLUGIN(kernel_panic, KernelPanic::create);

int KernelPanic::init(
const Engine::PluginArgs& args,
const PluginConstructionContext& /* unused */) {
return argParser_.parse(args) ? 0 : 1;
}

Engine::PluginRet KernelPanic::run(OomdContext& /* unused */) {
const auto fd = Fs::Fd::open("/proc/sysrq-trigger", false);
if (!fd) {
OLOG << "Failed to open /proc/sysrq-trigger";
return Engine::PluginRet::CONTINUE;
}
if (Util::writeFull(fd->fd(), "c", 1) != 1) {
OLOG << "Failed to trigger kernel panic";
return Engine::PluginRet::CONTINUE;
}
return Engine::PluginRet::STOP;
}

} // namespace Oomd
39 changes: 39 additions & 0 deletions src/oomd/plugins/KernelPanic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2018-present, Facebook, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include "oomd/engine/BasePlugin.h"

namespace Oomd {

class KernelPanic : public Oomd::Engine::BasePlugin {
public:
int init(
const Engine::PluginArgs& args,
const PluginConstructionContext& context) override;

Engine::PluginRet run(OomdContext& /* unused */) override;

static KernelPanic* create() {
return new KernelPanic();
}

~KernelPanic() override = default;
};

} // namespace Oomd

0 comments on commit 54bb4db

Please sign in to comment.