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 7430473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:08:46+00:00 2026-05-29T09:08:46+00:00

I have a kernel module that allocates a large buffer of memory, this buffer

  • 0

I have a kernel module that allocates a large buffer of memory, this buffer is then mmap-ed into userspace.
The module recieves some data from hardware, and then puts the new data into the buffer with a flag in front of it. (memory is initialized to zero, flag is 1).

The userspace program reads the flag in a loop before returning a pointer to valid data

simplified version of the code:

uint8_t * getData()
{
    while(1)
   {
      if(*((volatile uint32_t*)this->buffer) == 1)
          return this->buffer+sizeof(uint32_t);
   }
}

the memory region is mapped as shared and a full buffer memory dump confirms that the buffer is written to correctly.

The problem is that after a certain number of correct reads, this function stops returning.
Could this be due to CPU caching? Is there a way to circumvent that and make sure that the read is made directly from RAM each time and not from cache?

  • 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-05-29T09:08:48+00:00Added an answer on May 29, 2026 at 9:08 am

    Yes it’s likely due to the cpu cache on the reader side. One might think the “volatile” keyword should protect against this sort of problem but that’s not quite right since volatile is simply a directive to the compiler not to registerize the variable, not quite the same thing as directing the cpu to read directly from main memory every time.

    The problem needs to be solved on the write side. From your description, it sounds like the write is happening in the kernel module and read from the user side. If these two operations are happening on different cpus (different caching domains), and there’s nothing to trigger a cache invalidation on the read side, you’ll get stuck on the read side as you are describing. You need to force a store buffer flush on the linux kernel after your store instruction. Assuming it’s the linux kernel, inserting a call to smp_mb right after you’ve set the flag and the value from the module will most likely do the right thing on all architectures.

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

Sidebar

Related Questions

I'm trying to debug kernel module. I suspect to have there some memory leaks.
I have a kernel module that provides data to a userland process through read().
On an x86 system, I have a Linux kernel module (watcher module) that gets
I have a module that I load it by Kernel when my application starts
I have a problem loading a kernel module, there is a large data structure,
I'm trying to code some basic kernel module - userspace program communication using netlink
I have a kernel module that needs to have access to the kernel's _stext
I writing a linux kernel module that does some work with /proc... I'm trying
I have the following code in a kernel module that walks up the process
I am looking to get into operating system kernel development and figured and have

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.