From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755973AbdLONTh (ORCPT ); Fri, 15 Dec 2017 08:19:37 -0500 Received: from mail-qk0-f177.google.com ([209.85.220.177]:39666 "EHLO mail-qk0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755409AbdLONTg (ORCPT ); Fri, 15 Dec 2017 08:19:36 -0500 X-Google-Smtp-Source: ACJfBotp/dJn/bW2nDK1fEpV+2Wu8pT0okvVWbbvh7DqqJLgOqPZAa9rBTJTIFScNT1un4DHlgKRIA== Date: Fri, 15 Dec 2017 05:19:32 -0800 From: Tejun Heo To: Christophe LEROY Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, "linux-kernel@vger.kernel.org" Subject: Re: sysfs_kf_seq_show() spends 87% of time in memset() Message-ID: <20171215131932.GE3919388@devbig577.frc2.facebook.com> References: <1855b755-177f-f5be-64b5-3d22e454d3ff@c-s.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1855b755-177f-f5be-64b5-3d22e454d3ff@c-s.fr> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Fri, Dec 15, 2017 at 01:59:55PM +0100, Christophe LEROY wrote: > Doing a 'perf record' on an application using GPIOs a lot, I > discovered that most of the time spent in the read() system call of > the 'value' sysfs file of that GPIO (which returns "0\n" or "1\n") > is indeed spent in memset() zeroing a buffer of size PAGE_SIZE for a > 2 bytes read: ... > As far as I can see, that memset() was introduced by your commit > f5c16f29bf5e5 ("sysfs: make sure read buffer is zeroed") > > Is that really necessary, taking into account that the ->show will > overwrite it ? We were doing get_zeroed_pages() before, so the commit is restoring the previous behavior, and, yeah, I think there's some risk of leaking uninitialized data. The way the ->show() interface is defined doesn't give us a lot of leeway. The right thing to do would be switching the said driver to prealloc read or ->bin_read. Thanks. -- tejun