Morbius
Morbius

Reputation: 1

Memory mapping data files in Linux kernel code

Here's my question: I want to memory map part of a data file from code running in Linux kernel space. I want to later undo the same memory map, also from code running in Linux kernel space. How do I do these and how do they differ from using mmap(2)/munmap(2) in user space?

I'm trying to do this solely in kernel space where there is no user process.

I've been through web searches and onlne Linux kernel books, including "Understanding the Linux Kernel", by Bovet and Cesati. A fine book, but it doesn't answer my question.

Upvotes: 0

Views: 2135

Answers (1)

R.D.
R.D.

Reputation: 2631

It's discouraged to directly access the file system to do anything in the kernel. The best way to approach this would be to open and mmap the file in userspace and pass the resulting user virtual address to kernel space. In kernel space, you'd need set up kernel virtual addresses that point to the same physical memory that the userspace address is pointing to.

This SO question gives a code sample as to how to implement the second part: https://stackoverflow.com/a/13745255/639069

Upvotes: 3

Related Questions