Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.development.system > #807

Re: Linux/C/mmap(): Avoiding the flushing of memory mapped region created using mmap to the underlying file

From Richard Kettlewell <invalid@invalid.invalid>
Newsgroups comp.os.linux.development.system
Subject Re: Linux/C/mmap(): Avoiding the flushing of memory mapped region created using mmap to the underlying file
Date 2023-03-06 17:20 +0000
Organization terraraq NNTP server
Message-ID <wwvttyx94py.fsf@LkoBDZeT.terraraq.uk> (permalink)
References <f6078236-3464-4bb9-a6ce-f5e844ff6ca8n@googlegroups.com>

Show all headers | View raw


Pavankumar S V <pavankumarsv96@gmail.com> writes:
>           I am using mmap() to map device file "mtdblock0" into
> virtual address space of one process1. Some data whose value changes
> continuously for some time are stored in memory mapped region as
> well. I want to prevent these data changes to be flushed from memory
> mapped region to the device file for some time until the calculations
> are over(so that process2 which is mapping to the same file does not
> see these changes). Note: The same device file is mapped by another
> process also to read the data.
>
> Assuming that mmap() syncing works for the device files in the same
> way as for regular files, I tried setting "dirty_writeback_centisecs"
> to 0 to disable the kernel threads that perform the flushing. Then I'm
> setting "dirty_writeback_centisecs" to default value after some time
> to again enable the flushing. This is working partially. But the data
> is still getting flushed to the device file occassionally even when
> "dirty_writeback_centisecs" is 0. Please help me to know why this is
> not working.

The kernel will also flush if there is more than a certain number of
modified pages.

> Does the mmap() syncing works for the device files in the same way as
> for regular files?
>
> Are the same set of threads that are responsible for flushing the page
> cache are also responsible for flushing the memory mapped region to
> the underlying file?
>
> Files mapped using mmap() are directly mapped from the disk to the
> virtual address space of process. They don't use intermediate page
> cache. So any flushing done through msync() happens directly between
> memory map and disk. Is my understanding right?
>
> If this method is not possible, are there any other ways of achieving
> this?(I have tried mysnc() with INVALIDATE and it does not work)

I don’t think this is a viable strategy in its current form; you need
some explicit synchronization between the two processes.

-- 
https://www.greenend.org.uk/rjk/

Back to comp.os.linux.development.system | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Linux/C/mmap(): Avoiding the flushing of memory mapped region created using mmap to the underlying file Pavankumar S V <pavankumarsv96@gmail.com> - 2023-03-04 23:37 -0800
  Re: Linux/C/mmap(): Avoiding the flushing of memory mapped region created using mmap to the underlying file Richard Kettlewell <invalid@invalid.invalid> - 2023-03-06 17:20 +0000
    Re: Linux/C/mmap(): Avoiding the flushing of memory mapped region created using mmap to the underlying file Pavankumar S V <pavankumarsv96@gmail.com> - 2023-03-07 22:31 -0800
      Re: Linux/C/mmap(): Avoiding the flushing of memory mapped region created using mmap to the underlying file Richard Kettlewell <invalid@invalid.invalid> - 2023-03-08 08:53 +0000
        Re: Linux/C/mmap(): Avoiding the flushing of memory mapped region created using mmap to the underlying file Pavankumar S V <pavankumarsv96@gmail.com> - 2023-03-09 04:10 -0800

csiph-web