On Monday, 6 March 2023 at 22:50:28 UTC+5:30, Richard Kettlewell wrote:
> Pavankumar S V <
pavanku...@gmail.com> writes:
Thanks for your inputs.
> The kernel will also flush if there is more than a certain number of
> modified pages.
Yes. In combination with "dirty_writeback_centisecs", I had also tried increasing the values of kernel parameters "dirty_background_ratio", "dirty_ratio" to large values to increase the number of dirty pages that can be kept in memory before flushing to disk.
But this also did not work.
> I don’t think this is a viable strategy in its current form; you need
> some explicit synchronization between the two processes.
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.
As per my understanding, since shared memory object "prevent_read" uses the mmap() concept, again kernel has to do the flushing of data from the memory mapped region to the shared memory object "prevent_read".
So whenever process1 writes '1' to ""prevent_read", it actually writes to the memory mapped region of process1. So kernel has to do the flushing from memory mapped region to shared memory object "prevent_read". If this flushing is delayed, then process2 can read
'0' from "prevent_read" and can access "mtdblock0" until the flushing is completed. So this mechanism is failing sometimes.
Is there any way to do flushing immediately that will help in this case? (I tried msync, but msync is not syncing because msync's behavior is undefined if used on a shared memory object as per the man page.)
Thanks in Advance.
> --
>
https://www.greenend.org.uk/rjk/