Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5483031rwl; Tue, 11 Apr 2023 06:12:28 -0700 (PDT) X-Google-Smtp-Source: AKy350bMktTf8ucXYNpmk75FHkZenH5fPNTtAeWrk6xacmj2oHrLIrfcBLKsf3Lo4VCjYFi5lJIO X-Received: by 2002:aa7:c608:0:b0:4fb:80cf:89e6 with SMTP id h8-20020aa7c608000000b004fb80cf89e6mr8292278edq.8.1681218748541; Tue, 11 Apr 2023 06:12:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681218748; cv=none; d=google.com; s=arc-20160816; b=WDnn41oMnbgiojslUTpvul4ecQZLhLXWkvZczeT9o33POUT3FKFJq/IF70wIYhsG8s jS1xy3Ge/SxjnoWUtBs8shFLrqm2SLLQtb0jAW0bF97RHEow6eLgaBYv6IosQVkH6rot a1dKk7VMfZqi+c8IV27gqFtE+VIP/aBcZ/eVpCVdOQ67VXrYHH4S05dcpAwGVdZjBt1C GEhon+TRI73wayzypAI4IwryRVC6jnaU6fTMUxhXhmXGozw2hPVI+Sh9rIyYBUuZIpTf Jxmdl+PNzYOzv+B9OduCdH7M/82WH6FPy/LoGFg/WSMptTvclL7kBc9m+2M85qEWYDvD d8rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=NBx4mqd0NFtfwppHJL++TSzb0Baer6Kkn/nnYP2tRoQ=; b=nTW0oCPHCks/ECILFezmkyFQxYE6pGeyDsEcgNX49JeLZ1Q9q0JAVnIpnBfBcUsxip u7E8aWeC03sBIz9rdAlIh0RJ4zZaeo9Eo0Wr5abPocWcTnJ7uocLZiLJyw4eqVfCoY7g 8JJkuxyartMdm1wlvK8LJ9X3l2yuNaKysjmDU++pikQFLCwfOBclelohVH+w4PP/45co DhY4RLsp8YbMU9EtO2PdxTd4VcirL8gTgP9yuip2hSnbCcSlcMtGaSpSN9tXbnlHkC3b Z+OGE0Z2C0PjDaaPvXWTNdoqbTZvm9hopZSJLXEU3/vvUaJq+hejO9hu1Z7mp5+V8oVc rZJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=gPXDLOW2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a056402068300b00504b3e0d1d0si281036edy.231.2023.04.11.06.12.01; Tue, 11 Apr 2023 06:12:28 -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=@efficios.com header.s=smtpout1 header.b=gPXDLOW2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230302AbjDKNKT (ORCPT + 99 others); Tue, 11 Apr 2023 09:10:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjDKNKO (ORCPT ); Tue, 11 Apr 2023 09:10:14 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 400C34691 for ; Tue, 11 Apr 2023 06:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1681218611; bh=F4WwQC4ssFxJtwjW/TnXAnGUbfZVX9MmC9hHRnJil/k=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=gPXDLOW2v+xI5Io3c1VmebBRotqPAv9B6jeMs+h8Bdjcz+BSTkqp76NU1NAi/hDDZ hkhHdjmMdERL8/gv7T7uMh9N7gfrD6Mx/6QVULxDKrjSzLKANQEpIFulHRwvKmvdRb xYrF0sYjkuKp+5TH9+6VLbdk7/OmclTkKaDCpG7uocU8Qv9zgz8aSh1m0RwGrPUS50 1tSYcPXY03xj5f9uZT7jDILXO2nqMYgkWnvHj/R3D/Fbi+84oWRFcGk/NPOd2zT/uV vEzfhcvwXE3o3wGDEPPgDhjbBUxbGoj1iy57HMm8a++UL02ghu4jHLLLTjS5VBm4Ql 8I7L9kP1SRzYg== Received: from [172.16.0.188] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4PwmR65HddzvR0; Tue, 11 Apr 2023 09:10:10 -0400 (EDT) Message-ID: Date: Tue, 11 Apr 2023 09:10:10 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [RFC PATCH v3] sched: Fix performance regression introduced by mm_cid Content-Language: en-US To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Aaron Lu , Olivier Dion , michael.christie@oracle.com 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> <20230411102532.GA580235@hirez.programming.kicks-ass.net> From: Mathieu Desnoyers In-Reply-To: <20230411102532.GA580235@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS 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 2023-04-11 06:25, Peter Zijlstra wrote: > 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. For sake of completeness, here is the updated comment: /* * user -> user transition guarantees a memory barrier through * switch_mm() when current->mm changes. If current->mm is * unchanged, no barrier is needed. */ Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com