From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933348AbdCKT2e (ORCPT ); Sat, 11 Mar 2017 14:28:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57724 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750960AbdCKT2W (ORCPT ); Sat, 11 Mar 2017 14:28:22 -0500 Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20170311101510.6504-1-ebiggers3@gmail.com> References: <20170311101510.6504-1-ebiggers3@gmail.com> To: Eric Biggers Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, Al Viro , linux-kernel@vger.kernel.org, Eric Biggers Subject: Re: [PATCH] statx: optimize copy of struct statx to userspace MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9623.1489260500.1@warthog.procyon.org.uk> Date: Sat, 11 Mar 2017 19:28:20 +0000 Message-ID: <9624.1489260500@warthog.procyon.org.uk> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 11 Mar 2017 19:28:23 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Eric Biggers wrote: > From: Eric Biggers > > I found that statx() was significantly slower than stat(). As a > microbenchmark, I compared 10,000,000 invocations of fstat() on a tmpfs > file to the same with statx() passed a NULL path: > > $ time ./stat_benchmark > > real 0m1.464s > user 0m0.275s > sys 0m1.187s > > $ time ./statx_benchmark > > real 0m5.530s > user 0m0.281s > sys 0m5.247s > > statx is expected to be a little slower than stat because struct statx > is larger than struct stat, but not by *that* much. It turns out that > most of the overhead was in copying struct statx to userspace, > apparently mostly in all the stac/clac instructions that got generated > for each __put_user() call. (This was on x86_64, but some other > architectures, e.g. arm64, have something similar now too.) > > stat() instead initializes its struct on the stack and copies it to > userspace with a single call to copy_to_user(). This turns out to be > much faster, and changing statx to do this makes it almost as fast as > stat: > > $ time ./statx_benchmark > > real 0m1.573s > user 0m0.229s > sys 0m1.344s > > Signed-off-by: Eric Biggers Acked-by: David Howells