Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7993119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:45:21+00:00 2026-06-04T13:45:21+00:00

Let’s say the buffer is allocated using a page based scheme. One way to

  • 0

Let’s say the buffer is allocated using a page based scheme. One way to implement mmap would be to use remap_pfn_range but LDD3 says this does not work for conventional memory. It appears we can work around this by marking the page(s) reserved using SetPageReserved so that it gets locked in memory. But isn’t all kernel memory already non-swappable i.e. already reserved? Why the need to set the reserved bit explicitly?

Does this have something to do with pages allocated from HIGH_MEM?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:45:23+00:00Added an answer on June 4, 2026 at 1:45 pm

    The simplest way to map a set of pages from the kernel in your mmap method is to use the fault handler to map the pages. Basically you end up with something like:

    static int my_mmap(struct file *filp, struct vm_area_struct *vma)
    {
        vma->vm_ops = &my_vm_ops;
        return 0;
    }
    
    static const struct file_operations my_fops = {
        .owner  = THIS_MODULE,
        .open   = nonseekable_open,
        .mmap   = my_mmap,
        .llseek = no_llseek,
    };
    

    (where the other file operations are whatever your module needs). Also in my_mmap you do whatever range checking etc. is needed to validate the mmap parameters.

    Then the vm_ops look like:

    static int my_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
    {
        vmf->page = my_page_at_index(vmf->pgoff);
        get_page(vmf->page);
    
        return 0;
    } 
    
    static const struct vm_operations_struct my_vm_ops = {
        .fault      = my_fault
    }
    

    where you just need to figure out for a given vma / vmf passed to your fault function which page to map into userspace. This depends on exactly how your module works. For example, if you did

    my_buf = vmalloc_user(MY_BUF_SIZE);
    

    then the page you use would be something like

    vmalloc_to_page(my_buf + (vmf->pgoff << PAGE_SHIFT));
    

    But you could easily create an array and allocate a page for each entry, use kmalloc, whatever.

    [just noticed that my_fault is a slightly amusing name for a function]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have an facebook application running using the JS SDK. First user
Let's say I have a C++ Visual Studio 2010 solution with 2 projects: one
Let's say I have one class User, and it has a property of type
Let me frame it this way.. Say I have an application server running on
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say you create a wizard in an HTML form. One button goes back,
Let's say I've got two tables: one with customer data, one with location data.
Let's say i have two tables in db: Car and Part. Car owns arbitrialy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.