From patchwork Fri Oct 25 14:17:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13850801 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 E2D0AD0C614 for ; Fri, 25 Oct 2024 14:17:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C8876B00A5; Fri, 25 Oct 2024 10:17:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 778B36B00A6; Fri, 25 Oct 2024 10:17:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 640A46B00A7; Fri, 25 Oct 2024 10:17:33 -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 461356B00A5 for ; Fri, 25 Oct 2024 10:17:33 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F40BBC0BA9 for ; Fri, 25 Oct 2024 14:17:11 +0000 (UTC) X-FDA: 82712326998.22.C9CAFF5 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) by imf17.hostedemail.com (Postfix) with ESMTP id E2A574000C for ; Fri, 25 Oct 2024 14:17:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=jTqgKprc; spf=pass (imf17.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.45 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729865798; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=wFJ7qeo3WN9Qtar7fFSc4KOFTyi0KFll6s9kH9IhHuM=; b=wj+L5Np84lWXDTPWaMK+bBcbXOxrXTP4u9kBsVHhcFcvP0Olk+Fqv6kRErgG0p5kVQHfDz oLNkSW3lFwKp/8g6bpJx6qtcB+zMYeHLzR8apbe7X+gcFZmIcVSGB3ZEzIyk9QggYswfsD prVRIaaXvvUV678ttyMLTd2LZU9igl8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=jTqgKprc; spf=pass (imf17.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.45 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729865798; a=rsa-sha256; cv=none; b=e0rYCMkPaLJyOAFyKMTMRT62xBG8mMMVtYR+hicF2ydvGqsE5UjXeiQo5+fZjmSsCR6zO+ 14t3Xd1YCFrUPtZawxItaj31AETGhmk+J/jMeoFy2zaTHWOdMDg7L2e91uLo23tqrN4rps 1y6eiHZmFa2d5NdCw8i4P5EOdDg5ND4= Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6cbc28f8e1bso12838856d6.0 for ; Fri, 25 Oct 2024 07:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1729865850; x=1730470650; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wFJ7qeo3WN9Qtar7fFSc4KOFTyi0KFll6s9kH9IhHuM=; b=jTqgKprcMaS99JiU/M6qUMa3an/N/6lvBtAzGwaNwT3STDMwKMqCwytyPLREcwdJD9 +CJB3MwFwmOF7eX/75ll+0NQCZ/qU89odUh3+52nS1La3XpLH5fwuzB+BAs7zDXxAcNS 3LIZp6t0qsCXnZUi2YS4oK1XbpDBPS65RsCDOlbtg7zYPXtnGrL1kffpVLNSe1Cygdjr FMJ54fsQzDul1oVQC8fzisi18or7Xl7qXb0TyQ3gzBSapUc2XPklSurIHEZ3I19l7UV2 isJqLb3MDvJWvbz0XDuApi/mb9MM0YqZh6GOXB+yju+X5fhK9Dm/q5lUIjO/cbXKRZeC IE5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729865850; x=1730470650; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wFJ7qeo3WN9Qtar7fFSc4KOFTyi0KFll6s9kH9IhHuM=; b=RMjbtp01O4IrgyBaLgW5bPqoBJShQGlg9jrUw0QlInW+Rz5YSpOPnYioDaEv4vcRvB l9+FtKQmBkAvXt+poOLvGisM3d8oGF6uNsQXRizJ5paGz+BGcbVxkUWLWTO8ptFQewIh ciQCur5B/nMilkj8skz3poAv91nlMh6p0JZAcKXKOeYyQhzLrRofJXVWyJuidvobEwJM fkENe79hlPDw+WgGXD4t5mu2QPWK3ZSPgel9ybYAwv3S7kpq1793MFULPmjpDylxKadO b9wbhkFESiWURMMi8DOdkQAV++TyKxkKiMVlWkAPaH6P/EEXov6BEbONi19iZAXM00m+ dECg== X-Forwarded-Encrypted: i=1; AJvYcCU7IRvaFzyW+bDLOmzagou5D9WbIRPx8GzwMZDsp7tB90tGxhNpIxsfYEGGF5ad9oIXdaWr6sam2Q==@kvack.org X-Gm-Message-State: AOJu0YyOkHBFVXeCozKu3dHZGmaA56hkl9jPCVhuMKygKwZTi3w1I8o2 KS2tSYk3RfzFS/aOslsFbavXQBYtrqYcRUHBTyFcHZumqqMHqDag2pUSidgTo2U= X-Google-Smtp-Source: AGHT+IE7mLrQ4PS1T6eK7H6zyqpO+N3XayG6pjPmJzubg5i3rO0Sb5RLmu37pfnSWox+jGrQ8fS7Pg== X-Received: by 2002:a05:6214:5bc4:b0:6ce:12da:1dfc with SMTP id 6a1803df08f44-6d08d6dbc20mr74253646d6.4.1729865848617; Fri, 25 Oct 2024 07:17:28 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d179753621sm6115576d6.22.2024.10.25.07.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 07:17:28 -0700 (PDT) From: Gregory Price To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel-team@meta.com, akpm@linux-foundation.org, ying.huang@intel.com, weixugc@google.com, dave.hansen@linux.intel.com, osalvador@suse.de, shy828301@gmail.com, stable@vger.kernel.org Subject: [PATCH] vmscan,migrate: fix double-decrement on node stats when demoting pages Date: Fri, 25 Oct 2024 10:17:24 -0400 Message-ID: <20241025141724.17927-1-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: dr6derdybeh8bbesh3czrha3fffs1s7w X-Rspamd-Queue-Id: E2A574000C X-Rspamd-Server: rspam11 X-HE-Tag: 1729865835-118371 X-HE-Meta: U2FsdGVkX195zc3TQqWlp8embxrqAw37+KE7lieyoPRd5FjAjuoWvxJ1IuL/Bwev1rq4Qu+N27Ua1ATzNG+uB+06ftwfyTYXtw/8cI19qN/jZe/Yyqg3o0bNzR6FsLtVyJuCPK9SWq650D1lMkFGqWp1eqiwaPKxFlvYjf4TGkjHqREwEO7ChzVjzT8738NzwXxKMGTLXFndCvYYEqxnk1ablpsY7nrL5cTzcQeasD/lFPcCDTYTq56+rGAkcWNZ2+gQQtlZAdqosngKrUBmEGHeKJlaIXMZp3yjMuZT6mpwP4Fiz0mLKfNOWFu8J+5SJhJwL1qv7ml91G+8UGhP3izm/KulmjXx2Z2lEdhApN98DrrF7OfRdXqhsJbmmceGxBt/6AkwgvgzT1m3BY/PCoqh8fbzNzYY5P2Zpx3Z0xhWGFGDLwz3a08W0XDd2elCfLLwhMTGLJ2frWDLues6LBn96Fd32bo3uddd1gWtKr66VMZo4nALOvIa4NZYyN2BlwuDz4ozfNdFGc+0Myf9JwSCSls5EldKRtJ8Xs7mdvJoQ38hbGvQQ5ZjmMuEq6SF4nvd/0YVACSau4X0j0nhKxoCYwMQ1k/aPkY1j5uaWiwi2UYyiVKkiYudfJD9piD2T+FjtrMq7QqFcMb7yE7OEo5rhw8VtLFY0o7j+Nt4IruPbpyiGOA+LbzLBkzzrACPU4OmmlUNfs6Aky0Zm/EZ0dsD+HOhKv2vEeVlRPRmvdatOeoNYYbkxRTDKHblbX0+ndViCRfEqHJslnRLCl3NZdN1lcAX+cJtWlmy9IX1ixQPfXhLsCX/4jYUMd9NfFotyYVOhkV4rrfUmDOlBzwNkxVfyaqyefgUkJnGpyJCX0EmiO59x4E99vh80rPZb9Xj2WSbG6HuBDhb5upkQs1SAq/dSmeMlNE7NiGRyR7lLQqe8XNT+5quyKPL10RJV0YaTARdkT++vwz0B2Hxzen BwBf9Kzb n0zPrNA/vMSN+88zXk1E1KlA99v64UR8zWHPDeyHjBhxaS6kMSPbrCZq/ON1Tw4rPZBLUPYVb0Ubh4pCUzm4l2/FrE3l5dxW514uPKzmF/Rdv0/NeZBQnaA4DQ7dJKqsL7zickUD+8suOoVPk/UFdan2JrOzpELMNmF4+a0DVgRGxxax67ZdPjHoXBTbxd21sL5ssIG0u3qgg8b5KpJ/amWTgNfChtIKrd54UaUTXK/U0ht5bsm+CARn2iDRprSfcanoskilDh/WOKGKlNuffghIRzpY0wbgpz8M8xk4XeY5dwZG3pzp+iFb+YPR9QY1mIZE9K+cKwveGLa4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When numa balancing is enabled with demotion, vmscan will call migrate_pages when shrinking LRUs. Successful demotions will cause node vmstat numbers to double-decrement, leading to an imbalanced page count. The result is dmesg output like such: $ cat /proc/sys/vm/stat_refresh [77383.088417] vmstat_refresh: nr_isolated_anon -103212 [77383.088417] vmstat_refresh: nr_isolated_file -899642 This negative value may impact compaction and reclaim throttling. The double-decrement occurs in the migrate_pages path: caller to shrink_folio_list decrements the count shrink_folio_list demote_folio_list migrate_pages migrate_pages_batch migrate_folio_move migrate_folio_done mod_node_page_state(-ve) <- second decrement This path happens for SUCCESSFUL migrations, not failures. Typically callers to migrate_pages are required to handle putback/accounting for failures, but this is already handled in the shrink code. When accounting for migrations, instead do not decrement the count when the migration reason is MR_DEMOTION. As of v6.11, this demotion logic is the only source of MR_DEMOTION. Signed-off-by: Gregory Price Fixes: 26aa2d199d6f2 ("mm/migrate: demote pages during reclaim") Cc: stable@vger.kernel.org Reviewed-by: "Huang, Ying" Reviewed-by: Shakeel Butt Reviewed-by: Davidlohr Bueso Reviewed-by: Oscar Salvador --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 923ea80ba744..e3aac274cf16 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1099,7 +1099,7 @@ static void migrate_folio_done(struct folio *src, * not accounted to NR_ISOLATED_*. They can be recognized * as __folio_test_movable */ - if (likely(!__folio_test_movable(src))) + if (likely(!__folio_test_movable(src)) && reason != MR_DEMOTION) mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + folio_is_file_lru(src), -folio_nr_pages(src));