Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3025120pxb; Mon, 18 Oct 2021 06:50:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye9MXHnDZ5fU3QPTnW8knXFJJ8JfTzfy3B1H6WN0znpV5WrivHXT+aXaTN6WUeE8j1orrY X-Received: by 2002:a63:790e:: with SMTP id u14mr23266711pgc.478.1634565055351; Mon, 18 Oct 2021 06:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565055; cv=none; d=google.com; s=arc-20160816; b=hlRhNKCuWeCOuctcePe4U0NMP7NJ8iV+44rdBXeomipDhft3FoZFoC590bDemCeDcs xyBwZBGWxACsti9LkG4RQAoAgMk89pNY7ys0Nuva/X4hLYwYOKc+3pfvsKBRg3k9RikK 7qxXGQGP9Gl4iY76IlRdUXHvxZyVZRXepZ4Um6BtqrgHDiaUarPSeldzVsSLC8b4LtEk UpPRtt/oryuA86shCJHsGMVBP0H0qn+UxLrqbTOVhR8GDw0DB2ElJ9uH51IFGj8E5TCc 1nwhgXlEbU3NqaEtQWo+yFZRRjetLcn2rwLoFX//wqJvnmjuAk1HRLcdojB2UdbZAj4O AuVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=rdQLpDz+nfY1TlGLs+NvvIutOxSxMmLPIUFImf7asnM=; b=innrJFwkQv54Sl7Bh2HzO9C43rcj/uw35tkmLMYx4b2Lmm/9y5ZQFsw/VcSwWKCmN9 OOEw96o+8KwIvq0SOZs60ded4dttHJO1mR8p4fQtZH3RcumSzwjcSR/Riypj8YQwDxCC L9/F6eSicPKdJ/N/1gjonFEjguIKxpXfaKXyUQAu6oWrXwpzI3aQ8Iyep+EduhwMFrUB reVKf3A/RZ/DTh6jzxHeQkoztxvUGs7zg9k91mQX5x8wkT7v6YyOktxQoREKLaqO1767 NlrhRcuUsbX1k3PNuZ1blJO+lWuQgZD73qGO0UkR9C3+JPT9KpQ1HksaSnQelbHs/Tci +tdg== ARC-Authentication-Results: i=1; mx.google.com; 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 f185si20465023pgc.274.2021.10.18.06.50.42; Mon, 18 Oct 2021 06:50:55 -0700 (PDT) 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; 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 S233660AbhJRNvj (ORCPT + 99 others); Mon, 18 Oct 2021 09:51:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:50006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232892AbhJRNtg (ORCPT ); Mon, 18 Oct 2021 09:49:36 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 05B7E61882; Mon, 18 Oct 2021 13:37:32 +0000 (UTC) Date: Mon, 18 Oct 2021 09:37:31 -0400 From: Steven Rostedt To: Yang Jihong Cc: , linux-kernel Subject: Re: [QUESTION] Performance deterioration caused by commit 85f726a35e504418 Message-ID: <20211018093731.2dd5917f@gandalf.local.home> In-Reply-To: <992d3b1c-70db-5cc7-8400-39caa5d502d5@huawei.com> References: <992d3b1c-70db-5cc7-8400-39caa5d502d5@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 18 Oct 2021 11:23:14 +0800 Yang Jihong wrote: > Hi Tom and Steven, > > commit 85f726a35e504418 use strncpy instead of memcpy when copying comm, > on ARM64 machine, this commit causes performance degradation. > > I test the number of instructions executed by invoking the > trace_sched_switch function once on an arm64 machine: > 1. Use memcpy, the number of instructions executed is 850. > 2. Use strncpy, the number of instructions executed 1100. > That is, use strncpy is almost 250 more instructions than memcpy. > > Has the impact on performance been considered in this commit? :) > What is the impact of revert the patch? > It's a security issue. And like everything security, there's always going to be a performance impact. Look at the performance impact due to spectre and meltdown! That said, although memcpy() may not be used, we don't need strncpy. strncpy() will pad the rest of the string with nul bytes. But since the memory the string is being recorded into is already initialized (or can be if it isn't), we could use the faster strlcpy(). Have you tried testing it by switching strncpy() with strlcpy()? -- Steve