LKML Archive mirror
 help / color / mirror / Atom feed
* How to find all the tasks with a Sys V shm?
@ 2006-03-07 18:41 Kamran Karimi
  2006-03-07 21:14 ` Hugh Dickins
  0 siblings, 1 reply; 2+ messages in thread
From: Kamran Karimi @ 2006-03-07 18:41 UTC (permalink / raw
  To: linux-kernel

Hello all,

In 2.2 kernels one could access the vma segments of a Sys V shared memory 
(shm) through:
shp->attaches. In 2.6 kernels a shm is managed through a file. The question 
is: given a Sys V  key value, how can we find all the tasks that have 
attached the corresponding shm?

We can do the following (with error checking ignored):

    id = ipc_findkey(&shm_ids, key);
    shp = shm_lock(id);

    tsk = find_task_by_pid(shp->shm_cprid);

    vma = tsk->mm->mmap;
    while(vma) {
                 if(vma->vm_file == shp->shm_file)
                  break;
                 vma = vma->vm_next;
    }
    shm_unlock(shp);

But here we only get the vma of the task that created the shm, and not any 
other task who has attached it.

How can we find all the vma structures that represent a shm?

-Kamran



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

* Re: How to find all the tasks with a Sys V shm?
  2006-03-07 18:41 How to find all the tasks with a Sys V shm? Kamran Karimi
@ 2006-03-07 21:14 ` Hugh Dickins
  0 siblings, 0 replies; 2+ messages in thread
From: Hugh Dickins @ 2006-03-07 21:14 UTC (permalink / raw
  To: Kamran Karimi; +Cc: linux-kernel

On Tue, 7 Mar 2006, Kamran Karimi wrote:
> 
> id = ipc_findkey(&shm_ids, key);
> shp = shm_lock(id);
> ...
> 
> But here we only get the vma of the task that created the shm, and not any
> other task who has attached it.
> 
> How can we find all the vma structures that represent a shm?

The simplest example to follow would be reset_vma_truncate_counts() in
mm/memory.c: shp->shm_file->f_mapping gives you the struct address_space *
mapping to pass to vma_prio_tree_foreach().  Ignore the i_mmap_nonlinear
lines, you can't get nonlinear shm (because shm_vm_ops lacks .populate).
You'll need to spin_lock(&mapping->i_mmap_lock) first, spin_unlock after.

Hugh

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

end of thread, other threads:[~2006-03-07 21:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-07 18:41 How to find all the tasks with a Sys V shm? Kamran Karimi
2006-03-07 21:14 ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).