From patchwork Wed Aug 2 02:56:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13337538 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 DB8D9EB64DD for ; Wed, 2 Aug 2023 02:56:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 682B628011A; Tue, 1 Aug 2023 22:56:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60A97280112; Tue, 1 Aug 2023 22:56:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D27B28011A; Tue, 1 Aug 2023 22:56:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 39687280112 for ; Tue, 1 Aug 2023 22:56:18 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 036E414066B for ; Wed, 2 Aug 2023 02:56:17 +0000 (UTC) X-FDA: 81077650836.26.9FF8DFD Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 2BB1640004 for ; Wed, 2 Aug 2023 02:56:15 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=33TVVDzX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3z8XJZAsKCK4YOZSgVgWbUVUccUZS.QcaZWbil-aaYjOQY.cfU@flex--kaleshsingh.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3z8XJZAsKCK4YOZSgVgWbUVUccUZS.QcaZWbil-aaYjOQY.cfU@flex--kaleshsingh.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690944976; 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:in-reply-to: references:dkim-signature; bh=aqehfJB+hF+Fne+AdGJurbsZIYsQCeOte57mRi2GAJw=; b=1f9VVMRtlPqyanRQ403J0o9Q0iCSKwyPEI+96VMdrL48jx2n0a7A95aN1Q6qErGG1ToXUu zJ76V6uHvY9+8jSSeCvL7djjGTto6Aqi8/9ybjkEKnT+NEmTOYT+T26eOAVkFtA8/QSMyk o1B2jXLmUpg+QcmSKjr0wyTEvUJR2YY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=33TVVDzX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3z8XJZAsKCK4YOZSgVgWbUVUccUZS.QcaZWbil-aaYjOQY.cfU@flex--kaleshsingh.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3z8XJZAsKCK4YOZSgVgWbUVUccUZS.QcaZWbil-aaYjOQY.cfU@flex--kaleshsingh.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690944976; a=rsa-sha256; cv=none; b=QNP/1qhC6gSR6/WPJcfAm2wsNDPnxHorFUAb+shp/cI58H5WWAQb4kiUJS9I0m/rBi3f6x 7ARu+bncMjTIFmRq5nk3f+gPZ15J5JkDekfN4z2iYCCIU/n5MUTSh8xW8VMH9WrENOYLdW MW0d/fVMTf6I0hUrYN172347Xn0LUfY= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-583c49018c6so71993997b3.0 for ; Tue, 01 Aug 2023 19:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690944975; x=1691549775; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=aqehfJB+hF+Fne+AdGJurbsZIYsQCeOte57mRi2GAJw=; b=33TVVDzXg6eBl7/Vpt8F6zz+Hj/NOmdXdllc0HT3+fXbEBhkPYtEkaq37eNBBfQ//f huzyAhMvUorpNH56dDYRwA06JZVdYTEAbzfGjbqw3gBWiic0SbSYYIRLI7+dUO6KJeP/ QbLSh8xuVcrhWjh4oWX9BfGiIQ2WhcFjEVln6zdtkNbTrb8Vr/FaB0bbjGe719xWxqpC hL3EQTp/eSWIIOfcyzhoc5/BO66sBZZeI+o1Tma4ICZmtHB5eUiGscJSklwG5yeK8aOP pOTWKEoNcoXV0uOzF2WA7ODrKPaZuVgMaXvYUoulWRPVnXT17L+Vmq1QR0HZFgWxuJek tQWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690944975; x=1691549775; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aqehfJB+hF+Fne+AdGJurbsZIYsQCeOte57mRi2GAJw=; b=NxrnU6AyN3+MHG2qIM/mkFmUhE2ik/NvJHFyxiBPxhBU6XiwFHcTU3EfDCqJIUeNAB txYeFrsbOj6hgpPyl5+u+mXbuxbqXF7tNwyyFiQ0dHdIGFHPpA85mu5dCQWscjExkfem LsOcc6yxhbE+AiqAUoMsDY0v1RL+TYdzn5cHLX9Y1OYL8h7ESQm6/vKyd0qoH0n0UyPa DaQ687zQrrmCHkl1ykarZGzEBeJCSN6YArSOuF4AFvdoJO08XggwlMw9kYNrFxUYxFZz HNEZobH9jrx9fhEir595zYzKRf1Ug7msS2YS6L+jIjrzcotiAEjzr/06OJ4GJjs7uQcM XmCA== X-Gm-Message-State: ABy/qLaBT0Z+isBHPrNK4CDo5lkE4YZevAzxWXKuH2iUloYH75WOGDnA 1EYYAkWO4eHzIGNP6nURcPbPKfI+zKFy34U/Nw== X-Google-Smtp-Source: APBJJlGu4CGYprEhx9EAJQV2bkMTULOViWk9fNZltzmcAuDxS7zR2BS8SgTh3oU+2KBCXMRrlqL63XtCKu/qeEPcYg== X-Received: from kalesh.mtv.corp.google.com ([2620:15c:211:201:aa5f:ff75:318:255]) (user=kaleshsingh job=sendgmr) by 2002:a05:6902:100f:b0:cf9:3564:33cc with SMTP id w15-20020a056902100f00b00cf9356433ccmr116986ybt.13.1690944975112; Tue, 01 Aug 2023 19:56:15 -0700 (PDT) Date: Tue, 1 Aug 2023 19:56:02 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230802025606.346758-1-kaleshsingh@google.com> Subject: [PATCH v2 1/3] mm-unstable: Multi-gen LRU: Fix per-zone reclaim From: Kalesh Singh To: yuzhao@google.com, akpm@linux-foundation.org Cc: surenb@google.com, android-mm@google.com, kernel-team@android.com, Kalesh Singh , stable@vger.kernel.org, Charan Teja Kalla , Lecopzer Chen , Matthias Brugger , AngeloGioacchino Del Regno , Suleiman Souhlal , Oleksandr Natalenko , "Jan Alexander Steffens (heftig)" , Qi Zheng , Steven Barrett , Brian Geffon , Barry Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2BB1640004 X-Stat-Signature: tdfdf6dgm5h5cnn1pzwtzsmxuyjubo45 X-Rspam-User: X-HE-Tag: 1690944975-908486 X-HE-Meta: U2FsdGVkX1+AXi9KoEiU2LJuYqfHbwNxcQnZifW/QPzMRZlP2KOAEiVIDFWJN95MqumxXsWfKkGp/HjtM2s4HdjE90GY5ykmGSl6cmRWGHoRNR3jzjTJ3XCh8rfKE/IV1uMIiJJmKRqLOwl4hVItywBC+MqSQuEN/NfRoIXxN5R7DNS+9gOC+EnFqR5KjMv6FqRv5uyIbtVP1iJ+kiv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Dc3KcFBfCtpGw8nYVxcad9pD6PqEJ5xGsijND4eTHxSqQlWOCj7ETRYQotnJPoh7OAcytAxMNdTgkV4/k3n1uvgWr6/jjr7xeDTeljNcpWilL2qcvB24Js8yO6CsRP3BiIK++Ln0SjwyPs1bCmUIFg9JJGMDlJoJkcdjFFPds1GyAE/TtpgFVGW2xVlu42OlikMN7XkJa8tGe2xLIz66azQzWEcYT4jqgbEGeFRR/KKkZ1IGcHoBeUZIQYyKX52wV1Vuwj7NIbAQrXxdoZicXkV8jzKOfxWva3WG4V5FrGXNhQm4pedytxoWQ4jBLaqXjssZv6UX4kSe0VuazXilGv4zcTE+RdueX7l0REJiUBHpg82axO0/ZOGPRd0QIK05MzAacwd/UQ5WQO/S1j1jSUgj1EwG2Jl6cNLLKlU5RRV+IKgSz+D4dtcN/aJI1lY/NBLwdXcQqxfinoLKkIelvA8RL7hnXJRMkarViW/DYrrGTTEOODQgk4wongzimWOaFr1IHVBNuaHhtYC5RfXCyR5E1/AVGxrPk3PDgEQdFX4/NiBHZ5Byqc0R1QykjfiHGRZR6rf//xmUsFVeUcMw5CLp+rKnczWId2vd7hCO1gOsXBrqwI6GWqM2v3BeR46lUnTrvWMdQUDYUcyYztJdYxwsogqYo/VW7ijv4TTDu3t3suU+MX9 rPX2tNJ1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: MGLRU has a LRU list for each zone for each type (anon/file) in each generation: long nr_pages[MAX_NR_GENS][ANON_AND_FILE][MAX_NR_ZONES]; The min_seq (oldest generation) can progress independently for each type but the max_seq (youngest generation) is shared for both anon and file. This is to maintain a common frame of reference. In order for eviction to advance the min_seq of a type, all the per-zone lists in the oldest generation of that type must be empty. The eviction logic only considers pages from eligible zones for eviction or promotion. scan_folios() { ... for (zone = sc->reclaim_idx; zone >= 0; zone--) { ... sort_folio(); // Promote ... isolate_folio(); // Evict } ... } Consider the system has the movable zone configured and default 4 generations. The current state of the system is as shown below (only illustrating one type for simplicity): Type: ANON Zone DMA32 Normal Movable Device Gen 0 0 0 4GB 0 Gen 1 0 1GB 1MB 0 Gen 2 1MB 4GB 1MB 0 Gen 3 1MB 1MB 1MB 0 Now consider there is a GFP_KERNEL allocation request (eligible zone index <= Normal), evict_folios() will return without doing any work since there are no pages to scan in the eligible zones of the oldest generation. Reclaim won't make progress until triggered from a ZONE_MOVABLE allocation request; which may not happen soon if there is a lot of free memory in the movable zone. This can lead to OOM kills, although there is 1GB pages in the Normal zone of Gen 1 that we have not yet tried to reclaim. This issue is not seen in the conventional active/inactive LRU since there are no per-zone lists. If there are no (not enough) folios to scan in the eligible zones, move folios from ineligible zone (zone_index > reclaim_index) to the next generation. This allows for the progression of min_seq and reclaiming from the next generation (Gen 1). Qualcomm, Mediatek and raspberrypi [1] discovered this issue independently. [1] https://github.com/raspberrypi/linux/issues/5395 Fixes: ac35a4902374 ("mm: multi-gen LRU: minimal implementation") Cc: stable@vger.kernel.org Cc: Yu Zhao Cc: Andrew Morton Reported-by: Charan Teja Kalla Reported-by: Lecopzer Chen Signed-off-by: Kalesh Singh Tested-by: AngeloGioacchino Del Regno Tested-by: Charan Teja Kalla --- Changes in v2: - Add Fixes tag and cc stable mm/vmscan.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 4039620d30fe..489a4fc7d9b1 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4889,7 +4889,8 @@ static int lru_gen_memcg_seg(struct lruvec *lruvec) * the eviction ******************************************************************************/ -static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx) +static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_control *sc, + int tier_idx) { bool success; int gen = folio_lru_gen(folio); @@ -4939,6 +4940,13 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int tier_idx) return true; } + /* ineligible */ + if (zone > sc->reclaim_idx) { + gen = folio_inc_gen(lruvec, folio, false); + list_move_tail(&folio->lru, &lrugen->folios[gen][type][zone]); + return true; + } + /* waiting for writeback */ if (folio_test_locked(folio) || folio_test_writeback(folio) || (type == LRU_GEN_FILE && folio_test_dirty(folio))) { @@ -4987,7 +4995,8 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, int type, int tier, struct list_head *list) { - int gen, zone; + int i; + int gen; enum vm_event_item item; int sorted = 0; int scanned = 0; @@ -5003,9 +5012,10 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, gen = lru_gen_from_seq(lrugen->min_seq[type]); - for (zone = sc->reclaim_idx; zone >= 0; zone--) { + for (i = MAX_NR_ZONES; i > 0; i--) { LIST_HEAD(moved); int skipped = 0; + int zone = (sc->reclaim_idx + i) % MAX_NR_ZONES; struct list_head *head = &lrugen->folios[gen][type][zone]; while (!list_empty(head)) { @@ -5019,7 +5029,7 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, scanned += delta; - if (sort_folio(lruvec, folio, tier)) + if (sort_folio(lruvec, folio, sc, tier)) sorted += delta; else if (isolate_folio(lruvec, folio, sc)) { list_add(&folio->lru, list); From patchwork Wed Aug 2 02:56:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13337539 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 F1AE5C001DF for ; Wed, 2 Aug 2023 02:56:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5704428011B; Tue, 1 Aug 2023 22:56:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FBC1280112; Tue, 1 Aug 2023 22:56:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3741E28011B; Tue, 1 Aug 2023 22:56:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2329F280112 for ; Tue, 1 Aug 2023 22:56:23 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F0FFD14063A for ; Wed, 2 Aug 2023 02:56:22 +0000 (UTC) X-FDA: 81077651004.23.23FD8AA Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf22.hostedemail.com (Postfix) with ESMTP id 34D5CC000D for ; Wed, 2 Aug 2023 02:56:20 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Jrr8nzKX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 31MXJZAsKCLMdTeXlalbgZaZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--kaleshsingh.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=31MXJZAsKCLMdTeXlalbgZaZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--kaleshsingh.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690944981; a=rsa-sha256; cv=none; b=FkO0FV945Fw7002NY/chA8VXs8YEHm4OCvPxMf4Iwjtux9uJWJzNRTJPjsLwEn4Aal/Pvp XyeimAfnxg8kSb75+snEXMaEh6d0seL0mmoSAaLlLG5XKj9xJEcKjznRkKP3QtAd/mKkyb eWwgsocPZrp2HLv07sWHxCJQOXkohRs= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Jrr8nzKX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 31MXJZAsKCLMdTeXlalbgZaZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--kaleshsingh.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=31MXJZAsKCLMdTeXlalbgZaZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--kaleshsingh.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690944981; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=J6cxPzKelBRogs1RcqlDIpKMeY4RfiCOB4MpGgBN/Dg=; b=yGcNw8Cg8GeZ2dQ6EwxAv/U9qGPZz93vdqH95Qdi0pvEcIjpcbXoy0fjwp3nVHQ3IayyR3 iW/BiEkXqkOGaycUU4qQhzbdlwp5updfTX4/7S2e0SkfqiD4nkKMvTtNeNQhoap+vcY3L8 1GE08qJjzzGvZ5DXgqgDG5RuCJZUqhg= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-c647150c254so860890276.1 for ; Tue, 01 Aug 2023 19:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690944980; x=1691549780; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=J6cxPzKelBRogs1RcqlDIpKMeY4RfiCOB4MpGgBN/Dg=; b=Jrr8nzKXxGfH9rZ05coei/Z5XkXPQKYffsRvq0JJPMkpPWKSPML6OO06eZDIof3ZxE FqR3adURv8HbiY0CSWCrzORDmomvxAk0WLRY9cf18uCIkdSyJjl/VvbdCY4q9Wy7Oc4w +pskRXdmBEFfcC42q/5pqN3PxM0TzWr4gK4sE9xc5wu50UZc34qQkFTahmwhRGZJVytQ iQt96NsYT5jF6oFb+S9xqxKcAjWxbIwls+nZQCaZUiFG50rjkxYUVoWP/KSzWH+XfZJr RVj4ctwi+migEpHkjEJI3k5GUHjwOtKhv4c0gSFmtgVSST9QuZmYcyIVrwx+qWlaHlyG UnUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690944980; x=1691549780; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J6cxPzKelBRogs1RcqlDIpKMeY4RfiCOB4MpGgBN/Dg=; b=Vkai1KPBWnYWPETN7UQ30RyX93lR+f/sxZXmct11ykczTt2i2kLbqV5mWKzSvMPU8F 9YzP8o1qUkwCS1av0auuO4yI8WqQomPHZvZuun65SNTkqh17t5EMsspavM9QuLuoDaQP C+3kArCShEC7QSEcG3TseTMUw4q3Y5ODRT0ZU+GicR7J+X6fCCSpHeW7fkIFXLQDY8+t J9i+Qi/1uyphC5TF4SyfcLsr5ZRCQvpimoTJnOpaD/x/eC3I9a8pQdrph7dvxi5gC6Bj nz+us1mGNXEbF42ZyG/cUcXN8+1sLLELszFa8ivP3JiY7dgfnJrY9Ua4WEkNcvfE8kMK F3gA== X-Gm-Message-State: ABy/qLZAUXFCWwxNf0maZD8J6fva+SPhHgqbAwl6jj4FuxlLr4ItdJGO ljk/M9jImLLVhM2UjC74Hz+Q2iPNBkoTMze2Ag== X-Google-Smtp-Source: APBJJlHvG4mc4jsYVOJYfZ7h42Tv/EwdyD/HOeVXUVvtcmr8y48s75g7rEDYvVAnOWGuPl5UYIq68sSDD86PJyMPYA== X-Received: from kalesh.mtv.corp.google.com ([2620:15c:211:201:aa5f:ff75:318:255]) (user=kaleshsingh job=sendgmr) by 2002:a25:b084:0:b0:bd5:dc2d:9d7f with SMTP id f4-20020a25b084000000b00bd5dc2d9d7fmr167401ybj.4.1690944980290; Tue, 01 Aug 2023 19:56:20 -0700 (PDT) Date: Tue, 1 Aug 2023 19:56:03 -0700 In-Reply-To: <20230802025606.346758-1-kaleshsingh@google.com> Mime-Version: 1.0 References: <20230802025606.346758-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230802025606.346758-2-kaleshsingh@google.com> Subject: [PATCH v2 2/3] mm-unstable: Multi-gen LRU: Avoid race in inc_min_seq() From: Kalesh Singh To: yuzhao@google.com, akpm@linux-foundation.org Cc: surenb@google.com, android-mm@google.com, kernel-team@android.com, Kalesh Singh , stable@vger.kernel.org, Aneesh Kumar K V , Matthias Brugger , AngeloGioacchino Del Regno , "Jan Alexander Steffens (heftig)" , Oleksandr Natalenko , Brian Geffon , Steven Barrett , Suleiman Souhlal , Qi Zheng , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 34D5CC000D X-Stat-Signature: ojgnap87xn7ffgpg8a1ua9fgmt97kpxi X-HE-Tag: 1690944980-662320 X-HE-Meta: U2FsdGVkX19fON8PBReDNzTG0aT1M/IdOGgCpd19YJ4FNhnW3QsVS3Jao8eRto0ENHbr9MJx4LJsyASTXphEvbwgcGh9m8SDWkJ5ukO23F6aMbmc7OOOOhZBYMa+/XA88UcRzqVYxWaYRohQNx4tRc30Q0X6Lj0opT/XQ29HCQnMLQBb7kiGE8QM/IpdXOlHsD5iFcJ08yIFmU4zL6gD//VrBWc2OTf+3CfQVuqB4zCFpva5IvEz2Mgmn7YhQIyr8KYeIGexL9HrXMHDrvvd8JuPK2kfgDh9T2XT8fMt8NcmnScok/vxeFRk2SYe/5Eg6iGkChrmTeQQGrdrx+ndiJgLPzx2hIIbeKsQgSznqHg0xbRarW5JDzkhn3Q8jJk02jKgNMzvlO3Ctzlj5w/yW9SEz5RXQdwHihjG6dz2jyNRTldsc76UtiVuSlcJ9yUpezEvCJFdgfc/yB1J1mz7r3zCp//K1RZMTVPnFwbDSKMDMv9AznvIrNtLDOZSzdK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x4BNRl0mJJfGChB0u1nhwmIBwGqUw9x+NdAkPcbGFqllvR5YqJo78Zyizs1Sk8Plc5UjvphqObhQznFhJteiJ8vfA2MJEl52AN30ZkffCOle4kqfDvD8HDSi4Rw7cJ1gij3+kjSUj5ntDzwd9EsFoI/OlddC/0RSpm7+fNOj7HKxIpyFaH+lNfnKTU1SVADBK3ibeNzzKI0Ic49/XqiXhZ8D2DSQJDQt+RwhAtlwymeNTDte/YM79LlhN7qhqAv1nRgEN24a0P8EUCu6xCkwc3btTE4uLP7VTtmVWiSYC9JtvS8ixSQK8e8nMzEo3/scAm3huO/GhsdFBXfsaZgIrI/LSrylC9EP/j1lc95Y9xZgCCDXWF8= 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: inc_max_seq() will try to inc_min_seq() if nr_gens == MAX_NR_GENS. This is because the generations are reused (the last oldest now empty generation will become the next youngest generation). inc_min_seq() is retried until successful, dropping the lru_lock and yielding the CPU on each failure, and retaking the lock before trying again: while (!inc_min_seq(lruvec, type, can_swap)) { spin_unlock_irq(&lruvec->lru_lock); cond_resched(); spin_lock_irq(&lruvec->lru_lock); } However, the initial condition that required incrementing the min_seq (nr_gens == MAX_NR_GENS) is not retested. This can change by another call to inc_max_seq() from run_aging() with force_scan=true from the debugfs interface. Since the eviction stalls when the nr_gens == MIN_NR_GENS, avoid unnecessarily incrementing the min_seq by rechecking the number of generations before each attempt. This issue was uncovered in previous discussion on the list by Yu Zhao and Aneesh Kumar [1]. [1] https://lore.kernel.org/linux-mm/CAOUHufbO7CaVm=xjEb1avDhHVvnC8pJmGyKcFf2iY_dpf+zR3w@mail.gmail.com/ Fixes: d6c3af7d8a2b ("mm: multi-gen LRU: debugfs interface") Cc: stable@vger.kernel.org Cc: Yu Zhao Cc: Aneesh Kumar K V Cc: Andrew Morton Signed-off-by: Kalesh Singh --- Changes in v2: - Add Fixes tag and cc stable mm/vmscan.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 489a4fc7d9b1..6eecd291756c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4439,7 +4439,7 @@ static void inc_max_seq(struct lruvec *lruvec, bool can_swap, bool force_scan) int prev, next; int type, zone; struct lru_gen_folio *lrugen = &lruvec->lrugen; - +restart: spin_lock_irq(&lruvec->lru_lock); VM_WARN_ON_ONCE(!seq_is_valid(lruvec)); @@ -4450,11 +4450,12 @@ static void inc_max_seq(struct lruvec *lruvec, bool can_swap, bool force_scan) VM_WARN_ON_ONCE(!force_scan && (type == LRU_GEN_FILE || can_swap)); - while (!inc_min_seq(lruvec, type, can_swap)) { - spin_unlock_irq(&lruvec->lru_lock); - cond_resched(); - spin_lock_irq(&lruvec->lru_lock); - } + if (inc_min_seq(lruvec, type, can_swap)) + continue; + + spin_unlock_irq(&lruvec->lru_lock); + cond_resched(); + goto restart; } /* From patchwork Wed Aug 2 02:56:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13337540 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 00551EB64DD for ; Wed, 2 Aug 2023 02:56:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5221828011C; Tue, 1 Aug 2023 22:56:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D215280112; Tue, 1 Aug 2023 22:56:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3736928011C; Tue, 1 Aug 2023 22:56:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2559C280112 for ; Tue, 1 Aug 2023 22:56:27 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E797A1C9D80 for ; Wed, 2 Aug 2023 02:56:26 +0000 (UTC) X-FDA: 81077651172.02.A4CB688 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 1E0CA40011 for ; Wed, 2 Aug 2023 02:56:24 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=NaC24ZAN; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf01.hostedemail.com: domain of 32MXJZAsKCLchXibpepfkdedlldib.Zljifkru-jjhsXZh.lod@flex--kaleshsingh.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=32MXJZAsKCLchXibpepfkdedlldib.Zljifkru-jjhsXZh.lod@flex--kaleshsingh.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690944985; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/hIR85jBvXabpNDlh2e7xtBRwmCRiojtCshBAYjOX1Y=; b=TrECxDCe14Gn5aZpau9Jn1kGNqVlvmT7BXtFS2giU7QNpd/HSgGnHf9tM2yl0HwsZGe3Af gf28W0AWVuNDJJ5kEH8AiVD7z3FAYrvLxC71V4M6BmH1oGH+OEBi/uCP+CrdoecnG1MgxP jA8U+uiN7XxJjPnyHS67pP/oHmTcnfc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=NaC24ZAN; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf01.hostedemail.com: domain of 32MXJZAsKCLchXibpepfkdedlldib.Zljifkru-jjhsXZh.lod@flex--kaleshsingh.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=32MXJZAsKCLchXibpepfkdedlldib.Zljifkru-jjhsXZh.lod@flex--kaleshsingh.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690944985; a=rsa-sha256; cv=none; b=pEeSJeWAc2Kf1WiHl6iklE6u+gFISEAQOt5EKkd0sCEBkP2Mn60trVxeWRk3QKKYQTxlV0 q3rPDCVOciuaNhg+b0ABHpeGFBUHA9dM3nF2AXREPTWNocxoo050iDNnQ/BAec0tK2i7gG 14JQ6iO/tgtJgu8ws1ewM/Au0tKGBW0= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-564fb1018bcso74364147b3.0 for ; Tue, 01 Aug 2023 19:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690944984; x=1691549784; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/hIR85jBvXabpNDlh2e7xtBRwmCRiojtCshBAYjOX1Y=; b=NaC24ZANDfp+9XAVYJ2zthvJ8rUBTQ6l5oOsseG6mfA3cvF+arl71fQG1qHAhLbqJ9 9qeh16JOmABIOlkWmOSbROyLEpFlmq9EQUA6/uFoeGgx/95B08yoDHueOaoh/i5155mY XVuhu3IiHZBf1PozmtFvavLXWlrDny3HMWCrGbcbi3wm/Avg9RqMK4JG4u4VTr67QtHd KbHI/PNLuqrNbAwO5JvECyVMzM5KsSmQk2W4uE2b/bpTqBDpICou5hRnR2Ky2iDO0WiX xNEzbL/OrqT3RifP1ne+1qALr+MKSfhXAnsSEvF0phJYNv0q7iAwZlhSP5UEXbHyOUib Cf7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690944984; x=1691549784; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/hIR85jBvXabpNDlh2e7xtBRwmCRiojtCshBAYjOX1Y=; b=He8nf/xJZHs5an9Qdn3tR+FKzd7aegJELxI03Bbu1F2fvnSoyMkZb+qZpllU4X8C3I YAlR58J9ZJYCdbYzC/OYe367K1ZvUrycwRRtp8vkNHoWbZ5qgTSuxuf44qTtwVSBBmjG boTjzeYp7N9fTGxb8Ic1qRMadc41qoqm53dBKj0reepqfO4cbHvot5wr7mJDEFNchnWB Xg+w+Ae7mofFDOPwW1nMuAu2R1VMbQ/ECszkhwytIsTuMGrhI0zbor9SV7ZtSF7zyaxi lig+1G7CYbNeyYlrRhcOC9dyFDAZjmC924Rjbh7QODJ2JDj4AWk6nEOiLdihNHixi0lp wpsA== X-Gm-Message-State: ABy/qLYCKY5lFjx79zhLIzUvXwPV48wj21uTd5Pe5Oqj6RiIAU2uChFU keoIOcoQLaRsymKoLs99E0wVg2j8uuNgiI8Ymw== X-Google-Smtp-Source: APBJJlHj0tBKgoeUZ7ci0leYLXMuHGiQZrYMbH4Cl/uWTIvoLc5trBzIvMofv2F1eZ7phbcd71NDee6Wx5e539GPkA== X-Received: from kalesh.mtv.corp.google.com ([2620:15c:211:201:aa5f:ff75:318:255]) (user=kaleshsingh job=sendgmr) by 2002:a81:a706:0:b0:583:4f82:b9d9 with SMTP id e6-20020a81a706000000b005834f82b9d9mr120587ywh.5.1690944984182; Tue, 01 Aug 2023 19:56:24 -0700 (PDT) Date: Tue, 1 Aug 2023 19:56:04 -0700 In-Reply-To: <20230802025606.346758-1-kaleshsingh@google.com> Mime-Version: 1.0 References: <20230802025606.346758-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230802025606.346758-3-kaleshsingh@google.com> Subject: [PATCH v2 3/3] mm-unstable: Multi-gen LRU: Fix can_swap in lru_gen_look_around() From: Kalesh Singh To: yuzhao@google.com, akpm@linux-foundation.org Cc: surenb@google.com, android-mm@google.com, kernel-team@android.com, Kalesh Singh , Matthias Brugger , AngeloGioacchino Del Regno , Suleiman Souhlal , Steven Barrett , Oleksandr Natalenko , "Jan Alexander Steffens (heftig)" , Qi Zheng , Brian Geffon , Barry Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-Rspamd-Queue-Id: 1E0CA40011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: f6p5yefkd3r5zgnn1ehdxwcyj59c7t64 X-HE-Tag: 1690944984-186973 X-HE-Meta: U2FsdGVkX198YjRYsn0L8S07JWUiZmvPmqXdCggoLbMolua5pg/8AGAZphRg4D1dtGTk0i53lsv2nV7fYSFjyolX9ZK5nQBApGOdG1unIz/iRziaHutLdtk02rWXLefC7wVMdGJJ5zKJkhGEIMKXRHt//f/1mA9Ez0tMKMXWxU1N44GHBj0EXb4Tt1bqkEliNbkq+iW0vyDrNgLMrvkvrnVCWa7flU0XAGXKcf5HCvPI8IQ5DMZwxBB1HkWr6V1zlY0eu8clSEvA3nqPxV8wBNwD2vGBqBw5ud2TWo0Oj7g54o2zIdk43seeyLJx0b27Ze8euD8QYTEz76ea9zOnUsUkB9In6cnDTfPsHuKAA1NYr6QZZoNYdoQwXmQlPd2Y0HGWqoNtByMlj2VYI1zzXpq+mtzDerAzCUqzj2xM9vyzQydkWKWpiBeQDAA7iPzb5lKQljibdIfWnWwtertu+kuCcDlWUXYqgjMiBa7brAlpqFi1b7xr0RAZ9nI3xie7tEQmWmZ3HjHygncDkq6u3n0SYmPOXqPemSPCd5JXXxd+lPuIWessMluJtidgtD5SZgvyPqUBxW2d9uwIhlSILMRvxMsJ1BOWw772uBjjqyTVwb5RM7YeYeLMYH7teVEOVAdq05JXZN2lLBQbaG2w25EyzlZM6HVgf3ipZbsD2WHgmweqsXF0H9gfkonHfpRsWeIz09WfQHQqVzFCzhOgxf0d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XsMW06C 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: walk->can_swap might be invalid since it's not guaranteed to be initialized for the particular lruvec. Instead deduce it from the folio type (anon/file). Fixes: 018ee47f1489 ("mm: multi-gen LRU: exploit locality in rmap") Cc: Yu Zhao Cc: Andrew Morton Signed-off-by: Kalesh Singh --- Changes in v2: - Add Fixes tag mm/vmscan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 6eecd291756c..b4329f93a682 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4656,6 +4656,7 @@ void lru_gen_look_around(struct page_vma_mapped_walk *pvmw) pte_t *pte = pvmw->pte; unsigned long addr = pvmw->address; struct folio *folio = pfn_folio(pvmw->pfn); + bool can_swap = !folio_is_file_lru(folio); struct mem_cgroup *memcg = folio_memcg(folio); struct pglist_data *pgdat = folio_pgdat(folio); struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat); @@ -4704,7 +4705,7 @@ void lru_gen_look_around(struct page_vma_mapped_walk *pvmw) if (!pte_young(ptent)) continue; - folio = get_pfn_folio(pfn, memcg, pgdat, !walk || walk->can_swap); + folio = get_pfn_folio(pfn, memcg, pgdat, can_swap); if (!folio) continue;