lkml.org 
[lkml]   [2008]   [Mar]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][-mm] Memory controller add mm->owner
On Wed, Mar 26, 2008 at 3:29 AM, Balbir Singh <balbir@linux.vnet.ibm.com> wrote:
> >>
> >> - in the worst case, it's not going to be worse than doing a
> >> for_each_thread() loop
> >>
>
> This will have to be the common case, since you never know what combination of
> clone calls did CLONE_VM and what did CLONE_THREAD. At exit time, we need to pay
> a for_each_process() overhead.

I'm not convinced of this. All we have to do is find some other
process p where p->mm == current->mm and make it the new owner.
Exactly what sequence of clone() calls was used to cause the sharing
isn't really relevant. I really think that a suitable candidate will
be found amongst your children or your first sibling in 99.9% of those
cases where more than one process is using an mm.

The actual sequence would have to go something like:

static inline bool need_new_owner(struct mm_struct *mm) {
return (mm && mm->owner == current && atomic_read(&mm->users) > 1);
}
static inline void try_give_mm_ownership(
struct task_struct *task,
struct mm_struct *mm) {
if (task->mm != mm) return;
task_lock(task);
if (task->mm == mm) {
mm->owner = task;
}
task_unlock(task);
}

struct mm_struct *mm = current->mm;
task_lock(current);
current->mm = NULL;
task_unlock(current);

/* First try my children */
if (need_new_owner(mm)) {
for_each_child(current, c) {
try_give_mm_ownership(c);
if (!need_new_owner(mm)) break;
}
}

/* Then try my siblings */
if (need_new_owner(mm)) {
for_each_child(current->real_parent, c) {
try_give_mm_ownership(c);
if (!need_new_owner(mm)) break;
}
}

if (need_new_owner(mm)) {
/* We'll almost never get here */
for_each_process(p) {
try_give_mm_ownership(p);
if (!need_new_owner(mm)) break;
}
}

Paul


\
 
 \ /
  Last update: 2008-03-26 12:23    [W:0.447 / U:0.512 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site