shared memory via /dev/shm?

Nicholas Murphy halcyonic at
Thu Jul 30 19:03:51 EDT 2015

Apologies if this has been asked before:

Yes, I’ve read all the disclaimers against accessing files in the kernel, but I want to set up a shared memory segment between a kernel module and one or more user processes, and /dev/shm seems like a good way to do that.

Given that, what’s the preferred way to access files within the kernel (specifically within a kernel module)?  At the moment, I’m using filp_open() on module load to open the file (which seems to work), then:

filp_close() to close the file *
kern_path() to get the entry for the /dev/shm file
vfs_unlink() to delete the /dev/shm file
dput() to free the dentry
path_put() to free the path

…on module unload, and it hangs.  Any suggestions what I’m doing wrong?


More information about the Kernelnewbies mailing list