From 54d4cca6cb0c92a09b364974438d91d4331a036f Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Sun, 21 Mar 2021 06:32:07 +0530 Subject: [PATCH] LU-13594 obdclass: Add OOM handler for obdclass This patch adds OOM handler for obdclass. The handler currently only prints max memory that was used by obdclass along with current memory being used before attempting to kill the user process. Currently, when the handler is kicked in the output under dmesg would look like: Output: ~~~~~~~~ ... Mar 21 07:02:02 devbox kernel: obd_memory max: 244859953, obd_memory current: 0 ... Test-Parameters: trivial Signed-off-by: Arshad Hussain Change-Id: I0259f800b1f219ff3427f1d2a17b6a874dd456d3 Reviewed-on: https://review.whamcloud.com/42121 Tested-by: jenkins Reviewed-by: Aurelien Degremont Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/obdclass/class_obd.c | 62 ++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index d8c5cc9..f0c6118 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -99,33 +100,49 @@ struct lprocfs_stats *obd_memory = NULL; EXPORT_SYMBOL(obd_memory); #endif +static int obdclass_oom_handler(struct notifier_block *self, + unsigned long notused, void *nfreed) +{ +#ifdef CONFIG_PROC_FS + /* in bytes */ + pr_info("obd_memory max: %llu, obd_memory current: %llu\n", + obd_memory_max(), obd_memory_sum()); +#endif /* CONFIG_PROC_FS */ + + return NOTIFY_OK; +} + +static struct notifier_block obdclass_oom = { + .notifier_call = obdclass_oom_handler +}; + static int class_resolve_dev_name(__u32 len, const char *name) { - int rc; - int dev; + int rc; + int dev; - ENTRY; - if (!len || !name) { - CERROR("No name passed,!\n"); - GOTO(out, rc = -EINVAL); - } - if (name[len - 1] != 0) { - CERROR("Name not nul terminated!\n"); - GOTO(out, rc = -EINVAL); - } + ENTRY; + if (!len || !name) { + CERROR("No name passed,!\n"); + GOTO(out, rc = -EINVAL); + } + if (name[len - 1] != 0) { + CERROR("Name not nul terminated!\n"); + GOTO(out, rc = -EINVAL); + } - CDEBUG(D_IOCTL, "device name %s\n", name); - dev = class_name2dev(name); - if (dev == -1) { - CDEBUG(D_IOCTL, "No device for name %s!\n", name); - GOTO(out, rc = -EINVAL); - } + CDEBUG(D_IOCTL, "device name %s\n", name); + dev = class_name2dev(name); + if (dev == -1) { + CDEBUG(D_IOCTL, "No device for name %s!\n", name); + GOTO(out, rc = -EINVAL); + } - CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev); - rc = dev; + CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev); + rc = dev; out: - RETURN(rc); + RETURN(rc); } #define OBD_MAX_IOCTL_BUFFER 8192 @@ -659,6 +676,8 @@ static int __init obdclass_init(void) LCONSOLE_INFO("Lustre: Build Version: "LUSTRE_VERSION_STRING"\n"); + register_oom_notifier(&obdclass_oom); + libcfs_kkuc_init(); err = obd_init_checks(); @@ -789,6 +808,7 @@ cleanup_obd_memory: lprocfs_free_stats(&obd_memory); #endif + unregister_oom_notifier(&obdclass_oom); return err; } @@ -856,6 +876,8 @@ static void __exit obdclass_exit(void) memory_max, memory_leaked); #endif /* CONFIG_PROC_FS */ + unregister_oom_notifier(&obdclass_oom); + EXIT; } -- 1.8.3.1