From patchwork Thu May 26 17:38:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12862566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F199C433F5 for ; Thu, 26 May 2022 17:38:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 004878D0003; Thu, 26 May 2022 13:38:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF9148D0001; Thu, 26 May 2022 13:38:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9A3D8D0003; Thu, 26 May 2022 13:38:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C38F78D0001 for ; Thu, 26 May 2022 13:38:57 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 9D84A803D0 for ; Thu, 26 May 2022 17:38:57 +0000 (UTC) X-FDA: 79508604714.07.BAC5BBF Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf07.hostedemail.com (Postfix) with ESMTP id 4312B4002A for ; Thu, 26 May 2022 17:38:46 +0000 (UTC) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24QDTPaG028522 for ; Thu, 26 May 2022 10:38:55 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=hKApRetDHP7lPOI5DiT073yP/mEw3uAhNIIoin1tkJU=; b=NLKFLC2BJ2a3bNrXPimlGGenozHcvSXmmW+x68t9ACH9/dZBAu1sl40j2kjS+B5Kp3wZ gRX35jOe74st8h4bPnA6Igtcdy8oHyJgniQYH9Nx7axqjiNty7gI5dIGkzgJ8Y+zZjOf G2e3Ja8l/3FQYXk5NhqM3vtfT2sEzg7Sxe4= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gaafu1srp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 26 May 2022 10:38:55 -0700 Received: from twshared24024.25.frc3.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:21d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 26 May 2022 10:38:54 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 5D6A7FA621CC; Thu, 26 May 2022 10:38:45 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , Subject: [PATCH v6 00/16] io-uring/xfs: support async buffered writes Date: Thu, 26 May 2022 10:38:24 -0700 Message-ID: <20220526173840.578265-1-shr@fb.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: 0zMrx7RWhoB8gGxgs9wD5ZAAg2mkgVpg X-Proofpoint-ORIG-GUID: 0zMrx7RWhoB8gGxgs9wD5ZAAg2mkgVpg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-26_09,2022-05-25_02,2022-02-23_01 X-Rspamd-Queue-Id: 4312B4002A X-Stat-Signature: mhc8mqyo7bb5ufww47xz633fnskhnt8z Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=NLKFLC2B; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf07.hostedemail.com: domain of "prvs=6145f8dd45=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=6145f8dd45=shr@fb.com" X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1653586726-493022 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: This patch series adds support for async buffered writes when using both xfs and io-uring. Currently io-uring only supports buffered writes in the slow path, by processing them in the io workers. With this patch series it is now possible to support buffered writes in the fast path. To be able to use the fast path the required pages must be in the page cache, the required locks in xfs can be granted immediately and no additional blocks need to be read form disk. Updating the inode can take time. An optimization has been implemented for the time update. Time updates will be processed in the slow path. While there is already a time update in process, other write requests for the same file, can skip the update of the modification time. Performance results: For fio the following results have been obtained with a queue depth of 1 and 4k block size (runtime 600 secs): sequential writes: without patch with patch libaio psync iops: 77k 209k 195K 233K bw: 314MB/s 854MB/s 790MB/s 953MB/s clat: 9600ns 120ns 540ns 3000ns For an io depth of 1, the new patch improves throughput by over three times (compared to the exiting behavior, where buffered writes are processed by an io-worker process) and also the latency is considerably reduced. To achieve the same or better performance with the exisiting code an io depth of 4 is required. Increasing the iodepth further does not lead to improvements. In addition the latency of buffered write operations is reduced considerably. Support for async buffered writes: To support async buffered writes the flag FMODE_BUF_WASYNC is introduced. In addition the check in generic_write_checks is modified to allow for async buffered writes that have this flag set. Changes to the iomap page create function to allow the caller to specify the gfp flags. Sets the IOMAP_NOWAIT flag in iomap if IOCB_NOWAIT has been set and specifies the requested gfp flags. Adds the iomap async buffered write support to the xfs iomap layer. Adds async buffered write support to the xfs iomap layer. Support for async buffered write support and inode time modification Splits the functions for checking if the file privileges need to be removed in two functions: check function and a function for the removal of file privileges. The same split is also done for the function to update the file modification time. Implement an optimization that while a file modification time is pending other requests for the same file don't need to wait for the file modification update. This avoids that a considerable number of buffered async write requests get punted. Take the ilock in nowait mode if async buffered writes are enabled and enable the async buffered writes optimization in io_uring. Support for write throttling of async buffered writes: Add a no_wait parameter to the exisiting balance_dirty_pages() function. The function will return -EAGAIN if the parameter is true and write throttling is required. Add a new function called balance_dirty_pages_ratelimited_async() that will be invoked from iomap_write_iter() if an async buffered write is requested. Enable async buffered write support in xfs This enables async buffered writes for xfs. Testing: This patch has been tested with xfstests and fio. Changes: V6: - pass in iter->flags to calls in iomap_page_create() V5: - Refreshed to 5.19-rc1 - Merged patch 3 and patch 4 "mm: Prepare balance_dirty_pages() for async buffered writes" and "mm: Add balance_dirty_pages_ratelimited_flags() function" - Reformatting long file in iomap_page_create() - Replacing gfp parameter with flags parameter in iomap_page_create() This makes sure that the gfp setting is done in one location. - Moved variable definition outside of loop in iomap_write_iter() - Merged patch 7 with patch 6. - Introduced __file_remove_privs() that get the iocb_flags passed in as an additional parameter - Removed file_needs_remove_privs() function - Renamed file_needs_update_time() inode_needs_update_time() - inode_needs_update_time() no longer passes the file pointer - Renamed file_modified_async() to file_modified_flags() - Made file_modified_flags() an internal function - Removed extern keyword in file_modified_async definition - Added kiocb_modified function. - Separate patch for changes to xfs_ilock_for_iomap() - Separate patch for changes to xfs_ilock_inode() - Renamed xfs_ilock_xfs_inode()n back to xfs_ilock_iocb() - Renamed flags parameter to iocb_flags in function xfs_ilock_iocb() - Used inode_set_flags() to manipulate inode flags in the function file_modified_flags() V4: - Reformat new code in generic_write_checks_count(). - Removed patch that introduced new function iomap_page_create_gfp(). - Add gfp parameter to iomap_page_create() and change all callers All users will enforce the number of blocks check - Removed confusing statement in iomap async buffer support patch - Replace no_wait variable in __iomap_write_begin with check of IOMAP_NOWAIT for easier readability. - Moved else if clause in __iomap_write_begin into else clause for easier readability - Removed the balance_dirty_pages_ratelimited_async() function and reverted back to the earlier version that used the function balance_dirty_pages_ratelimited_flags() - Introduced the flag BDP_ASYNC. - Renamed variable in iomap_write_iter from i_mapping to mapping. - Directly call balance_dirty_pages_ratelimited_flags() in the function iomap_write_iter(). - Re-ordered the patches. V3: - Reformat new code in generic_write_checks_count() to line lengthof 80. - Remove if condition in __iomap_write_begin to maintain current behavior. - use GFP_NOWAIT flag in __iomap_write_begin - rename need_file_remove_privs() function to file_needs_remove_privs() - rename do_file_remove_privs to __file_remove_privs() - add kernel documentation to file_remove_privs() function - rework else if branch in file_remove_privs() function - add kernel documentation to file_modified() function - add kernel documentation to file_modified_async() function - rename err variable in file_update_time to ret - rename function need_file_update_time() to file_needs_update_time() - rename function do_file_update_time() to __file_update_time() - don't move check for FMODE_NOCMTIME in generic helper - reformat __file_update_time for easier reading - add kernel documentation to file_update_time() function - fix if in file_update_time from < to <= - move modification of inode flags from do_file_update_time to file_modified() When this function is called, the caller must hold the inode lock. - 3 new patches from Jan to add new no_wait flag to balance_dirty_pages(), remove patch 12 from previous series - Make balance_dirty_pages_ratelimited_flags() a static function - Add new balance_dirty_pages_ratelimited_async() function V2: - Remove atomic allocation - Use direct write in xfs_buffered_write_iomap_begin() - Use xfs_ilock_for_iomap() in xfs_buffered_write_iomap_begin() - Remove no_wait check at the end of xfs_buffered_write_iomap_begin() for the COW path. - Pass xfs_inode pointer to xfs_ilock_iocb and rename function to xfs_lock_xfs_inode - Replace existing uses of xfs_ilock_iocb with xfs_ilock_xfs_inode - Use xfs_ilock_xfs_inode in xfs_file_buffered_write() - Callers of xfs_ilock_for_iomap need to initialize lock mode. This is required so writes use an exclusive lock - Split of _balance_dirty_pages() from balance_dirty_pages() and return sleep time - Call _balance_dirty_pages() in balance_dirty_pages_ratelimited_flags() - Move call to balance_dirty_pages_ratelimited_flags() in iomap_write_iter() to the beginning of the loop Jan Kara (3): mm: Move starting of background writeback into the main balancing loop mm: Move updates of dirty_exceeded into one place mm: Add balance_dirty_pages_ratelimited_flags() function Stefan Roesch (13): iomap: Add flags parameter to iomap_page_create() iomap: Add async buffered write support fs: Add check for async buffered writes to generic_write_checks fs: add __remove_file_privs() with flags parameter fs: Split off inode_needs_update_time and __file_update_time fs: Add async write file modification handling. fs: Optimization for concurrent file time updates. io_uring: Add support for async buffered writes io_uring: Add tracepoint for short writes xfs: Specify lockmode when calling xfs_ilock_for_iomap() xfs: Change function signature of xfs_ilock_iocb() xfs: Add async buffered write support xfs: Enable async buffered write support fs/inode.c | 177 ++++++++++++++++++++++++-------- fs/io_uring.c | 32 +++++- fs/iomap/buffered-io.c | 50 +++++++-- fs/read_write.c | 4 +- fs/xfs/xfs_file.c | 34 +++--- fs/xfs/xfs_iomap.c | 11 +- include/linux/fs.h | 7 ++ include/linux/writeback.h | 7 ++ include/trace/events/io_uring.h | 25 +++++ mm/page-writeback.c | 86 +++++++++------- 10 files changed, 311 insertions(+), 122 deletions(-) base-commit: 140e40e39a29c7dbc188d9b43831c3d5e089c960