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 X-Spam-Level: X-Spam-Status: No, score=-5.7 required=3.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 402C0C433B4 for ; Fri, 30 Apr 2021 06:43:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 79C41613BF for ; Fri, 30 Apr 2021 06:43:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79C41613BF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0BDB66B00E5; Fri, 30 Apr 2021 02:43:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0459C6B00E7; Fri, 30 Apr 2021 02:43:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E28736B00E8; Fri, 30 Apr 2021 02:43:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id C492A6B00E5 for ; Fri, 30 Apr 2021 02:43:27 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 721CF8249980 for ; Fri, 30 Apr 2021 06:43:27 +0000 (UTC) X-FDA: 78088092054.04.34158C8 Received: from r3-21.sinamail.sina.com.cn (r3-21.sinamail.sina.com.cn [202.108.3.21]) by imf27.hostedemail.com (Postfix) with SMTP id 9B94780192EB for ; Fri, 30 Apr 2021 06:42:59 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([221.199.207.228]) by sina.com (172.16.97.32) with ESMTP id 608BA70600021741; Fri, 30 Apr 2021 14:43:20 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 689180628756 From: Hillf Danton To: Xing Zhengjun Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, ying.huang@intel.com, tim.c.chen@linux.intel.com, Shakeel Butt , Hillf Danton , Michal Hocko , yuzhao@google.com, wfg@mail.ustc.edu.cn Subject: Re: [RFC] mm/vmscan.c: avoid possible long latency caused by too_many_isolated() Date: Fri, 30 Apr 2021 14:43:19 +0800 Message-Id: <20210430064319.2189-1-hdanton@sina.com> In-Reply-To: <9795a050-12a4-55c6-13e1-969cd4bbf795@linux.intel.com> References: <20210416023536.168632-1-zhengjun.xing@linux.intel.com> <20210422102325.1332-1-hdanton@sina.com> MIME-Version: 1.0 Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.21 as permitted sender) smtp.mailfrom=hdanton@sina.com X-Stat-Signature: tzmhod68f1bc3hnyx1b6kzgkg141mt4u X-Rspamd-Queue-Id: 9B94780192EB X-Rspamd-Server: rspam05 Received-SPF: none (sina.com>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=r3-21.sinamail.sina.com.cn; client-ip=202.108.3.21 X-HE-DKIM-Result: none/none X-HE-Tag: 1619764979-84677 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000024, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, 30 Apr 2021 13:33:57 +0800 Xing Zhengjun wrote: > > I use my compaction test case to test it, 1/10 ratio can reproduce 100m= s > sleep. > > 60) @ 103942.6 us | shrink_node(); > > 60) @ 103795.8 us | shrink_node(); Thanks for your test. In bid to cut the number of 100ms sleepers further down, add another plac= e for them to nap by flushing lru cache before falling in sleep, instead of mulling why 50ms or 10ms is more adequate. Alternatively, and simpler IMHO, take a 5ms nap one time until !tmi. --- y/mm/vmscan.c +++ x/mm/vmscan.c @@ -118,6 +118,9 @@ struct scan_control { /* The file pages on the current node are dangerously low */ unsigned int file_is_tiny:1; =20 + unsigned int file_tmi:1; /* too many isolated */ + unsigned int anon_tmi:1; + /* Allocation order */ s8 order; =20 @@ -2092,6 +2095,22 @@ static int current_may_throttle(void) bdi_write_congested(current->backing_dev_info); } =20 +static void set_sc_tmi(struct scan_control *sc, bool file, int tmi) +{ + if (file) + sc->file_tmi =3D tmi; + else + sc->anon_tmi =3D tmi; +} + +static bool is_sc_tmi(struct scan_control *sc, bool file) +{ + if (file) + return sc->file_tmi !=3D 0; + else + return sc->anon_tmi !=3D 0; +} + /* * shrink_inactive_list() is a helper for shrink_node(). It returns the= number * of reclaimed pages @@ -2109,11 +2128,23 @@ shrink_inactive_list(unsigned long nr_to enum vm_event_item item; struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); bool stalled =3D false; + bool drained =3D false; =20 while (unlikely(too_many_isolated(pgdat, file, sc))) { if (stalled) return 0; =20 + if (!is_sc_tmi(sc, file)) { + set_sc_tmi(sc, file, 1); + return 0; + } + + if (!drained) { + drained =3D true; + lru_add_drain_all(); + continue; + } + /* wait a bit for the reclaimer. */ msleep(100); stalled =3D true; @@ -2123,6 +2154,9 @@ shrink_inactive_list(unsigned long nr_to return SWAP_CLUSTER_MAX; } =20 + if (is_sc_tmi(sc, file)) + set_sc_tmi(sc, file, 0); + lru_add_drain(); =20 spin_lock_irq(&lruvec->lru_lock);