* [question] shm_nattch in sys_shmat?
@ 2003-01-31 22:35 Matthew Dobson
2003-02-03 19:48 ` Christoph Rohland
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Dobson @ 2003-01-31 22:35 UTC (permalink / raw)
To: linux-mm, William Lee Irwin III, Martin J. Bligh
Hello all!
In case it wasn't obvious from the subject, I've got a question about a
piece of code in ipc/shm.c:sys_shmat(), more specifically about the use
of the shm_nattch counter. This is supposed to be used to count the
number of times the shared memory segment has been attatched to a
processes adress space. For example, shm_open & shm_mmap both increment
shm_nattch, and shm_close decrements shm_nattch. I would be inclined to
think that sys_shmat should increment this counter, to keep track of a
new attatchment of the shared segment to a processes adress space.
sys_shmat, does in fact increment shm_nattch, but only to decrement it
again a few lines later, as seen in this code snippet. Can anyone
please explain why this is?
> file = shp->shm_file;
> size = file->f_dentry->d_inode->i_size;
>>> shp->shm_nattch++;
> shm_unlock(shp);
>
> down_write(¤t->mm->mmap_sem);
> if (addr && !(shmflg & SHM_REMAP)) {
> user_addr = ERR_PTR(-EINVAL);
> if (find_vma_intersection(current->mm, addr, addr + size))
> goto invalid;
> /*
> * If shm segment goes below stack, make sure there is some
> * space left for the stack to grow (at least 4 pages).
> */
> if (addr < current->mm->start_stack &&
> addr > current->mm->start_stack - size - PAGE_SIZE * 5)
> goto invalid;
> }
>
> user_addr = (void*) do_mmap (file, addr, size, prot, flags, 0);
>
>invalid:
> up_write(¤t->mm->mmap_sem);
>
> down (&shm_ids.sem);
> if(!(shp = shm_lock(shmid)))
> BUG();
>>> shp->shm_nattch--;
> if(shp->shm_nattch == 0 &&
> shp->shm_flags & SHM_DEST)
> shm_destroy (shp);
> else
> shm_unlock(shp);
> up (&shm_ids.sem);
Thanks!
-Matt
--
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [question] shm_nattch in sys_shmat?
2003-01-31 22:35 [question] shm_nattch in sys_shmat? Matthew Dobson
@ 2003-02-03 19:48 ` Christoph Rohland
2003-02-03 23:43 ` Matthew Dobson
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Rohland @ 2003-02-03 19:48 UTC (permalink / raw)
To: colpatch; +Cc: linux-mm, William Lee Irwin III, Martin J. Bligh
Hi Matthew,
On Fri, 31 Jan 2003, Matthew Dobson wrote:
> sys_shmat, does in fact increment shm_nattch, but only to
> decrement it again a few lines later, as seen in this code
> snippet. Can anyone please explain why this is?
sys_shmat temporarily increases shm_nattch to make sure it's never zero:
> >>> shp->shm_nattch++;
Make sure shm_nattch is greater than zero.
> > user_addr = (void*) do_mmap (file, addr, size, prot,
map the segment which increments shm_nattch in shm_mmap accounting for
the actual mapping
> >>> shp->shm_nattch--;
Correct it again.
Greetings
Christoph
--
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [question] shm_nattch in sys_shmat?
2003-02-03 19:48 ` Christoph Rohland
@ 2003-02-03 23:43 ` Matthew Dobson
0 siblings, 0 replies; 3+ messages in thread
From: Matthew Dobson @ 2003-02-03 23:43 UTC (permalink / raw)
To: Christoph Rohland; +Cc: linux-mm, William Lee Irwin III, Martin J. Bligh
Christoph Rohland wrote:
> Hi Matthew,
>
> On Fri, 31 Jan 2003, Matthew Dobson wrote:
>
>> sys_shmat, does in fact increment shm_nattch, but only to
>> decrement it again a few lines later, as seen in this code
>> snippet. Can anyone please explain why this is?
>
>
> sys_shmat temporarily increases shm_nattch to make sure it's never zero:
>
>
>> >>> shp->shm_nattch++;
>
>
> Make sure shm_nattch is greater than zero.
>
>
>> > user_addr = (void*) do_mmap (file, addr, size, prot,
>
>
> map the segment which increments shm_nattch in shm_mmap accounting for
> the actual mapping
>
>
>> >>> shp->shm_nattch--;
>
>
> Correct it again.
>
> Greetings
> Christoph
Ah ha... I hadn't followed the do_mmap call chain deep enough to
notice that it would call the shm_mmap call through the f_op function
pointer. Thanks for pointing that out. It makes much more sense now.
A small comment in there would make it *much* more obvious what is going on.
Cheers!
-Matt
--
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-02-03 23:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-31 22:35 [question] shm_nattch in sys_shmat? Matthew Dobson
2003-02-03 19:48 ` Christoph Rohland
2003-02-03 23:43 ` Matthew Dobson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox