From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B75DC433EF for ; Mon, 18 Oct 2021 13:49:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F11F60555 for ; Mon, 18 Oct 2021 13:49:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233693AbhJRNvk (ORCPT ); Mon, 18 Oct 2021 09:51:40 -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