Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp34916pxb; Mon, 18 Oct 2021 19:54:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUrW2aOlhOP7ThD2y2sbQaigdg8k/wqCZZQwdmhYK49oHsofFSbP3OWnrOb4XWRvm2FavP X-Received: by 2002:a17:90a:de0b:: with SMTP id m11mr3332556pjv.39.1634612096926; Mon, 18 Oct 2021 19:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634612096; cv=none; d=google.com; s=arc-20160816; b=IopCy1hcoT0j0QlCR+6OFRlT/PjtLeVYCYyg/Lauec9fKoB1qPiZ7XBbRQG4YUH/qW Pfm1MW258wYuPRnZrQEvYG6GW92V8u3C/zyJaw8PoccMcr6yiNPK2pdN4LT/qamR+5ma odg5J3e3rHCCEfm2buIZG44uovyWrRl2FSAXhxvFfvEB8BxS/V8mgPP6b0y7+qPFS+qy dKDezSb1xJi7JHW6vJE3V+dQ+nMdorp076QMukOdGki52vEp0t34tHd5dvM3wkK2WPPn mWaoSfVoYWPCibtlaVUN56fFPmSuq06zEjpn0Du4d1XxN3dmjUY6YgyrA9bs+7mys76Q tMYw== 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=1sb/KOX3hhfoawlpg8UsWwGEk1lhGemPprlH555lkIY=; b=Rp8oyEwbHwd83lhpLMgxCRhKq/Z/txN1KNy7wa5dGeyccR5nfgLy0qfx4AdT8ICsN1 u+I00oPLc+Yy9SR9DlquQF9Bkqs65vUUhjgSc9a+TLYjhDBY/wYLst0aEp7YqJkKk8YP OmhOKjaS59KXZnUA9aC43ZXh3Lqv7o3nhb8Fx4109DqfyloOHK/z9SwX0iQy3wxYU63d fEofKjW2dwByhmaZoZJMPVrJo19JLxyLczJPTiqHeohyDxsvm1HJB3Oxr+GZBXaPUANC qQ6d74bUbHM0bBa50W7a1v3KKyXLve78kFkpqK8ipF4F3anxf2+Dykajz7lJ5R8TxOJ4 Uf1A== 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 j3si9824944plx.247.2021.10.18.19.54.43; Mon, 18 Oct 2021 19:54:56 -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 S231858AbhJSCx1 (ORCPT + 99 others); Mon, 18 Oct 2021 22:53:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:48324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbhJSCx0 (ORCPT ); Mon, 18 Oct 2021 22:53:26 -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 7DF636128E; Tue, 19 Oct 2021 02:51:14 +0000 (UTC) Date: Mon, 18 Oct 2021 22:51:12 -0400 From: Steven Rostedt To: Yang Jihong Cc: , linux-kernel Subject: Re: [QUESTION] Performance deterioration caused by commit 85f726a35e504418 Message-ID: <20211018225112.3f6bda99@gandalf.local.home> In-Reply-To: <19e4222c-c9ac-5c1a-0c3a-b8bfd3524ab7@huawei.com> References: <992d3b1c-70db-5cc7-8400-39caa5d502d5@huawei.com> <20211018093731.2dd5917f@gandalf.local.home> <19e4222c-c9ac-5c1a-0c3a-b8bfd3524ab7@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 Tue, 19 Oct 2021 10:39:47 +0800 Yang Jihong wrote: > Hi Steve, > > On 2021/10/18 21:37, Steven Rostedt wrote: > > 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()? > > > I have tried testing it by switching strncpy() with strlcpy(), there is > no performance improvement, probably because the strlen function is > called in strlpy and the string is traversed each time. Then there's not much we can do. Security trumps performance. Not to mention, the garbage in the comm after the '\0' causes the histograms to produce strange results. Now for the saved_cmdlines, since it isn't exported directly to user space, that one may be put back to memcpy(). Tom, was there a reason to change saved_cmdlines(), as I'm not sure that is leaked. It looks like it is printed with the normal seq_printf() in saved_cmdlines_show(). And it doesn't even look like the saved_cmdlines() is even initialized to zero, so it itself could leak memory if it was exposed. -- Steve