From patchwork Thu Jun 23 17:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893025 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 40FF1C43334 for ; Thu, 23 Jun 2022 18:08:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E28758E0177; Thu, 23 Jun 2022 14:08:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D948F8E0144; Thu, 23 Jun 2022 14:08:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A303A8E0178; Thu, 23 Jun 2022 14:08:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 83A748E0144 for ; Thu, 23 Jun 2022 14:08:19 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 50C5620B9F for ; Thu, 23 Jun 2022 18:08:19 +0000 (UTC) X-FDA: 79610285118.19.3CE1274 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf24.hostedemail.com (Postfix) with ESMTP id CEB85180033 for ; Thu, 23 Jun 2022 18:08:18 +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 25NHutr7020390 for ; Thu, 23 Jun 2022 11:08: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=A7gR5Xw2SOdP/LhUFKnTV5QpJ4jfbl81LezZhYpt5cGZi0n3B5/q0zVgMKm6Mc7Qjn4H DbdOyKNIUkfTWsh0KoxMZZBB7IsZtGD1eEfEEY6cCnsJylDhKS6Lp+Vw+uGV+UsknpJZ cORUIQehKoaQ/xU3BhIBsi2gbhJ+88DQo3s= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gv2nast06-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:08:17 -0700 Received: from twshared1457.37.frc1.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, 23 Jun 2022 11:08:14 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 53F3710C5DC48; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [RESEND PATCH v9 01/14] mm: Move starting of background writeback into the main balancing loop Date: Thu, 23 Jun 2022 10:51:44 -0700 Message-ID: <20220623175157.1715274-2-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: U8_9H3mO9ZWs4pkF9DgfokXVNWuYZno2 X-Proofpoint-GUID: U8_9H3mO9ZWs4pkF9DgfokXVNWuYZno2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=A7gR5Xw2; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf24.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656007699; 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=VCJEOD+CZBKTq6zGQbYjjwvdExwnsvnwMSDBqgjJa4h9flavqDWRz7bAAB87HBRf9HKQ3C eY+w0YVUQdyg4WyxrvLvkFvgZ/7r3ow72r662KV5jiwCFFwaHjZjoPYnMbYfxxXhFU3b/k 4rT8E48c2KLwAioWJmIuH1ODOk1FwaM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007699; a=rsa-sha256; cv=none; b=XO1Wn1/9xWZEDSeU2naVVjyaSgrzpzEEuEbJF8Vc49eFpwEdvAMugXpun73Ip95zdk64Fp ZIMn3Pl7pyAUvOVhlEATISxR822jWR6CfZedUC8XKmd0po+c8s+jp4eV3ChWafFCsaIi9c 9ijwNP7xGjgzkKj773Gw3YKDQx0wnCc= X-Stat-Signature: g384dkpq518sqch1e4h1j6355c6u3zmo X-Rspamd-Queue-Id: CEB85180033 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=A7gR5Xw2; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf24.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspamd-Server: rspam12 X-HE-Tag: 1656007698-339594 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 23 17:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893026 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 AC99AC433EF for ; Thu, 23 Jun 2022 18:08:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91FF28E0178; Thu, 23 Jun 2022 14:08:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A86E8E0144; Thu, 23 Jun 2022 14:08:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65D1E8E0178; Thu, 23 Jun 2022 14:08:20 -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 47A658E0144 for ; Thu, 23 Jun 2022 14:08:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 2AA89605B7 for ; Thu, 23 Jun 2022 18:08:20 +0000 (UTC) X-FDA: 79610285160.22.9ACE534 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf11.hostedemail.com (Postfix) with ESMTP id A5F2340036 for ; Thu, 23 Jun 2022 18:08:19 +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 25NHuptl020517 for ; Thu, 23 Jun 2022 11:08: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=kEVeF1raHjzqCCTZ1PYGpmk3OQwPxUvEougAHhggs/M=; b=ZG/D6IUOGKAHaOYGBpqnig0zJoDmBYDJ4kYcbcjSs0sJFgS9N4VgzQoyUpc5IAfyxIkF lARhqlWjBFNa9pht0ooMsDASbloXgeJPWPlJJrfzSwe86a7hNHBYTLMTmivPs5HX5OS1 FY8c+913psUQ72uA8Ank57bqNr7rr7CIe/g= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net (PPS) with ESMTPS id 3gvce7wk10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:08:18 -0700 Received: from twshared35153.14.frc2.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, 23 Jun 2022 11:08:18 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 5B38C10C5DC4A; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [RESEND PATCH v9 02/14] mm: Move updates of dirty_exceeded into one place Date: Thu, 23 Jun 2022 10:51:45 -0700 Message-ID: <20220623175157.1715274-3-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: ccCGmepI6ZlIJiyG4TPuFB0ilbVg8M2S X-Proofpoint-ORIG-GUID: ccCGmepI6ZlIJiyG4TPuFB0ilbVg8M2S X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007699; a=rsa-sha256; cv=none; b=ZsUAuJo3fZgBqaWK3gd3KJwJSeKKNkP+u/t4vsTzucqf0aFdM8/5yuglkoLKEhgtDOjYnA MQb55VjhTPEh9tVWvSafsyBCQpzXlqc/HYQOf4iRTaGZDdh+Tdb/R0p9wmmC4UbFA0XfOU +gCsA2L4geMzvPZCR5RBaYkncx1jgQk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b="ZG/D6IUO"; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf11.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656007699; 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=fMk3tPAhuKSQjFj1bLddWvYX9d+RbP2Iq0HDT6OKLqaTpjZH0vcTnD6JnMKXT3YxEVpHOx Y0THjdSpr+8hWGyeAy8z/U0rs/uA74TIOE+rIOXqnm9I+FJGJakFukn9xl6N+zH9ZVCM6b MbiT1PMV2UKLLG2oe6s48MWxyPtfWoc= X-Rspam-User: X-Stat-Signature: abpfbx8hw3n9pst7kg5ydeagcuqwi31i X-Rspamd-Queue-Id: A5F2340036 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b="ZG/D6IUO"; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf11.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspamd-Server: rspam03 X-HE-Tag: 1656007699-43328 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 23 17:51:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893022 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 3FE0FC43334 for ; Thu, 23 Jun 2022 18:08:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C54838E0174; Thu, 23 Jun 2022 14:08:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDB358E0144; Thu, 23 Jun 2022 14:08:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7BE68E0174; Thu, 23 Jun 2022 14:08:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9428B8E0144 for ; Thu, 23 Jun 2022 14:08:16 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6E05E3448D for ; Thu, 23 Jun 2022 18:08:16 +0000 (UTC) X-FDA: 79610284992.29.931701B Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf19.hostedemail.com (Postfix) with ESMTP id B723B1A002B for ; Thu, 23 Jun 2022 18:08:15 +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 25NHumFw020170 for ; Thu, 23 Jun 2022 11:08:14 -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=nDkuJyTiitSipJ4AMJ/rAac//wOPEjP9mrLd8VBu3iNQ43WDw+9x48/XveKLKtoaAO/c 2suo7wloZxFSUg7NToIm3XqM2zvWxK0vZrvHI7pIgdwmj/Nw+YtallP+0HhMp6llcDYG pjAPI3uwItEcaLXU44BE8BE6FfBP+6NWbWI= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gvqnbthgd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:08:14 -0700 Received: from twshared22934.08.ash9.facebook.com (2620:10d:c085:208::f) 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, 23 Jun 2022 11:08:13 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 67C3F10C5DC4C; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig Subject: [RESEND PATCH v9 03/14] mm: Add balance_dirty_pages_ratelimited_flags() function Date: Thu, 23 Jun 2022 10:51:46 -0700 Message-ID: <20220623175157.1715274-4-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: WS8-KWdXF1UkQI9bs3KI94irNMtpyyik X-Proofpoint-GUID: WS8-KWdXF1UkQI9bs3KI94irNMtpyyik X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007695; a=rsa-sha256; cv=none; b=Q09wGR8rjbzbQLkPqwFP+SYV1bMAOQGhJOtB5FX00vtV3TLjbQnvA0jW3mK7ng8zvK4DKv BNnRBK/xiHNkpfn7TygMxeEuW8yhJXjK7LALlR53uAdV7WGg80MvJdij3eS1y7kaI8hN2T iqCa59V8fKPqWIfbmujFEXtkSM2dHo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656007695; 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=Xcr0LaaVV8i5P2eSibKr029drhFSx63bDYcXI356pmseq2zD+SjyCSqpB8oLqcLuRj5FLj UpWoITYFTma1DUgNmlOcrQjnCaAs8iAXUFxZ3mYXabIVxfNx4pMNuq0dcmuIMlD99b6YT6 FyCJ7DVAbimlGiv7khxG/TDy1CKfmIo= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=nDkuJyTi; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf19.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Stat-Signature: 9yz3q4kgo4n7z8uqstxzizxs6e6ytecc X-Rspamd-Queue-Id: B723B1A002B Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=nDkuJyTi; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf19.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1656007695-284642 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 --- 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 23 17:51:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893033 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 8F5F2C43334 for ; Thu, 23 Jun 2022 18:24:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26CD68E017F; Thu, 23 Jun 2022 14:24:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 21D068E0144; Thu, 23 Jun 2022 14:24:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E5568E017F; Thu, 23 Jun 2022 14:24:49 -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 F3C2D8E0144 for ; Thu, 23 Jun 2022 14:24:48 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CC48D2C823 for ; Thu, 23 Jun 2022 18:24:43 +0000 (UTC) X-FDA: 79610326446.17.C60026C Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf18.hostedemail.com (Postfix) with ESMTP id E69D31C009E for ; Thu, 23 Jun 2022 18:24:42 +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 25NHunFc016009 for ; Thu, 23 Jun 2022 11:24: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=gfRc1/nPFIvCPltEInFLBIIZpX8aj3lmAi2CboYoUQA=; b=kjAHNst19W6eiv1QGvc1zvRmfMOwLybaOSp/UmzV/QOJbRJOLgPWvVi3Go32Zd/oJZUY kV5HUIUOvNRmrLhTtp7A/7pg7FX+XAU4wlcsKFMQ5e1Ln+WR0OduNozEiDAcXuOmTh1j bXHUSFreQRDCyGAVdQWAAfFCZkbzRQ1cZ+Q= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gv51n94fq-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:24:16 -0700 Received: from twshared22934.08.ash9.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, 23 Jun 2022 11:24:11 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 6E12610C5DC52; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , "Darrick J . Wong" Subject: [RESEND PATCH v9 04/14] iomap: Add flags parameter to iomap_page_create() Date: Thu, 23 Jun 2022 10:51:47 -0700 Message-ID: <20220623175157.1715274-5-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: R1VXN7EMtaEGP01V5QelG0YC21XhcWMt X-Proofpoint-ORIG-GUID: R1VXN7EMtaEGP01V5QelG0YC21XhcWMt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=kjAHNst1; spf=none (imf18.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=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=1656008683; 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=tuScfOde+/6F2myke7drmG0AvnD0uqFIGApHt8ot4i6aL86f4yEykb9orMcLC8WNb62QbF p4qysaMVjkKRT3c+tEmJIYw2zk9EQwu7t3aCWwUakxXPA8g9Veb+pd/vrUxJkGptOCeebn Gx0Kbv1zfxArbpjK/JG9J0zCBt/+eYw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656008683; a=rsa-sha256; cv=none; b=afQ8GdZFyYHQdDsKGNffat/ihNRPLNNBr7DhpYhfgZG0GPmpHpBfTna2os3b7N9cN+57VV HTrSGJzb8fQ5nCR1Vz9xI6VgSaYtDaqDQ5v5mVlI130f+5W3HYLdBTBAyTwDaYFUW9N4fn DKUsHFx58XYpvFdjMgvXDiQ7CKonApA= X-Stat-Signature: swpeb4nw9km4b7tioj6rmargemei1jb4 X-Rspamd-Queue-Id: E69D31C009E X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=kjAHNst1; spf=none (imf18.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspamd-Server: rspam02 X-HE-Tag: 1656008682-555208 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 23 17:51:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893019 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 C3904C43334 for ; Thu, 23 Jun 2022 18:02:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B3D48E0170; Thu, 23 Jun 2022 14:02:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 289ED8E0144; Thu, 23 Jun 2022 14:02:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 153068E0170; Thu, 23 Jun 2022 14:02:17 -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 02D528E0144 for ; Thu, 23 Jun 2022 14:02:17 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C57D8355BB for ; Thu, 23 Jun 2022 18:02:16 +0000 (UTC) X-FDA: 79610269872.14.B0BDA34 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf02.hostedemail.com (Postfix) with ESMTP id 25C3A80036 for ; Thu, 23 Jun 2022 18:02:15 +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 25NHuujn013649 for ; Thu, 23 Jun 2022 11:02:15 -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=m64twwTiU58dmsv0dot3CaWugOfXDG7FnNY9gf1sBrm1B9qHmocs0+bVWHH2/dIjSnxW z4Gg/v/ntfyyqdXbpq93eUFPgEfFu32ldYnI23zpIUgsF7jRwLFOppCV8KDn9QIXmDnX XvSGWlRaw0KsoTj+VoKrttkXRHAJHoeDlwg= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gvqxxt8vg-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:02:15 -0700 Received: from twshared1457.37.frc1.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, 23 Jun 2022 11:02:12 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 7486A10C5DC54; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig Subject: [RESEND PATCH v9 05/14] iomap: Add async buffered write support Date: Thu, 23 Jun 2022 10:51:48 -0700 Message-ID: <20220623175157.1715274-6-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: mNASZHn0Omg5__q3-pw9FaaJ39VoHnJy X-Proofpoint-GUID: mNASZHn0Omg5__q3-pw9FaaJ39VoHnJy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=m64twwTi; spf=none (imf02.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=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=1656007336; 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=AVzV+pIgTLxXycoLMFCvFLv2Vv/SBr+DvK58pvlZzRNmRG1W+t02E3jGVVeqGjOwJxtTzx utLoEh5JqupWyUt2AgE2VWFNn0IW/NFpwBmTCsp8+fj1weGZWGywcZCEToVLVe8XCAvjBQ B+sz1CaO54KOAnzXghqw2V3RXNq6IIU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007336; a=rsa-sha256; cv=none; b=zHSbRkr7uhS0Ki1+np7Gt49gIv9e6Do6rFMAgIhKj3wwDni9tZixv6NuJc0olw6T5I968y QoCqz/JVDp6p0HTYb3CA+wC+iIC/vOlkQ0dX41kjjxvBT/QgH48ymZ9qM8el+I25H1L5N2 jjLcy69rnpxGVJBPUFW3/XdD7+zsnNc= X-Stat-Signature: 8nxhmm8gsgt31b61es98xwdogokh7snf X-Rspamd-Queue-Id: 25C3A80036 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=m64twwTi; spf=none (imf02.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspamd-Server: rspam02 X-HE-Tag: 1656007335-624931 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 23 17:51:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893024 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 1A80DC433EF for ; Thu, 23 Jun 2022 18:08:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96EA18E0176; Thu, 23 Jun 2022 14:08:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FE7C8E0177; Thu, 23 Jun 2022 14:08:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 747BC8E0176; Thu, 23 Jun 2022 14:08:19 -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 5F0C88E0144 for ; Thu, 23 Jun 2022 14:08:19 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3B05860CEF for ; Thu, 23 Jun 2022 18:08:19 +0000 (UTC) X-FDA: 79610285118.31.1584DAC Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf27.hostedemail.com (Postfix) with ESMTP id BA20540037 for ; Thu, 23 Jun 2022 18:08:18 +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 25NHus0P028703 for ; Thu, 23 Jun 2022 11:08: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=Y55cVOBKiXeRDoBnXl4t1cftHngh7dGKga/NccAHsxM=; b=rFK+Q4oEOhnP7rVN1yFE4X7sFKedjbEUzTy7w10spVzTiy1dvL/8F1EF9BSUMMV+CupK 36UO23QtezPSt57WzyqHfzeUTOBOw86Obgca1i6N2j+QYpA3Gmi5kn0+SVUx9iCueffu Ec95wGrKT/HwNCR9+V7LYSOXv5pddSL1wIw= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gvp68au18-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:08:17 -0700 Received: from twshared17349.03.ash7.facebook.com (2620:10d:c085:208::11) 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, 23 Jun 2022 11:08:14 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 7A45910C5DC57; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [RESEND PATCH v9 06/14] iomap: Return -EAGAIN from iomap_write_iter() Date: Thu, 23 Jun 2022 10:51:49 -0700 Message-ID: <20220623175157.1715274-7-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: vfjP3P16eBnDtopgMUx5_XXVZb4VbUgy X-Proofpoint-ORIG-GUID: vfjP3P16eBnDtopgMUx5_XXVZb4VbUgy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007698; a=rsa-sha256; cv=none; b=sw2o0QZgrM8Zkwul8ClYMARMxyDURrKRkvEucshuWHXVpUKPEsG2HsZsFiPjoXDm0kpbEF Oy5iEFcGnUHYVcLSaA1fGz1BzJvEcnJsTDyHIwrVCznrrIiVB5B8QuzWVT4+z8Nffyoc9r dtSsYKuGIrJuQUrs2eAMo7SEstDkVMo= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=rFK+Q4oE; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf27.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656007698; 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=0hNTWSm3VwL+VzGThcJN51yLjHKRRX0FxzMHMp2/+bLcBY2neLM+EMGjmvBrgGEjomLcEP YhaWAA1HymdIEGtMLExY7xDJYRTtkmgHih/w7v9gIetF2sHKCBsS6VMTTDFvidmVnBo3AU mQf9EnhioKx8VP53vKrcAASuIDnaURU= X-Stat-Signature: j91njyhobuptzw89r63uycrf19gytidj X-Rspamd-Queue-Id: BA20540037 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=rFK+Q4oE; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf27.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1656007698-940497 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 Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- 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 23 17:51:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893023 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 DA053C433EF for ; Thu, 23 Jun 2022 18:08:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 354D38E0175; Thu, 23 Jun 2022 14:08:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 329668E0144; Thu, 23 Jun 2022 14:08:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C8A88E0175; Thu, 23 Jun 2022 14:08:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0CDC48E0144 for ; Thu, 23 Jun 2022 14:08:17 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D1DCA60E91 for ; Thu, 23 Jun 2022 18:08:16 +0000 (UTC) X-FDA: 79610284992.29.7E33DDD Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf24.hostedemail.com (Postfix) with ESMTP id 53440180033 for ; Thu, 23 Jun 2022 18:08:16 +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 25NHumGr015920 for ; Thu, 23 Jun 2022 11:08:15 -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=MwqMjStCOZv8f/liIHA0oXhGf7tRXGnB+GR0sJrR1fXE93libJ6tqbnu6U2IZaGOBjRo yFw1wMB1o9XAEgemaHbGQu36YB5vhjcBkm9HwBsknRDDgihq8mMfWGgXUwTFRbgbc4sL G+NX5bWaIFKgvXP9m3DnhKZPt7Oz4pU/plw= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gv51n919b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:08:15 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 23 Jun 2022 11:08:13 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 80EC910C5DC5B; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , Christian Brauner Subject: [RESEND PATCH v9 07/14] fs: Add check for async buffered writes to generic_write_checks Date: Thu, 23 Jun 2022 10:51:50 -0700 Message-ID: <20220623175157.1715274-8-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: KxVkfGHsDtNZ9ouSY34e2Bv6F83KesGj X-Proofpoint-ORIG-GUID: KxVkfGHsDtNZ9ouSY34e2Bv6F83KesGj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=MwqMjStC; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf24.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007696; a=rsa-sha256; cv=none; b=4GNOzw1rnqHdWqsOjf1R0eu4wEjRIHAn+UP+Vozh9ZEStJ5iENpwZ9Rj9EovZX266aCjfC CJEbyt/xtYtyUlIV+nq481gj+ekcIAq8rcgayuSl0BVJYAjrtDrnM33zqNngiLUj4DnhCY li+31DwJUY8o8ch+Z8ifP2rOYJpXJFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656007696; 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=HVMCouXJg6gznZmgMbntt2RcFHi7QSxsZcFK1VQy+p11mp3c+NvSX5jZHWMHs95Rv7DDvw cVlSPUVU9RqQlzthhXAuPnuozm+pgoJCpfBrruwohFrtNKCa6X0nqXeOQKTo2SqnSuXM+b WLu15VRcQaZbE8aCE+v3kbvJbnpof68= X-Stat-Signature: ygu7odfpb9fyawn61mhme5nxp6oye6by X-Rspamd-Server: rspam08 X-Rspam-User: X-Rspamd-Queue-Id: 53440180033 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=MwqMjStC; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf24.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-HE-Tag: 1656007696-500802 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 23 17:51:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893021 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 1F23CC43334 for ; Thu, 23 Jun 2022 18:08:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 992358E0173; Thu, 23 Jun 2022 14:08:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 942D18E0144; Thu, 23 Jun 2022 14:08:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80AC08E0173; Thu, 23 Jun 2022 14:08:13 -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 7126C8E0144 for ; Thu, 23 Jun 2022 14:08:13 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 443CE12092F for ; Thu, 23 Jun 2022 18:08:13 +0000 (UTC) X-FDA: 79610284866.15.8A47F38 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf27.hostedemail.com (Postfix) with ESMTP id BCE324001E for ; Thu, 23 Jun 2022 18:08:12 +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 25NHumUn031524 for ; Thu, 23 Jun 2022 11:08:11 -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=UbHoamVXCK7QXgicXgZ1DT2beuD+zgIY3XBvQmbi/eD4aO7csGf8wo+vNlo0nRDf7imB 8U7CxVtAD6g5LuadroLM1rWtoZhvOIQ4TeXHlpsZVJi6GVuHEP/Cj/JpWoM39jZwidwJ t7SehrZ6PrdhfQrLz8ExYBYVZW7uWCFkd+w= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gvvmj88jn-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:08:11 -0700 Received: from twshared1457.37.frc1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 23 Jun 2022 11:08:09 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 86F0510C5DC5E; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , Christian Brauner Subject: [RESEND PATCH v9 08/14] fs: add __remove_file_privs() with flags parameter Date: Thu, 23 Jun 2022 10:51:51 -0700 Message-ID: <20220623175157.1715274-9-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: ZnX5Wxq059LCrpTHuoNVuqvuBHqWQfa4 X-Proofpoint-GUID: ZnX5Wxq059LCrpTHuoNVuqvuBHqWQfa4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656007692; 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=4ioqsmJci5RYdCTUP47Mk8RKDht7y5ymcEiT3wHmIqFUaZ4vf42ycyrurkR65U5M1V8IE7 gam5J1lf5pDJ3bhSZyPGN0WA5+b5FEkz3kZzFpV3PRI3P7tZOh+CYxowdjMAFB5N2s6D8d AaXNyvE+J1bD/2FbhWoA9Z1s+9jGmT4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=UbHoamVX; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf27.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007692; a=rsa-sha256; cv=none; b=Mwi/A7+QEDltQsEOualN0IbXhKejsqLrACGnu0eUHN4adws9A6QMteLhmwj+GQCd+TiP5K SRkDUeKvj/LwYDDV2zrsaKF9VDXW7eCuJ+O+Ry9nTXZLW78lENwwrf8bCA6yBSGJM5UuZZ XyUjjILQav+5CaztF8gxjbWGE0BPlI4= X-Rspamd-Queue-Id: BCE324001E Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=UbHoamVX; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf27.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qd6ai3oxuwzdurd7u8ttdbnuz6w7gfhi X-HE-Tag: 1656007692-104173 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 23 17:51:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893018 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 7F901C43334 for ; Thu, 23 Jun 2022 18:02:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B64878E016F; Thu, 23 Jun 2022 14:02:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B15038E0144; Thu, 23 Jun 2022 14:02:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A036A8E016F; Thu, 23 Jun 2022 14:02:12 -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 91DB88E0144 for ; Thu, 23 Jun 2022 14:02:12 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 65B443569A for ; Thu, 23 Jun 2022 18:02:12 +0000 (UTC) X-FDA: 79610269704.25.950EC45 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf31.hostedemail.com (Postfix) with ESMTP id CD75D200BF for ; Thu, 23 Jun 2022 18:02:11 +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 25NHuqam025904 for ; Thu, 23 Jun 2022 11:02:11 -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=CmDDAQlqynY28763l7sI+aI7i9V+sA/UOfFzsgeNL63J7hp14qkYTlNRnnTKKoLXAkk+ i4nPRrNllQ0bkzTCih7Tr4h0j8AnkVmoc0tLLWvmQ9Jr18zpk2NTIEYywtoYVVqiFAzB 3qQKfHiP8U2XyJqZdWXf1Zjojy6W89hvnMg= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gvn9433cw-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:02:10 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 23 Jun 2022 11:02:08 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 8C5B410C5DC61; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christian Brauner Subject: [RESEND PATCH v9 09/14] fs: Split off inode_needs_update_time and __file_update_time Date: Thu, 23 Jun 2022 10:51:52 -0700 Message-ID: <20220623175157.1715274-10-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: d1GWIze-PBt6CU0vsXVFXGcfskMGEPnl X-Proofpoint-GUID: d1GWIze-PBt6CU0vsXVFXGcfskMGEPnl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007332; a=rsa-sha256; cv=none; b=niAqwLSEaarRNaN5a19v4LJR8pso0y3rvrBLrG0HlvBd30qlIa4ad3dLNfQwqI+YEjbDKP oVCq4aTo7H2RucaqN0tk1sp/1Hb28zVNTwPhuQNL5srv2WZF/ReeL1Zxuvt9DK4nSgqxFr VsTbVxtwUDklcOMEGE6DSBpPYgc01ZU= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=CmDDAQlq; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf31.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656007332; 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=aKJuaC5wH7tAExKzt219WRWCQcztKKPTOtMgfMuCfDgZY7lBAfyEqndjTObQr9/W4ri2dp UxHPdfUptj+dn/UhspCzal2mGAYvFn2Yxm4iPAVQIyLm/3onALf3RYAz40jxUtm0k+QrfF 30AMof48rFPn/4h+/OYi+AeinpPpYEU= X-Stat-Signature: 8yiwyhgrcckf3ozoas7wmy9keqe63xet X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CD75D200BF Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=CmDDAQlq; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf31.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-HE-Tag: 1656007331-247189 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 23 17:51:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893034 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 DE8D0C433EF for ; Thu, 23 Jun 2022 18:25:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EB3F8E0180; Thu, 23 Jun 2022 14:25:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79B8C8E0144; Thu, 23 Jun 2022 14:25:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6643D8E0180; Thu, 23 Jun 2022 14:25:42 -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 577C78E0144 for ; Thu, 23 Jun 2022 14:25:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 867B2359A4 for ; Thu, 23 Jun 2022 18:25:36 +0000 (UTC) X-FDA: 79610328672.02.E9F318F Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf30.hostedemail.com (Postfix) with ESMTP id F2E1180028 for ; Thu, 23 Jun 2022 18:25:35 +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 25NHune6016140 for ; Thu, 23 Jun 2022 11:25:10 -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=O+oAA287hMlBIkHI3WqhiMPVAPzXmevbwxYvC3V6smsqZKUfkzzNl5HEdFLGvuZvHrYF aZj3+x8pgfuWlFVPNLRP7e4Kf+7Y/RpJYL9G+8K08Yqg/Q8JcAr/Hrc4+v7kjOos4D/s zV9GRP9SahwLyQm5JNxDS88mUVaAQ6iTu+4= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net (PPS) with ESMTPS id 3gvqwxjeym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:25:10 -0700 Received: from twshared25107.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 23 Jun 2022 11:25:08 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 91F5C10C5DC64; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , Christian Brauner Subject: [RESEND PATCH v9 10/14] fs: Add async write file modification handling. Date: Thu, 23 Jun 2022 10:51:53 -0700 Message-ID: <20220623175157.1715274-11-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: Y1cGCvYkLYRMHoTEaQ9NJbj1TZ3GmDPI X-Proofpoint-GUID: Y1cGCvYkLYRMHoTEaQ9NJbj1TZ3GmDPI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656008736; 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=7BaDHz5afvO1OEMuWsRSzhAzpVDdnw+MX3/fj2fk8F/QqqOZagN2EaoRS0AM6WYGeXPzb3 HzziCJ5bXUUfffetdTtkGGabdRZrF8UouJ8keh04ojWZqWf/e/MLEeQw/DTmJRjFj127Qc u/6z8QZUUgDJIE6rIlBGzT6xBceOwCA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=O+oAA287; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf30.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656008736; a=rsa-sha256; cv=none; b=MtN+wlDFfI3FHzH10WQiJxfMNVmdSNuFo0IotSDoAE0z74Tq/Ul4RlB079yRLhHTTowxw4 LhG7xlyu14EY2X2ZnFkbfBKXy0J86we2asjWqk3YGG+9/7osht89noqXU9FsRTmnduP975 oizroW5Mc0BH2Ngnov1BblCJqMYDBbY= X-Rspamd-Queue-Id: F2E1180028 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=O+oAA287; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf30.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: foa4bzf6rj8u3xxms5c4z56o6e5bwk1z X-HE-Tag: 1656008735-315154 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 23 17:51:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893030 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 7C267C43334 for ; Thu, 23 Jun 2022 18:14:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 130CA8E017A; Thu, 23 Jun 2022 14:14:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E1308E0144; Thu, 23 Jun 2022 14:14:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F12858E017A; Thu, 23 Jun 2022 14:14:48 -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 E292E8E0144 for ; Thu, 23 Jun 2022 14:14:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 9895C81234 for ; Thu, 23 Jun 2022 18:14:37 +0000 (UTC) X-FDA: 79610300994.30.4E53F0A Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf04.hostedemail.com (Postfix) with ESMTP id 0DF3740021 for ; Thu, 23 Jun 2022 18:14:36 +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 25NHupI2020103 for ; Thu, 23 Jun 2022 11:14:11 -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=HJhJ+j3fM/4d2VJQBb3PcpTtgDac/wYEt/GUs/ZqGQJKWPVG00NHipNuDiLS4zAoYt5I nNHzBcdxnt2tKh7dN1+NsaAWxhglbGwc1HJo39oJAt0SSf09M0ai6wgTqbfmu3Jq/AzJ 3p7izgvkRDIPXpAsnkyaVbDC1rMFmLAOIgc= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gv2nasu9q-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:14:10 -0700 Received: from twshared18317.08.ash9.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, 23 Jun 2022 11:14:08 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 979A510C5DC67; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [RESEND PATCH v9 11/14] io_uring: Add support for async buffered writes Date: Thu, 23 Jun 2022 10:51:54 -0700 Message-ID: <20220623175157.1715274-12-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: J9ANYWr3ncZUz4Dp6DpHQz4ClDa-F-B4 X-Proofpoint-GUID: J9ANYWr3ncZUz4Dp6DpHQz4ClDa-F-B4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=HJhJ+j3f; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf04.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656008077; a=rsa-sha256; cv=none; b=DZEQfowiRFlBpw3AchtD3oSCnxfxVnw0oLe9YyrxpMFCY0dQABHpnQXhpwpcSVxMe5H7FS mVswOnx0WNYiviOdTqO0uCJqikULLyqDqVxq4nfjywu7Qw0QUpuqofyMt826R6EmtTFVqx 7FtIVRDCGpzUht4ZBjDxw5XaXl7SYWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656008077; 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=lEKTVzWAZkrkIgf8it5sq6qI695WfS96EBY0K+RmX0+eEDR9WZ13ds2z24xOsIhHs/R9Yz efP62ksbcjUaIdnjUPVEqb98JCVDXjhglSewarQnmHyRpNZsJECS/CJoJFeqgpqDuigV3a tDCAnKRZmo+nXd74FF+jBQancAxqCOo= X-Stat-Signature: 6hb6p7atsdx9bhfsr46ti5m53by54hm7 X-Rspamd-Server: rspam08 X-Rspam-User: X-Rspamd-Queue-Id: 0DF3740021 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=HJhJ+j3f; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf04.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-HE-Tag: 1656008076-203815 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 23 17:51:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893031 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 37FA6C433EF for ; Thu, 23 Jun 2022 18:14:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0B318E017B; Thu, 23 Jun 2022 14:14:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96B768E0144; Thu, 23 Jun 2022 14:14:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85A7E8E017B; Thu, 23 Jun 2022 14:14:49 -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 774458E0144 for ; Thu, 23 Jun 2022 14:14:49 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3EEBB34815 for ; Thu, 23 Jun 2022 18:14:49 +0000 (UTC) X-FDA: 79610301498.07.B53350D Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf14.hostedemail.com (Postfix) with ESMTP id BC0BF10001D for ; Thu, 23 Jun 2022 18:14:48 +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 25NHumEG031516 for ; Thu, 23 Jun 2022 11:14: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=YK7eG3j7NHy9n91qx9y5OPEq/Sc1sG64s/rjfArr8jQ=; b=JzMhRhJtiMvYgqi594MJOXivAVIlgaGWjaSMWepCRKvxuhi0qnGD4+22CMtAmQzUzOWo d83y/Gsf78FgdP0iA2of+K9UdZ80CFRqWxTotw62n/G7W7uv+Mw+cwat/oeX8cO8E1aC IWVjDAji9ai9uhfQq80hQ+DNX6URS8epmvQ= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gvvmj89tb-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:14:22 -0700 Received: from twshared5640.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, 23 Jun 2022 11:14:15 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 9CEDF10C5DC6A; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Subject: [RESEND PATCH v9 12/14] io_uring: Add tracepoint for short writes Date: Thu, 23 Jun 2022 10:51:55 -0700 Message-ID: <20220623175157.1715274-13-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: ui5V4Uinj4VMuqnfTyWV95ORtcyq0AO4 X-Proofpoint-GUID: ui5V4Uinj4VMuqnfTyWV95ORtcyq0AO4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656008088; a=rsa-sha256; cv=none; b=mhm4VbHNUMNcTyJxACdGifdR5M/NH8k3EOs+C4/DMzY7erwa5mT1xs92JSP3hopatpBfii r91Y+Tz7SIqyC0IIgCB52uTj2dRROeY0/wrdpRcr2hIeaVRuyM5DaWuvoNGeehjN8/ma2j VQIFtfLlVy57KAdpgiDEeRRaSihbzXQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=JzMhRhJt; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf14.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656008088; 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=6ZH5YJBm9zjsKs58+om6A2UFiveThOJmJgkSSa3xUyAREk3dbtfJj74viWZdKCKdmJFc3P CKu36he/S191Z7zEbKEvp79zrGX7yw7n5ZlVJ7LpZB+/8MuCPDSEAP0I6+xev5CH9LF/Qn cq0UHigVc4OQV9FcdE8VL+otcW8tKtM= X-Stat-Signature: nqrw5gqp8451t88m1s4jk4c49hn6w74h X-Rspamd-Queue-Id: BC0BF10001D Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=JzMhRhJt; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf14.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1656008088-143193 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 23 17:51:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893100 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 392CBC433EF for ; Thu, 23 Jun 2022 19:03:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CDE98E0184; Thu, 23 Jun 2022 15:03:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 956A28E0144; Thu, 23 Jun 2022 15:03:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F7448E0184; Thu, 23 Jun 2022 15:03:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6CA158E0144 for ; Thu, 23 Jun 2022 15:03:32 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 346EC35E02 for ; Thu, 23 Jun 2022 19:03:27 +0000 (UTC) X-FDA: 79610424054.20.6C00FAD Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf31.hostedemail.com (Postfix) with ESMTP id A0CE320039 for ; Thu, 23 Jun 2022 19:03:26 +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 25NHunJ3020209 for ; Thu, 23 Jun 2022 11:31:13 -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=ZEiJdep0uxRsGy9QldhJqt3wJFaObvZBaMkoPVrnBrC3Nv7NFnOn4pra716yJ95LNDGP HEZi1QoCVTVFQPxUSn5BnztMm8dUmUmDHtW5lir/CPvWHLU6Hj4vPUUzbue2ELU5PNAp a4k5ddv2IRUaaJM3/SpbYMLyP+U/4rg3avc= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gvqnbtp7j-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:31:12 -0700 Received: from twshared1457.37.frc1.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, 23 Jun 2022 11:31:11 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id A256710C5DC6D; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , "Darrick J . Wong" Subject: [RESEND PATCH v9 13/14] xfs: Specify lockmode when calling xfs_ilock_for_iomap() Date: Thu, 23 Jun 2022 10:51:56 -0700 Message-ID: <20220623175157.1715274-14-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: FW6fjuH_-mT6fH_6k8Vf8ZK0VRfIuH9X X-Proofpoint-GUID: FW6fjuH_-mT6fH_6k8Vf8ZK0VRfIuH9X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_08,2022-06-23_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656011006; a=rsa-sha256; cv=none; b=cTkNW8U1Tw+PapJ9m1H97L+23AtaNesDOVNyj6LaFfzspT7QjQF+rPnu4uXI/vWmPXkzj5 F25orKvNU0PEWkiOQFfmUs3WI2aKthjXVlFlH12vtWdyKABWH1Zo9phoNnpwK4BaJ+R0dH JpEboPNSjxwGNpqF069swAbNLNciB1g= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=ZEiJdep0; spf=none (imf31.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=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=1656011006; 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=JE8yp85y0ePfdb3Jut+wKwD2XdZIf8s3uO/9vuyeG5Qj45OxS8WJsHj5YSI96HQLqSC942 1Ngx6m5gHhio/Gfrc4wbM6z6o8rEQ5T1FtVXZHKHL4GKjewMNB/VrtKhEJifryeKdPhbo/ VLYhXgZ4ckhWs00vppk0TedoMjUBzg0= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A0CE320039 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=ZEiJdep0; spf=none (imf31.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=71737354e2=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspam-User: X-Stat-Signature: j78t96x3tnr4qbs6gpdr35qxpjtccyy3 X-HE-Tag: 1656011006-723647 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 23 17:51:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12893032 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 BBADDC433EF for ; Thu, 23 Jun 2022 18:20:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 292928E017C; Thu, 23 Jun 2022 14:20:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2430A8E0144; Thu, 23 Jun 2022 14:20:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1324C8E017C; Thu, 23 Jun 2022 14:20:46 -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 F40388E0144 for ; Thu, 23 Jun 2022 14:20:45 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 376B261439 for ; Thu, 23 Jun 2022 18:20:36 +0000 (UTC) X-FDA: 79610316072.31.B66EC4E Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf16.hostedemail.com (Postfix) with ESMTP id A0991180022 for ; Thu, 23 Jun 2022 18:20:34 +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 25NHuoAQ020485 for ; Thu, 23 Jun 2022 11:20:08 -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=VZKdRcr9LZs38Nb/xm+f8yCJQ2LEwgYgKqLoqtcoIKjvPUftIcIpsu2xozwBnKKuy6tZ LVSsYl7JBzzlujPfrA44g2DXGa13rey6uliU1N/LMmpMT3PwXWBOfhSEbmLZyME5DWih Isa6jAM15RB7/8skv0JIJa94uA2B0jrt2bo= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net (PPS) with ESMTPS id 3gvce7wndn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:20:08 -0700 Received: from twshared18317.08.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, 23 Jun 2022 11:20:07 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id A7D8A10C5DC70; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig Subject: [RESEND PATCH v9 14/14] xfs: Add async buffered write support Date: Thu, 23 Jun 2022 10:51:57 -0700 Message-ID: <20220623175157.1715274-15-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: Bx8CKIfkfScDAddNfU-SnaWUQrMa8CHN X-Proofpoint-ORIG-GUID: Bx8CKIfkfScDAddNfU-SnaWUQrMa8CHN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656008435; a=rsa-sha256; cv=none; b=WmGz2ih5VyVJJVjP3KSBHMIzgmdKQs13MKX3j11g5VRf/+tkVt8VeLPzrgdAAyAgbYLhx4 7p9M7NVdYbZbz9DvrLJdoXy8lnN/WRAY9rqjcMYhbtqRVc9XxWjyEDT9oTmySngCpjEXLF qWHi0+HuGg4Dtw9INdsPvxH4baXxAJg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=VZKdRcr9; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf16.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656008435; 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=FYp7K+/jjFOyq4YI4B7THhQhq/pcDHX4a+1tudS5ih3Pk6+SDsDaSQ3ntKTCCNE+RhOT2g aMk+3F1nyyVbS61KGjAyiZqoAwZnrDlkvJnQE/UXnbvHpY9MSVJoo55lYfsYuRB5XLP40c P0tCNB2WrdHjadGHYS++MfXeeaXdw6k= X-Stat-Signature: kpkhy4q6io5r8a7df17wsxcqum7e1maw X-Rspamd-Queue-Id: A0991180022 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=VZKdRcr9; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf16.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1656008434-786704 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)) {