How to write huge data to the kernel

I am trying to write a huge output of data from the kernel. In fact, I am trying to register all the ways to switch processes in the kernel. For even 1 min of profiling, the recorded data will be huge. How can i do this. I need to open a huge buffer, write data to it, and then send it to user space for further analysis.

EDIT: To find out how big the โ€œBIGโ€ below is the exact problem, I am trying to solve it with about 10,000 lines of output

+4
source share
2 answers

My suggestion is to use the same idea as the linux kernel to capture packets, in particular a packet ring buffer (search: PACKET_RX_RING).

The idea is pretty simple in your custom space program to highlight a ring. Then pass this ring to the โ€œdriverโ€ (your kernel module), then your driver can simply write data points to the ring, and your user space program can read them. Since this is a ring, you can simply continue to write, and the client can continue to read - if the client is behind, it is likely that your driver can pick up (as soon as he was in the ring), but I am sure that you can size the ring properly.

Each slot in the ring should contain your โ€œserializedโ€ data, which the user space program can simply read. This type of ring should be easy enough to use locks, and most likely you want your client to hang to see if there is any data.

+6
source

Well, the โ€œstandardโ€ way to export so much data is to use debugfs. You can see how ftrace does this (kernel / trace / ftrace.c).

And to get more data, you can use the relayfs interface (kernel / relay.c). You can see how blktrace does this (kernel / trace / blktrace.c).

0
source

Source: https://habr.com/ru/post/1446675/


All Articles