From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935037AbbI2Qyp (ORCPT ); Tue, 29 Sep 2015 12:54:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35748 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932194AbbI2Qyh (ORCPT ); Tue, 29 Sep 2015 12:54:37 -0400 Date: Tue, 29 Sep 2015 18:51:27 +0200 From: Oleg Nesterov To: Ingo Molnar Cc: Linus Torvalds , Linux Kernel Mailing List , linux-mm , Andy Lutomirski , Andrew Morton , Denys Vlasenko , Brian Gerst , Peter Zijlstra , Borislav Petkov , "H. Peter Anvin" , Waiman Long , Thomas Gleixner Subject: Re: [PATCH 02/11] x86/mm/hotplug: Remove pgd_list use from the memory hotplug code Message-ID: <20150929165127.GA17319@redhat.com> References: <1442903021-3893-1-git-send-email-mingo@kernel.org> <1442903021-3893-3-git-send-email-mingo@kernel.org> <20150923114453.GA8480@redhat.com> <20150929084238.GA332@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150929084238.GA332@gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/29, Ingo Molnar wrote: > > * Oleg Nesterov wrote: > > > struct task_struct *next_task_with_mm(struct task_struct *p) > > { > > struct task_struct *t; > > > > p = p->group_leader; > > while ((p = next_task(p)) != &init_task) { > > if (p->flags & PF_KTHREAD) > > continue; > > > > t = find_lock_task_mm(p); > > if (t) > > return t; > > } > > > > return NULL; > > } > > > > #define for_each_task_lock_mm(p) > > for (p = &init_task; (p = next_task_with_mm(p)); task_unlock(p)) > > > > > > So that you can do > > > > for_each_task_lock_mm(p) { > > do_something_with(p->mm); > > > > if (some_condition()) { > > // UNFORTUNATELY you can't just do "break" > > task_unlock(p); > > break; > > } > > } > > > > do you think it makes sense? > > Sure, I'm inclined to use the above code from you. > > > In fact it can't be simpler, we can move task_unlock() into next_task_with_mm(), > > it can check ->mm != NULL or p != init_task. > > s/can't/can ? yes, sorry, > But even with that I'm not sure I can parse your suggestion. Got some (pseudo) code > perhaps? I meant struct task_struct *next_task_lock_mm(struct task_struct *p) { struct task_struct *t; if (p) { task_unlock(p); p = p->group_leader; } else { p = &init_task; } while ((p = next_task(p)) != &init_task) { if (p->flags & PF_KTHREAD) continue; t = find_lock_task_mm(p); if (t) return t; } return NULL; } #define for_each_task_lock_mm(p) for (p = NULL; (p = next_task_lock_mm(p)); ) Oleg.