Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp723473pxk; Thu, 3 Sep 2020 10:59:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrV5xbVHRtoxPCnydRVx0tJLAho+UFps63Y8c1oDOpK5/eIg3C7uhm+lbKIitGs2BPt+wg X-Received: by 2002:a50:c182:: with SMTP id m2mr4344186edf.70.1599155948875; Thu, 03 Sep 2020 10:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599155948; cv=none; d=google.com; s=arc-20160816; b=F8CShU0PY7RuoDOm2Knwe8+0x3fWJptrpQyLcEqQUWQvf9peGU9GYJyOAezhv5GPPv lCZkCh2ytCR/Q+o9QX5kYYPoLHsRZQ/z/N/TQg02I++zhxxBh17UQYgk2lRKEYQ6Uo1s TI5mEpZKsI4A+TPOTAOpbY1EQChn8dlJajZWNCTHtw4N4o281fLUXA0xz8HWoUSR+6yK JWT3UEpBbOZSsGyeZc55WpFVAJuaNu9KSMke/PpBZowT74s1Yj5NAE17V6ypAGkeVsrP tPRMtn/hnomyMxEeZnuXp93wtnybNDQpm/3GBBDFKC9wfz6JHAm/4yBV4kxcFhbfV3Db u7TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=3m0sn9AYpb4yJMENUVCsHySlI36b8g9jeErcciFLzdg=; b=TES5cyZqYbLLeL2Y0JzFfjuZ/Es6PYkXhsMNlrYYivRnvg+wt5fhDODR2dHEd3QST4 MSHmwvlyxbXTo436P1/UOUPycrXordgpcZBkQcekIQsTr5g8Hc0FZ9SmV2orRaDCRQ6f 8Ls9gW55BkNi21zVaUgelLwBRFZN4cFTuxuFUbAMr8tlb4s36TD9KolibA16umxBAIBD 0XLPhiMxEWvIDJYioMRQhVhfmEJSgUoywfEHrcIJgCIkWTNY1Ce4dnuik/yQF0CPMywu HsRd4oP1QktbfmrN1pkFqzEt7ksKvXdk0OIYhutifp7uKRSWogHLpYxrabfgq8KCHVFV dBPw== 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 k6si2030212edv.504.2020.09.03.10.58.43; Thu, 03 Sep 2020 10:59:08 -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 S1727065AbgICR5F (ORCPT + 99 others); Thu, 3 Sep 2020 13:57:05 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:64673 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726025AbgICR5E (ORCPT ); Thu, 3 Sep 2020 13:57:04 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4Bj7mX08rVz9vG1Z; Thu, 3 Sep 2020 19:57:00 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id czc54Tj7o-AE; Thu, 3 Sep 2020 19:56:59 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4Bj7mW6QXJz9vG1Y; Thu, 3 Sep 2020 19:56:59 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AB9F48B805; Thu, 3 Sep 2020 19:57:01 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id GvL1dM65fFS4; Thu, 3 Sep 2020 19:57:01 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6350C8B803; Thu, 3 Sep 2020 19:57:01 +0200 (CEST) Subject: Re: [PATCH] /dev/zero: also implement ->read To: Christoph Hellwig , arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org References: <20200903155922.1111551-1-hch@lst.de> From: Christophe Leroy Message-ID: <1bc34841-f1a3-8a9b-cb48-10930ec55d71@csgroup.eu> Date: Thu, 3 Sep 2020 19:51:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20200903155922.1111551-1-hch@lst.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > .write_iter = write_iter_zero, > .mmap = mmap_zero, > .get_unmapped_area = get_unmapped_area_zero, > Christophe