Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp728503pxk; Thu, 3 Sep 2020 11:05:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBybp2mZyphrneYiIfJkzfqUncimHSnlTQ7aGUqxLklxOAEyeBKM2FBYXrDhdkoXbdDdQE X-Received: by 2002:a17:906:f950:: with SMTP id ld16mr3298691ejb.489.1599156330211; Thu, 03 Sep 2020 11:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599156330; cv=none; d=google.com; s=arc-20160816; b=NItQ0Xl41dvkeKR1S2Sxk2JfjNSN+U5elfW0/UqKg/4yM8lCHYOkB+wtHVKsyCZAfD w3ZCHzDphWhIxcWEBVuZPg9hSg+Q57GAjc5aOgVG7c8Q2DTNvT0su24W8kOXkPCu2x8Z GcMP4GDZntlWvl7QReXvlzT673SK6YFKrCNijStGMspMaHhXg6MvPVz3fFkQiovI+PdQ FsxbtUamVzQIlOlm44z1KMj/FCV/DN0hXl4RIpvxHsijQghwaT97CnJJ63Trgt10xQiV yzlJjiXpIrSHnzmQKhs9MuKBuDx6emhhImmudMbIhGQ3JJkNKtq0alt1AR1m7dz1G2Eb UV8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=XoolkOoWxSk2jY4HnUjdnDl7ysnuGh2MDrGQ+qdM2j4=; b=Ixh2s+pX2GtdwQKx7VTKjxNYQJv3uFL7daRI8qkf/4xLK17ZUgsDQllz3LhWNicfTy tZL/UU8+kwfrz4vk01v+AAmr+dy312uunFVPOg/FGnt5TDNF229xXSYwdNxIEgu6pokP woCEtSFa5omzkSQawH5wCGpbh3HOvmbw3f3MCqwO5SN44g0e+w7HosbFDoyIIG17pcbf nB29lOnfgB4qtd0q/Dcv11Tpgwosm84tNFjTecqzdQfNIBWPhzXO62lOQ9AgJOaUltKv BQzEm4x2SfB+YL+XghniPGVdg4FWBAJqp1GFVjIc8AGnOfvUXIuyMbygbEG+dopnV6sK cVFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ELauOPuU; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mf8si2374746ejb.197.2020.09.03.11.05.05; Thu, 03 Sep 2020 11:05:30 -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; dkim=pass header.i=@kernel.org header.s=default header.b=ELauOPuU; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728903AbgICSB5 (ORCPT + 99 others); Thu, 3 Sep 2020 14:01:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:34920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727065AbgICSB4 (ORCPT ); Thu, 3 Sep 2020 14:01:56 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 CE81520716; Thu, 3 Sep 2020 18:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599156115; bh=g/zK/ClT1m5soG/tnXSY+wGtMX3SLoeeyKDXpcFFi+8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ELauOPuUtZVMDFEfwjDgxAIBXYDHvYmSzCpUf2Grzewy1io84bdEPRClmezPdJ+Tc 8VayzXho4//0jrpJPwObQ/+LiUOL+aJux/rm7O/0TD93UAHCwrs3UM6Co7DGWhEmoN DPk1GRp2dVdFN8RC2KJ4Tgf4nV7LC/C5/2hmZnJk= Date: Thu, 3 Sep 2020 20:02:17 +0200 From: Greg KH To: Christophe Leroy Cc: Christoph Hellwig , arnd@arndb.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] /dev/zero: also implement ->read Message-ID: <20200903180217.GA2038804@kroah.com> References: <20200903155922.1111551-1-hch@lst.de> <1bc34841-f1a3-8a9b-cb48-10930ec55d71@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1bc34841-f1a3-8a9b-cb48-10930ec55d71@csgroup.eu> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 03, 2020 at 07:51:07PM +0200, Christophe Leroy wrote: > > > Le 03/09/2020 ? 17:59, Christoph Hellwig a ?crit?: > > Christophe reported a major speedup due to avoiding the iov_iter > > overhead, so just add this trivial function. Note that /dev/zero > > already implements both an iter and non-iter writes so this just > > makes it more symmetric. > > > > Christophe Leroy > > Signed-off-by: Christoph Hellwig > > --- > > drivers/char/mem.c | 22 ++++++++++++++++++++++ > > 1 file changed, 22 insertions(+) > > > > diff --git a/drivers/char/mem.c b/drivers/char/mem.c > > index abd4ffdc8cdebc..1dc99ab158457a 100644 > > --- a/drivers/char/mem.c > > +++ b/drivers/char/mem.c > > @@ -726,6 +726,27 @@ static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter) > > return written; > > } > > +static ssize_t read_zero(struct file *file, char __user *buf, > > + size_t count, loff_t *ppos) > > +{ > > + size_t cleared = 0; > > + > > + while (count) { > > + size_t chunk = min_t(size_t, count, PAGE_SIZE); > > + > > + if (clear_user(buf + cleared, chunk)) > > + return cleared ? cleared : -EFAULT; > > + cleared += chunk; > > + count -= chunk; > > + > > + if (signal_pending(current)) > > + return cleared ? cleared : -ERESTARTSYS; > > + cond_resched(); > > + } > > + > > + return cleared; > > +} > > + > > static int mmap_zero(struct file *file, struct vm_area_struct *vma) > > { > > #ifndef CONFIG_MMU > > @@ -921,6 +942,7 @@ static const struct file_operations zero_fops = { > > .llseek = zero_lseek, > > .write = write_zero, > > .read_iter = read_iter_zero, > > + .read = read_zero, > > Wondering if .read should be before .write, so that we get in order read, > write, read_iter, write_iter. It really does not matter :) thanks, greg k-h