From mboxrd@z Thu Jan 1 00:00:00 1970 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 95212C433FE for ; Wed, 18 May 2022 23:37:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D8238D0009; Wed, 18 May 2022 19:37:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 889188D0002; Wed, 18 May 2022 19:37:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68DE78D0009; Wed, 18 May 2022 19:37:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4DABD8D0002 for ; Wed, 18 May 2022 19:37:54 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3343E31DD1 for ; Wed, 18 May 2022 23:37:54 +0000 (UTC) X-FDA: 79480478868.21.BD5AC37 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf06.hostedemail.com (Postfix) with ESMTP id D6A071800CD for ; Wed, 18 May 2022 23:37:50 +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 24IN6Eqf007654 for ; Wed, 18 May 2022 16:37:53 -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=fNgFPteUPRSul4YL74K0HyPjAeD4pJsVpM/yBNzJ9mk=; b=jt+h995YXw8439ZAsanKmo0IQots139EyYPv+T82ddhOJ2QmthafY+Xb4dZ9gfzTEvHh UhA8i/PVaEJPKO6Pyf9RYOuD4ZFA+HIclSRW0asm2iVRxwrqPNcSfAJlHXm80uIEe188 gX/mPFsUykf83G+FtTgd2ShLjkWOOwNp7vo= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3g4p9gfta3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 18 May 2022 16:37:52 -0700 Received: from twshared35748.07.ash9.facebook.com (2620:10d:c085:208::f) 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; Wed, 18 May 2022 16:37:51 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 137DBF3ED86F; Wed, 18 May 2022 16:37:13 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , Subject: [RFC PATCH v3 15/18] mm: Add balance_dirty_pages_ratelimited_async() function Date: Wed, 18 May 2022 16:37:06 -0700 Message-ID: <20220518233709.1937634-16-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 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: H7Uw4gpScHMcU9d7rVEy3JBS-7SxvrOm X-Proofpoint-GUID: H7Uw4gpScHMcU9d7rVEy3JBS-7SxvrOm 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-Rspamd-Queue-Id: D6A071800CD X-Stat-Signature: cx6ubq9qhm6s5ipiudoxneiaygseo73m X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=jt+h995Y; spf=none (imf06.hostedemail.com: domain of "prvs=6137e46c81=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=6137e46c81=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspamd-Server: rspam09 X-HE-Tag: 1652917070-941442 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 helper function balance_dirty_pages_ratelimited_flags(). It adds the parameter no_wait to balance_dirty_pages_ratelimited(). For async buffered writes no_wait will be true. A new function called balance_dirty_pages_ratelimited_async() is introduced that calls balance_dirty_pages_ratelimited_flags with no_wait set to true. If write throttling is enabled, it retuns -EAGAIN, so the write request can be punted to the io-uring worker. For non-async writes the current behavior is maintained. Signed-off-by: Stefan Roesch --- include/linux/writeback.h | 1 + mm/page-writeback.c | 60 +++++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index fec248ab1fec..15eb0242d3ef 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -373,6 +373,7 @@ unsigned long wb_calc_thresh(struct bdi_writeback *wb= , unsigned long thresh); =20 void wb_update_bandwidth(struct bdi_writeback *wb); void balance_dirty_pages_ratelimited(struct address_space *mapping); +int balance_dirty_pages_ratelimited_async(struct address_space *mapping= ); bool wb_over_bg_thresh(struct bdi_writeback *wb); =20 typedef int (*writepage_t)(struct page *page, struct writeback_control *= wbc, diff --git a/mm/page-writeback.c b/mm/page-writeback.c index fc3b79acd90b..d6a67fc07c55 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1851,28 +1851,18 @@ static DEFINE_PER_CPU(int, bdp_ratelimits); */ DEFINE_PER_CPU(int, dirty_throttle_leaks) =3D 0; =20 -/** - * 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 sy= stem'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) +static int balance_dirty_pages_ratelimited_flags(struct address_space *m= apping, + bool no_wait) { struct inode *inode =3D mapping->host; struct backing_dev_info *bdi =3D inode_to_bdi(inode); struct bdi_writeback *wb =3D NULL; int ratelimit; + int ret =3D 0; int *p; =20 if (!(bdi->capabilities & BDI_CAP_WRITEBACK)) - return; + return ret; =20 if (inode_cgwb_enabled(inode)) wb =3D wb_get_create_current(bdi, GFP_KERNEL); @@ -1912,12 +1902,52 @@ void balance_dirty_pages_ratelimited(struct addre= ss_space *mapping) preempt_enable(); =20 if (unlikely(current->nr_dirtied >=3D ratelimit)) - balance_dirty_pages(wb, current->nr_dirtied, false); + balance_dirty_pages(wb, current->nr_dirtied, no_wait); =20 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 sy= stem'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, false); } EXPORT_SYMBOL(balance_dirty_pages_ratelimited); =20 +/** + * balance_dirty_pages_ratelimited_async - 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 sy= stem'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. + * + * This is the async version of the API. It only checks if it is require= d to + * balance dirty pages. In case it needs to balance dirty pages, it retu= rns + * -EAGAIN. + */ +int balance_dirty_pages_ratelimited_async(struct address_space *mapping= ) +{ + return balance_dirty_pages_ratelimited_flags(mapping, true); +} +EXPORT_SYMBOL(balance_dirty_pages_ratelimited_async); + /** * wb_over_bg_thresh - does @wb need to be written back? * @wb: bdi_writeback of interest --=20 2.30.2