How use rust lang to observe OOM?

Good afternoon everyone. I read some code about Linux/notifier.c and some example about bindgen's use to achieve FFI. In my list, I want to use Linux kernel's code such as notifier.c and so on by bindgen. And then i can observe the OOM and when the OOM accurs, I will rember memory information. Is there some data or project i can use? Or do you think this project is available for me? Hope your advice!

It's not really clear what you mean. You say that you want to observe OOM, but normally running out of memory will just crash your program. What exactly do you want to observe, and what do you intend to do with it?

Perhaps you could give an example of what you want in a different language?

1 Like

Ok, I will improve my description tomorrow. Thank you!

When an OOM occurs in Linux, it records log information, including time, memory information, and the process that triggered the OOM. And what I want to do is to use the Rust language to implement a feature where I will record more information when an OOM occurs. In this process, to monitor the occurrence of OOM, it is necessary to use Linux's notifier. c and other libraries. I would like to know if there are any previous projects available for me to refer to?

In case of an OOM the target process of the OOM killer will get SIGKILL, which is a signal you can't respond to with a signal handler. It will always kill your process. Furthermore I believe the logs of the OOM killer are only visible through dmesg, which is only accessible as root.

Do you have a link to that? I don't know what file you are referring to.

When oom occurs, Linux's /var/log/messages will record the message about oom. It depends on kernel notifier chain. I want to register a notifier on the kernel notifier chain. So when the oom occurs, my program will begin to collect memory information and other information. This is the file notifier.c's path: linux/kernel/notifier.c at master · gregkh/linux (

I found register_oom_notifier, but it doesn't seem that is exposed to userspace through a syscall. AFAICT it is just for kernel modules.

1 Like

Yes, this function will be used. My partner has implemented the function I described using C language through this function, and I want to use rust language to implement the function I described. So I'm looking for ffi and information related to this.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.