From patchwork Thu Jun 16 21:22:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884862 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 9BC5CC43334 for ; Thu, 16 Jun 2022 21:25:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 293316B0072; Thu, 16 Jun 2022 17:25:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2428E6B0087; Thu, 16 Jun 2022 17:25:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E47D6B0088; Thu, 16 Jun 2022 17:25:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EC4ED6B0072 for ; Thu, 16 Jun 2022 17:25:18 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C219234E59 for ; Thu, 16 Jun 2022 21:25:18 +0000 (UTC) X-FDA: 79585379916.10.CC4E748 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf02.hostedemail.com (Postfix) with ESMTP id 2FD878008E for ; Thu, 16 Jun 2022 21:25:17 +0000 (UTC) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPVNV024441 for ; Thu, 16 Jun 2022 14:25:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=+IYV+ohWMnP9Z2WqVp2E+CnW9cqqI1fK3UacqUP+NEU=; b=lnXyN5VaZy0jkf97IXIxihXSHAqSNnJcPl4o74ExLjQfPVwLMsID3kE8O5bN7ICiVJ00 OYa+gdNnJBWq0vMjeq5l6P3XvmFJsVqpNJL6n5jip9rKv1hQE+npX5l3e7tWVA8PDLHj ZcJJ1KPGAuhlEbGWQJw8i+vpnlLmR9sz+N8= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gqd2byu9b-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:25:16 -0700 Received: from twshared25107.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:25:15 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 8B053108B7093; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [PATCH v9 01/14] mm: Move starting of background writeback into the main balancing loop Date: Thu, 16 Jun 2022 14:22:08 -0700 Message-ID: <20220616212221.2024518-2-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: yrOiPS8TDuDojA7AI02hOhGwj9-axVdW X-Proofpoint-ORIG-GUID: yrOiPS8TDuDojA7AI02hOhGwj9-axVdW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655414718; a=rsa-sha256; cv=none; b=FLWJ0JiasdRRYLXe35yUfy4F1QvkNojqxBf8UCoJd3d9uMUOXuMk4WSOzShFVcu8mAI1Oo jRXGrLyvNAx5dK0bGyThm6W6wd6eNhTQ8cuA64ZWvDG70M12BIn5CdrmaycN5GCCvVr9RF XeJ3SW5FIl4EF+kyTEQ4H5zbLelsKvU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=lnXyN5Va; spf=none (imf02.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655414718; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+IYV+ohWMnP9Z2WqVp2E+CnW9cqqI1fK3UacqUP+NEU=; b=KfVP2Z79DIm4vx00U2ls9TexdtnZxGA/msmtrb+NJcqPXeeaMU28iP6lIGuehlfLq8I+XI 97eMFzt1L77NduulKxiyyaecT7Pbp94gAk6oLuJCYTM/HcBLEgvdJSsDQA7pD73XAWfcQ8 /UxCAj809pt6QjQEZ7LCwLl6WsyAxNs= X-Stat-Signature: n5ji9eohum6fe65o88u3my8dtcewtpg1 X-Rspamd-Queue-Id: 2FD878008E Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=lnXyN5Va; spf=none (imf02.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1655414717-985815 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: From: Jan Kara We start background writeback if we are over background threshold after exiting the main loop in balance_dirty_pages(). This may result in basing the decision on already stale values (we may have slept for significant amount of time) and it is also inconvenient for refactoring needed for async dirty throttling. Move the check into the main waiting loop. Signed-off-by: Jan Kara Signed-off-by: Stefan Roesch --- mm/page-writeback.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 55c2776ae699..e59c523aed1a 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1627,6 +1627,19 @@ static void balance_dirty_pages(struct bdi_writeback *wb, } } + /* + * In laptop mode, we wait until hitting the higher threshold + * before starting background writeout, and then write out all + * the way down to the lower threshold. So slow writers cause + * minimal disk activity. + * + * In normal mode, we start background writeout at the lower + * background_thresh, to keep the amount of dirty memory low. + */ + if (!laptop_mode && nr_reclaimable > gdtc->bg_thresh && + !writeback_in_progress(wb)) + wb_start_background_writeback(wb); + /* * Throttle it only when the background writeback cannot * catch-up. This avoids (excessively) small writeouts @@ -1657,6 +1670,7 @@ static void balance_dirty_pages(struct bdi_writeback *wb, break; } + /* Start writeback even when in laptop mode */ if (unlikely(!writeback_in_progress(wb))) wb_start_background_writeback(wb); @@ -1823,23 +1837,6 @@ static void balance_dirty_pages(struct bdi_writeback *wb, if (!dirty_exceeded && wb->dirty_exceeded) wb->dirty_exceeded = 0; - - if (writeback_in_progress(wb)) - return; - - /* - * In laptop mode, we wait until hitting the higher threshold before - * starting background writeout, and then write out all the way down - * to the lower threshold. So slow writers cause minimal disk activity. - * - * In normal mode, we start background writeout at the lower - * background_thresh, to keep the amount of dirty memory low. - */ - if (laptop_mode) - return; - - if (nr_reclaimable > gdtc->bg_thresh) - wb_start_background_writeback(wb); } static DEFINE_PER_CPU(int, bdp_ratelimits); From patchwork Thu Jun 16 21:22:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884863 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 E6531C43334 for ; Thu, 16 Jun 2022 21:25:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EAFE6B0087; Thu, 16 Jun 2022 17:25:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79A2E6B0088; Thu, 16 Jun 2022 17:25:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63B5B6B0089; Thu, 16 Jun 2022 17:25:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5479D6B0087 for ; Thu, 16 Jun 2022 17:25:21 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 26633679 for ; Thu, 16 Jun 2022 21:25:21 +0000 (UTC) X-FDA: 79585380042.16.92EA92D Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf22.hostedemail.com (Postfix) with ESMTP id A0530C008C for ; Thu, 16 Jun 2022 21:25:20 +0000 (UTC) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPWlh032025 for ; Thu, 16 Jun 2022 14:25:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=kEVeF1raHjzqCCTZ1PYGpmk3OQwPxUvEougAHhggs/M=; b=G1MjJwdD5PalkJ2RTEk/KfUzsOeYWuUlma+oPKFKpQ10w0YVrYt9iGcUjc7ANb+h1j+R v8/AZfHpMDDO+BlylzMdXyH/rM3Pd36Ge3cTOGVRRAnwGIhM86SyBGZQWOQdAD01NEFf 6oUF+vy4oC6mVF9DCdJy5ZCu+MvUPytlLEw= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gqxc5yhpt-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:25:19 -0700 Received: from twshared5131.09.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:25:17 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 93E6F108B7095; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [PATCH v9 02/14] mm: Move updates of dirty_exceeded into one place Date: Thu, 16 Jun 2022 14:22:09 -0700 Message-ID: <20220616212221.2024518-3-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: GTK_qDuMBfQeuVQXZslTlw9-2T9RcVjo X-Proofpoint-ORIG-GUID: GTK_qDuMBfQeuVQXZslTlw9-2T9RcVjo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655414720; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kEVeF1raHjzqCCTZ1PYGpmk3OQwPxUvEougAHhggs/M=; b=UgbOvQBdMajUd+lR++sapiqgGVLCdGj6wGbzBB5gRdaJfi64t9yItxkwO87twsK9xrzWTL +Az4SBnp3iOp8Mf0xSzouRLY8i7b8oxZ1f9lufi9mt6qANu5HE+j9w+Ry4tYLIAG8hpdj1 fj4RyzDjode/xZmg1t6rJu33rZBVoyk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=G1MjJwdD; spf=none (imf22.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655414720; a=rsa-sha256; cv=none; b=Nt0kE0CH6OlDdwTA54vd7OrY9JRT412bfWEPabYAiZOHJzdNIYk2Z9VH8U4QMZuaOmGg4P FZ6UyDLevkFfJ3v4HpX+kycX3DzZIhoYOcaZOP2oSwX3ZLXWpZXdILsA20FfVICaP4WLgP 1XAJVoSkE9FW4CqUse81vvrcb+HDaS8= X-Stat-Signature: m3rsqxmgrk3xiwf8u5gphwfzdgxmbjcp X-Rspamd-Queue-Id: A0530C008C X-Rspamd-Server: rspam11 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=G1MjJwdD; spf=none (imf22.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-HE-Tag: 1655414720-202698 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: From: Jan Kara Transition of wb->dirty_exceeded from 0 to 1 happens before we go to sleep in balance_dirty_pages() while transition from 1 to 0 happens when exiting from balance_dirty_pages(), possibly based on old values. This does not make a lot of sense since wb->dirty_exceeded should simply reflect whether wb is over dirty limit and so we should ratelimit entering to balance_dirty_pages() less. Move the two updates together. Signed-off-by: Jan Kara Signed-off-by: Stefan Roesch --- mm/page-writeback.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index e59c523aed1a..90b1998c16a1 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1729,8 +1729,8 @@ static void balance_dirty_pages(struct bdi_writeback *wb, sdtc = mdtc; } - if (dirty_exceeded && !wb->dirty_exceeded) - wb->dirty_exceeded = 1; + if (dirty_exceeded != wb->dirty_exceeded) + wb->dirty_exceeded = dirty_exceeded; if (time_is_before_jiffies(READ_ONCE(wb->bw_time_stamp) + BANDWIDTH_INTERVAL)) @@ -1834,9 +1834,6 @@ static void balance_dirty_pages(struct bdi_writeback *wb, if (fatal_signal_pending(current)) break; } - - if (!dirty_exceeded && wb->dirty_exceeded) - wb->dirty_exceeded = 0; } static DEFINE_PER_CPU(int, bdp_ratelimits); From patchwork Thu Jun 16 21:22:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884865 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 C9A21CCA47A for ; Thu, 16 Jun 2022 21:28:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C7DD6B0087; Thu, 16 Jun 2022 17:28:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 578056B0089; Thu, 16 Jun 2022 17:28:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 418206B008A; Thu, 16 Jun 2022 17:28:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 32E0D6B0087 for ; Thu, 16 Jun 2022 17:28:18 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 15D356C7 for ; Thu, 16 Jun 2022 21:28:18 +0000 (UTC) X-FDA: 79585387476.14.3D912AA Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf31.hostedemail.com (Postfix) with ESMTP id 8ED9220042 for ; Thu, 16 Jun 2022 21:28:17 +0000 (UTC) Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPSwW020230 for ; Thu, 16 Jun 2022 14:28:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=V4TkoQ7WXm0jJu0pyVno6F/WdfdTQwfd01SRs7zvVjU=; b=eFMT/WnlE3uD4DSMpityR+D9RsFeVopvkHCY0i1z52oE1pFQg0f182KxO0KAj8NFBX+V 0VwbBSNGPWdv2cjE4ltuYfaJzc8O857JVoS8yHBcE8zu3iNI9hiHDwyKRopoxtnXfQBf AtEWjTuiQALH9xy9HZurHZ8niezDOxxjOg8= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gqve427wj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:28:16 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:28:15 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 9B98D108B7097; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig Subject: [PATCH v9 03/14] mm: Add balance_dirty_pages_ratelimited_flags() function Date: Thu, 16 Jun 2022 14:22:10 -0700 Message-ID: <20220616212221.2024518-4-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: _Fs4oUwuN9xxGzs5Kn4qDwD_OB1v2wQb X-Proofpoint-GUID: _Fs4oUwuN9xxGzs5Kn4qDwD_OB1v2wQb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655414897; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V4TkoQ7WXm0jJu0pyVno6F/WdfdTQwfd01SRs7zvVjU=; b=0EiqYaExPx9aGbUoBfoF0IteOd1YsKhPFE0bw/jTJPnOpA3O5GSj9pbL3yp8uY7LB/CI9K 4bu9NuL/Ulu8NO/hfLydE6qK8tobCQG8DZssDmzXpkYjWSCv1pXgh05PYtz+1SLhE4UA3m Mii5Wjf2Ype+eaBu5Gq7bcMzDbG+JJ4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655414897; a=rsa-sha256; cv=none; b=7t/mOJdUwBCFRG1PSixBXmFi2ud1ddSGTpPhUjt6SLXfZD8PlyBaNW8pxMlaGY27Z5QH85 eMOM1Jku+zTkDiD+61iaJkfbU39wWoqno9lNVxr+ho0JD1A2t96cLz3du6ZFCrwF+vji28 pyakUbM/onRkYRIYIa+/NOZzqXO6Pq8= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b="eFMT/Wnl"; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf31.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Stat-Signature: zbu31y51ydowgcwifr5s45jsewxmsbmj X-Rspamd-Queue-Id: 8ED9220042 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b="eFMT/Wnl"; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf31.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspamd-Server: rspam01 X-Rspam-User: X-HE-Tag: 1655414897-409419 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: From: Jan Kara This adds the helper function balance_dirty_pages_ratelimited_flags(). It adds the parameter flags to balance_dirty_pages_ratelimited(). The flags parameter is passed to balance_dirty_pages(). For async buffered writes the flag value will be BDP_ASYNC. If balance_dirty_pages() gets called for async buffered write, we don't want to wait. Instead we need to indicate to the caller that throttling is needed so that it can stop writing and offload the rest of the write to a context that can block. The new helper function is also used by balance_dirty_pages_ratelimited(). Signed-off-by: Jan Kara Signed-off-by: Stefan Roesch Reviewed-by: Christoph Hellwig Reported-by: kernel test robot --- include/linux/writeback.h | 7 ++++++ mm/page-writeback.c | 51 +++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index da21d63f70e2..b8c9610c2313 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -364,7 +364,14 @@ void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty); unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh); void wb_update_bandwidth(struct bdi_writeback *wb); + +/* Invoke balance dirty pages in async mode. */ +#define BDP_ASYNC 0x0001 + void balance_dirty_pages_ratelimited(struct address_space *mapping); +int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, + unsigned int flags); + bool wb_over_bg_thresh(struct bdi_writeback *wb); typedef int (*writepage_t)(struct page *page, struct writeback_control *wbc, diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 90b1998c16a1..bfca433640fc 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1554,8 +1554,8 @@ static inline void wb_dirty_limits(struct dirty_throttle_control *dtc) * If we're over `background_thresh' then the writeback threads are woken to * perform some writeout. */ -static void balance_dirty_pages(struct bdi_writeback *wb, - unsigned long pages_dirtied) +static int balance_dirty_pages(struct bdi_writeback *wb, + unsigned long pages_dirtied, unsigned int flags) { struct dirty_throttle_control gdtc_stor = { GDTC_INIT(wb) }; struct dirty_throttle_control mdtc_stor = { MDTC_INIT(wb, &gdtc_stor) }; @@ -1575,6 +1575,7 @@ static void balance_dirty_pages(struct bdi_writeback *wb, struct backing_dev_info *bdi = wb->bdi; bool strictlimit = bdi->capabilities & BDI_CAP_STRICTLIMIT; unsigned long start_time = jiffies; + int ret = 0; for (;;) { unsigned long now = jiffies; @@ -1803,6 +1804,10 @@ static void balance_dirty_pages(struct bdi_writeback *wb, period, pause, start_time); + if (flags & BDP_ASYNC) { + ret = -EAGAIN; + break; + } __set_current_state(TASK_KILLABLE); wb->dirty_sleep = now; io_schedule_timeout(pause); @@ -1834,6 +1839,7 @@ static void balance_dirty_pages(struct bdi_writeback *wb, if (fatal_signal_pending(current)) break; } + return ret; } static DEFINE_PER_CPU(int, bdp_ratelimits); @@ -1855,27 +1861,34 @@ static DEFINE_PER_CPU(int, bdp_ratelimits); DEFINE_PER_CPU(int, dirty_throttle_leaks) = 0; /** - * balance_dirty_pages_ratelimited - balance dirty memory state - * @mapping: address_space which was dirtied + * balance_dirty_pages_ratelimited_flags - Balance dirty memory state. + * @mapping: address_space which was dirtied. + * @flags: BDP flags. * * Processes which are dirtying memory should call in here once for each page * which was newly dirtied. The function will periodically check the system's * dirty state and will initiate writeback if needed. * - * Once we're over the dirty memory limit we decrease the ratelimiting - * by a lot, to prevent individual processes from overshooting the limit - * by (ratelimit_pages) each. + * See balance_dirty_pages_ratelimited() for details. + * + * Return: If @flags contains BDP_ASYNC, it may return -EAGAIN to + * indicate that memory is out of balance and the caller must wait + * for I/O to complete. Otherwise, it will return 0 to indicate + * that either memory was already in balance, or it was able to sleep + * until the amount of dirty memory returned to balance. */ -void balance_dirty_pages_ratelimited(struct address_space *mapping) +int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, + unsigned int flags) { struct inode *inode = mapping->host; struct backing_dev_info *bdi = inode_to_bdi(inode); struct bdi_writeback *wb = NULL; int ratelimit; + int ret = 0; int *p; if (!(bdi->capabilities & BDI_CAP_WRITEBACK)) - return; + return ret; if (inode_cgwb_enabled(inode)) wb = wb_get_create_current(bdi, GFP_KERNEL); @@ -1915,9 +1928,27 @@ void balance_dirty_pages_ratelimited(struct address_space *mapping) preempt_enable(); if (unlikely(current->nr_dirtied >= ratelimit)) - balance_dirty_pages(wb, current->nr_dirtied); + balance_dirty_pages(wb, current->nr_dirtied, flags); wb_put(wb); + return ret; +} + +/** + * balance_dirty_pages_ratelimited - balance dirty memory state. + * @mapping: address_space which was dirtied. + * + * Processes which are dirtying memory should call in here once for each page + * which was newly dirtied. The function will periodically check the system's + * dirty state and will initiate writeback if needed. + * + * Once we're over the dirty memory limit we decrease the ratelimiting + * by a lot, to prevent individual processes from overshooting the limit + * by (ratelimit_pages) each. + */ +void balance_dirty_pages_ratelimited(struct address_space *mapping) +{ + balance_dirty_pages_ratelimited_flags(mapping, 0); } EXPORT_SYMBOL(balance_dirty_pages_ratelimited); From patchwork Thu Jun 16 21:22:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884911 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 E64AAC433EF for ; Thu, 16 Jun 2022 21:58:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A9D86B0071; Thu, 16 Jun 2022 17:58:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 733516B0072; Thu, 16 Jun 2022 17:58:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AB8D6B0073; Thu, 16 Jun 2022 17:58:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 475896B0071 for ; Thu, 16 Jun 2022 17:58:19 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 16D0F6EE for ; Thu, 16 Jun 2022 21:58:19 +0000 (UTC) X-FDA: 79585463118.27.0873108 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf09.hostedemail.com (Postfix) with ESMTP id 9808C140015 for ; Thu, 16 Jun 2022 21:58:18 +0000 (UTC) Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 25GKPSJN002330 for ; Thu, 16 Jun 2022 14:58:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=gfRc1/nPFIvCPltEInFLBIIZpX8aj3lmAi2CboYoUQA=; b=mJJzHxJWruRY+XzkOXFjGrWhslWDW/S18UQlMYNqQdAFfL7zFIten8OmSXvReEAvgWHu Dalv8ndxlBSHfe3yG84FobcTvX+xCer9H1V3jBPPnwb3+YGUk72UV1MfKngSgi99Lx4h A7fGj1Q0KPxTd5dPGZXVapRkNORSO68dxg0= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net (PPS) with ESMTPS id 3gpw7rnspx-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:58:17 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:58:15 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id A3BE7108B709D; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , "Darrick J . Wong" Subject: [PATCH v9 04/14] iomap: Add flags parameter to iomap_page_create() Date: Thu, 16 Jun 2022 14:22:11 -0700 Message-ID: <20220616212221.2024518-5-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: z7IPytL2nmsaRdc9r63CTeP2vf7bdsKW X-Proofpoint-ORIG-GUID: z7IPytL2nmsaRdc9r63CTeP2vf7bdsKW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655416698; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gfRc1/nPFIvCPltEInFLBIIZpX8aj3lmAi2CboYoUQA=; b=ST7iqIIm8ruGLVAhXm9WEyS4F0KXnSxHehzlkJeStnpCrNEZz/1Vht54i6UE3ZHaTWyoy5 ysV4aq0QnFfdzxtrT0DMeu598QbcJSXIBl3oX1AnH4BjbOLZ7si8NtnQHYF4NY6FeuxPdH W37LyUht6QkV1+jmUsuLYixql+djt0c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655416698; a=rsa-sha256; cv=none; b=dXzynz7l6XEIVbSFhxuf/ryGZg+jdOi4dHtRbKQg+3mnFTCcgvXWO8AHs3biVF0f6+xDwC KlYRiJqFt6nK75OfygmiEjJKZNUPofhmxtFl5g4ncHUdCZNe15MEPJYAGkM28ip+rbSyKP u2YkKHPY9yWGfve0At61CFIzvciXjYM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=mJJzHxJW; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf09.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com" Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=mJJzHxJW; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf09.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: mfeim4p4kxtnixkdgffo8dk17xf5aqpf X-Rspamd-Queue-Id: 9808C140015 X-HE-Tag: 1655416698-14411 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: Add the kiocb flags parameter to the function iomap_page_create(). Depending on the value of the flags parameter it enables different gfp flags. No intended functional changes in this patch. Signed-off-by: Stefan Roesch Reviewed-by: Jan Kara Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/iomap/buffered-io.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index d2a9f699e17e..3c97b713f831 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -44,20 +44,28 @@ static inline struct iomap_page *to_iomap_page(struct folio *folio) static struct bio_set iomap_ioend_bioset; static struct iomap_page * -iomap_page_create(struct inode *inode, struct folio *folio) +iomap_page_create(struct inode *inode, struct folio *folio, unsigned int flags) { struct iomap_page *iop = to_iomap_page(folio); unsigned int nr_blocks = i_blocks_per_folio(inode, folio); + gfp_t gfp; if (iop || nr_blocks <= 1) return iop; + if (flags & IOMAP_NOWAIT) + gfp = GFP_NOWAIT; + else + gfp = GFP_NOFS | __GFP_NOFAIL; + iop = kzalloc(struct_size(iop, uptodate, BITS_TO_LONGS(nr_blocks)), - GFP_NOFS | __GFP_NOFAIL); - spin_lock_init(&iop->uptodate_lock); - if (folio_test_uptodate(folio)) - bitmap_fill(iop->uptodate, nr_blocks); - folio_attach_private(folio, iop); + gfp); + if (iop) { + spin_lock_init(&iop->uptodate_lock); + if (folio_test_uptodate(folio)) + bitmap_fill(iop->uptodate, nr_blocks); + folio_attach_private(folio, iop); + } return iop; } @@ -226,7 +234,7 @@ static int iomap_read_inline_data(const struct iomap_iter *iter, if (WARN_ON_ONCE(size > iomap->length)) return -EIO; if (offset > 0) - iop = iomap_page_create(iter->inode, folio); + iop = iomap_page_create(iter->inode, folio, iter->flags); else iop = to_iomap_page(folio); @@ -264,7 +272,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, return iomap_read_inline_data(iter, folio); /* zero post-eof blocks as the page may be mapped */ - iop = iomap_page_create(iter->inode, folio); + iop = iomap_page_create(iter->inode, folio, iter->flags); iomap_adjust_read_range(iter->inode, folio, &pos, length, &poff, &plen); if (plen == 0) goto done; @@ -547,7 +555,7 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, size_t len, struct folio *folio) { const struct iomap *srcmap = iomap_iter_srcmap(iter); - struct iomap_page *iop = iomap_page_create(iter->inode, folio); + struct iomap_page *iop; loff_t block_size = i_blocksize(iter->inode); loff_t block_start = round_down(pos, block_size); loff_t block_end = round_up(pos + len, block_size); @@ -558,6 +566,8 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, return 0; folio_clear_error(folio); + iop = iomap_page_create(iter->inode, folio, iter->flags); + do { iomap_adjust_read_range(iter->inode, folio, &block_start, block_end - block_start, &poff, &plen); @@ -1329,7 +1339,7 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc, struct writeback_control *wbc, struct inode *inode, struct folio *folio, u64 end_pos) { - struct iomap_page *iop = iomap_page_create(inode, folio); + struct iomap_page *iop = iomap_page_create(inode, folio, 0); struct iomap_ioend *ioend, *next; unsigned len = i_blocksize(inode); unsigned nblocks = i_blocks_per_folio(inode, folio); From patchwork Thu Jun 16 21:22:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884905 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 213FCC433EF for ; Thu, 16 Jun 2022 21:52:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BA326B0071; Thu, 16 Jun 2022 17:52:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 867E06B0072; Thu, 16 Jun 2022 17:52:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 730B86B0073; Thu, 16 Jun 2022 17:52:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 62DEA6B0071 for ; Thu, 16 Jun 2022 17:52:20 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 318E235279 for ; Thu, 16 Jun 2022 21:52:20 +0000 (UTC) X-FDA: 79585448040.24.E45A322 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf26.hostedemail.com (Postfix) with ESMTP id 8A87114009F for ; Thu, 16 Jun 2022 21:52:19 +0000 (UTC) Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPTwL020276 for ; Thu, 16 Jun 2022 14:52:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=Ynwi9SDirpjeaykEJbYhjcV/3AMQY22jWj0npJc0zwc=; b=T+KrILDy+2qw2Spbt8zh88B6udlxLj5RiMNAizsQ3xpk6rcwlDkncLomG9GmnLHiFvho L0LEz4KXCVZhyXBAfCmoWBKC+o6BeiKF9na2cCPhbhuLqlUTFIK9+SNUdf2ChQ/ZceiR dK1TzRz8hG40uY6lhJoE6ECfzRKx8Nju2uo= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gqve42c29-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:52:18 -0700 Received: from snc-exhub201.TheFacebook.com (2620:10d:c085:21d::7) by snc-exhub204.TheFacebook.com (2620:10d:c085:21d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:52:17 -0700 Received: from twshared25107.07.ash9.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:52:17 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id ABE25108B709F; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig Subject: [PATCH v9 05/14] iomap: Add async buffered write support Date: Thu, 16 Jun 2022 14:22:12 -0700 Message-ID: <20220616212221.2024518-6-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: rTcL5b91QuDUuVC88NvaJ8bDtvn6cdVg X-Proofpoint-GUID: rTcL5b91QuDUuVC88NvaJ8bDtvn6cdVg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655416339; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ynwi9SDirpjeaykEJbYhjcV/3AMQY22jWj0npJc0zwc=; b=g3a9f1CbsouNvpzax7h+2JD5xQMmhcLXjMSPY3VZ6wpo4/UTTbKzLGEt8nJU5VeaDYu5Gw lcVPmOYr32n4tQI6oyGPTjTzpN1KJxd9lYX3zFPkQPFII5cLnVIbqeSNLhlUA3lMKrd0bJ g2ocRGhq98l1KRcM6tzL6f2eiJt0CLY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655416339; a=rsa-sha256; cv=none; b=8cVhN7jYndg96K0ztioQ6OTOYTFT5yJjkV3TlVk6BmHmuagahCWWsQJ/M1bKYdkE/aPBea K5I4SqzwQU+c4Fgwj0WdntwwG65/ntB36dUPBOEg6Gqs0NelbnrRkkhuVBzSY/2OXO80Dn KpJjV0VkCDxYfsjVMobFwexrt9JkTe0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=T+KrILDy; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf26.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Stat-Signature: umdmrmwonp6n3ga5chx9c6peco6nyfwz X-Rspamd-Queue-Id: 8A87114009F Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=T+KrILDy; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf26.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspamd-Server: rspam01 X-Rspam-User: X-HE-Tag: 1655416339-757956 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 adds async buffered write support to iomap. This replaces the call to balance_dirty_pages_ratelimited() with the call to balance_dirty_pages_ratelimited_flags. This allows to specify if the write request is async or not. In addition this also moves the above function call to the beginning of the function. If the function call is at the end of the function and the decision is made to throttle writes, then there is no request that io-uring can wait on. By moving it to the beginning of the function, the write request is not issued, but returns -EAGAIN instead. io-uring will punt the request and process it in the io-worker. By moving the function call to the beginning of the function, the write throttling will happen one page later. Signed-off-by: Stefan Roesch Reviewed-by: Jan Kara Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 3c97b713f831..83cf093fcb92 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -559,6 +559,7 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, loff_t block_size = i_blocksize(iter->inode); loff_t block_start = round_down(pos, block_size); loff_t block_end = round_up(pos + len, block_size); + unsigned int nr_blocks = i_blocks_per_folio(iter->inode, folio); size_t from = offset_in_folio(folio, pos), to = from + len; size_t poff, plen; @@ -567,6 +568,8 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, folio_clear_error(folio); iop = iomap_page_create(iter->inode, folio, iter->flags); + if ((iter->flags & IOMAP_NOWAIT) && !iop && nr_blocks > 1) + return -EAGAIN; do { iomap_adjust_read_range(iter->inode, folio, &block_start, @@ -584,7 +587,12 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, return -EIO; folio_zero_segments(folio, poff, from, to, poff + plen); } else { - int status = iomap_read_folio_sync(block_start, folio, + int status; + + if (iter->flags & IOMAP_NOWAIT) + return -EAGAIN; + + status = iomap_read_folio_sync(block_start, folio, poff, plen, srcmap); if (status) return status; @@ -613,6 +621,9 @@ static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos, unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS; int status = 0; + if (iter->flags & IOMAP_NOWAIT) + fgp |= FGP_NOWAIT; + BUG_ON(pos + len > iter->iomap.offset + iter->iomap.length); if (srcmap != &iter->iomap) BUG_ON(pos + len > srcmap->offset + srcmap->length); @@ -632,7 +643,7 @@ static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos, folio = __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, fgp, mapping_gfp_mask(iter->inode->i_mapping)); if (!folio) { - status = -ENOMEM; + status = (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; goto out_no_page; } if (pos + len > folio_pos(folio) + folio_size(folio)) @@ -750,6 +761,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) loff_t pos = iter->pos; ssize_t written = 0; long status = 0; + struct address_space *mapping = iter->inode->i_mapping; + unsigned int bdp_flags = (iter->flags & IOMAP_NOWAIT) ? BDP_ASYNC : 0; do { struct folio *folio; @@ -762,6 +775,11 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) bytes = min_t(unsigned long, PAGE_SIZE - offset, iov_iter_count(i)); again: + status = balance_dirty_pages_ratelimited_flags(mapping, + bdp_flags); + if (unlikely(status)) + break; + if (bytes > length) bytes = length; @@ -770,6 +788,10 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) * Otherwise there's a nasty deadlock on copying from the * same page as we're writing to, without it being marked * up-to-date. + * + * For async buffered writes the assumption is that the user + * page has already been faulted in. This can be optimized by + * faulting the user page. */ if (unlikely(fault_in_iov_iter_readable(i, bytes) == bytes)) { status = -EFAULT; @@ -781,7 +803,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) break; page = folio_file_page(folio, pos >> PAGE_SHIFT); - if (mapping_writably_mapped(iter->inode->i_mapping)) + if (mapping_writably_mapped(mapping)) flush_dcache_page(page); copied = copy_page_from_iter_atomic(page, offset, bytes, i); @@ -806,8 +828,6 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) pos += status; written += status; length -= status; - - balance_dirty_pages_ratelimited(iter->inode->i_mapping); } while (iov_iter_count(i) && length); return written ? written : status; @@ -825,6 +845,9 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, }; int ret; + if (iocb->ki_flags & IOCB_NOWAIT) + iter.flags |= IOMAP_NOWAIT; + while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = iomap_write_iter(&iter, i); if (iter.pos == iocb->ki_pos) From patchwork Thu Jun 16 21:22:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884907 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 D2083C43334 for ; Thu, 16 Jun 2022 21:52:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49AD66B0073; Thu, 16 Jun 2022 17:52:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44BBD6B0074; Thu, 16 Jun 2022 17:52:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EA486B0075; Thu, 16 Jun 2022 17:52:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 223426B0073 for ; Thu, 16 Jun 2022 17:52:26 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id F164D1205A8 for ; Thu, 16 Jun 2022 21:52:25 +0000 (UTC) X-FDA: 79585448250.31.A905034 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf01.hostedemail.com (Postfix) with ESMTP id 896464009C for ; Thu, 16 Jun 2022 21:52:25 +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 25GKPR11014444 for ; Thu, 16 Jun 2022 14:52:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=Y55cVOBKiXeRDoBnXl4t1cftHngh7dGKga/NccAHsxM=; b=L4nJ8QUVxzifUlZu+6nWFjpqB+sYhMo1mFr2NgW1ptQnApABtLVSpu9lxVyZ5HNoMXH6 i9BpH2O0tQ8sRgojBiP0drzJa2jBCIqx9XZq3OoU4fG46WB7BJxau5GrHZbbeGXjeXXI 7Jw5p0ZfHhMWfeIwja8GvrKWS2WS0ttBybc= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gr3tr450s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:52:24 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:52:22 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id B3EAA108B70A4; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [PATCH v9 06/14] iomap: Return -EAGAIN from iomap_write_iter() Date: Thu, 16 Jun 2022 14:22:13 -0700 Message-ID: <20220616212221.2024518-7-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: KEQ6hLo_zT5wU8uhPxXXZyZlc1YtvqWp X-Proofpoint-GUID: KEQ6hLo_zT5wU8uhPxXXZyZlc1YtvqWp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655416345; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Y55cVOBKiXeRDoBnXl4t1cftHngh7dGKga/NccAHsxM=; b=wJCmlWUBjQQzfKSB3N+fUfV+tj4KzkwZbJWL+TcE3SCusdEdlxfFD8WfZk7M31hC82pvsj EC1ECKXoEguUCLII66fH0f70sqBdKsSRvuumX7UM4BIxBr0nc5VEUxbM4UYHC6AyFqEYPW NqyYA2j6oFfq7xuDBCPqVKr9yP99psc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655416345; a=rsa-sha256; cv=none; b=mUu9CtGIWq0x5t/tCRb5sN2znyJSaapvnRGWglbhgs3ac0dMeJ2iBjA/5ke48frDFDEB48 bGmnsqtMTNHVSrpI4C2fWujIek/0YyjSGav50lTi/w2kWz0W50ej9joU6db9s3GfG1Hx8/ 8Pxw0vee00FvI2PZLv43DIC+ZM3BM1c= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=L4nJ8QUV; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf01.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=L4nJ8QUV; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf01.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 896464009C X-Stat-Signature: u4p8nw44nexpmgu6pgyefzhh89i87uu7 X-HE-Tag: 1655416345-908033 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: If iomap_write_iter() encounters -EAGAIN, return -EAGAIN to the caller. Signed-off-by: Stefan Roesch --- fs/iomap/buffered-io.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 83cf093fcb92..f2e36240079f 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -830,7 +830,13 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) length -= status; } while (iov_iter_count(i) && length); - return written ? written : status; + if (status == -EAGAIN) { + iov_iter_revert(i, written); + return -EAGAIN; + } + if (written) + return written; + return status; } ssize_t From patchwork Thu Jun 16 21:22:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884945 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 56493C43334 for ; Thu, 16 Jun 2022 22:08:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D03EE6B0071; Thu, 16 Jun 2022 18:08:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8CA96B0072; Thu, 16 Jun 2022 18:08:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2E586B0073; Thu, 16 Jun 2022 18:08:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9C9696B0071 for ; Thu, 16 Jun 2022 18:08:24 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6184234488 for ; Thu, 16 Jun 2022 22:08:24 +0000 (UTC) X-FDA: 79585488528.29.6563337 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf22.hostedemail.com (Postfix) with ESMTP id D868DC000B for ; Thu, 16 Jun 2022 22:08:23 +0000 (UTC) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPVeB002137 for ; Thu, 16 Jun 2022 15:08:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=KS1xFKQqVwoSACeYU9DEyyuaT6PkVs/zrO98r3Io/rM=; b=Um9Xo4Xc4hg2gmS8Ue4r0sZzspv8WzADuAoXmiyrv5TGse9spGYH4psOpg6J1CKb0tCR Q4kICqUEZ3erHA1aBpk5zfocrVGLoqHkzOMSIGKkRB8pT6etmFkzUFuC3Y5lkSRJjNNn Z8eX1DpmS8Ay+oJUuSlmJcq/nEPWAFCPvB0= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gp8ax3v9q-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 15:08:22 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:21d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 15:08:19 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id BB583108B70A9; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , Christian Brauner Subject: [PATCH v9 07/14] fs: Add check for async buffered writes to generic_write_checks Date: Thu, 16 Jun 2022 14:22:14 -0700 Message-ID: <20220616212221.2024518-8-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: 2i2_t06x0OpVkI-aqbjN_QvSAT9LuX_B X-Proofpoint-ORIG-GUID: 2i2_t06x0OpVkI-aqbjN_QvSAT9LuX_B X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=Um9Xo4Xc; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf22.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655417304; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KS1xFKQqVwoSACeYU9DEyyuaT6PkVs/zrO98r3Io/rM=; b=V9ZUcJo+zDskMILHmLd2qPDp3WOTn8Ay24lW7pYqg/O/ZNIxsc79rZKWcAY/AGNBpGq7Jw 39gE0/KuUC0uC6JDojPUPeMIfdXrZizIenDUuSeAO33zE/8cqlrJ5lN8XzORzNIaxKIvYQ KumAo9dPzfC5/fPFCg/83vIjmYiHWrg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655417304; a=rsa-sha256; cv=none; b=FRnremIMwejBXR2sSpBSXtgPb3Go52oRc/ATMNeq6woH/ruOBmf2b2CAJjVAylOX8iFas5 Avxpj6cJqFMRl9XCckTEMA4oHDdUoUnSpifiA/FRPXgF7XOfogmPOwVs4WH6ZbAM+0Biir Y8ZkvsGmySLPhvhRZ32x1LhapwrJPWM= X-Rspam-User: X-Stat-Signature: yrzoxsu1zjqo56ximopjh3b4x1s7copk X-Rspamd-Queue-Id: D868DC000B Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=Um9Xo4Xc; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf22.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspamd-Server: rspam05 X-HE-Tag: 1655417303-306137 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 introduces the flag FMODE_BUF_WASYNC. If devices support async buffered writes, this flag can be set. It also modifies the check in generic_write_checks to take async buffered writes into consideration. Signed-off-by: Stefan Roesch Reviewed-by: Christoph Hellwig Reviewed-by: Christian Brauner (Microsoft) --- fs/read_write.c | 4 +++- include/linux/fs.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index b1b1cdfee9d3..a1f4d45c2406 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1649,7 +1649,9 @@ int generic_write_checks_count(struct kiocb *iocb, loff_t *count) if (iocb->ki_flags & IOCB_APPEND) iocb->ki_pos = i_size_read(inode); - if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT)) + if ((iocb->ki_flags & IOCB_NOWAIT) && + !((iocb->ki_flags & IOCB_DIRECT) || + (file->f_mode & FMODE_BUF_WASYNC))) return -EINVAL; return generic_write_check_limits(iocb->ki_filp, iocb->ki_pos, count); diff --git a/include/linux/fs.h b/include/linux/fs.h index 9ad5e3520fae..bc84847c201e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -180,6 +180,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, /* File supports async buffered reads */ #define FMODE_BUF_RASYNC ((__force fmode_t)0x40000000) +/* File supports async nowait buffered writes */ +#define FMODE_BUF_WASYNC ((__force fmode_t)0x80000000) + /* * Attribute flags. These should be or-ed together to figure out what * has been changed! From patchwork Thu Jun 16 21:22:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884881 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 40470C433EF for ; Thu, 16 Jun 2022 21:38:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B71E16B0071; Thu, 16 Jun 2022 17:38:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B216C6B0073; Thu, 16 Jun 2022 17:38:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C2486B0074; Thu, 16 Jun 2022 17:38:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8A5E66B0071 for ; Thu, 16 Jun 2022 17:38:25 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 638DD1205EE for ; Thu, 16 Jun 2022 21:38:25 +0000 (UTC) X-FDA: 79585412970.04.1AAD8DC Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf22.hostedemail.com (Postfix) with ESMTP id 56BEBC0037 for ; Thu, 16 Jun 2022 21:38:24 +0000 (UTC) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPVAv024419 for ; Thu, 16 Jun 2022 14:38:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=Trwy/AbLNn7HIKjn2Mbz1b1rbKIGVu8VH4/5kOnxGYo=; b=c2RiRoq/0urbd7PVvoal+I8AL4A8iQawOLWuMJGEzNSAtlzOYzjdMPORv/qVMcOyV2tH jGbju6zJ4Zx8levz0traDcOyef5/d0o1Er7dex9UjS6TCTyplnIXsz0OAvE9TvuKzZm/ xiT9PoK5OWFJ7rB9Ro4yiWa/5SPCWYn7iuQ= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gqd2bywjv-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:38:23 -0700 Received: from snc-exhub201.TheFacebook.com (2620:10d:c085:21d::7) by snc-exhub203.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, 16 Jun 2022 14:38:21 -0700 Received: from twshared17349.03.ash7.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:38:21 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id C2C1D108B70AC; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , Christian Brauner Subject: [PATCH v9 08/14] fs: add __remove_file_privs() with flags parameter Date: Thu, 16 Jun 2022 14:22:15 -0700 Message-ID: <20220616212221.2024518-9-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: iK4NnJ4kS39bhSAmID5fvJuFPlyydWA- X-Proofpoint-ORIG-GUID: iK4NnJ4kS39bhSAmID5fvJuFPlyydWA- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b="c2RiRoq/"; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf22.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655415504; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Trwy/AbLNn7HIKjn2Mbz1b1rbKIGVu8VH4/5kOnxGYo=; b=INDILNRNIMIEXVfmQCct88rabMgjxoi/k1ZyyGBksru9B1qJG4yaJVtF6RsXytozKeeWPo vzf7HWPV/uoKI65pPJx9REtTLeQ1O9fhyhC2gfCVWCEKOBGCkMV5KqAEbFjmvFTKzgpHb6 vJ/n4pxg1klK8SGZAhVYc1yfTRoywxY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655415504; a=rsa-sha256; cv=none; b=hrnXj8cCP1S4+NZedtxAQI6Tky2LOfxvuSPNqYMNM9XPDPXoppuiz7OYULUG2nBsnlMfPj mRSRdtITMua/pv9rC4aV2XRU56HgSPesITKcGdi9cmxj3uy/euH45xGbZOzyuAS7HLpcb7 Y9y8+ZjEEzeDQhgBPyQUxxocHrbg55U= X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 56BEBC0037 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b="c2RiRoq/"; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf22.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Stat-Signature: f83wn4io7jn6mujrm87hncc5ya5kr9iq X-HE-Tag: 1655415504-531231 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 adds the function __remove_file_privs, which allows the caller to pass the kiocb flags parameter. No intended functional changes in this patch. Signed-off-by: Stefan Roesch Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Christian Brauner (Microsoft) --- fs/inode.c | 57 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index bd4da9c5207e..a2e18379c8a6 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2010,36 +2010,43 @@ static int __remove_privs(struct user_namespace *mnt_userns, return notify_change(mnt_userns, dentry, &newattrs, NULL); } -/* - * Remove special file priviledges (suid, capabilities) when file is written - * to or truncated. - */ -int file_remove_privs(struct file *file) +static int __file_remove_privs(struct file *file, unsigned int flags) { struct dentry *dentry = file_dentry(file); struct inode *inode = file_inode(file); + int error; int kill; - int error = 0; - /* - * Fast path for nothing security related. - * As well for non-regular files, e.g. blkdev inodes. - * For example, blkdev_write_iter() might get here - * trying to remove privs which it is not allowed to. - */ if (IS_NOSEC(inode) || !S_ISREG(inode->i_mode)) return 0; kill = dentry_needs_remove_privs(dentry); - if (kill < 0) + if (kill <= 0) return kill; - if (kill) - error = __remove_privs(file_mnt_user_ns(file), dentry, kill); + + if (flags & IOCB_NOWAIT) + return -EAGAIN; + + error = __remove_privs(file_mnt_user_ns(file), dentry, kill); if (!error) inode_has_no_xattr(inode); return error; } + +/** + * file_remove_privs - remove special file privileges (suid, capabilities) + * @file: file to remove privileges from + * + * When file is modified by a write or truncation ensure that special + * file privileges are removed. + * + * Return: 0 on success, negative errno on failure. + */ +int file_remove_privs(struct file *file) +{ + return __file_remove_privs(file, 0); +} EXPORT_SYMBOL(file_remove_privs); /** @@ -2090,18 +2097,28 @@ int file_update_time(struct file *file) } EXPORT_SYMBOL(file_update_time); -/* Caller must hold the file's inode lock */ +/** + * file_modified - handle mandated vfs changes when modifying a file + * @file: file that was modified + * + * When file has been modified ensure that special + * file privileges are removed and time settings are updated. + * + * Context: Caller must hold the file's inode lock. + * + * Return: 0 on success, negative errno on failure. + */ int file_modified(struct file *file) { - int err; + int ret; /* * Clear the security bits if the process is not being run by root. * This keeps people from modifying setuid and setgid binaries. */ - err = file_remove_privs(file); - if (err) - return err; + ret = __file_remove_privs(file, 0); + if (ret) + return ret; if (unlikely(file->f_mode & FMODE_NOCMTIME)) return 0; From patchwork Thu Jun 16 21:22:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884875 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 C46A8C43334 for ; Thu, 16 Jun 2022 21:33:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46B166B0087; Thu, 16 Jun 2022 17:33:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F3986B0089; Thu, 16 Jun 2022 17:33:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2460B6B008A; Thu, 16 Jun 2022 17:33:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0FC746B0087 for ; Thu, 16 Jun 2022 17:33:24 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E186A34F5D for ; Thu, 16 Jun 2022 21:33:23 +0000 (UTC) X-FDA: 79585400286.27.5614560 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf09.hostedemail.com (Postfix) with ESMTP id 5706014008C for ; Thu, 16 Jun 2022 21:33:23 +0000 (UTC) Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPXia024109 for ; Thu, 16 Jun 2022 14:33:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=hg9mOHqe8lbN/Pa620EqWCYSM90BEn33RivumAhrzAE=; b=GWyZVaw3xkTWIdDstvRPeaNMsgXRLrr6bDzOW8PdCq+1iFfqL029ldH6mu+hFJEjJKwz GL2WTmUE/XPfJrMit0PUZI8ekIaVJEtlWzUm9cSZSFpQvRUU0ryT4N05QoC6+mI2drwP 5otmHRVP3fstAcl19jN+ipx2hzUV8l5Cpac= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gr4xmkh97-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:33:22 -0700 Received: from twshared17349.03.ash7.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:21d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:33:20 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id C98EA108B70AF; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christian Brauner Subject: [PATCH v9 09/14] fs: Split off inode_needs_update_time and __file_update_time Date: Thu, 16 Jun 2022 14:22:16 -0700 Message-ID: <20220616212221.2024518-10-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: DoDH9BlE2e0q96fEYSE06xvMca8RaRRC X-Proofpoint-ORIG-GUID: DoDH9BlE2e0q96fEYSE06xvMca8RaRRC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655415203; a=rsa-sha256; cv=none; b=Ms87KC8HXkxQ87m6CGzWmLEHmeWq7SrI9Fr+fEIxTEGe5JA70iNIQPNE8s+5hqombO4wEl M3qmoqSxWBDqJXKDH5oA5IOoluX06qAAgAr4wuCzBsosJdA4jri47ukLSXj138J+Ttylma 9QRJZpzPOzlCiRZZvr5FV99h/9XWY1I= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=GWyZVaw3; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf09.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655415203; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hg9mOHqe8lbN/Pa620EqWCYSM90BEn33RivumAhrzAE=; b=q+bHw55+9UTTVxE0cVI6pa7NIoYUT/VR7UX9/IinADXIHaSkf3R0EA5X72Vpjg/rew9Cjd mOyBZnMZzXskYw9qbOuHnoh3NPHMGycNrtNhE+O9pnXQrYgJfw9T9rmjyins7jxguYxyfO sC4vgitsF0haA1VIEbGTgqsOtVQO57Y= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=GWyZVaw3; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf09.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspam-User: X-Stat-Signature: 5ubbt1x6oadfw1hzeyfc5jg6eh5dctww X-Rspamd-Queue-Id: 5706014008C X-Rspamd-Server: rspam08 X-HE-Tag: 1655415203-875631 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 splits off the functions inode_needs_update_time() and __file_update_time() from the function file_update_time(). This is required to support async buffered writes. No intended functional changes in this patch. Signed-off-by: Stefan Roesch Reviewed-by: Jan Kara Reviewed-by: Christian Brauner (Microsoft) --- fs/inode.c | 76 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index a2e18379c8a6..ff726d99ecc7 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2049,35 +2049,18 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); -/** - * file_update_time - update mtime and ctime time - * @file: file accessed - * - * Update the mtime and ctime members of an inode and mark the inode - * for writeback. Note that this function is meant exclusively for - * usage in the file write path of filesystems, and filesystems may - * choose to explicitly ignore update via this function with the - * S_NOCMTIME inode flag, e.g. for network filesystem where these - * timestamps are handled by the server. This can return an error for - * file systems who need to allocate space in order to update an inode. - */ - -int file_update_time(struct file *file) +static int inode_needs_update_time(struct inode *inode, struct timespec64 *now) { - struct inode *inode = file_inode(file); - struct timespec64 now; int sync_it = 0; - int ret; /* First try to exhaust all avenues to not sync */ if (IS_NOCMTIME(inode)) return 0; - now = current_time(inode); - if (!timespec64_equal(&inode->i_mtime, &now)) + if (!timespec64_equal(&inode->i_mtime, now)) sync_it = S_MTIME; - if (!timespec64_equal(&inode->i_ctime, &now)) + if (!timespec64_equal(&inode->i_ctime, now)) sync_it |= S_CTIME; if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode)) @@ -2086,15 +2069,50 @@ int file_update_time(struct file *file) if (!sync_it) return 0; - /* Finally allowed to write? Takes lock. */ - if (__mnt_want_write_file(file)) - return 0; + return sync_it; +} + +static int __file_update_time(struct file *file, struct timespec64 *now, + int sync_mode) +{ + int ret = 0; + struct inode *inode = file_inode(file); - ret = inode_update_time(inode, &now, sync_it); - __mnt_drop_write_file(file); + /* try to update time settings */ + if (!__mnt_want_write_file(file)) { + ret = inode_update_time(inode, now, sync_mode); + __mnt_drop_write_file(file); + } return ret; } + +/** + * file_update_time - update mtime and ctime time + * @file: file accessed + * + * Update the mtime and ctime members of an inode and mark the inode for + * writeback. Note that this function is meant exclusively for usage in + * the file write path of filesystems, and filesystems may choose to + * explicitly ignore updates via this function with the _NOCMTIME inode + * flag, e.g. for network filesystem where these imestamps are handled + * by the server. This can return an error for file systems who need to + * allocate space in order to update an inode. + * + * Return: 0 on success, negative errno on failure. + */ +int file_update_time(struct file *file) +{ + int ret; + struct inode *inode = file_inode(file); + struct timespec64 now = current_time(inode); + + ret = inode_needs_update_time(inode, &now); + if (ret <= 0) + return ret; + + return __file_update_time(file, &now, ret); +} EXPORT_SYMBOL(file_update_time); /** @@ -2111,6 +2129,8 @@ EXPORT_SYMBOL(file_update_time); int file_modified(struct file *file) { int ret; + struct inode *inode = file_inode(file); + struct timespec64 now = current_time(inode); /* * Clear the security bits if the process is not being run by root. @@ -2123,7 +2143,11 @@ int file_modified(struct file *file) if (unlikely(file->f_mode & FMODE_NOCMTIME)) return 0; - return file_update_time(file); + ret = inode_needs_update_time(inode, &now); + if (ret <= 0) + return ret; + + return __file_update_time(file, &now, ret); } EXPORT_SYMBOL(file_modified); From patchwork Thu Jun 16 21:22:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884882 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 7C652C433EF for ; Thu, 16 Jun 2022 21:39:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 161246B0071; Thu, 16 Jun 2022 17:39:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 110666B0073; Thu, 16 Jun 2022 17:39:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF3776B0074; Thu, 16 Jun 2022 17:39:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DF8956B0071 for ; Thu, 16 Jun 2022 17:39:27 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id B4D77605BB for ; Thu, 16 Jun 2022 21:39:27 +0000 (UTC) X-FDA: 79585415574.26.BCA97A6 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf10.hostedemail.com (Postfix) with ESMTP id 5B33DC0072 for ; Thu, 16 Jun 2022 21:39:27 +0000 (UTC) Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 25GKPgTx013455 for ; Thu, 16 Jun 2022 14:39:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=wzl40ncu9+N8GznKN7zuVZtUu0h7x3PlOCjn2K//01I=; b=PelcxXzsTc6vfuU1UwtXbTg6A9oF5CUUkuikGIfh4MFg2dyZgsZX/Qmhnt6Vdvb+fGxg LGagvk6kVNZ5PboByWAX/YD//MaIu7TjcXjl6LnfTsvM8RPndNXTBYKYxh+1mRZI9LBd C7qZRb0VRORg9gjcX1coRwxXPnoD5rUKa1M= Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net (PPS) with ESMTPS id 3gr09vp11r-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:39:26 -0700 Received: from twshared17349.03.ash7.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:39:24 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id D01C6108B70B2; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , Christian Brauner Subject: [PATCH v9 10/14] fs: Add async write file modification handling. Date: Thu, 16 Jun 2022 14:22:17 -0700 Message-ID: <20220616212221.2024518-11-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: Yc8CS6emSpwvXdjU_Uewk4Lt1cgyH9nU X-Proofpoint-ORIG-GUID: Yc8CS6emSpwvXdjU_Uewk4Lt1cgyH9nU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=PelcxXzs; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf10.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655415567; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wzl40ncu9+N8GznKN7zuVZtUu0h7x3PlOCjn2K//01I=; b=Re9NSyf1ui7G1ahx55SNaBNqffAWNjoVoM1/IZDsdg7vAciHJwpZV45mEG1HTpwkgBhgCn 453biyX/w1f7Uck4YRGSA3LtL+ZEXxW9e7XLzryklFDJULqIb+OrctZrav1G0H2REzuy5m MhfnjD73kjtZyLJgeeTSAgF81YRLpLM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655415567; a=rsa-sha256; cv=none; b=rV/opjR9LBZ13yZN96cyg8bkIAaK0CbPYWnSISSOIwm3Xmj4xn6lSsruwj6Mnl182rjg7+ T4PCZMT0lz6TkL9Npmsbl5z4chzaJ/3sb1yvZsjeeesOlhd04VYv6edwNqU355UL85MZjV 2clj9idH2x+kTItVMOIuAk2YIh7NRPU= X-Stat-Signature: 75xea6i7ta9prbzg5r11mbyenirwjckb X-Rspamd-Queue-Id: 5B33DC0072 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=PelcxXzs; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf10.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspamd-Server: rspam10 X-HE-Tag: 1655415567-49569 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 adds a file_modified_async() function to return -EAGAIN if the request either requires to remove privileges or needs to update the file modification time. This is required for async buffered writes, so the request gets handled in the io worker of io-uring. Signed-off-by: Stefan Roesch Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Christian Brauner (Microsoft) --- fs/inode.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- include/linux/fs.h | 1 + 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index ff726d99ecc7..259ebf438893 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2116,17 +2116,21 @@ int file_update_time(struct file *file) EXPORT_SYMBOL(file_update_time); /** - * file_modified - handle mandated vfs changes when modifying a file + * file_modified_flags - handle mandated vfs changes when modifying a file * @file: file that was modified + * @flags: kiocb flags * * When file has been modified ensure that special * file privileges are removed and time settings are updated. * + * If IOCB_NOWAIT is set, special file privileges will not be removed and + * time settings will not be updated. It will return -EAGAIN. + * * Context: Caller must hold the file's inode lock. * * Return: 0 on success, negative errno on failure. */ -int file_modified(struct file *file) +static int file_modified_flags(struct file *file, int flags) { int ret; struct inode *inode = file_inode(file); @@ -2136,7 +2140,7 @@ int file_modified(struct file *file) * Clear the security bits if the process is not being run by root. * This keeps people from modifying setuid and setgid binaries. */ - ret = __file_remove_privs(file, 0); + ret = __file_remove_privs(file, flags); if (ret) return ret; @@ -2146,11 +2150,46 @@ int file_modified(struct file *file) ret = inode_needs_update_time(inode, &now); if (ret <= 0) return ret; + if (flags & IOCB_NOWAIT) + return -EAGAIN; return __file_update_time(file, &now, ret); } + +/** + * file_modified - handle mandated vfs changes when modifying a file + * @file: file that was modified + * + * When file has been modified ensure that special + * file privileges are removed and time settings are updated. + * + * Context: Caller must hold the file's inode lock. + * + * Return: 0 on success, negative errno on failure. + */ +int file_modified(struct file *file) +{ + return file_modified_flags(file, 0); +} EXPORT_SYMBOL(file_modified); +/** + * kiocb_modified - handle mandated vfs changes when modifying a file + * @iocb: iocb that was modified + * + * When file has been modified ensure that special + * file privileges are removed and time settings are updated. + * + * Context: Caller must hold the file's inode lock. + * + * Return: 0 on success, negative errno on failure. + */ +int kiocb_modified(struct kiocb *iocb) +{ + return file_modified_flags(iocb->ki_filp, iocb->ki_flags); +} +EXPORT_SYMBOL_GPL(kiocb_modified); + int inode_needs_sync(struct inode *inode) { if (IS_SYNC(inode)) diff --git a/include/linux/fs.h b/include/linux/fs.h index bc84847c201e..c0d99b5a166b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2390,6 +2390,7 @@ static inline void file_accessed(struct file *file) } extern int file_modified(struct file *file); +int kiocb_modified(struct kiocb *iocb); int sync_inode_metadata(struct inode *inode, int wait); From patchwork Thu Jun 16 21:22:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884876 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 DB49BC43334 for ; Thu, 16 Jun 2022 21:34:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 704206B0071; Thu, 16 Jun 2022 17:34:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 68C556B0073; Thu, 16 Jun 2022 17:34:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 506E86B0074; Thu, 16 Jun 2022 17:34:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 402216B0071 for ; Thu, 16 Jun 2022 17:34:22 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 15B2260591 for ; Thu, 16 Jun 2022 21:34:22 +0000 (UTC) X-FDA: 79585402764.08.6F0B100 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf08.hostedemail.com (Postfix) with ESMTP id 8449916008C for ; Thu, 16 Jun 2022 21:34:21 +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 25GKPRYY014421 for ; Thu, 16 Jun 2022 14:34:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=I1DsOb8+/RCOQDjc5VvCIS0HQO+cqihPjCkv7YhigVI=; b=X1ad1hZutk3Y7LHgrpZFWNn4Sa9yK2iSTqlFW+rGNYywg4Kvqy3bSBo7Ji/6KUJJyiE3 hcIrNBAM4SAYfPRfk98SOKrS5SuQA2k65YS5NEiuXjwHukgmLOI9/86pZVVqF1AOtNgS 1cpr6JqRlW2fQ6ykYaYIkWlEIp/iWmcs0yg= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gr3tr41rs-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:34:20 -0700 Received: from twshared18317.08.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:34:17 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id D6E37108B70B5; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [PATCH v9 11/14] io_uring: Add support for async buffered writes Date: Thu, 16 Jun 2022 14:22:18 -0700 Message-ID: <20220616212221.2024518-12-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: Jkq11SJMwd61UlfCIVMMqXmK3j-LDUUd X-Proofpoint-GUID: Jkq11SJMwd61UlfCIVMMqXmK3j-LDUUd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655415261; a=rsa-sha256; cv=none; b=pmsdI/b74MBHlL4vXGr85FgdRTVAFY+oIf5gxIhMZ2Ej4+9xsqVLUP1TRZFUbZ4K6tIqYt ON58ScUwBf8UyCf+MYZ+eKVUVwlEpuP52WrIBHKddFADYmOwNLnT8tEkQUXfxaDoaCzmwc 4BV2tpPKTu+VChAGo/J9zdFXsnt8MG8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=X1ad1hZu; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf08.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655415261; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=I1DsOb8+/RCOQDjc5VvCIS0HQO+cqihPjCkv7YhigVI=; b=C7LvpYTzdxV+xPpXB3V1PKAWmhzxRqrTif6Yty4wW4ZWe0fpAYBEMcIFXO04fA3pkuOCQZ tEq1eWpGv1XdR3g2GkJ7U8sRjhI9XOi6PaN5xR5IChh8vkXlu6vrFD09pPZTC5h0Db2FQ1 3KgNtChvu6AEtI303bMkAWeZAPuxQx4= Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=X1ad1hZu; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf08.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspam-User: X-Stat-Signature: d6j3g1fnr49k64bp8r97ybapmgtrphas X-Rspamd-Queue-Id: 8449916008C X-Rspamd-Server: rspam08 X-HE-Tag: 1655415261-376833 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 enables the async buffered writes for the filesystems that support async buffered writes in io-uring. Buffered writes are enabled for blocks that are already in the page cache or can be acquired with noio. Signed-off-by: Stefan Roesch --- fs/io_uring.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 3aab4182fd89..22a0bb8c5fe5 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4311,7 +4311,7 @@ static inline int io_iter_do_read(struct io_kiocb *req, struct iov_iter *iter) return -EINVAL; } -static bool need_read_all(struct io_kiocb *req) +static bool need_complete_io(struct io_kiocb *req) { return req->flags & REQ_F_ISREG || S_ISBLK(file_inode(req->file)->i_mode); @@ -4440,7 +4440,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags) } else if (ret == -EIOCBQUEUED) { goto out_free; } else if (ret == req->cqe.res || ret <= 0 || !force_nonblock || - (req->flags & REQ_F_NOWAIT) || !need_read_all(req)) { + (req->flags & REQ_F_NOWAIT) || !need_complete_io(req)) { /* read all, failed, already did sync or don't want to retry */ goto done; } @@ -4536,9 +4536,10 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(!io_file_supports_nowait(req))) goto copy_iov; - /* file path doesn't support NOWAIT for non-direct_IO */ - if (force_nonblock && !(kiocb->ki_flags & IOCB_DIRECT) && - (req->flags & REQ_F_ISREG)) + /* File path supports NOWAIT for non-direct_IO only for block devices. */ + if (!(kiocb->ki_flags & IOCB_DIRECT) && + !(kiocb->ki_filp->f_mode & FMODE_BUF_WASYNC) && + (req->flags & REQ_F_ISREG)) goto copy_iov; kiocb->ki_flags |= IOCB_NOWAIT; @@ -4592,6 +4593,24 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags) /* IOPOLL retry should happen for io-wq threads */ if (ret2 == -EAGAIN && (req->ctx->flags & IORING_SETUP_IOPOLL)) goto copy_iov; + + if (ret2 != req->cqe.res && ret2 >= 0 && need_complete_io(req)) { + struct io_async_rw *rw; + + /* This is a partial write. The file pos has already been + * updated, setup the async struct to complete the request + * in the worker. Also update bytes_done to account for + * the bytes already written. + */ + iov_iter_save_state(&s->iter, &s->iter_state); + ret = io_setup_async_rw(req, iovec, s, true); + + rw = req->async_data; + if (rw) + rw->bytes_done += ret2; + + return ret ? ret : -EAGAIN; + } done: kiocb_done(req, ret2, issue_flags); } else { From patchwork Thu Jun 16 21:22:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884883 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 7D759CCA47C for ; Thu, 16 Jun 2022 21:40:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECE526B0071; Thu, 16 Jun 2022 17:40:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7DFA6B0073; Thu, 16 Jun 2022 17:40:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1F096B0074; Thu, 16 Jun 2022 17:40:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C311E6B0071 for ; Thu, 16 Jun 2022 17:40:20 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 9943E605F9 for ; Thu, 16 Jun 2022 21:40:20 +0000 (UTC) X-FDA: 79585417800.31.9A41A60 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf19.hostedemail.com (Postfix) with ESMTP id 292A61A005D for ; Thu, 16 Jun 2022 21:40:19 +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 25GKPSgR014576 for ; Thu, 16 Jun 2022 14:40:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=YK7eG3j7NHy9n91qx9y5OPEq/Sc1sG64s/rjfArr8jQ=; b=pXUvPIe1K2fZc6M+4DH7No7pEMolSqYHQSmSSClwbgH7qJZ7GNAp4x1+TFQbawIVPu78 lZCZfUThwLgIgfH7NsX2k+Rnu5Dp2tEkoGnrOpdFYioa48xNRcQL6irFS91+D5skarNO PNaT/xUjTfg0nEOSXGuUbNpA2bzuDS49aQU= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gr3tr42xd-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:40:17 -0700 Received: from twshared18317.08.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:40:15 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id DD35C108B70B8; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [PATCH v9 12/14] io_uring: Add tracepoint for short writes Date: Thu, 16 Jun 2022 14:22:19 -0700 Message-ID: <20220616212221.2024518-13-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: 8vq3YT20DAO4gpEuMJm-IvPsbvqZjjHj X-Proofpoint-GUID: 8vq3YT20DAO4gpEuMJm-IvPsbvqZjjHj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655415620; a=rsa-sha256; cv=none; b=Ohg9T4r8gP2kZhFLmqxgpFhqhclZwGZbw38rBgaQCbmpBDCQk1mjzHs/1kToNhkzO6zsui nyFwZ2HE7qvia4PS28yof5EX2RPj6ux8yt4IWl2nz3FMXiFR1O1g409C9s2kkyRDCQJNoE SGYuvthvJSQOIvvD7QVRDBhefn8/Kq4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=pXUvPIe1; spf=none (imf19.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655415620; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YK7eG3j7NHy9n91qx9y5OPEq/Sc1sG64s/rjfArr8jQ=; b=F7KGQ6ZIpyrSQhbBhRDhuXcJ+0tqjepjJRVs7lNAosDSAHS9XYZst3VFiwhCP11mkabKNN IusPU7D0GKhHq8zh9I29pAB587+WHlErEoEqV2JzY1cdjtxxJ9AAzCGH8ToaY7+Yf7rxIf O7OJwBO8Ir3a8KoWBHlOtdm0wUGcFUQ= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 292A61A005D X-Stat-Signature: 37d3adtqjgwua3etyehnh1p14tieo1br Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=pXUvPIe1; spf=none (imf19.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspam-User: X-HE-Tag: 1655415619-30497 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 adds the io_uring_short_write tracepoint to io_uring. A short write is issued if not all pages that are required for a write are in the page cache and the async buffered writes have to return EAGAIN. Signed-off-by: Stefan Roesch --- fs/io_uring.c | 3 +++ include/trace/events/io_uring.h | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 22a0bb8c5fe5..510c09192832 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4597,6 +4597,9 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags) if (ret2 != req->cqe.res && ret2 >= 0 && need_complete_io(req)) { struct io_async_rw *rw; + trace_io_uring_short_write(req->ctx, kiocb->ki_pos - ret2, + req->cqe.res, ret2); + /* This is a partial write. The file pos has already been * updated, setup the async struct to complete the request * in the worker. Also update bytes_done to account for diff --git a/include/trace/events/io_uring.h b/include/trace/events/io_uring.h index 66fcc5a1a5b1..25df513660cc 100644 --- a/include/trace/events/io_uring.h +++ b/include/trace/events/io_uring.h @@ -600,6 +600,31 @@ TRACE_EVENT(io_uring_cqe_overflow, __entry->cflags, __entry->ocqe) ); +TRACE_EVENT(io_uring_short_write, + + TP_PROTO(void *ctx, u64 fpos, u64 wanted, u64 got), + + TP_ARGS(ctx, fpos, wanted, got), + + TP_STRUCT__entry( + __field(void *, ctx) + __field(u64, fpos) + __field(u64, wanted) + __field(u64, got) + ), + + TP_fast_assign( + __entry->ctx = ctx; + __entry->fpos = fpos; + __entry->wanted = wanted; + __entry->got = got; + ), + + TP_printk("ring %p, fpos %lld, wanted %lld, got %lld", + __entry->ctx, __entry->fpos, + __entry->wanted, __entry->got) +); + #endif /* _TRACE_IO_URING_H */ /* This part must be outside protection */ From patchwork Thu Jun 16 21:22:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884906 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 C7298C43334 for ; Thu, 16 Jun 2022 21:52:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EB006B0072; Thu, 16 Jun 2022 17:52:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 470CC6B0073; Thu, 16 Jun 2022 17:52:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3117C6B0074; Thu, 16 Jun 2022 17:52:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2338D6B0072 for ; Thu, 16 Jun 2022 17:52:24 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E91FB204FD for ; Thu, 16 Jun 2022 21:52:23 +0000 (UTC) X-FDA: 79585448166.24.503DE9C Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf05.hostedemail.com (Postfix) with ESMTP id 7B2BB10008C for ; Thu, 16 Jun 2022 21:52:23 +0000 (UTC) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPY8g000858 for ; Thu, 16 Jun 2022 14:52:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=2ubX2t1H4jw4S3E5cOEtl91kfZ1W/8/gWyZU2hf/FHo=; b=J83b7S549fYOhTzcdmPbe/tvUGsNdbenkBYy0QTpozHtH2wyOKyLK7rbRsO/HgZXHfpV yekdgPy8ULnIZxmaiU3dodR3JF/h1pxeFJftwfXa2fxTXdQX3AEKCB2N2Bu1kTvxMMwr 7ozWqyKeiUMU7eM8aBIfacOkKBWL6aTg7A8= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gqktgwm78-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:52:22 -0700 Received: from twshared18317.08.ash9.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:52:21 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id E3A19108B70BB; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , "Darrick J . Wong" Subject: [PATCH v9 13/14] xfs: Specify lockmode when calling xfs_ilock_for_iomap() Date: Thu, 16 Jun 2022 14:22:20 -0700 Message-ID: <20220616212221.2024518-14-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: 2ENoIW9hbGe5qrZTE8wPQPigdNh3QOHv X-Proofpoint-GUID: 2ENoIW9hbGe5qrZTE8wPQPigdNh3QOHv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655416343; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2ubX2t1H4jw4S3E5cOEtl91kfZ1W/8/gWyZU2hf/FHo=; b=26yVokJNBcrngmnnUlcbQDB2AGUwbq2SdUztzy6UIZZ1ISxJ0f5xhpHJm6C0TXv9Rj3kDz ZWWyOpflhABHT7sHKvlGajeJBvbOiEcriXr3bQiW2zENu418tHhbGBd865pYPKs3FF1kze z76z2PJCZ5C/roS7wrEI1wjaD7D8X34= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655416343; a=rsa-sha256; cv=none; b=VOM60HJRN7oFk0TDOsJZXq87xGj/EL0F/Cswo7J3RG9MIkM3h3QCYpz1DEaOlLOfzQPQlk cyeingk2+VaZTGl5VFg+L8iifpr963cBR8V9brbE6BdJlp5xIv0BE5yh/+yGuBgt+GwClH hPD3GhJOLlNTxE7WXwhd3JLP/vuNWCI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=J83b7S54; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf05.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=J83b7S54; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf05.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: cekem118ast3149pr6qefu6b5rax56w7 X-Rspamd-Queue-Id: 7B2BB10008C X-HE-Tag: 1655416343-175931 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 changes the helper function xfs_ilock_for_iomap such that the lock mode must be passed in. Signed-off-by: Stefan Roesch Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_iomap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 5a393259a3a3..bcf7c3694290 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -664,7 +664,7 @@ xfs_ilock_for_iomap( unsigned flags, unsigned *lockmode) { - unsigned mode = XFS_ILOCK_SHARED; + unsigned int mode = *lockmode; bool is_write = flags & (IOMAP_WRITE | IOMAP_ZERO); /* @@ -742,7 +742,7 @@ xfs_direct_write_iomap_begin( int nimaps = 1, error = 0; bool shared = false; u16 iomap_flags = 0; - unsigned lockmode; + unsigned int lockmode = XFS_ILOCK_SHARED; ASSERT(flags & (IOMAP_WRITE | IOMAP_ZERO)); @@ -1172,7 +1172,7 @@ xfs_read_iomap_begin( xfs_fileoff_t end_fsb = xfs_iomap_end_fsb(mp, offset, length); int nimaps = 1, error = 0; bool shared = false; - unsigned lockmode; + unsigned int lockmode = XFS_ILOCK_SHARED; ASSERT(!(flags & (IOMAP_WRITE | IOMAP_ZERO))); From patchwork Thu Jun 16 21:22:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12884891 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 68515C433EF for ; Thu, 16 Jun 2022 21:46:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF7C66B0071; Thu, 16 Jun 2022 17:46:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E809D6B0073; Thu, 16 Jun 2022 17:46:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAB8C6B0074; Thu, 16 Jun 2022 17:46:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B82736B0071 for ; Thu, 16 Jun 2022 17:46:23 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 87B6C213D2 for ; Thu, 16 Jun 2022 21:46:23 +0000 (UTC) X-FDA: 79585433046.25.0C9F9AE Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf22.hostedemail.com (Postfix) with ESMTP id E82F0C00AD for ; Thu, 16 Jun 2022 21:46:20 +0000 (UTC) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25GKPTeX024831 for ; Thu, 16 Jun 2022 14:46:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=mUyYlJXItg61v1JvQQks15Uucu0ATZYHM7QlCl3c3gQ=; b=iA2nAn0G8g76s6ASVrU0F+Pd+gbCqqD0R+T3hbr3jiYqgi/lS2VxAYlvNUaYv9D3uyCc TKy2x8Vl/An4ja/b5j93UIx/ALn2nEDpi6Qvn+yYYfjmZ2VYGFkNcNtCMh6ydqwrCXZL gBIDNuXa40snx9eTo4d5W91NV/HSmJcjm0k= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gqt6fph14-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jun 2022 14:46:19 -0700 Received: from twshared14577.08.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 16 Jun 2022 14:46:16 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id E9EA5108B70BE; Thu, 16 Jun 2022 14:22:23 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig Subject: [PATCH v9 14/14] xfs: Add async buffered write support Date: Thu, 16 Jun 2022 14:22:21 -0700 Message-ID: <20220616212221.2024518-15-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616212221.2024518-1-shr@fb.com> References: <20220616212221.2024518-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: qzjUwJmBRr3AFGw0ix-EaTZfz1ahom41 X-Proofpoint-ORIG-GUID: qzjUwJmBRr3AFGw0ix-EaTZfz1ahom41 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_18,2022-06-16_01,2022-02-23_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655415981; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mUyYlJXItg61v1JvQQks15Uucu0ATZYHM7QlCl3c3gQ=; b=tMjT09IZ3ns1wh5VMknOYOlXZ49B2f1hXN8mhPKzv8apjm+P9uAERbtLYgM0XLr1Iq3cCm YqOHA+ML1ynXFQtFVdkaVNoe2Tq3zNYiA9oQQw0cHPfPdR5tzuFL0UfuO96FzSWg+1MjYu kmrPXwd+LZunJBs9kTlyKQqD/K4lHq4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655415981; a=rsa-sha256; cv=none; b=xDJe7QRLGyN1h/ozRphqCTEF7tfkNTL21qP3KhYOtp3wjNXbwUPUliOKoPLkB0OE6pW1RJ F3Y9Nz73AhV6bSwnZMj2sEMDfndtpsx/UiONTavtmcuIIAbu+GMgWSVkbqGfY5Mq+d9H6C zaIvu4Df2UIu54tzPZFXgdf0WfrnLP4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=iA2nAn0G; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf22.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=iA2nAn0G; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf22.hostedemail.com: domain of "prvs=7166657324=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=7166657324=shr@fb.com" X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E82F0C00AD X-Stat-Signature: jnd59krzucegt1gnyxy6j3i3og1wi44a X-HE-Tag: 1655415980-540361 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 adds the async buffered write support to XFS. For async buffered write requests, the request will return -EAGAIN if the ilock cannot be obtained immediately. Signed-off-by: Stefan Roesch Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 11 +++++------ fs/xfs/xfs_iomap.c | 5 ++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 5a171c0b244b..8d9b14d2b912 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -410,7 +410,7 @@ xfs_file_write_checks( spin_unlock(&ip->i_flags_lock); out: - return file_modified(file); + return kiocb_modified(iocb); } static int @@ -700,12 +700,11 @@ xfs_file_buffered_write( bool cleared_space = false; unsigned int iolock; - if (iocb->ki_flags & IOCB_NOWAIT) - return -EOPNOTSUPP; - write_retry: iolock = XFS_IOLOCK_EXCL; - xfs_ilock(ip, iolock); + ret = xfs_ilock_iocb(iocb, iolock); + if (ret) + return ret; ret = xfs_file_write_checks(iocb, from, &iolock); if (ret) @@ -1165,7 +1164,7 @@ xfs_file_open( { if (xfs_is_shutdown(XFS_M(inode->i_sb))) return -EIO; - file->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC; + file->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC | FMODE_BUF_WASYNC; return generic_file_open(inode, file); } diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index bcf7c3694290..5d50fed291b4 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -886,6 +886,7 @@ xfs_buffered_write_iomap_begin( bool eof = false, cow_eof = false, shared = false; int allocfork = XFS_DATA_FORK; int error = 0; + unsigned int lockmode = XFS_ILOCK_EXCL; if (xfs_is_shutdown(mp)) return -EIO; @@ -897,7 +898,9 @@ xfs_buffered_write_iomap_begin( ASSERT(!XFS_IS_REALTIME_INODE(ip)); - xfs_ilock(ip, XFS_ILOCK_EXCL); + error = xfs_ilock_for_iomap(ip, flags, &lockmode); + if (error) + return error; if (XFS_IS_CORRUPT(mp, !xfs_ifork_has_extents(&ip->i_df)) || XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BMAPIFORMAT)) {