I need to share about 100KiB of kernel memory to userspace. Userspace daemon will access this memory in read-only manner several (5-10) times a second. Does procfs
is the best way for implementing it?
Asked
Active
Viewed 1.2k times
4
-
`procfs` is certainly not the best way of implementing it. It's not even a good one for many reasons. There _is_ a way to share memory between kernel and user spaces (and not necessarily read-only), but alas I don't personally know it. However, my guess would be getting a couple of pages (as much as you need) in the kernel module and to share them, add those pages (with their permissions) to the virtual address of the process you are interested in. I'm not really sure if that's the real way or what complications there are, but that may get you started! – Shahbaz Nov 27 '13 at 12:42
-
Possible duplicate of [Share memory from a Linux kernel module for a userspace process to access](https://stackoverflow.com/questions/14289081/share-memory-from-a-linux-kernel-module-for-a-userspace-process-to-access) – Ciro Santilli OurBigBook.com Jul 18 '17 at 18:43
1 Answers
3
kmalloc and vmalloc are the way to go.
But check these before proceeding: What is the difference between vmalloc and kmalloc?
mmap kernel buffer to user space
Allocating memory for user space from kernel thread
As already mentioned, procfs is poor way to share data. It is used for settings per se.