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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68589C433F5 for ; Fri, 8 Oct 2021 13:54:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 09C7161042 for ; Fri, 8 Oct 2021 13:54:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 09C7161042 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 9DA276B007B; Fri, 8 Oct 2021 09:54:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98A1B6B007D; Fri, 8 Oct 2021 09:54:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 879136B007E; Fri, 8 Oct 2021 09:54:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 7A9FA6B007B for ; Fri, 8 Oct 2021 09:54:46 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4684F28DA5 for ; Fri, 8 Oct 2021 13:54:46 +0000 (UTC) X-FDA: 78673415772.25.767ABB2 Received: from outbound-smtp17.blacknight.com (outbound-smtp17.blacknight.com [46.22.139.234]) by imf10.hostedemail.com (Postfix) with ESMTP id B34006001E57 for ; Fri, 8 Oct 2021 13:54:45 +0000 (UTC) Received: from mail.blacknight.com (pemlinmail06.blacknight.ie [81.17.255.152]) by outbound-smtp17.blacknight.com (Postfix) with ESMTPS id 79A511C3DDB for ; Fri, 8 Oct 2021 14:54:44 +0100 (IST) Received: (qmail 7524 invoked from network); 8 Oct 2021 13:54:44 -0000 Received: from unknown (HELO stampy.112glenside.lan) (mgorman@techsingularity.net@[84.203.17.29]) by 81.17.254.9 with ESMTPA; 8 Oct 2021 13:54:44 -0000 From: Mel Gorman To: Linux-MM Cc: NeilBrown , Theodore Ts'o , Andreas Dilger , "Darrick J . Wong" , Matthew Wilcox , Michal Hocko , Dave Chinner , Rik van Riel , Vlastimil Babka , Johannes Weiner , Jonathan Corbet , Linux-fsdevel , LKML , Mel Gorman Subject: [PATCH 6/8] mm/vmscan: Centralise timeout values for reclaim_throttle Date: Fri, 8 Oct 2021 14:53:30 +0100 Message-Id: <20211008135332.19567-7-mgorman@techsingularity.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008135332.19567-1-mgorman@techsingularity.net> References: <20211008135332.19567-1-mgorman@techsingularity.net> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B34006001E57 X-Stat-Signature: 38oip96fyw5y5rmkjdizerhrfp871geg Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.139.234 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net X-HE-Tag: 1633701285-541287 Content-Transfer-Encoding: quoted-printable 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: Neil Brown raised concerns about callers of reclaim_throttle specifying a timeout value. The original timeout values to congestion_wait() were probably pulled out of thin air or copy&pasted from somewhere else. This patch centralises the timeout values and selects a timeout based on the reason for reclaim throttling. These figures are also pulled out of the same thin air but better values may be derived Running a workload that is throttling for inappropriate periods and tracing mm_vmscan_throttled can be used to pick a more appropriate value. Excessive throttling would pick a lower timeout where as excessive CPU usage in reclaim context would select a larger timeout. Ideally a large value would always be used and the wakeups would occur before a timeout but that requires careful testing. Signed-off-by: Mel Gorman --- mm/compaction.c | 2 +- mm/internal.h | 3 +-- mm/page-writeback.c | 2 +- mm/vmscan.c | 39 +++++++++++++++++++++++++++++++-------- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 7359093d8ac0..151b04c4dab3 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -828,7 +828,7 @@ isolate_migratepages_block(struct compact_control *cc= , unsigned long low_pfn, if (cc->mode =3D=3D MIGRATE_ASYNC) return -EAGAIN; =20 - reclaim_throttle(pgdat, VMSCAN_THROTTLE_ISOLATED, HZ/10); + reclaim_throttle(pgdat, VMSCAN_THROTTLE_ISOLATED); =20 if (fatal_signal_pending(current)) return -EINTR; diff --git a/mm/internal.h b/mm/internal.h index 06d0c376efcd..f8d203cfd4e1 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -129,8 +129,7 @@ extern unsigned long highest_memmap_pfn; */ extern int isolate_lru_page(struct page *page); extern void putback_lru_page(struct page *page); -extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_stat= e reason, - long timeout); +extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_stat= e reason); =20 /* * in mm/rmap.c: diff --git a/mm/page-writeback.c b/mm/page-writeback.c index f34f54fcd5b4..4b01a6872f9e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2374,7 +2374,7 @@ int do_writepages(struct address_space *mapping, st= ruct writeback_control *wbc) * guess as any. */ reclaim_throttle(NODE_DATA(numa_node_id()), - VMSCAN_THROTTLE_WRITEBACK, HZ/50); + VMSCAN_THROTTLE_WRITEBACK); } /* * Usually few pages are written by now from those we've just submitted diff --git a/mm/vmscan.c b/mm/vmscan.c index cdebfc618179..e096e81dcbd8 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1006,11 +1006,10 @@ static void handle_write_error(struct address_spa= ce *mapping, unlock_page(page); } =20 -void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reaso= n, - long timeout) +void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reaso= n) { wait_queue_head_t *wqh =3D &pgdat->reclaim_wait[reason]; - long ret; + long timeout, ret; DEFINE_WAIT(wait); =20 /* @@ -1027,6 +1026,30 @@ void reclaim_throttle(pg_data_t *pgdat, enum vmsca= n_throttle_state reason, node_page_state(pgdat, NR_THROTTLED_WRITTEN)); } =20 + /* + * These figures are pulled out of thin air. + * VMSCAN_THROTTLE_ISOLATED is a transient condition based on too many + * parallel reclaimers which is a short-lived event so the timeout is + * short. Failing to make progress or waiting on writeback are + * potentially long-lived events so use a longer timeout. This is shaky + * logic as a failure to make progress could be due to anything from + * writeback to a slow device to excessive references pages at the tail + * of the inactive LRU. + */ + switch(reason) { + case VMSCAN_THROTTLE_NOPROGRESS: + case VMSCAN_THROTTLE_WRITEBACK: + timeout =3D HZ/10; + break; + case VMSCAN_THROTTLE_ISOLATED: + timeout =3D HZ/50; + break; + default: + WARN_ON_ONCE(1); + timeout =3D HZ; + break; + } + prepare_to_wait(wqh, &wait, TASK_UNINTERRUPTIBLE); ret =3D schedule_timeout(timeout); finish_wait(wqh, &wait); @@ -2307,7 +2330,7 @@ shrink_inactive_list(unsigned long nr_to_scan, stru= ct lruvec *lruvec, =20 /* wait a bit for the reclaimer. */ stalled =3D true; - reclaim_throttle(pgdat, VMSCAN_THROTTLE_ISOLATED, HZ/10); + reclaim_throttle(pgdat, VMSCAN_THROTTLE_ISOLATED); =20 /* We are about to die and free our memory. Return now. */ if (fatal_signal_pending(current)) @@ -3239,7 +3262,7 @@ static void shrink_node(pg_data_t *pgdat, struct sc= an_control *sc) * until some pages complete writeback. */ if (sc->nr.immediate) - reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK, HZ/10); + reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); } =20 /* @@ -3263,7 +3286,7 @@ static void shrink_node(pg_data_t *pgdat, struct sc= an_control *sc) if (!current_is_kswapd() && current_may_throttle() && !sc->hibernation_mode && test_bit(LRUVEC_CONGESTED, &target_lruvec->flags)) - reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK, HZ/10); + reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); =20 if (should_continue_reclaim(pgdat, sc->nr_reclaimed - nr_reclaimed, sc)) @@ -3335,7 +3358,7 @@ static void consider_reclaim_throttle(pg_data_t *pg= dat, struct scan_control *sc) =20 /* Throttle if making no progress at high prioities. */ if (sc->priority < DEF_PRIORITY - 2) - reclaim_throttle(pgdat, VMSCAN_THROTTLE_NOPROGRESS, HZ/10); + reclaim_throttle(pgdat, VMSCAN_THROTTLE_NOPROGRESS); } =20 /* @@ -3804,7 +3827,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct m= em_cgroup *memcg, z =3D first_zones_zonelist(zonelist, sc.reclaim_idx, sc.nodemask); pgdat =3D zonelist_zone(z)->zone_pgdat; =20 - reclaim_throttle(pgdat, VMSCAN_THROTTLE_NOPROGRESS, HZ/10); + reclaim_throttle(pgdat, VMSCAN_THROTTLE_NOPROGRESS); } =20 return nr_reclaimed; --=20 2.31.1