Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1537962pxb; Fri, 10 Sep 2021 08:05:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJXV6+Sq0RFj9bUzkNPG8Hf20Xa+P9xViuEYpI4n8v79I9QcUOl1q/aHOX3dsULVG4KaYk X-Received: by 2002:a92:190b:: with SMTP id 11mr6388397ilz.4.1631286359524; Fri, 10 Sep 2021 08:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631286359; cv=none; d=google.com; s=arc-20160816; b=kHykiLtn8XmhpGX3bphg9jbhPGMQwPal1VwcHCXH9BnsPZcCEWZWX58xVHoAYHciUX 0NYViesHg29a+N9RKu0zwhVrolyujfDF2L2IOCJyZRWkh4lSg/qdgjfrVMsIu8/hOY+K I9BgNoNKJ/Wq+BFWgb5lSUwxT5FlS5fgHKIz5AzMsTi9+v7ahM8SQEyYFhx0JNWuB9sh P3NqlSmI8paVYGyPSIBihfeMZbccKTNT35xazByYl6PUV07HokvJZeRjxAD7T2uw3bB2 J5IYKBekg1jicJCXjId/PJZa4TltdhjJuO9Ntdqgr5sZK0ygNLtqHQr9eN0lyCBCcLU+ kFGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=1pwlVxDkfCa0su9+pm6vroWkQFMoA+AryU161sjcxfk=; b=0S+VXsf9g9EOdN4SX/4KHKrEwJCP7t96iRBbMOFE+Ft82aKeUyCA6zEa0RoAAf18hn mvVuQ9ZfmqAEvxMbhj90XmRWjZO8BZ3q0TFE5GBm3pa1i8jumgkScXQqF7lwO0nWczw0 Y7/4MhxmCDGFCjK6pOkOvVhHE3Dlolq/iXeuPM+ZXQozyGchOdovAauMvySlphCq4Bp0 CGmzixScpOs8MyTSP/9BiXDnbLOZnakLKys6pUaFk7V7dsN9ZdRYWkOKp4cYsWmZf29m OsYbM9terqcXJIwyWg+jpWYGrPSS74o7+Jt1jTtJ7iRme3jsZUafvc7Lt5fSCAY8cRLK oRDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=Upka5ZzT; 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 o4si5209871ilf.130.2021.09.10.08.05.36; Fri, 10 Sep 2021 08:05:59 -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-dk.20150623.gappssmtp.com header.s=20150623 header.b=Upka5ZzT; 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 S234163AbhIJPFk (ORCPT + 99 others); Fri, 10 Sep 2021 11:05:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbhIJPFj (ORCPT ); Fri, 10 Sep 2021 11:05:39 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AAD3C061574 for ; Fri, 10 Sep 2021 08:04:28 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id bd1so3302680oib.5 for ; Fri, 10 Sep 2021 08:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=1pwlVxDkfCa0su9+pm6vroWkQFMoA+AryU161sjcxfk=; b=Upka5ZzTcAbnaXhLgktHI/hEk3sA+dwVQL8Kt+LeTHdDwSOL5teaXo51VLxQLrhTY0 zHaWBnbao+/ZYQx7iQ8KNffO8Bwbw3ZrHKOfKEOWTxxgq+zd9iZ0xBxL2zkqLVuGUR6C 3I1+nnsaV1qxKKvfek19l7XxI5oG5T1gDXUHzxFkcqwMbgCJD1MazII9eIFRVbqjJsXO IKiOtRNl9mjhkvh46uw34cfWYOwMduNhvPj40XmfrZaa2b96CUkLr8iDIYwlLZmWoFtc ooHZx5cKluVeam5DJudtqN6O9eSdqoCM3BIAn/oNpmSD+wPhZDmiiJ+yRcmjPefk7x/9 n5MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=1pwlVxDkfCa0su9+pm6vroWkQFMoA+AryU161sjcxfk=; b=j29v7LSptHKW1Dh41HfEgvIMQtojKuFbYfRGZiKRCMh1nwr5CSH4lBWwxCTOhmpPyP sNBGJvsSkD5Q4lMjLfXE908hQaCvnSXkxxzNQY5jH0hHA7w1WoyJL1D6u2RYXWDxCrIG SwONPKpxGajqSeoyfXrB45KSkvJiyRdjTHQFq4Dphk1QEUGpw/HmIrU7B1dqTbA7uOBs M9rRsS74LRrCqVg/hVIVyyjxnYJePkLJ+ghDNccPqkv/4bzR5KUUDNxJMMOl9t2wn9lW p4AcSJkWKV8C1v91BWV93GZhqSGXcx4Pp28wEUVS3Lmw1rAnCwVP6rAnPWevdkzar4qW w1PA== X-Gm-Message-State: AOAM533+A7Qj748JE+W/q389SttZWjewQ38cfTzEa0G9cL8IJwcezvPP 3yrWmkXhCpFJ0CeakETb+IfWzQ== X-Received: by 2002:aca:d02:: with SMTP id 2mr4489656oin.126.1631286267793; Fri, 10 Sep 2021 08:04:27 -0700 (PDT) Received: from [192.168.1.30] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id 99sm1276993otd.2.2021.09.10.08.04.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Sep 2021 08:04:27 -0700 (PDT) Subject: Re: [git pull] iov_iter fixes From: Jens Axboe To: Al Viro Cc: Linus Torvalds , Pavel Begunkov , Linux Kernel Mailing List , linux-fsdevel References: <5971af96-78b7-8304-3e25-00dc2da3c538@kernel.dk> <9ae5f07f-f4c5-69eb-bcb1-8bcbc15cbd09@kernel.dk> <9855f69b-e67e-f7d9-88b8-8941666ab02f@kernel.dk> Message-ID: <4b26d8cd-c3fa-8536-a295-850ecf052ecd@kernel.dk> Date: Fri, 10 Sep 2021 09:04:26 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <9855f69b-e67e-f7d9-88b8-8941666ab02f@kernel.dk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/10/21 7:57 AM, Jens Axboe wrote: > On 9/9/21 9:36 PM, Al Viro wrote: >> On Thu, Sep 09, 2021 at 09:30:03PM -0600, Jens Axboe wrote: >> >>>> Again, we should never, ever modify the iovec (or bvec, etc.) array in >>>> ->read_iter()/->write_iter()/->sendmsg()/etc. instances. If you see >>>> such behaviour anywhere, report it immediately. Any such is a blatant >>>> bug. >>> >>> Yes that was wrong, the iovec is obviously const. But that really >>> doesn't change the original point, which was that copying the iov_iter >>> itself unconditionally would be miserable. >> >> Might very well be true, but... won't your patch hit the reimport on >> every short read? And the cost of uaccess in there is *much* higher >> than copying of 48 bytes into local variable... >> >> Or am I misreading your patch? Note that short reads on reaching >> EOF are obviously normal - it's not a rare case at all. > > It was just a quick hack, might very well be too eager to go through > those motions. But pondering this instead of sleeping, we don't need to > copy all of iov_iter in order to restore the state, and we can use the > same advance after restoring. So something like this may be more > palatable. Caveat - again untested, and I haven't tested the performance > impact of this at all. Passes basic testing for me. I added a sysctl switch for this so I can compare performance, running my usual peak-perf-single-core benchmark. That one does ~3.5M IOPS, using polled IO. There's always a slight variability between boots and builds, hence the sysctl so I could toggle this behavior on the fly. Did a few runs, and the differences are very stable. With this enabled, we spend about 0.15% more time in io_read(). That's only worth about 5K IOPS at 3.5M, not enough to notice as the variation for the 1 second reporting window usually swings more than that: Old behavior: IOPS=3536512, IOS/call=32/31, inflight=(75) IOPS=3541888, IOS/call=32/32, inflight=(64) IOPS=3529056, IOS/call=32/31, inflight=(119) IOPS=3521184, IOS/call=32/32, inflight=(96) IOPS=3527456, IOS/call=32/31, inflight=(128) IOPS=3525504, IOS/call=32/32, inflight=(128) IOPS=3524288, IOS/call=32/32, inflight=(128) IOPS=3536192, IOS/call=32/32, inflight=(96) IOPS=3535840, IOS/call=32/32, inflight=(96) IOPS=3533728, IOS/call=32/31, inflight=(128) IOPS=3528384, IOS/call=32/32, inflight=(128) IOPS=3518400, IOS/call=32/32, inflight=(64) Turning it on: IOPS=3533824, IOS/call=32/31, inflight=(64) IOPS=3541408, IOS/call=32/32, inflight=(32) IOPS=3533024, IOS/call=32/31, inflight=(64) IOPS=3528672, IOS/call=32/32, inflight=(35) IOPS=3522272, IOS/call=32/31, inflight=(107) IOPS=3517632, IOS/call=32/32, inflight=(57) IOPS=3516000, IOS/call=32/31, inflight=(96) IOPS=3513568, IOS/call=32/32, inflight=(34) IOPS=3525600, IOS/call=32/31, inflight=(96) IOPS=3527136, IOS/call=32/31, inflight=(101) I think that's tolerable, it was never going to be absolutely free. What do you think of this approach? Parts of iov_iter are going to remain constant, like iter_type and data_source. io_uring already copies iter->count, so that just leaves restoring iov (and unionized friends), nr_segs union, and iov_offset; We could pretty this up and have the state part be explicit in iov_iter, and have the store/restore parts end up in uio.h. That'd tie them closer together, though I don't expect iov_iter changes to be an issue. It would make it more maintainable, though. I'll try and hack up this generic solution, see if that looks any better. -- Jens Axboe