Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2857464lqp; Mon, 25 Mar 2024 11:09:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWm99AVHZtJwVqcUV3tX1aPsG+qJp200OKm5TlIaLP8FEuIZc+k9CpyqViwh2O7P7KlxjEE9jpBmxprRQmq77mcGDbSChK4/2iqYjRxEw== X-Google-Smtp-Source: AGHT+IHKKXtGG4cw+HVLlWME2XalzC4us8cPW6qLreFvxUTUt4U5Z5gIeh0R8cxRDFz3Md+2Ns5u X-Received: by 2002:a17:906:1401:b0:a46:635b:bb3e with SMTP id p1-20020a170906140100b00a46635bbb3emr4374841ejc.52.1711390194982; Mon, 25 Mar 2024 11:09:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711390194; cv=pass; d=google.com; s=arc-20160816; b=wwYiz4xXFANPR6SJ3HhnS8D0hZPwZZXrWRXR3Ll76rbDJ5NF4s/0KMpiRcnNerEkYW XKbi6NZ+nvfk5glxYW2fCWpEF+wD67jn8YOoJnGDAM/mDMbxQlrLCUSDNXhlmpA8nfAw zKGqm6UVEozk6jstpIv+7pCStgsDMU2daRW51U8oWXOKxTBYsPNV5heECpduZGOFvipP K2fAO+mVR/y6nZ8JEYHAZ+Gj1oebm4ygnymSJFCOLQJYQCLt18z+aRvVP2UfxXSgWvYg f/eSPXa9jt01aCy699GbjtlONN++AFDiRMoHEjQIQ3ZOiEoALpwqqs1vNCQ6mM79JnBf 8iiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=Sa3z2217X6fUx6p/cBiZWKstN9/uVhy7ssYwZcnFGPU=; fh=vvqSKaptSfoNb2PxtYEZP64R1qpLIhbA8ZfZg/6EgWM=; b=BbYa1St3zgCGNEYDGdeEyR8NehwGV9BlDdwFVXiod8MHMfnrizsyeY2y3GwXnUNJCo rOGKMgsywvOIv90od6sFMuPm89LBIzEYWflqvxqYukco54QhSWiOGagi88nJlZQ8ul4r VaFO/c1DerTwIb4Tl9cJ0SFJEiDu0unCB5apwAIY6RCFpKyylhClWtdvU+3NxXNMvtqs KukksZZwRUtfpbAi+f2VyghkgjcEPKc6cxvvnyeYa0f8TURJ1uV1s/pUREyzhr+yN0aL KY9ykPfne21ApJsmK8NxinrprUj6zXsiQD1Ip5ZvXW1cK8ucxxhENY4fWBm+2DW3ME+n UJjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ieauYavy; arc=pass (i=1 spf=pass spfdomain=flex--peternewman.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-117602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o16-20020a17090637d000b00a462acefc47si2710957ejc.871.2024.03.25.11.09.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 11:09:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ieauYavy; arc=pass (i=1 spf=pass spfdomain=flex--peternewman.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-117602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D92381F673E5 for ; Mon, 25 Mar 2024 18:08:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 698DF1311A0; Mon, 25 Mar 2024 17:27:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ieauYavy" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB24F130E5D for ; Mon, 25 Mar 2024 17:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711387669; cv=none; b=B/cHU+hL/42F96ySS2IDIxeVCGaWU9bIkxxMJoVHfcbyl5vQKIavAnsG0HoRp/W7nTOZVnwkWqd1fEf01Q0hMPhDOmzqQNObTFMrXyFffjPh3x0FjpCW8weWikMuvI+xDBZU/5UB3Djuww7hB23FGXgb0YJi/wCYqc0d8Ujc0rc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711387669; c=relaxed/simple; bh=yTMbYEK5awdComl/ezDEyjlZWsoayimTaKfd0CBe8zE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VCJK4/5851Ahy4/lY3V70NGY4jS66WpwElB62MiOo41MMYp6a1kKd0ik8UDAlktn5SfNlu3TEPh4OQSwJMnzWk//xGCxoRf7nuprs8YloFxdVQcdgGZTeS56EELZYJ7gfqlfXSlaQpAjwkwIPaNtfyq0XikU6ejJj4kP6fw+a2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--peternewman.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ieauYavy; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--peternewman.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcbfe1a42a4so8683403276.2 for ; Mon, 25 Mar 2024 10:27:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711387666; x=1711992466; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Sa3z2217X6fUx6p/cBiZWKstN9/uVhy7ssYwZcnFGPU=; b=ieauYavyZvxryp7MsmLBEGUgJQ4Eiyzz24lxTemWYG27K7NPLTGBU4vfuxh6/vOoqw duFzqs47tuEPn0E/ENrX1XDsbkA6uWGeONWdIu5ROtNF85+Box37JCvXIobNOATtIXWr LHm3P1DMqaRPah+AxisbFCtPNprRj6LZ0IrlrfaEOp6YdnAiZ4ExxlgIE3So8XJZWQJy 2CiK0TIDeD+CwbTQTPZECRTfCT6r7R0Ah2u6vjob8BkElunsT2yhiBYSCfa0qhNOYMx7 +Q7hqdk3T8xEdp2C29s6s52AR2Y28KLaPTzmt3QV94aZeALo/nr1KTlWJ6efqjtp1uPq pI1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711387666; x=1711992466; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Sa3z2217X6fUx6p/cBiZWKstN9/uVhy7ssYwZcnFGPU=; b=p+lhhojV/ZNt3RBq/cQ4jVENy1wiKA6l9os7SJ15q0Q1Em7MAEeLWVmThuwwp3zcY4 kzo9BrOjboGa/GB8qyWDnK57oxy7yy6qo8HJ7SDdgSyBKk1GV506PsgDQ6/21GH4ev4a a4niUu7V5kGQ+4Ne1eR3WkbYD3flpcs5a+xMfn7WbGLt4tTlaCDyorRlaDECXHUzsh+x mShrQzZ6juOyxn8DfphlEKc1r9qJSDZN8ElbZczm/Lkk2AnB0UmPauN9fRQ27Et02hcc d5vEzlmEG8HD13zKTPzdUspiQisYZxk1PUYNOdVBBaPPf8ULe0X4rl/g4uMCLmLvHMoP oBVw== X-Forwarded-Encrypted: i=1; AJvYcCVGJvo9EjcpPHNRzrX6KpUksz5TDuqyeSmMtryTcuRqSE0T0BGsAW6PF3j82PlNRdG09LbeWpkqL832B1CHVA4FJS7kewX0p42hLg27 X-Gm-Message-State: AOJu0YwaDrD9RAu0S3US8T30A8ILTssXlt18+muHIcLjy09kO1Xloh1B xralWucySkCD16Wv5XoPq1Ph4eFUZfEYx6Podhc09JIFg4h1W9b5NHTV3svH2ngNx73Muxa1wEm YVi2BYJ+ViFMKuJa4ay/s6g== X-Received: from peternewman-us.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3dcc]) (user=peternewman job=sendgmr) by 2002:a05:6902:2388:b0:dcc:5a91:aee9 with SMTP id dp8-20020a056902238800b00dcc5a91aee9mr2359571ybb.7.1711387666713; Mon, 25 Mar 2024 10:27:46 -0700 (PDT) Date: Mon, 25 Mar 2024 10:27:07 -0700 In-Reply-To: <20240325172707.73966-1-peternewman@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240325172707.73966-1-peternewman@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Message-ID: <20240325172707.73966-7-peternewman@google.com> Subject: [PATCH v1 6/6] x86/resctrl: Don't search tasklist in mongroup rename From: Peter Newman To: Fenghua Yu , Reinette Chatre , James Morse Cc: Stephane Eranian , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Uros Bizjak , Mike Rapoport , "Kirill A. Shutemov" , Rick Edgecombe , Xin Li , Babu Moger , Shaopeng Tan , Maciej Wieczor-Retman , Jens Axboe , Christian Brauner , Oleg Nesterov , Andrew Morton , Tycho Andersen , Nicholas Piggin , Beau Belgrave , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Peter Newman Content-Type: text/plain; charset="UTF-8" Iterating over all task_structs while read-locking the tasklist_lock results in significant task creation/destruction latency. Back-to-back move operations can thus be disastrous to the responsiveness of threadpool-based services. Now that the CLOSID is determined indirectly through a reference to the task's current rdtgroup, it is not longer necessary to update the CLOSID in all tasks belonging to the moved mongroup. The context switch handler just needs to be prepared for concurrent writes to the parent pointer. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 +++++++------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index bd067f7ed5b6..a007c0ec478f 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -388,8 +388,11 @@ void __resctrl_sched_in(struct task_struct *tsk) * by a full barrier and synchronous IPI * broadcast before proceeding to free the * group. + * + * parent can be concurrently updated to a new + * group as a result of mongrp_reparent(). */ - closid = rgrp->mon.parent->closid; + closid = READ_ONCE(rgrp->mon.parent)->closid; } else { closid = rgrp->closid; } @@ -3809,8 +3812,7 @@ static int rdtgroup_rmdir(struct kernfs_node *kn) * Monitoring data for the group is unaffected by this operation. */ static void mongrp_reparent(struct rdtgroup *rdtgrp, - struct rdtgroup *new_prdtgrp, - cpumask_var_t cpus) + struct rdtgroup *new_prdtgrp) { struct rdtgroup *prdtgrp = rdtgrp->mon.parent; @@ -3825,13 +3827,10 @@ static void mongrp_reparent(struct rdtgroup *rdtgrp, list_move_tail(&rdtgrp->mon.crdtgrp_list, &new_prdtgrp->mon.crdtgrp_list); - rdtgrp->mon.parent = new_prdtgrp; + WRITE_ONCE(rdtgrp->mon.parent, new_prdtgrp); rdtgrp->closid = new_prdtgrp->closid; - /* Propagate updated closid to all tasks in this group. */ - rdt_move_group_tasks(rdtgrp, rdtgrp, cpus); - - update_closid_rmid(cpus, NULL); + update_closid_rmid(cpu_online_mask, NULL); } static int rdtgroup_rename(struct kernfs_node *kn, @@ -3839,7 +3838,6 @@ static int rdtgroup_rename(struct kernfs_node *kn, { struct rdtgroup *new_prdtgrp; struct rdtgroup *rdtgrp; - cpumask_var_t tmpmask; int ret; rdtgrp = kernfs_to_rdtgroup(kn); @@ -3909,16 +3907,6 @@ static int rdtgroup_rename(struct kernfs_node *kn, goto out; } - /* - * Allocate the cpumask for use in mongrp_reparent() to avoid the - * possibility of failing to allocate it after kernfs_rename() has - * succeeded. - */ - if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) { - ret = -ENOMEM; - goto out; - } - /* * Perform all input validation and allocations needed to ensure * mongrp_reparent() will succeed before calling kernfs_rename(), @@ -3927,9 +3915,7 @@ static int rdtgroup_rename(struct kernfs_node *kn, */ ret = kernfs_rename(kn, new_parent, new_name); if (!ret) - mongrp_reparent(rdtgrp, new_prdtgrp, tmpmask); - - free_cpumask_var(tmpmask); + mongrp_reparent(rdtgrp, new_prdtgrp); out: mutex_unlock(&rdtgroup_mutex); -- 2.44.0.396.g6e790dbe36-goog