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.
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)
Pavankumar S V <pavanku...@gmail.com> writes:
The kernel will also flush if there is more than a certain number of modified pages.
I don’t think this is a viable strategy in its current form; you needI am trying now with explicit synchronization mechanism like this:
some explicit synchronization between the two processes.
--
https://www.greenend.org.uk/rjk/
I am trying now with explicit synchronization mechanism like this:
1) Created a shared memory object of size 1 byte in /dev/shm(let's
consider its name as "prevent_read"). Memory mapped this to the
virtual address space of both the processes.
2) When I want to prevent the process2 from reading "mtdblock0"
region, then I'm writing "prevent_read" with '1' from process1.
3) process2 checks "prevent_read"(value is set as 1 by process1)
before reading "mtdblock0" region and it should not read.
4) After some time, process1 writes '0' to "prevent_read".
5) process2 checks "prevent_read"(value is set as 0 by process1)
before reading "mtdblock0" region and it should be able to read.
But above mechanism is also not working. Note: Both process1 and
process2 are independent processes running on different cores.
Pavankumar S V <pavanku...@gmail.com> writes:
That has a time-of-check/time-of-use bug even on a single core, and there’s no chance it’ll work across multiple cores due to the lack of memory synchronization.
By synchronization mechanism I mean something like fctnl with F_SETLK,
or pthread_mutex_lock (with a mutex initialized with PTHREAD_PROCESS_SHARED).
--
https://www.greenend.org.uk/rjk/
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 31:01:13 |
Calls: | 6,707 |
Files: | 12,239 |
Messages: | 5,353,038 |