Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5312703rwl; Tue, 11 Apr 2023 03:44:43 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXy/5vpLmyCnJrqrFlL3V0PFfJDxT796sSdFY43GByLptnhUOb16cqTawlipD1Ql9KXxQb X-Received: by 2002:a62:7b54:0:b0:634:9694:96b0 with SMTP id w81-20020a627b54000000b00634969496b0mr9085164pfc.33.1681209883019; Tue, 11 Apr 2023 03:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681209883; cv=none; d=google.com; s=arc-20160816; b=dj/BC7SeVnHEWd884yRQ8OFX3YO6uCMSjmosnX/39RTuYPjXqv5rLf5JtXnM2nTBPX PgvQ2YmrqrdRUSmWyrZCD3kEQXhH04HGteRgDnxrYDgW2aj9mwnzO+XBPm5AIQzqJPGe XaDb5cjG3cjhqE/WbpS2Ost5GjjahnzZLu3ITq4OYQGUJ8RU/dcoPN9kNPXNxqjQV9oK ZuW3P5xRrmyfBqN3uLA70sRBG1h8lvgpfRFpSPyUECglAs5gpPldG0hvRD2JTunzZhQy hpKo3J03E/xm5JIQruWeZfeDDIix1uSgyXKtu86onE5wfo2qjkOUSugWIRbZoioTjJUJ 3qOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PLqOn2HyQHOs+iLBUKsTfwgjognJqNpL2tZOST+MURo=; b=rnBElhkqiCLquoLOfoqZg/z3wHcQplMulsz5DcsmpJUDzbBboQNIClZ+h+cGbMZZ9I Sc44R2qL/0trueMNuRLrS0e/pvfhNRS2GZauhg6pbjMHmeNZW5756bV5PUPZ84iG439f apluy23JbMsTyRyBukWjYhkOsrAMUQdUaKmj2Hfe/evW+s6g9kdGsjmYNBYPh8/6OzYe F/3I6Z7Y+o2ESTtSmONFK7sPU6cNUZxTmI4CJNshRfo8RXM+EsM95qZ80VcRKCRUEeSL pC9tuZzwkg3zITu1mAHpDFvH6gCz+oUUOb0tX2sbAMoR/FtA4sVQd/zdpHYhIf44pWiO RWfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Ncvpfd0t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a636904000000b0050be42c6f04si12555907pgc.539.2023.04.11.03.44.31; Tue, 11 Apr 2023 03:44:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Ncvpfd0t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229706AbjDKKZv (ORCPT + 99 others); Tue, 11 Apr 2023 06:25:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbjDKKZu (ORCPT ); Tue, 11 Apr 2023 06:25:50 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A38F358D for ; Tue, 11 Apr 2023 03:25:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=PLqOn2HyQHOs+iLBUKsTfwgjognJqNpL2tZOST+MURo=; b=Ncvpfd0tUU+PoID3akHaVYyshB D84zQjyy0sa2DsB8+wThltqXk+WpzVzxju79viaoUZdq7GDfQ77SEvuuSNd8Qj42lH0Yksv86LxB1 qpfAUoB4MIcQRk16gxY+cq5i6Gaxe5gVw9knmUlWAEStO7QZFqJmcZOMS0Za2Uk/+Ic+dHhziY9UD iOSKA5yha/zzIk/ny+zc5CR/GnB4hEoO18zI9dOwuIWa1LSvvi/qQsAI2MTBLFXN+XZS44z/ylu1u 5SDctFpjIOLkpGiDcNhDoH5Bo3G/oZyq5dyN/m+LXWuRsc5yeCAG8ViyZz5S64sYkG6/DfbwfLdv5 vWYnpnDg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pmBBu-00DJru-0P; Tue, 11 Apr 2023 10:25:34 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D0B61300102; Tue, 11 Apr 2023 12:25:32 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B49C32CB52A23; Tue, 11 Apr 2023 12:25:32 +0200 (CEST) Date: Tue, 11 Apr 2023 12:25:32 +0200 From: Peter Zijlstra To: Mathieu Desnoyers Cc: linux-kernel@vger.kernel.org, Aaron Lu , Olivier Dion , michael.christie@oracle.com Subject: Re: [RFC PATCH v3] sched: Fix performance regression introduced by mm_cid Message-ID: <20230411102532.GA580235@hirez.programming.kicks-ass.net> References: <20230405162635.225245-1-mathieu.desnoyers@efficios.com> <386a6e32-a746-9eb1-d5ae-e5bedaa8fc75@efficios.com> <20230406095122.GF386572@hirez.programming.kicks-ass.net> <3b4684ea-5c0d-376b-19cf-195684ec4e0e@efficios.com> <20230411093705.GB578657@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230411093705.GB578657@hirez.programming.kicks-ass.net> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 11, 2023 at 11:37:05AM +0200, Peter Zijlstra wrote: > On Fri, Apr 07, 2023 at 09:14:36PM -0400, Mathieu Desnoyers wrote: > > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > > index bc0e1cd0d6ac..f3e7dc2cd1cc 100644 > > --- a/kernel/sched/sched.h > > +++ b/kernel/sched/sched.h > > @@ -3354,6 +3354,37 @@ static inline int mm_cid_get(struct mm_struct *mm) > > static inline void switch_mm_cid(struct task_struct *prev, struct task_struct *next) > > { > > + /* > > + * Provide a memory barrier between rq->curr store and load of > > + * {prev,next}->mm->pcpu_cid[cpu] on rq->curr->mm transition. > > + * > > + * Should be adapted if context_switch() is modified. > > + */ > > + if (!next->mm) { // to kernel > > + /* > > + * user -> kernel transition does not guarantee a barrier, but > > + * we can use the fact that it performs an atomic operation in > > + * mmgrab(). > > + */ > > + if (prev->mm) // from user > > + smp_mb__after_mmgrab(); > > + /* > > + * kernel -> kernel transition does not change rq->curr->mm > > + * state. It stays NULL. > > + */ > > + } else { // to user > > + /* > > + * kernel -> user transition does not provide a barrier > > + * between rq->curr store and load of {prev,next}->mm->pcpu_cid[cpu]. > > + * Provide it here. > > + */ > > + if (!prev->mm) // from kernel > > + smp_mb(); > > + /* > > + * user -> user transition guarantees a memory barrier through > > + * switch_mm(). > > + */ > > What about the user->user case where next->mm == prev->mm ? There > sys_membarrier() relies on finish_task_switch()'s mmdrop(), but we > can't. Ah, I suppose that's either a N->N or Y->Y transition and we don't care. Not the clearest comment though.