Skip to contentSkip to conversation

Memory mapped files question

DISCUSSION Bryan Shumsky 5 participants 7 messages Apr 14, 2003

lore
Share & tools
lore
#0 lore raw

Hi, everyone. I'm running into a problem that I hope someone else has seen, and maybe can help solve. We're using the mmap system function for memory mapped files, but our updates never get flushed until we munmap or msysnc. Are we missing something? Is there a tunable parameter in the kernel or filing system that can be set to flag these updates as 'write required'?

Any advice or suggestions would be appreciated.

Regards,

-- Bryan Shumsky
Director of Engineering
Via Systems, Inc.

#1 lore raw
Quoted 5 lines

Hi, everyone. I'm running into a problem that I hope someone else has seen, and maybe can help solve. We're using the mmap system function for memory mapped files, but our updates never get flushed until we munmap or msysnc. Are we missing something? Is there a tunable parameter in the kernel or filing system that can be set to flag these updates as 'write required'?

This was discussed about a week ago on either linux-kernel or linux-mm. The short answer is "yes, that's deliberate", but an archive search would probably be fruitful.

M.

#2 lore raw
Quoted 11 lines · Martin J. Bligh
Quoted 5 lines

Hi, everyone. I'm running into a problem that I hope someone else has seen, and maybe can help solve. We're using the mmap system function for memory mapped files, but our updates never get flushed until we munmap or msysnc. Are we missing something? Is there a tunable parameter in the kernel or filing system that can be set to flag these updates as 'write required'?

This was discussed about a week ago on either linux-kernel or linux-mm. The short answer is "yes, that's deliberate", but an archive search would probably be fruitful.

M.

Martin, something which was not mentioned last week (I've just checked).

It's OK if we never write to disk unless explicitely told, but will we writeback when we munmap?

Greets, Antonio.

#3 lore raw
Quoted 4 lines

Martin, something which was not mentioned last week (I've just checked).

It's OK if we never write to disk unless explicitely told, but will we writeback when we munmap?

Don't know for sure - you'd have to read the code (do_munmap) ... I couldn't see anything there at a quick glance. However, I'd guess we don't write it, as multiple people could have the file mapped, or we could remap it again from somewhere. Presumably the standard LRU will just flush it out.

M.

#4 lore raw
Followup to:  <11640000.1050332688@[10.10.2.4]>
By author:    "Martin J. Bligh" <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 11 lines
Quoted 5 lines

Martin, something which was not mentioned last week (I've just checked).

It's OK if we never write to disk unless explicitely told, but will we writeback when we munmap?

Don't know for sure - you'd have to read the code (do_munmap) ... I couldn't see anything there at a quick glance. However, I'd guess we don't write it, as multiple people could have the file mapped, or we could remap it again from somewhere. Presumably the standard LRU will just flush it out.

munmap() and fsync() or msync() will flush it to disk; there is no reason munmap() should unless perhaps the file was opened O_SYNC.

-hpa

Signature · 3 lines
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64
#5 lore raw
Quoted 10 lines · H. Peter Anvin

Followup to: <11640000.1050332688@[10.10.2.4]> By author: "Martin J.
Bligh" <[email protected]> In newsgroup: linux.dev.kernel

Quoted 4 lines
Quoted 4 lines

Martin, something which was not mentioned last week (I've just checked).

It's OK if we never write to disk unless explicitely told, but will we writeback when we munmap?

munmap() and fsync() or msync() will flush it to disk; there is no reason munmap() should unless perhaps the file was opened O_SYNC.

Wait a minute. Shouldn't a file opened O_SYNC flush the writes as they happen,
removing the requirement for any explicit syncing? If it doesn't there are some very broken apps around.

Chris

Signature · 4 lines
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: [email protected]
#6 lore raw
Quoted 9 lines · Chris Friesen
Quoted 3 lines

munmap() and fsync() or msync() will flush it to disk; there is no reason munmap() should unless perhaps the file was opened O_SYNC.

Wait a minute. Shouldn't a file opened O_SYNC flush the writes as they happen,
removing the requirement for any explicit syncing? If it doesn't there are some very broken apps around.

Not for mmap().

-hpa