From patchwork Thu Sep 5 08:08:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Li X-Patchwork-Id: 13791918 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 EF0C6CD4F5B for ; Thu, 5 Sep 2024 08:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80A486B01A9; Thu, 5 Sep 2024 04:08:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BA036B01AE; Thu, 5 Sep 2024 04:08:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65A406B01AB; Thu, 5 Sep 2024 04:08:27 -0400 (EDT) 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 446E56B01A9 for ; Thu, 5 Sep 2024 04:08:27 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E785AC09FE for ; Thu, 5 Sep 2024 08:08:26 +0000 (UTC) X-FDA: 82529957412.16.730876B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id 4C1ED1C0023 for ; Thu, 5 Sep 2024 08:08:25 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HxLC40y4; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of chrisl@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725523626; a=rsa-sha256; cv=none; b=lrjJRUoDHqkWaZtODdSiWUkZNWmXFdGFp2YqXU3vcf4QHfZXhWFOeZlky1VAqVg4Djg3SF 8K4RH2lL9K6g3eeamaWsD1WkDrngNbomwdu8T7U44qn3bpV929D9X0Uki54lSEt2jVjlh3 l90fKDhu/NfXGAf7m/ZbH2gNuIpIn+4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HxLC40y4; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of chrisl@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725523626; 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: references:dkim-signature; bh=kufGTuSUc5gypnIPXSVnFryxu21Pcf9uHuLVAw7aOLM=; b=u1YgW62Ap+cem7iIcPxAC1aIINGnmrFWnbyA8CinkOaMy48OF+ua5c+XVcFnSLUUef8afV p6ZcS2l5YLYvNpf4AB7FtzPrf8mML3VrDHnzR3uEKxyHqOrpl1x7iCcYk7ebHH0FBnyeV8 bmuUjlzPgx3sKtaZgHsqo+3y0WaF1Dk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 66714A44377; Thu, 5 Sep 2024 08:08:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1E6BC4CEC7; Thu, 5 Sep 2024 08:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523704; bh=pq4mgLOgPtjR7988qotE7KO6q3NyEFvajJ+jBZy0/Sw=; h=From:Date:Subject:To:Cc:From; b=HxLC40y4Wy5DCF2zi8WOTcbrT1aMCw3+A+bRHtHlZ7BbCgLQgSbIDVsIKa4dcCy+z 42bxu4Uc5+QPtkiLXeBhBbvvIv/dvKO7yZIuadnkPq7skPgUHkkl+qgJz5LW8U13DI aVSwXa/yOuq0FZmOZdL/Dj4fZHQb0LeCjVO+Tw4ZfG+egaVYJEP7rj3auRRBWniqiy amLD77Mt+gyeZAlC7hW66Qjcr2dwi8H+PdG6orWprIsFW61O40w3QnOVdoI6h6ykeh +ruH9YxPdXL0YpWxKKMocr8y77BpjqMLWfPNhjgcCsWqntGhUdrh88fbCLDkr325GU FdqxQrjyA3Z3g== From: Chris Li Date: Thu, 05 Sep 2024 01:08:17 -0700 Subject: [PATCH v2] mm: vmscan.c: fix OOM on swap stress test MIME-Version: 1.0 Message-Id: <20240905-lru-flag-v2-1-8a2d9046c594@kernel.org> X-B4-Tracking: v=1; b=H4sIAPBm2WYC/23MQQ7CIBCF4as0sxYDFNC68h6mC9IOlEioGZRoG u4udu3yf3n5NshIATNcug0IS8hhTS3koYNpsckjC3NrkFwqPnDFIr2Yi9YzaZ10g9YnxRHa/UH ownunbmPrJeTnSp9dLuK3/kGKYIL1xvTn2Vgt1XS9IyWMx5U8jLXWLxKtoimhAAAA To: Andrew Morton , yangge Cc: Yu Zhao , David Hildenbrand , Hugh Dickins , baolin.wang@linux.alibaba.com, Kairui Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Li X-Mailer: b4 0.13.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4C1ED1C0023 X-Stat-Signature: jk9u19ypgutokmiydfrwmp56g6sjpb7i X-Rspam-User: X-HE-Tag: 1725523705-939826 X-HE-Meta: U2FsdGVkX1+RNkfPvv6Tbd3fXsa+YogCauC39o/rF6rHbWN6kAkd568OK/xYdH5rTsblthS8NYAf7vXEX25VxqNE41G9/BsRa82B6dY72Vu1Uxvr9KIKZXDUhuKMgXobMLoF56oqhpB1OJmCllv4m1JmIIFKsh9xQF/CApED+5PThudY/GX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c+v6Z8X0MF7GMYljzUHP71dlhdc7 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: List-Subscribe: List-Unsubscribe: I found a regression on mm-unstable during my swap stress test, using tmpfs to compile linux. The test OOM very soon after the make spawns many cc processes. It bisects down to this change: 33dfe9204f29b415bbc0abb1a50642d1ba94f5e9 (mm/gup: clear the LRU flag of a page before adding to LRU batch) Yu Zhao propose the fix: "I think this is one of the potential side effects -- Huge mentioned earlier about isolate_lru_folios():" I test that with it the swap stress test no longer OOM. Link: https://lore.kernel.org/r/CAOUHufYi9h0kz5uW3LHHS3ZrVwEq-kKp8S6N-MZUmErNAXoXmw@mail.gmail.com/ Fixes: 33dfe9204f29 ("mm/gup: clear the LRU flag of a page before adding to LRU batch") Suggested-by: Yu Zhao Suggested-by: Hugh Dickins Tested-by: Chris Li Closes: https://lore.kernel.org/all/CAF8kJuNP5iTj2p07QgHSGOJsiUfYpJ2f4R1Q5-3BN9JiD9W_KA@mail.gmail.com/ Signed-off-by: Chris Li --- Changes in v2: - Add Closes tag suggested by Yu and Thorsten. - Link to v1: https://lore.kernel.org/r/20240904-lru-flag-v1-1-36638d6a524c@kernel.org --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: 756ca36d643324d028b325a170e73e392b9590cd change-id: 20240904-lru-flag-2af2f955740e Best regards, diff --git a/mm/vmscan.c b/mm/vmscan.c index a9b6a8196f95..96abf4a52382 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4323,7 +4323,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c } /* ineligible */ - if (zone > sc->reclaim_idx) { + if (!folio_test_lru(folio) || zone > sc->reclaim_idx) { gen = folio_inc_gen(lruvec, folio, false); list_move_tail(&folio->lru, &lrugen->folios[gen][type][zone]); return true;