Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1845291pxb; Fri, 5 Mar 2021 00:38:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJyV+aKg2ju41tpqERuF4U7sZVO3b7Y7je0couei5bXMHvR0HQHGTbT7CKTJWxOredv3isXY X-Received: by 2002:a05:6602:2008:: with SMTP id y8mr7087276iod.48.1614933534577; Fri, 05 Mar 2021 00:38:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614933534; cv=none; d=google.com; s=arc-20160816; b=ePLRfSGEdrnjJu4W4J95HT4FL0a3M0GieukrMMnqwBDpey44ebIt5dorgHzE3TF+Da bedYDYqO5+lMMbImBa/syp+h+KugCwGAZIiZXl/dYc+fAXP/elo9eJTw/7idpd4EgySD YhN6K80rDGLfsXQnRBkqRYpOAKE+sk72Drg1Bo0xo422itkM4noI4VdwG5BMWGOmVjQc Mlw+8DF2L8BoRWq6UPVdAIbKlQLLVvc5N0Hx61GgYZyOvw+lCqqpDE2Nz+e0x2q9bJPN bPMPyOGlsRiwE3Cbr4a34btqNOykueX69VCi/KAlQ3jPgvzOIx7D5Ts/xjWQJpbMT3bn AYJQ== 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=4o8nFaUqdE3XidEkNAZS9FXz8f1fPatJYS1B5VPdZWg=; b=jY6fCYE5KagEFNNudOT/NzcBVT6P50Qx1Vk5Y6ldeSwZp+ILm1CfZHmikxgSgr7FWJ KYlYze3xABqDzzQSLx/29D1PCezaRIFAgQ8n5QnJ3vw3/lTZCS6OHr1FMrhg9cNUAXar IqXTzvkeMcDBUSaWQS3myFDFIrTAuZXnCjk6biioiW5zoV3X4t+JzeEkr7JS3l7aFOvd VVf0+9X5TkByr/41CCdHFTlohUJqDFci4MMnKWf23fu/6hp7XIqcl3aT7c/8k6TEiajZ 9WtIJYj6WfygR2uISV7g+zjPVYUt9idHKN7kepGB1uJI59gTUmazcNm2dx5E5CTXiAQ/ qLQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=vx3tzdqH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v7si1986956jat.21.2021.03.05.00.38.41; Fri, 05 Mar 2021 00:38:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=vx3tzdqH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229526AbhCEIhE (ORCPT + 99 others); Fri, 5 Mar 2021 03:37:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbhCEIgs (ORCPT ); Fri, 5 Mar 2021 03:36:48 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F83CC061574 for ; Fri, 5 Mar 2021 00:36:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=4o8nFaUqdE3XidEkNAZS9FXz8f1fPatJYS1B5VPdZWg=; b=vx3tzdqHWopV7m2mf3R2uMIZLz jyvOHTaQlnsPaIBaxI17YADAwkSgwZcbR/oSX1fOOuLiNqnXyixRHA7+CgHqMh0nu3hckW5Y6Px9G +Rsd9okcPpiCUH/QOhlCjvmypAjSIch7EWzPkx5eJ5kMCBficpUVXtE2DRHE9OOTLqkKNaik/8zxR Vi/XuQZh0cNoyiYOMV23g96+huqGeImyGPUOHYoOFFtkBWjWuF+k0DO+ntqbzdnsexDNUhPq+TQUt pBAHbApsVLEqJo7Y9BcD+p7VYeRlvSpoLmr/zklVcB8ZxY5y1Oke80NcPvpfZlli5P6bKKN89B88V quIuRi0A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lI5wn-00ArwV-Ca; Fri, 05 Mar 2021 08:36:36 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 991113011E6; Fri, 5 Mar 2021 09:36:30 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7E0202BA960C6; Fri, 5 Mar 2021 09:36:30 +0100 (CET) Date: Fri, 5 Mar 2021 09:36:30 +0100 From: Peter Zijlstra To: Linus Torvalds Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Linux Kernel Mailing List Subject: Re: "struct perf_sample_data" alignment Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 04, 2021 at 07:45:44PM -0800, Linus Torvalds wrote: > That ____cacheline_aligned goes back many years, this is not new, it > seems to come from back in 2014: commit 2565711fb7d7 ("perf: Improve > the perf_sample_data struct layout"). long time ago... > But it really seems entirely and utterly bogus. That cacheline > alignment makes things *worse*, when the variables are on the local > stack. The local stack is already going to be dirty and in the cache, > and aligning those things isn't going to - and I quote from the code > in that commend in that commit - "minimize the cachelines touched". > > Quite the reverse. It's just going to make the stack frame use *more* > memory, and make any cacheline usage _worse_. IIRC there is more history here, but I can't seem to find references just now. What I remember is that since perf_sample_data is fairly large, unconditionally initializing the whole thing is *slow* (and -fauto-var-init=zero will hurt here). So at some point I removed that full initialization and made sure we only unconditionally touched the first few variables, which gave a measurable speedup. Then things got messy again and the commit 2565711fb7d7 referenced above was cleanup, to get back to that initial state. Now, you're right that __cacheline_aligned on on-stack (and this is indeed mostly on-stack) is fairly tedious (there were a few patches recently to reduce the amount of on-stack instances). I'll put it on the todo list, along with that hotplug stuff (which I tried to fix but ended up with an even bigger mess). I suppose we can try and not have the alignment for the on-stack instances while preserving it for the few off-stack ones. Also; we're running on the NMI stack, and that's not typically hot.