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 79199C4332F for ; Sun, 11 Dec 2022 04:00:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 849038E0003; Sat, 10 Dec 2022 23:00:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7C58E0001; Sat, 10 Dec 2022 23:00:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BFA78E0003; Sat, 10 Dec 2022 23:00:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5B29B8E0001 for ; Sat, 10 Dec 2022 23:00:00 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 16E6A12052B for ; Sun, 11 Dec 2022 04:00:00 +0000 (UTC) X-FDA: 80228672160.06.572170D Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf21.hostedemail.com (Postfix) with ESMTP id 532E41C0002 for ; Sun, 11 Dec 2022 03:59:54 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=chenwandun@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670731197; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DPyYytK/dY6mRlqNTn6No381tN/XGUs6XK23uvKbgPI=; b=5uWNI9m4AGxwRSUNOxSk+dLcP8XolmWy5NRC4FI0LPN/Nvu1hq12acodJ+BUjzsDi4cC0f g7t39kjaC2hTFzALz7vtlaKqt9a+i8JsQn5KNEf6687vwKQVHjiG104/N5A2eX8R5PvpyF 5pPNOW88iHTVs0MsCaXDOa+wj4txyBM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=chenwandun@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670731197; a=rsa-sha256; cv=none; b=QbzUSoCCyNh7tqOT0hewKZoc178OizWuZMm3LIkQiS/pQ5RQoEfjpCz0ULNTU2tU421+z6 1wfV/owaAksb8qvwFdTBmDEafz6RwaZjoqvpgNZ/uPiS9rUZvMoK8o//OdYgtb33AEFvOD GrMYeTp9np3rfizcmwivxnzkXUWPiW8= Received: from dggpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NV9wv5wnwz15MPT; Sun, 11 Dec 2022 11:58:55 +0800 (CST) Received: from [10.174.178.178] (10.174.178.178) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sun, 11 Dec 2022 11:59:49 +0800 Message-ID: Date: Sun, 11 Dec 2022 11:59:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: Re: [PATCH mm-unstable v1 3/8] mm: multi-gen LRU: remove eviction fairness safeguard To: Yu Zhao CC: Johannes Weiner , Jonathan Corbet , Michael Larabel , Michal Hocko , Mike Rapoport , Roman Gushchin , Suren Baghdasaryan , , , , Andrew Morton References: <20221201223923.873696-1-yuzhao@google.com> <20221201223923.873696-4-yuzhao@google.com> From: Chen Wandun In-Reply-To: <20221201223923.873696-4-yuzhao@google.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.178] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 532E41C0002 X-Stat-Signature: oq86b4icidpg8asg9g63zttwxx5e784p X-HE-Tag: 1670731194-578695 X-HE-Meta: U2FsdGVkX1870pYlbrSLFCwo4y/0tT/uP5xuQHO9b9cJfq+BR+V3zsYCHRKeOxhvd45akmhODFGlSzLzkj7EBUjKx8LI/Km0I4BYVt1rnH6IpPsfgDg2wZ5L1Mu66WvAg8yIKbeT/Em2D/sDo3Yf2XaRkitRPjSzzFf/3zFpbbir4GiQRMeJlCcybGYrhBRHQO57+V6jaGeuIiB/NgG6fjdCyDZWvqA1u23dFuDjUqt/wGosQrRS7c/Mh2JUCs7jm5u5FmH/pAjtuWusygzRF+gzNZDyFRCaw+WQLEH63iZd3bC877AdE8B8rtIz4c1JT8HhIZhmKedqsXJOiOSMp19YN10Iq558wzoJcXfKqJeZLZFkTGGUInzkztGdL2Ui3v+vIA9ILr/CGqcy1mvqefDnqriVTaJDiu7ET3aVUnuRFXoQTYnOrpxqB2AhcyV4x3pbctv3o40NktEj1bhIG/znOyeqyqhlPCMqEQiVD9ovXXtddIhMfmdUk+JItpJxvW5voll+R7IaTm/W3MAFfJHoKwtc2UsrqpalnFxnNJijzlOcxYRrJQjpAX+HO39oD2CSL7r22+EShBuRDtekM9Hoayo3GU/KlXb9g6K7IhyvQXpBwS8Tz3Obire84S2XC4rCHXOJenXooPattFmcgAzNSxO/jh4IQ+4OE9AI2Vvy3EMJaEokOoB8L+aPhYhCEUXPsaqtmWzuNEPVcRPt7iNrgi4lsPEBruVV4ty5TqID/LvBOWYOhLSx4fSDmLtRgpiHUfXXg2mfNYpIdMt1a4qhZLd4LwzHhr8D2nfbqdoq7KjAHZ8HQFnB5sFiDjffV3cd9lfOPE0= 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: 在 2022/12/2 6:39, Yu Zhao 写道: > Recall that the eviction consumes the oldest generation: first it > bucket-sorts folios whose gen counters were updated by the aging and > reclaims the rest; then it increments lrugen->min_seq. > > The current eviction fairness safeguard for global reclaim has a > dilemma: when there are multiple eligible memcgs, should it continue > or stop upon meeting the reclaim goal? If it continues, it overshoots > and increases direct reclaim latency; if it stops, it loses fairness > between memcgs it has taken memory away from and those it has yet to. > > With memcg LRU, the eviction, while ensuring eventual fairness, will > stop upon meeting its goal. Therefore the current eviction fairness > safeguard for global reclaim will not be needed. > > Note that memcg LRU only applies to global reclaim. For memcg reclaim, > the eviction will continue, even if it is overshooting. This becomes > unconditional due to code simplification. > > Signed-off-by: Yu Zhao > --- > mm/vmscan.c | 81 +++++++++++++++-------------------------------------- > 1 file changed, 23 insertions(+), 58 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index ebab1ec3d400..d714a777c88b 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -449,6 +449,11 @@ static bool cgroup_reclaim(struct scan_control *sc) > return sc->target_mem_cgroup; > } > > +static bool global_reclaim(struct scan_control *sc) > +{ > + return !sc->target_mem_cgroup || mem_cgroup_is_root(sc->target_mem_cgroup); > +} > + > /** > * writeback_throttling_sane - is the usual dirty throttling mechanism available? > * @sc: scan_control in question > @@ -499,6 +504,11 @@ static bool cgroup_reclaim(struct scan_control *sc) > return false; > } > > +static bool global_reclaim(struct scan_control *sc) > +{ > + return true; > +} > + > static bool writeback_throttling_sane(struct scan_control *sc) > { > return true; > @@ -4991,8 +5001,7 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw > return scanned; > } > > -static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swappiness, > - bool *need_swapping) > +static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swappiness) > { > int type; > int scanned; > @@ -5081,9 +5090,6 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap > goto retry; > } > > - if (need_swapping && type == LRU_GEN_ANON) > - *need_swapping = true; > - > return scanned; > } > > @@ -5122,67 +5128,26 @@ static unsigned long get_nr_to_scan(struct lruvec *lruvec, struct scan_control * > return min_seq[!can_swap] + MIN_NR_GENS <= max_seq ? nr_to_scan : 0; > } > > -static bool should_abort_scan(struct lruvec *lruvec, unsigned long seq, > - struct scan_control *sc, bool need_swapping) > +static unsigned long get_nr_to_reclaim(struct scan_control *sc) > { > - int i; > - DEFINE_MAX_SEQ(lruvec); > + /* don't abort memcg reclaim to ensure fairness */ > + if (!global_reclaim(sc)) > + return -1; The return type of the function is unsigned long. Does the return of - 1 mean something else? > > - if (!current_is_kswapd()) { > - /* age each memcg at most once to ensure fairness */ > - if (max_seq - seq > 1) > - return true; > + /* discount the previous progress for kswapd */ > + if (current_is_kswapd()) > + return sc->nr_to_reclaim + sc->last_reclaimed; > > - /* over-swapping can increase allocation latency */ > - if (sc->nr_reclaimed >= sc->nr_to_reclaim && need_swapping) > - return true; > - > - /* give this thread a chance to exit and free its memory */ > - if (fatal_signal_pending(current)) { > - sc->nr_reclaimed += MIN_LRU_BATCH; > - return true; > - } > - > - if (cgroup_reclaim(sc)) > - return false; > - } else if (sc->nr_reclaimed - sc->last_reclaimed < sc->nr_to_reclaim) > - return false; > - > - /* keep scanning at low priorities to ensure fairness */ > - if (sc->priority > DEF_PRIORITY - 2) > - return false; > - > - /* > - * A minimum amount of work was done under global memory pressure. For > - * kswapd, it may be overshooting. For direct reclaim, the allocation > - * may succeed if all suitable zones are somewhat safe. In either case, > - * it's better to stop now, and restart later if necessary. > - */ > - for (i = 0; i <= sc->reclaim_idx; i++) { > - unsigned long wmark; > - struct zone *zone = lruvec_pgdat(lruvec)->node_zones + i; > - > - if (!managed_zone(zone)) > - continue; > - > - wmark = current_is_kswapd() ? high_wmark_pages(zone) : low_wmark_pages(zone); > - if (wmark > zone_page_state(zone, NR_FREE_PAGES)) > - return false; > - } > - > - sc->nr_reclaimed += MIN_LRU_BATCH; > - > - return true; > + return max(sc->nr_to_reclaim, compact_gap(sc->order)); > } > > static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) > { > struct blk_plug plug; > bool need_aging = false; > - bool need_swapping = false; > unsigned long scanned = 0; > unsigned long reclaimed = sc->nr_reclaimed; > - DEFINE_MAX_SEQ(lruvec); > + unsigned long nr_to_reclaim = get_nr_to_reclaim(sc); > > lru_add_drain(); > > @@ -5206,7 +5171,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc > if (!nr_to_scan) > goto done; > > - delta = evict_folios(lruvec, sc, swappiness, &need_swapping); > + delta = evict_folios(lruvec, sc, swappiness); > if (!delta) > goto done; > > @@ -5214,7 +5179,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc > if (scanned >= nr_to_scan) > break; > > - if (should_abort_scan(lruvec, max_seq, sc, need_swapping)) > + if (sc->nr_reclaimed >= nr_to_reclaim) > break; > > cond_resched(); > @@ -5661,7 +5626,7 @@ static int run_eviction(struct lruvec *lruvec, unsigned long seq, struct scan_co > if (sc->nr_reclaimed >= nr_to_reclaim) > return 0; > > - if (!evict_folios(lruvec, sc, swappiness, NULL)) > + if (!evict_folios(lruvec, sc, swappiness)) > return 0; > > cond_resched();