From patchwork Wed Aug 2 00:19:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13337418 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 558BEC001E0 for ; Wed, 2 Aug 2023 00:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=FxGTOfAgPlbwwc4Z3Z8XYygqqHtw7ey7z04B4tL7E40=; b=XaC UwLh1NfUyNXzRNq8QPLRWTefd4AASoNDDxReCZAI+sP/J7du5sZ4++2RNpIyhYqfW7Gr2aKferbpX T5BQeH/hEBc29BnVS5a+r0Njroyr/CVv1sJAbgOIFktd/Z2bite3/iqqJEkEPBEx8uAkMxWZHBgRT uXax012yHjQ/jLOFyGnljrprgIlrKD3XAfjWAeroWL7Imr5hv+L1wN2JgnJA5QgeN0v4Ztw0BxNQQ 40oJDYqSmUN3tJnyh3P0lQMb+Hi6E5H6mYHilRtH7bOR2QeOX7JCnXG4grHymAn863sIJzazmC8Vc nx6sYwMt1qzlF8wFGevflJL2QT6HvKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQzap-003auK-0S; Wed, 02 Aug 2023 00:19:59 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQzal-003arT-0T for linux-arm-kernel@lists.infradead.org; Wed, 02 Aug 2023 00:19:56 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d114bc2057fso6427760276.3 for ; Tue, 01 Aug 2023 17:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690935588; x=1691540388; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=DXVsJSb9QIFOr/Cp0N+IT34pRw+slorysgAR9VBW/lM=; b=cm4Hai0RZYcjkOHwUMqYM8wK0SfBbq6tE/k3HPH9GmV1zBmvkpZFMcYL+r+O5/fJbr yVq3tNLgKEwKoly7oloPtCW9d6iQlb7bYEeqwEpyCEWI2sHa/uqdKA7oUbAlOw9+D+33 M61tOUgNo8fyyGNNXnxgduT41K+3pcW/oHczkSpQIGsd/5fEuI7YxntjfIFiICf3vyWk ViI9qV2uesdgd1VSF3s2Yl584bAMuwZjnbv8NIkoqTZnJcemCyasU28fzTMYmIe37CrO 2DtipcERam4z0HdG/CPTBtBJiKPAvtwqUVxtyD00zOgHXb6Rmfr2KoGteO8WsS1p37hY Y3eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690935588; x=1691540388; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DXVsJSb9QIFOr/Cp0N+IT34pRw+slorysgAR9VBW/lM=; b=k24Hw6SjNF82ua3bRUqD2XLl9R2zHFQrPE6k05Voyy/MxOZ0s60QE5rZgqx6NZAmwM ziQt0uOeErPUUIQLCxbsCeXQUaJjCgx/hrtgiVk4+FNI5wnE+X0q/qBcw27e9bqrGG+f Z+rcxlC8V6fwTd2zB0yyIQsNlgPWpHO2v72PDfRHk+V/P5W7RGHmHVDiNjBc69dP7gsR xJ0yak88faRIQj2xeKrj3xdyPI6Iwcp7bnUS+AvlV0JuxUHD3n77463U23i9Dik+ETK7 1SAkpnJvr7p19idK7pcl5XE1ekJgknH/mDn0sdu5+qZuzYQFs50jEkiVcvJ4uBZ5/glg XFyQ== X-Gm-Message-State: ABy/qLYdkKih2wpK/ElH4dtRc6RAOe821Y/K6nUiPccp7AHctQbOKG6M ysHBIe8ynQgZ/RZxFzZvBhBe4wakIpktI7YwfQ== X-Google-Smtp-Source: APBJJlFOYOnPjUqct44iRohOnc0mUP9ReqoYJeBrA5AVDrjW9wn0H6QdpajsQPU0LLHzoebktFORyvnYqlxBKUc5/Q== X-Received: from kalesh.mtv.corp.google.com ([2620:15c:211:201:aa5f:ff75:318:255]) (user=kaleshsingh job=sendgmr) by 2002:a25:ab86:0:b0:d0d:a7bc:4040 with SMTP id v6-20020a25ab86000000b00d0da7bc4040mr103482ybi.0.1690935587776; Tue, 01 Aug 2023 17:19:47 -0700 (PDT) Date: Tue, 1 Aug 2023 17:19:35 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230802001938.3913174-1-kaleshsingh@google.com> Subject: [PATCH 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 , Charan Teja Kalla , Lecopzer Chen , Matthias Brugger , AngeloGioacchino Del Regno , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230801_171955_181396_4DDE0971 X-CRM114-Status: GOOD ( 22.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Cc: Yu Zhao Cc: Andrew Morton Reported-by: Charan Teja Kalla Reported-by: Lecopzer Chen Signed-off-by: Kalesh Singh --- 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 00:19:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13337419 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7DF7BEB64DD for ; Wed, 2 Aug 2023 00:20:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=K0OCQ2yXQdhl5Th72RcvQlQE8evJMMGAQWOZlP93Y4Q=; b=NfvhPgkZSLC8QHjJnBXR94q1Sa wj9gjPcrj8ImhWtIerFaT8lXRzr5yA6YxZBEehICq0xEd4crg0dKLua7Xug/JtI0d3hgOLeN3Ig4e 1XXNY15Q2AK7n8oDzHiYtnPg170jFsKOU2F9sh7H/iVTHpOeG0YbsfShs598UdopzP8V5p8KJ/Kwh wrXKOKF+pr4Mx9cm7HX0K2b//S4TF86ym0GqYFV9iFyWhV6P/1UkfVydGL1PPIbWIM4agWvsmLDeV FJpJ9E/mKAnNTIPEl1A3wvRo1iVLuUnfaKNsSB1kEyeDmnECfBwzKm5tP3Agpf/ia9qa0Mapmk3Q3 jJs1IvqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQzas-003awA-2W; Wed, 02 Aug 2023 00:20:02 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQzap-003atV-2c for linux-arm-kernel@lists.infradead.org; Wed, 02 Aug 2023 00:20:01 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-569e7aec37bso56903937b3.2 for ; Tue, 01 Aug 2023 17:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690935595; x=1691540395; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oILqqqD951CZa6vFO5lwCGBJV16jZziGq+aTih9CvRM=; b=liEq2TRJ6uphA1n1WRctdr12b14csuDNelgmOB3P8uUfovqp001PwMVQtOenzPkHJi whIzAspyWYUBqUAPEv0+bxGp/kCYHZiDZCj4aPoXHdFKRGOuA0OAPUxh2lZcKRB9DmY4 +sVvZ4qnTj42uetZgk1spG0aKDlJUYjhXZPRCghRJr5QNKGlAn8bEhwP4JK0KqRABLaT fhKrvbkr8HehDdLCVM2/wiJlQ2zpWgZOa9ODGSx5g36gQV2AuKOzP/RpJ1d7pqrnbT8W MmvhG/Y18dFWO4yMQQmXypjHnDfl+eqfjiVHy0xIyI41FCe/pW+Xv7cf+eIVYSkn4fkR 1ENQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690935595; x=1691540395; 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=oILqqqD951CZa6vFO5lwCGBJV16jZziGq+aTih9CvRM=; b=lV/sEs7ehp+DJ2xc+jJ0900X4j4CNi11A6qm3noyTvdG8klEVXwNtBRjnO8yCQUZpP xSeP1OKwmfLXARFDR0gRY7w3iIwMS6Mpdj1nhI5ZTM9TSYtNHRrHtPNNXEtWQMvoj6kI Ckai4srFCzx6USJgeM4uPdR4SpiMZV+eaEQGWgdvUCXc8DwqGPHiW4mW+GcqHTuXLQHz 0KX/mqe8f2/0ZE0jV52ZSdCjkO3TltqNjkzXiowLHsxAAbV1QacbVM6I30AAXnYKk60N SjX91GSJ2XblI+gBNzENJzVGeD/dwaLD3mMAoRSImPuB5dQ2FybcS/h+Bto2k2HAxZar +sQQ== X-Gm-Message-State: ABy/qLZAnEFCvPWFZ4HatNGJatKoIIyFtUFJ3h+pqXirL/otsSKowA1N hxc/nETUMHVB5GUTAZ/KZN/+bguJj7VV8wQFkg== X-Google-Smtp-Source: APBJJlGVSXTcSf5HWtAwgVhVMNFG4pScdB5810WzB/3elwhK2y7pd9aNX9CzOkX3wIMvukUfcHZ5QeIzWXNdnmzMyw== X-Received: from kalesh.mtv.corp.google.com ([2620:15c:211:201:aa5f:ff75:318:255]) (user=kaleshsingh job=sendgmr) by 2002:a81:b301:0:b0:576:fdbe:76b2 with SMTP id r1-20020a81b301000000b00576fdbe76b2mr121491ywh.3.1690935595421; Tue, 01 Aug 2023 17:19:55 -0700 (PDT) Date: Tue, 1 Aug 2023 17:19:36 -0700 In-Reply-To: <20230802001938.3913174-1-kaleshsingh@google.com> Mime-Version: 1.0 References: <20230802001938.3913174-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230802001938.3913174-2-kaleshsingh@google.com> Subject: [PATCH 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 , Aneesh Kumar K V , Matthias Brugger , AngeloGioacchino Del Regno , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230801_171959_848334_42906AA7 X-CRM114-Status: GOOD ( 16.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/ Cc: Yu Zhao Cc: Aneesh Kumar K V Cc: Andrew Morton Signed-off-by: Kalesh Singh --- 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 00:19:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13337420 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B6ECEB64DD for ; Wed, 2 Aug 2023 00:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=lGkQm28wUD8EuuByaEZKz5LGMM+tCs7hfeDXEeyvWpI=; b=xMXYgbv/SvUnYOQymascirDDyt Si9dC85O24o+cmFbZZeYv2LZQP6SOH1UeAl01YsvCaHSTz7RfUvIr6AiQLwWbQlplDsXciY2iYQYH y+xZkrFcClrdgQOBL89xHi149GMeUyZjP2CToaxVhIu6ymevqY4fMRydyoIkFNHuDzC7io+dCzAoZ 1TDCug/VMFqJP7eYcxqOSy6d9F9RDC/3xX5RfNUHwAfCA+QKlfo/tOEWhMX4n2dip+0v2b5b3rh87 I+icnpubkfvHa+C4NLZhyZEDmF+lNEcCVG/b2dC43SbGqWU59rf4V+jw2rQjGuS1ANh3RdflIjjim aAf8rnHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQzax-003ayB-1J; Wed, 02 Aug 2023 00:20:07 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQzav-003aww-0I for linux-arm-kernel@lists.infradead.org; Wed, 02 Aug 2023 00:20:06 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d052f58b7deso6401738276.2 for ; Tue, 01 Aug 2023 17:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690935604; x=1691540404; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sQqMGlFvgvQ3yvXEv1c3TG8Zu+eyY93FF0SWidKY8Dg=; b=sjS9Sd/96ChnfQYaR1cO5sk2N9oknVX/qJB2yXG052CqPpTjyq29z2og4PvyAUfuFb BbtTttNXygAAyEGj4VDc+gc5Tv/jJm9VVufAhbVnxD9d2fZv9SEDE3pJ6CmBfTmsJ7/M 30pcgTpZEa5b5WZTWX8yFJI4winvc57m0RSu8uswlhLrD88MgHDJlMnwkJUHOUbaDiEX XFB8o/mR1Hsb5CgE+Zf1jutf81sOk0xLQ2PlXcTmJRipNCPc6eQScIC9DvSTQlXma76v y6rPEG/+3EoY9yWeyWMpqj6nc4br7aYthBDJY27Nv4jLmE5k9Zm7VQi5fBGYNijEtZwE qVdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690935604; x=1691540404; 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=sQqMGlFvgvQ3yvXEv1c3TG8Zu+eyY93FF0SWidKY8Dg=; b=MwhGbeLQQLJsdxYfhapumTXerDhaJjDwSBu0VDY/zHpkdfVgdTaeCRd8ZhFOBB45Ed 2H2TBlojAyodSeh9f0SUdjasOaz4KzLuY9wWUsALKyijY1tbYDfASDV3XHIkVyKab1o4 zM46bcNEMadF5Ib3qd5GxkFmp3utCWFVyy3+EoWo4LQQqlXARBLEBvtsXlLYnSMt61sF MN1DbQAAJb11ayUub4X8udgfHATbehfnponelhzftGo9He1f27xf4vpZuR/aVI2RdBd6 Il9qbMy6+0pUgklxsgkameywHGS3xJjOFt81g0u+m3ofg0R74CCS2g+aulHTSUgeJOg0 Cj0A== X-Gm-Message-State: ABy/qLYMQERUfNFOMBj5T9LtTIp6OaYWItCBEzJmsiSF4d7/itJdKm21 WUmIWZH4btJNV4vqpt83QIaLu1J3FVbFTOFk5g== X-Google-Smtp-Source: APBJJlEf7/u2/Z616hvXFPIg4IjabnaZmfD7pavvMQxNa0+Yi7QX2OhFnd4BlpzLjlUWlOxu9nZ4P/MXGt70cu1ftA== X-Received: from kalesh.mtv.corp.google.com ([2620:15c:211:201:aa5f:ff75:318:255]) (user=kaleshsingh job=sendgmr) by 2002:a25:48a:0:b0:d37:353:b7eb with SMTP id 132-20020a25048a000000b00d370353b7ebmr33827ybe.11.1690935603866; Tue, 01 Aug 2023 17:20:03 -0700 (PDT) Date: Tue, 1 Aug 2023 17:19:37 -0700 In-Reply-To: <20230802001938.3913174-1-kaleshsingh@google.com> Mime-Version: 1.0 References: <20230802001938.3913174-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230802001938.3913174-3-kaleshsingh@google.com> Subject: [PATCH 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 , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230801_172005_136619_21EE6245 X-CRM114-Status: GOOD ( 12.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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). Cc: Yu Zhao Cc: Andrew Morton Signed-off-by: Kalesh Singh --- 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;