Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2616482rwl; Thu, 13 Apr 2023 08:41:17 -0700 (PDT) X-Google-Smtp-Source: AKy350YwgGe5PD/Rr/AjePUhQ3q+fUtbedjdRUM02czGT+lrxJ47z35xQgWNMRfV5hY3+ktlajwk X-Received: by 2002:a17:903:11c8:b0:1a1:d70f:712d with SMTP id q8-20020a17090311c800b001a1d70f712dmr2941682plh.31.1681400477357; Thu, 13 Apr 2023 08:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681400477; cv=none; d=google.com; s=arc-20160816; b=d6yKIXlFMYx4NbX5UHm1/46LhX022/DU485uG/olz0ZtdLX2A1w44fGZ6QKeSxfFB0 8JIGWB7h/ajJjJPy8o+2GkOBrT7aW/EDZnS0xwaKRRwcP8GuvrYRjanjrT6KqPozHGfC K7FFrtVhZeWrHOhQN7jnLJYtVMm9p8PiSxp9SAZwsIztmiEQCJ+NSZw1OZfiOJHXx8Jw 2UBnQLigedDHqLjE837DQtZ3K474aIM6BphbrM2MxAmKB7OC/0O5MZZ9Xe9GIGbxHBqJ Wzx3AaLg5R/12LbF38lPkA8BH6P7ZbI04DoViacvEwnNYdvOseX/3CdpK51YmaPud5Oz UaSw== 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=YxwcxtgYHGZOE+ya6d+nDvAn8xBxDll4jOU30fSbrro=; b=dQwLQ17hSiA522BHFOoAvisIAXPHY+qCOKB8SMdrPDbxNtc0GOXDnANyK+1N0aOLkR KY3d1ZRLmiwtdVoD2n4ElhI45Hx7SCaePoofttnL3VKPGhWTbyet4JKA68Q8lSZuYzJ+ WF6vKK60hRSNjii5EVLBVK5CUoNSkkuiqm6weXqy3DvASkDOkQ3O98xLxd4RA3f2/MJ6 JPO6PozJYGuWsBHl5L2yccKXuDKGomoKTTOvdEXyt0wyRasg0fNLpEBbPy5g6+SHESal X6xvPJgaMAi7gVGR8RGJ6N78/Qqy5oy5pWw+myV1nuNVUR7Y5Hk/SEAEvipBZjR9YwLF kkAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b="kHRYyY/4"; 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 pg2-20020a17090b1e0200b0024698bb03a6si2476170pjb.4.2023.04.13.08.41.06; Thu, 13 Apr 2023 08:41:17 -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="kHRYyY/4"; 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 S230083AbjDMPhW (ORCPT + 99 others); Thu, 13 Apr 2023 11:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbjDMPhU (ORCPT ); Thu, 13 Apr 2023 11:37:20 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08F971712 for ; Thu, 13 Apr 2023 08:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1681400238; bh=fjXZqkHXe19Tq3jXBylPeWy5W3C2ybEhSf4v5enAkPA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=kHRYyY/4mX79LTldODq//iWHMzCCbRR4zHH7NWBG0SnwOI0BkuxqQS0iTcKZ8Rw+7 EGMd8H+gPwXukd8KQjaKOlTtxk9dW3zjGpoThW3lAUrfGvhxR3+iErLzmbmKnxNPu6 7R58SRxg4nGdGZES61FPiqlrk6IQR0m1KXpmfnMIRjossMSeI8H4hpQP++GD2xrKON uc8tLrnJpDNhvmNkuLTaxB4mL5IZrhuSkfVNvnv9RpeG929fkiTyXj8O9etIlGfMbH B5rkX0Iudr5fKcFREaMvgLlrqjY2XLMk02N47/ktz3ZfsSRTYsYvDsnRAHl4XduBUM 2kYi2BkguA1Hw== 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 4Py3by1BmZzvJj; Thu, 13 Apr 2023 11:37:18 -0400 (EDT) Message-ID: <47f42d31-4b74-0273-62c1-0b75fffbf066@efficios.com> Date: Thu, 13 Apr 2023 11:37:18 -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 v4] sched: Fix performance regression introduced by mm_cid Content-Language: en-US To: Peter Zijlstra Cc: Aaron Lu , linux-kernel@vger.kernel.org, Olivier Dion , michael.christie@oracle.com References: <20230410150150.2179062-1-mathieu.desnoyers@efficios.com> <20230411045225.GA3509@ziqianlu-desk2> <20230411131221.GA7356@ziqianlu-desk2> <20230412091043.GC4253@hirez.programming.kicks-ass.net> <20230412114240.GA155547@ziqianlu-desk2> <20230412142616.GI628377@hirez.programming.kicks-ass.net> <20230412143934.GB162902@ziqianlu-desk2> <20230413111047.GB83892@hirez.programming.kicks-ass.net> <6b8e63ab-e81e-470c-e03f-f3860c83bdb1@efficios.com> <20230413152023.GO4253@hirez.programming.kicks-ass.net> From: Mathieu Desnoyers In-Reply-To: <20230413152023.GO4253@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham 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-13 11:20, Peter Zijlstra wrote: > On Thu, Apr 13, 2023 at 09:56:38AM -0400, Mathieu Desnoyers wrote: > >>> Mathieu, WDYT? -- other than that the patch is an obvious hack :-) >> >> I hate it with passion :-) >> >> It is quite specific to your workload/configuration. >> >> If we take for instance a process with a large mm_users count which is >> eventually affined to a subset of the cpus with cpusets or >> sched_setaffinity, your patch will prevent compaction of the concurrency ids >> when it really should not. > > I don't think it will, it will only kick in once the higest cid is > handed out (I should've used num_online_cpus() instead of nr_cpu_ids), > and with affinity at play that should never happen. So in that case, this optimization will only work if affinity is not set. E.g. a hackbench with cpuset or sched_setaffinity excluding one core from the set will still be slower. > > Now, the more fancy scheme with: > > min(t->nr_cpus_allowed, atomic_read(&t->mm->mm_users)) > > that does get to be more complex; and I've yet to find a working version > that doesn't also need a for_each_cpu() loop on for reclaim :/ Indeed. And with a allowed cpus approach, we need to carefully consider what happens if we change a allowed cpu mask from one set to another set, e.g, from allowing cpus 0, 1 to allowing only cpus 2, 3. There will be task migration, and we need to reclaim the cids from 0, 1, but we can very well be in a case where the number of mm_users is above the number of allowed cpus. > > Anyway, I think the hack as presented is safe, but a hack none-the-less. I don't think it is _unsafe_, but it will only trigger in specific scenarios, which makes it harder to understand more subtle performance regressions for scenarios that are not covered by this hack. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com