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.8 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 CDD9EC433ED for ; Mon, 10 May 2021 09:46:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 111A8613DC for ; Mon, 10 May 2021 09:46:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 111A8613DC 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 2BBD16B0070; Mon, 10 May 2021 05:46:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2914C6B0071; Mon, 10 May 2021 05:46:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1326C6B0072; Mon, 10 May 2021 05:46:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id E94BD6B0070 for ; Mon, 10 May 2021 05:46:40 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A1BA08249980 for ; Mon, 10 May 2021 09:46:40 +0000 (UTC) X-FDA: 78124841760.38.8C2A82B Received: from r3-24.sinamail.sina.com.cn (r3-24.sinamail.sina.com.cn [202.108.3.24]) by imf16.hostedemail.com (Postfix) with SMTP id 48FB880192F3 for ; Mon, 10 May 2021 09:46:25 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([221.199.207.228]) by sina.com (172.16.97.23) with ESMTP id 609900F800031421; Mon, 10 May 2021 17:46:34 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 59154854919548 From: Hillf Danton To: Xing Zhengjun Cc: Hillf Danton , 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 , 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: Mon, 10 May 2021 17:46:26 +0800 Message-Id: <20210510094626.2914-1-hdanton@sina.com> In-Reply-To: References: <20210416023536.168632-1-zhengjun.xing@linux.intel.com> <20210422102325.1332-1-hdanton@sina.com> <20210430064319.2189-1-hdanton@sina.com> MIME-Version: 1.0 Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.24 as permitted sender) smtp.mailfrom=hdanton@sina.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 48FB880192F3 X-Stat-Signature: yri5f84xu9ee9rrsq4sfsdspesu86k1f Received-SPF: none (sina.com>: No applicable sender policy available) receiver=imf16; identity=mailfrom; envelope-from=""; helo=r3-24.sinamail.sina.com.cn; client-ip=202.108.3.24 X-HE-DKIM-Result: none/none X-HE-Tag: 1620639985-610756 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: On Mon, 10 May 2021 16:03:06 Xing Zhengjun wrote: >On 4/30/2021 2:43 PM, Hillf Danton wrote: >> 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 10= 0ms >>> sleep. >>> >>> 60) @ 103942.6 us | shrink_node(); >>> >>> 60) @ 103795.8 us | shrink_node(); >>=20 >> Thanks for your test. >>=20 >> In bid to cut the number of 100ms sleepers further down, add another p= lace >> for them to nap by flushing lru cache before falling in sleep, instead= of >> mulling why 50ms or 10ms is more adequate. >>=20 >> Alternatively, and simpler IMHO, take a 5ms nap one time until !tmi. >>=20 >> --- 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); >>=20 > >I tried the patch, it still can reproduce the 100ms sleep. > >52) @ 103829.8 us | shrink_lruvec(); Thanks for you data. What we learn from it is a 5ms nap a time and no longer than 100ms in tot= al is an acceptable option. Hillf