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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 12A3BC433DB for ; Tue, 16 Mar 2021 08:54:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9FD6A64F50 for ; Tue, 16 Mar 2021 08:54:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FD6A64F50 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 22E5E6B006C; Tue, 16 Mar 2021 04:54:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E00A6B006E; Tue, 16 Mar 2021 04:54:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 058E96B0070; Tue, 16 Mar 2021 04:54:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id DAC6A6B006C for ; Tue, 16 Mar 2021 04:54:02 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 938168249980 for ; Tue, 16 Mar 2021 08:54:02 +0000 (UTC) X-FDA: 77925125124.23.4DD9DD1 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf17.hostedemail.com (Postfix) with ESMTP id 3E3AC407F8DB for ; Tue, 16 Mar 2021 08:54:01 +0000 (UTC) IronPort-SDR: pUotIa+cn9xBZs4JDR+bt6wS/v26k/gQaYfdTxWf/luKMU1o3vKW4nDjqLCWaYrw2J/+sfUhLO LWAKBCgXKWww== X-IronPort-AV: E=McAfee;i="6000,8403,9924"; a="176821185" X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="176821185" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 01:53:59 -0700 IronPort-SDR: rcRhkGUDl0RczsHA8wP56mUOWLylR+48ApPPlnRhb3QDTJR1FaKwOzDNdJpiVTNlpATD+iBwYC cVQkNnLbP+iQ== X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="449654385" Received: from unknown (HELO yhuang6-desk1.ccr.corp.intel.com) ([10.239.13.1]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 01:53:55 -0700 From: "Huang, Ying" To: Yu Zhao Cc: linux-mm@kvack.org, Alex Shi , Andrew Morton , Dave Hansen , Hillf Danton , Johannes Weiner , Joonsoo Kim , Matthew Wilcox , Mel Gorman , Michal Hocko , Roman Gushchin , Vlastimil Babka , Wei Yang , Yang Shi , linux-kernel@vger.kernel.org, page-reclaim@google.com Subject: Re: [PATCH v1 10/14] mm: multigenerational lru: core References: <87im5rsvd8.fsf@yhuang6-desk1.ccr.corp.intel.com> <87wnu7y4hn.fsf@yhuang6-desk1.ccr.corp.intel.com> Date: Tue, 16 Mar 2021 16:53:53 +0800 In-Reply-To: (Yu Zhao's message of "Tue, 16 Mar 2021 02:24:45 -0600") Message-ID: <87sg4vxyvy.fsf@yhuang6-desk1.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Stat-Signature: zmxg43xuofjja3buaf94y9ahh8ad5476 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3E3AC407F8DB Received-SPF: none (intel.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from=""; helo=mga18.intel.com; client-ip=134.134.136.126 X-HE-DKIM-Result: none/none X-HE-Tag: 1615884841-744826 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: Yu Zhao writes: > On Tue, Mar 16, 2021 at 02:52:52PM +0800, Huang, Ying wrote: >> Yu Zhao writes: >> >> > On Tue, Mar 16, 2021 at 10:08:51AM +0800, Huang, Ying wrote: >> >> Yu Zhao writes: >> >> [snip] >> >> >> >> > +/* Main function used by foreground, background and user-triggered aging. */ >> >> > +static bool walk_mm_list(struct lruvec *lruvec, unsigned long next_seq, >> >> > + struct scan_control *sc, int swappiness) >> >> > +{ >> >> > + bool last; >> >> > + struct mm_struct *mm = NULL; >> >> > + int nid = lruvec_pgdat(lruvec)->node_id; >> >> > + struct mem_cgroup *memcg = lruvec_memcg(lruvec); >> >> > + struct lru_gen_mm_list *mm_list = get_mm_list(memcg); >> >> > + >> >> > + VM_BUG_ON(next_seq > READ_ONCE(lruvec->evictable.max_seq)); >> >> > + >> >> > + /* >> >> > + * For each walk of the mm list of a memcg, we decrement the priority >> >> > + * of its lruvec. For each walk of memcgs in kswapd, we increment the >> >> > + * priorities of all lruvecs. >> >> > + * >> >> > + * So if this lruvec has a higher priority (smaller value), it means >> >> > + * other concurrent reclaimers (global or memcg reclaim) have walked >> >> > + * its mm list. Skip it for this priority to balance the pressure on >> >> > + * all memcgs. >> >> > + */ >> >> > +#ifdef CONFIG_MEMCG >> >> > + if (!mem_cgroup_disabled() && !cgroup_reclaim(sc) && >> >> > + sc->priority > atomic_read(&lruvec->evictable.priority)) >> >> > + return false; >> >> > +#endif >> >> > + >> >> > + do { >> >> > + last = get_next_mm(lruvec, next_seq, swappiness, &mm); >> >> > + if (mm) >> >> > + walk_mm(lruvec, mm, swappiness); >> >> > + >> >> > + cond_resched(); >> >> > + } while (mm); >> >> >> >> It appears that we need to scan the whole address space of multiple >> >> processes in this loop? >> >> >> >> If so, I have some concerns about the duration of the function. Do you >> >> have some number of the distribution of the duration of the function? >> >> And may be the number of mm_struct and the number of pages scanned. >> >> >> >> In comparison, in the traditional LRU algorithm, for each round, only a >> >> small subset of the whole physical memory is scanned. >> > >> > Reasonable concerns, and insightful too. We are sensitive to direct >> > reclaim latency, and we tuned another path carefully so that direct >> > reclaims virtually don't hit this path :) >> > >> > Some numbers from the cover letter first: >> > In addition, direct reclaim latency is reduced by 22% at 99th >> > percentile and the number of refaults is reduced 7%. These metrics are >> > important to phones and laptops as they are correlated to user >> > experience. >> > >> > And "another path" is the background aging in kswapd: >> > age_active_anon() >> > age_lru_gens() >> > try_walk_mm_list() >> > /* try to spread pages out across spread+1 generations */ >> > if (old_and_young[0] >= old_and_young[1] * spread && >> > min_nr_gens(max_seq, min_seq, swappiness) > max(spread, MIN_NR_GENS)) >> > return; >> > >> > walk_mm_list(lruvec, max_seq, sc, swappiness); >> > >> > By default, spread = 2, which makes kswapd slight more aggressive >> > than direct reclaim for our use cases. This can be entirely disabled >> > by setting spread to 0, for worloads that don't care about direct >> > reclaim latency, or larger values, they are more sensitive than >> > ours. >> >> OK, I see. That can avoid the long latency in direct reclaim path. >> >> > It's worth noting that walk_mm_list() is multithreaded -- reclaiming >> > threads can work on different mm_structs on the same list >> > concurrently. We do occasionally see this function in direct reclaims, >> > on over-overcommitted systems, i.e., kswapd CPU usage is 100%. Under >> > the same condition, we saw the current page reclaim live locked and >> > triggered hardware watchdog timeouts (our hardware watchdog is set to >> > 2 hours) many times. >> >> Just to confirm, in the current page reclaim, kswapd will keep running >> until watchdog? This is avoided in your algorithm mainly via >> multi-threading? Or via direct vs. reversing page table scanning? > > Well, don't tell me you've seen the problem :) Let me explain one > subtle difference in how the aging works between the current page > reclaim and this series, and point you to the code. > > In the current page reclaim, we can't scan a page via the rmap without > isolating the page first. So the aging basically isolates a batch of > pages from a lru list, walks the rmap for each of the pages, and puts > active ones back to the list. > > In this series, aging walks page tables to update the generation > numbers of active pages without isolating them. The isolation is the > subtle difference: it's not a problem when there are few threads, but > it causes live locks when hundreds of threads running the aging and > hit the following in shrink_inactive_list(): > > while (unlikely(too_many_isolated(pgdat, file, sc))) { > if (stalled) > return 0; > > /* wait a bit for the reclaimer. */ > msleep(100); > stalled = true; > > /* We are about to die and free our memory. Return now. */ > if (fatal_signal_pending(current)) > return SWAP_CLUSTER_MAX; > } > > Thanks to Michal who has improved it considerably by commit > db73ee0d4637 ("mm, vmscan: do not loop on too_many_isolated for > ever"). But we still occasionally see live locks on over-overcommitted > machines. Reclaiming threads step on each other while interleaving > between the msleep() and the aging, on 100+ CPUs. Got it! Thanks a lot for detailed explanation! Best Regards, Huang, Ying