vm: weird behaviour when munmapping
Hmm, I'm probably missing something but I don't see what. Please be nice even if the question is really stupid ;)
I'm looking at mmap.c code and to understand it I decided to implement a dumb char device that implement its own foo_mmap() method. In this method it defined its own vma ops:
static void foo_vma_open(struct vm_area_struct *vma) static void foo_vma_close(struct vm_area_struct *vma)
A dumb application mmap the device in order to make foo_mmap() install the vma ops.
mmap(NULL, 16384, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
mmap returned 0x2aaae000 for example. Until now, foo_vma_open() and foo_vma_close() are not called.
Now I want to unmap the first part of the previous mapping to see how vma ops are called. So I did:
munmap(0x2aaae000, 1024);
and here's what happen:
foo_vma_open(vma) is called with:
vma->vm_start = 0x2aaae000
vma->vm_end = 0x2aaaf000
foo_vma_close(vma) is called with:
vma->vm_start = 0x2aaae000
vma->vm_end = 0x2aaaf000However I would have expected:
foo_vma_open(vma) is called with:
vma->vm_start = 0x2aaaf000
vma->vm_end = 0x2aaab2000
foo_vma_close(vma) is called with:
vma->vm_start = 0x2aaae000
vma->vm_end = 0x2aaaf000Can anybody tell me why I get this behaviour ?
thanks
Francis
___________________________________________________________________________
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions !
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses
http://fr.answers.yahoo.com
Quoted 43 lines · moreau francis
Hmm, I'm probably missing something but I don't see what. Please be nice even if the question is really stupid ;)
I'm looking at
mmap.ccode and to understand it I decided to implement a dumb char device that implement its ownfoo_mmap()method. In this method it defined its own vma ops:static void
foo_vma_open(struct vm_area_struct *vma)static voidfoo_vma_close(struct vm_area_struct *vma)A dumb application mmap the device in order to make
foo_mmap()install the vma ops.mmap(NULL, 16384, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);mmap returned
0x2aaae000for example. Until now,foo_vma_open()andfoo_vma_close()are not called.Now I want to unmap the first part of the previous mapping to see how vma ops are called. So I did:
munmap(0x2aaae000, 1024);and here's what happen:
foo_vma_open(vma) is called with: vma->vm_start = 0x2aaae000 vma->vm_end = 0x2aaaf000 foo_vma_close(vma) is called with: vma->vm_start = 0x2aaae000 vma->vm_end = 0x2aaaf000However I would have expected:
foo_vma_open(vma) is called with: vma->vm_start = 0x2aaaf000 vma->vm_end = 0x2aaab2000 foo_vma_close(vma) is called with: vma->vm_start = 0x2aaae000 vma->vm_end = 0x2aaaf000
Quoted 2 lines
Can anybody tell me why I get this behaviour ?
Chapter 15. Section 'Virtual Memory Areas'.
Basically; vm_ops->open() is not called on the first vma. With this munmap() you split the area in two, and it so happens the new vma is the lower one.