linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Question:  mmotm-081207 - Should i_mmap_writable go negative?
@ 2008-12-09 20:47 Lee Schermerhorn
  2008-12-10 13:27 ` Hugh Dickins
  0 siblings, 1 reply; 5+ messages in thread
From: Lee Schermerhorn @ 2008-12-09 20:47 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins, linux-mm

I've been trying to figure out how to determine when the last shared
mapping [vma with VM_SHARED] is removed from a mmap()ed file.  Looking
at the sources, it appears that vma->vm_file->f_mapping->i_mmap_writable
counts the number of vmas with VM_SHARED mapping the file.  However, in
2.6.28-rc7-mmotm-081207, it appears that i_mmap_writable doesn't get
incremented when a task fork()s, and can go negative when the parent and
child both unmap the file.

I instrumented a couple of functions in mmap.c that increment and
decrement i_mmap_writable and then mapped a file sharable, fork(), and
unmapped the file in the parent and child, using my memtoy ad hoc test
program.  Here's what I see [again, on 2.6.28-rc7-mmotm-081207]--right
after boot, so my test file should have zero mappers:

--------

root@dropout(root):memtoy
memtoy pid:  3301
memtoy>file /tmp/zf1
memtoy>map zf1 shared

console:__vma_link_file:  vma: ffff8803fdc090b8 - mapping->i_mmap_writable: 0 -> 1

memtoy>child c1
memtoy:  child c1 - pid 3302

me: I would have expected to see i_mmap_writable incremented again here, but
me: saw no console output from my instrumentation.

memtoy>unmap zf1	# unmap in parent

console:__remove_shared_vm_struct:  vma: ffff8803fdc090b8 - mapping->i_mmap_writable: 1 -> 0
console:__remove_shared_vm_struct:  vma: ffff8803fdc090b8 - removed last shared mapping

memtoy>/c1 show
  _____address______ ____length____ ____offset____ prot  share  name
f 0x00007f000ae68000 0x000001000000 0x000000000000  rw- shared  /tmp/zf1

me:  child still has zf1 mapped

memtoy>/c1 unmap zf1	# unmap in child

console:__remove_shared_vm_struct:  vma: ffff8803fe5d3170 - mapping->i_mmap_writable: 0 -> -1

--------

So, the file's i_mmap_writable goes negative.  Is this expected?

If I remap the file, whether or not I restart memtoy, I see that it's
i_mmap_writable has remained negative:

-------
memtoy>map zf1		# map private [!shared] - no change in i_mmap_writable

console:__vma_link_file:  vma: ffff8805fd0590b8 - mapping->i_mmap_writable: -1 -> -1

memtoy>unmap zf1	# unmap:  no change in i_mmap_writable

console:__remove_shared_vm_struct:  vma: ffff8805fd0590b8 - mapping->i_mmap_writable: -1 -> -1

memtoy>map zf1 shared	# mmap shared, again

console:__vma_link_file:  vma: ffff8805fd0590b8 - mapping->i_mmap_writable: -1 -> 0

--------

I recall that this used to work [as I expected] at one time.

Lee




--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-12-10 22:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-09 20:47 Question: mmotm-081207 - Should i_mmap_writable go negative? Lee Schermerhorn
2008-12-10 13:27 ` Hugh Dickins
2008-12-10 15:48   ` Lee Schermerhorn
2008-12-10 20:48   ` [PATCH] fix mapping_writably_mapped() Hugh Dickins
2008-12-10 22:22     ` Lee Schermerhorn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox