From patchwork Wed May 18 23:37:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12854317 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 B1772C4332F for ; Wed, 18 May 2022 23:37:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63F3C8D0006; Wed, 18 May 2022 19:37:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F5898D0002; Wed, 18 May 2022 19:37:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B73F8D0006; Wed, 18 May 2022 19:37:50 -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 38A5B8D0002 for ; Wed, 18 May 2022 19:37:50 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 1B92F606EA for ; Wed, 18 May 2022 23:37:50 +0000 (UTC) X-FDA: 79480478700.24.EE60EC2 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf29.hostedemail.com (Postfix) with ESMTP id 7FA2B1200E9 for ; Wed, 18 May 2022 23:37:40 +0000 (UTC) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24IN6FBU013632 for ; Wed, 18 May 2022 16:37:48 -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=YqpL7bjIpVC1T97cqx5/U3u744Lv+NFWKctjbk1tsPQ=; b=O1yAb8w1N1LFimCUIL56ovslFW04+3z1OBoK0HbYYJD3Hg8811rHF5Lil5O5Y4VLZ3e3 ulSJsERiQrFtWbMGxyYFJUuXFE8hlHLPIZ94ZOayu1XuOy6BSMoH2JF95wUxJonWRjRk VvisvwnPyknlbE3H4mF27BmlTk/eVcEzbTU= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3g4dea3tmh-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 18 May 2022 16:37:48 -0700 Received: from twshared11660.23.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; Wed, 18 May 2022 16:37:46 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 19715F3ED871; Wed, 18 May 2022 16:37:13 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , Subject: [RFC PATCH v3 16/18] iomap: Use balance_dirty_pages_ratelimited_flags in iomap_write_iter Date: Wed, 18 May 2022 16:37:07 -0700 Message-ID: <20220518233709.1937634-17-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220518233709.1937634-1-shr@fb.com> References: <20220518233709.1937634-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: xdk9HoACo7UB_hnseWdEpZtIsszH1j0Q X-Proofpoint-GUID: xdk9HoACo7UB_hnseWdEpZtIsszH1j0Q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-18_06,2022-05-17_02,2022-02-23_01 X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 7FA2B1200E9 X-Stat-Signature: xx36n9sumnwx5ghzom17htceiaf3opdf Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=O1yAb8w1; spf=none (imf29.hostedemail.com: domain of "prvs=6137e46c81=shr@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=6137e46c81=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-HE-Tag: 1652917060-414032 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 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 --- fs/iomap/buffered-io.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index b029e2b10e07..2b85ddfa6ea1 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -784,6 +784,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) do { struct folio *folio; struct page *page; + struct address_space *i_mapping = iter->inode->i_mapping; unsigned long offset; /* Offset into pagecache page */ unsigned long bytes; /* Bytes to write to page */ size_t copied; /* Bytes copied from user */ @@ -792,6 +793,14 @@ 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: + if (iter->flags & IOMAP_NOWAIT) { + status = balance_dirty_pages_ratelimited_async(i_mapping); + if (unlikely(status)) + break; + } else { + balance_dirty_pages_ratelimited(i_mapping); + } + if (bytes > length) bytes = length; @@ -815,7 +824,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(i_mapping)) flush_dcache_page(page); copied = copy_page_from_iter_atomic(page, offset, bytes, i); @@ -840,8 +849,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;