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 BB963CCA473 for ; Wed, 1 Jun 2022 21:01:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 536A76B0073; Wed, 1 Jun 2022 17:01:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E68C6B0074; Wed, 1 Jun 2022 17:01:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AD786B0075; Wed, 1 Jun 2022 17:01:54 -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 2915F6B0073 for ; Wed, 1 Jun 2022 17:01:54 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 9F7AC120856 for ; Wed, 1 Jun 2022 21:01:53 +0000 (UTC) X-FDA: 79530888948.10.8BEBBD9 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf07.hostedemail.com (Postfix) with ESMTP id D0FE840057 for ; Wed, 1 Jun 2022 21:01:40 +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 251DCuXn030631 for ; Wed, 1 Jun 2022 14:01:52 -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=TNdvL5H9Nnbr5ngz7PfC+qxRx5KoUDRycNbiHAywt2stgsiwkD+CJvAzRkQJig18OBKK qZAm40cAczX/wnle++9nk7FIfdVUQKDonMs75YhI66e8QeRkrZGvFdICsZ36p7PLwZ0D kKYhyyoqZKqPtXrYDJk0Z01/dwH9VyEofy4= Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net (PPS) with ESMTPS id 3gdv756p2n-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 01 Jun 2022 14:01:52 -0700 Received: from twshared4937.07.ash9.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 1 Jun 2022 14:01:50 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id B86C6FEB2394; Wed, 1 Jun 2022 14:01:42 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , Subject: [PATCH v7 01/15] mm: Move starting of background writeback into the main balancing loop Date: Wed, 1 Jun 2022 14:01:27 -0700 Message-ID: <20220601210141.3773402-2-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220601210141.3773402-1-shr@fb.com> References: <20220601210141.3773402-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: 5FFg13-7abvnHFpAlOc4nWOPcQh17itN X-Proofpoint-GUID: 5FFg13-7abvnHFpAlOc4nWOPcQh17itN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-01_08,2022-06-01_01,2022-02-23_01 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D0FE840057 X-Stat-Signature: e91u89g9fedp73uh9e8x64y6farc6dq8 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=TNdvL5H9; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf07.hostedemail.com: domain of "prvs=71517ce8a8=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71517ce8a8=shr@fb.com" X-HE-Tag: 1654117300-935673 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_writeba= ck *wb, } } =20 + /* + * 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_writebac= k *wb, break; } =20 + /* Start writeback even when in laptop mode */ if (unlikely(!writeback_in_progress(wb))) wb_start_background_writeback(wb); =20 @@ -1823,23 +1837,6 @@ static void balance_dirty_pages(struct bdi_writeba= ck *wb, =20 if (!dirty_exceeded && wb->dirty_exceeded) wb->dirty_exceeded =3D 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); } =20 static DEFINE_PER_CPU(int, bdp_ratelimits); --=20 2.30.2