From patchwork Sun May 24 19:21:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11567579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CDF6760D for ; Sun, 24 May 2020 19:22:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 86820207C3 for ; Sun, 24 May 2020 19:22:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="QoOW0b+9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86820207C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9F6BB80008; Sun, 24 May 2020 15:22:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9A7C680007; Sun, 24 May 2020 15:22:14 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BCE580008; Sun, 24 May 2020 15:22:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 73E3080007 for ; Sun, 24 May 2020 15:22:14 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3369D181AEF00 for ; Sun, 24 May 2020 19:22:14 +0000 (UTC) X-FDA: 76852583388.17.match05_137a0f724ea5e X-Spam-Summary: 50,0,0,6a03aa053c44e3b7,d41d8cd98f00b204,axboe@kernel.dk,,RULES_HIT:41:69:355:379:541:967:973:988:989:1260:1311:1314:1345:1437:1515:1535:1544:1605:1711:1730:1747:1777:1792:2194:2199:2393:2525:2560:2563:2682:2685:2690:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4118:4250:4605:4641:5007:6119:6261:6653:7903:7904:8527:9025:10004:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12663:12679:12683:12903:13146:13153:13161:13184:13228:13229:13230:13548:13845:13868:13894:14096:14181:14394:14721:21080:21324:21433:21444:21451:21627:21740:21795:30012:30034:30051:30054:30070,0,RBL:209.85.210.196:@kernel.dk:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: match05_137a0f724ea5e X-Filterd-Recvd-Size: 7252 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Sun, 24 May 2020 19:22:13 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id 145so7920713pfw.13 for ; Sun, 24 May 2020 12:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PRgTWBIUIof3K+e/CBH42LWEIO1ioATTUwPeCqp2UHQ=; b=QoOW0b+9anaSH1PynN6EMvziqcD6SYQPSEyhxExvJ4fIbobZWkV+qjOWZY58TVG7/j XFzrw/TO8ZNuU9Wy1Kf0MtJNqmALcX1/fJ/5NQp7C3CXyHN9qTAhMDHMuZ1P5N0QLICT SPtZkbXpx1yp8TjNzUYVx5kDRq5UU+8wJ4/KNP5CVFR4UX6FTCLFGCgQ1D3Lsqx7QjuV tYMuVOBoMg+OEnWFCvHKiMZQ4b/JUMaF2BwDINXvScHsgfWF3j0okK8Xtc5dWYKAP6mD Gfl8OHlvFdVv3AnJaeKNPTRCWKLc+m5FLCtY12XqW+yTOwdElb93BOVQczWu3zRG1Tfj 7hbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PRgTWBIUIof3K+e/CBH42LWEIO1ioATTUwPeCqp2UHQ=; b=NZ77+UFFy7cMt+dZcN+u/J3xs3en+ztFGLy/8I6B6NM0ikyFkojKIVj8PY1q2lauup ZWAnvog6O9tkYgjWvM3lc8bf5mTHrCLfNmP1g3Q2C/X3I57QfnQrMtpchCzbFZM/FmH3 HTRjwCAPNXOVo/syKH/6A0UZP15NK1zmn03FGia0f+PlcklKhgljMALOhkc2emhCIhxM rNcsQj1Nh1s2lyB6aHz1XZ5h7mIw2Uf16iFNDyjZ7QmOfqF8CXvOts7sG8AZiGrnJvQc qhq4AvRwJFgeSl5nGVlseHP9OFnbBCA14mEhGrPDIMJQaFdn34DEp4nVMcCPfQA4xwHI 4Lyg== X-Gm-Message-State: AOAM531Z/BxE0nBgfKXMofS1PICBiMi91d1BfGW7AOSRjMP8epJMZEko FsGxS1wMRXCwY8oVatYcor+b4w== X-Google-Smtp-Source: ABdhPJxpWNMA85eA4BcwCQuyHmnnwKmYr9/iXxe1Qr6NlCvQdWZu5puz/A2BlfDne/CKV/J4XCu1QA== X-Received: by 2002:a63:1207:: with SMTP id h7mr17624890pgl.241.1590348132344; Sun, 24 May 2020 12:22:12 -0700 (PDT) Received: from x1.lan ([2605:e000:100e:8c61:c871:e701:52fa:2107]) by smtp.gmail.com with ESMTPSA id t21sm10312426pgu.39.2020.05.24.12.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 12:22:11 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCHSET v4 0/12] Add support for async buffered reads Date: Sun, 24 May 2020 13:21:54 -0600 Message-Id: <20200524192206.4093-1-axboe@kernel.dk> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We technically support this already through io_uring, but it's implemented with a thread backend to support cases where we would block. This isn't ideal. After a few prep patches, the core of this patchset is adding support for async callbacks on page unlock. With this primitive, we can simply retry the IO operation. With io_uring, this works a lot like poll based retry for files that support it. If a page is currently locked and needed, -EIOCBQUEUED is returned with a callback armed. The callers callback is responsible for restarting the operation. With this callback primitive, we can add support for generic_file_buffered_read(), which is what most file systems end up using for buffered reads. XFS/ext4/btrfs/bdev is wired up, but probably trivial to add more. The file flags support for this by setting FMODE_BUF_RASYNC, similar to what we do for FMODE_NOWAIT. Open to suggestions here if this is the preferred method or not. In terms of results, I wrote a small test app that randomly reads 4G of data in 4K chunks from a file hosted by ext4. The app uses a queue depth of 32. If you want to test yourself, you can just use buffered=1 with ioengine=io_uring with fio. No application changes are needed to use the more optimized buffered async read. preadv for comparison: real 1m13.821s user 0m0.558s sys 0m11.125s CPU ~13% Mainline: real 0m12.054s user 0m0.111s sys 0m5.659s CPU ~32% + ~50% == ~82% This patchset: real 0m9.283s user 0m0.147s sys 0m4.619s CPU ~52% The CPU numbers are just a rough estimate. For the mainline io_uring run, this includes the app itself and all the threads doing IO on its behalf (32% for the app, ~1.6% per worker and 32 of them). Context switch rate is much smaller with the patchset, since we only have the one task performing IO. Also ran a simple fio based test case, varying the queue depth from 1 to 16, doubling every time: [buf-test] filename=/data/file direct=0 ioengine=io_uring norandommap rw=randread bs=4k iodepth=${QD} randseed=89 runtime=10s QD/Test Patchset IOPS Mainline IOPS 1 9046 8294 2 19.8k 18.9k 4 39.2k 28.5k 8 64.4k 31.4k 16 65.7k 37.8k Outside of my usual environment, so this is just running on a virtualized NVMe device in qemu, using ext4 as the file system. NVMe isn't very efficient virtualized, so we run out of steam at ~65K which is why we flatline on the patched side (nvme_submit_cmd() eats ~75% of the test app CPU). Before that happens, it's a linear increase. Not shown is context switch rate, which is massively lower with the new code. The old thread offload adds a blocking thread per pending IO, so context rate quickly goes through the roof. The goal here is efficiency. Async thread offload adds latency, and it also adds noticable overhead on items such as adding pages to the page cache. By allowing proper async buffered read support, we don't have X threads hammering on the same inode page cache, we have just the single app actually doing IO. Been beating on this and it's solid for me, and I'm now pretty happy with how it all turned out. Not aware of any missing bits/pieces or code cleanups that need doing. Series can also be found here: https://git.kernel.dk/cgit/linux-block/log/?h=async-buffered.4 or pull from: git://git.kernel.dk/linux-block async-buffered.4 fs/block_dev.c | 2 +- fs/btrfs/file.c | 2 +- fs/ext4/file.c | 2 +- fs/io_uring.c | 114 ++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_file.c | 2 +- include/linux/blk_types.h | 3 +- include/linux/fs.h | 10 +++- include/linux/pagemap.h | 67 ++++++++++++++++++++++ mm/filemap.c | 111 ++++++++++++++++++++++++------------- 9 files changed, 267 insertions(+), 46 deletions(-) Changes since v3: - io_uring: don't retry if REQ_F_NOWAIT is set - io_uring: alloc req->io if the request type didn't already - Add iocb->ki_waitq instead of (ab)using iocb->private Changes since v2: - Get rid of unnecessary wait_page_async struct, just use wait_page_async - Add another prep handler, adding wake_page_match() - Use wake_page_match() in both callers Changes since v1: - Fix an issue with inline page locking - Fix a potential race with __wait_on_page_locked_async() - Fix a hang related to not setting page_match, thus missing a wakeup