From patchwork Thu Dec 5 06:50:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13894748 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 E61ADE77171 for ; Thu, 5 Dec 2024 06:50:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 538E26B0083; Thu, 5 Dec 2024 01:50:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E9AF6B0085; Thu, 5 Dec 2024 01:50:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B0CA6B0088; Thu, 5 Dec 2024 01:50:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1B3E06B0083 for ; Thu, 5 Dec 2024 01:50:22 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 90EC81413E5 for ; Thu, 5 Dec 2024 06:50:21 +0000 (UTC) X-FDA: 82859980854.25.9ED2A05 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf03.hostedemail.com (Postfix) with ESMTP id D38E220011 for ; Thu, 5 Dec 2024 06:50:12 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="FqiSj/Nd"; spf=pass (imf03.hostedemail.com: domain of hughd@google.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733381404; 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=Cvk6ttttbcv19F25dJWS3cOizDMg1rIr9u4lTY5RSA0=; b=tR2O6C2diK+EtKfrqQ87sfENECwFBvcI05IJN5+s1pPUBkld6muUmY/gnnDyzdwOfntj8r iIXCQrZeIGPy36wL0V/Pv/1bF1wmo5YI4tSsoUj81j4/cIJoZ6HnXIMyepmvDQVk0nBNaH WrAZ4GF8WVCgcUplZVmCTBrCckvHPQQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733381404; a=rsa-sha256; cv=none; b=SOydJNuBDIAkJ4ukAJoO+logAyMD1gFLLqwfcF7fqnYmEt9gVqC7lpPOvy3dfVWl9YIOAH bBG4dizde6AIrqSKRTX2zadJCbAg0RuCKTjJBJwgt/ZRcbBse2imUOI/5SKFgZ3zKQ6jAO xgbXsKSAMQDQhlurXbGxIdVH1+M9VzE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="FqiSj/Nd"; spf=pass (imf03.hostedemail.com: domain of hughd@google.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ee345c1bbdso467021a91.1 for ; Wed, 04 Dec 2024 22:50:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733381418; x=1733986218; darn=kvack.org; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=Cvk6ttttbcv19F25dJWS3cOizDMg1rIr9u4lTY5RSA0=; b=FqiSj/NdyvzztddMyy5DbYgd1AFl+MYel22+dtwxy4dLzCxf5udOGD2X8R6sKM9rR1 QRPodJ3KwRQsuqbPt59QCZ/XbVOfpGofW+ngyald2H0CX0RnycsJpJvYq3QDyWfkQslH dWKU3WC0uySMVx7mAVhfChDcX03Y3bF5b6LJ1lqd25/6pqwgiFoEWPvwM09lLmO9Q0KQ t0MetFxI9eQEq1SsnIgPUFKZOx7tfR0Bwlpf0BhuY4NVX+6YGzZy2gi2XgMqKj7yDXjB LnVW9OjAhq2LxRW8D1Ox8ISDtIRPh+w7bro5/YElPDVcVkTUap2NaP3y7qH9vF7QlSZn y5Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733381418; x=1733986218; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Cvk6ttttbcv19F25dJWS3cOizDMg1rIr9u4lTY5RSA0=; b=QfkalYkWJLhdqsJAen3CFfGQMeVzvrw42mfDBN/uifsNpNeSbn/vPjJ/bSRHMD6Hv1 fzv3BmeLCqbBQwV/9r6Ob6PsROxePzSiSxDFCFlu6oB6z/ECB9K1UYHzgeLeWhSF0Bst TBPb2sWbUXPAXHmLhCC5Q225V4K3UDko2f+gdhiWdZANmnyo9R7ncRG3nVErkhfD1W0+ OwmT7tgXHRoK/rbGMuyeoynpHketJFjoYXGhuLOc/NNJiwDxJmJTiYP02z3wMJYahjJ2 u/mOqUkODUVvpIkj/OD0Y7QRqGoCFGgYJ73Wappu6j+2exnRQK8KDO2RBjsGVxxo6doP KXqQ== X-Forwarded-Encrypted: i=1; AJvYcCXnWu8ozxVAtAvdejGQkLgWVjkglarfbtdwhHEaMaXx5x02qgmjFaXYoq30WTg9OUfoZUNVojFnHw==@kvack.org X-Gm-Message-State: AOJu0YxvsLtwP1CXDlIOWKS7uwpBUjmVXhBcaD2mjMLyvUZLN6aklGo0 p0XU7PZgLNdelDXq1jRkSjCQJbY9CUvG1vUkcsyAwwj2OgW3OvYyWpxlUDIQtg== X-Gm-Gg: ASbGnctZ/j9LP5oBcE9a5k36ZisL43QCCthpieZ2+u9B/kqw2D30Kbg0fBPHNLnlo6U ET1G3LoaEziv44JSoNLUqu+ceMN1VeRHlUiQsBzmIMBQujniGkXLUPldOOkbPPtfgdhlBHA3tgk RHnmPI2LEVcreheJxYboeVCrZZ8TSoxH3411b6FZDsXsBoujB7Z0pMa+ivBgKyg3JLlAbalnTU1 G6kjkMIvGq2Sn55QbqsDxDB/Y9mvvI5aL4+tXsfis2g2VugaxnxpBLu125PlSXfaq6hRmAVHy9L uOa5lLjv+SNFinmm5l0c8pE7CGxczdHCxxs3CA== X-Google-Smtp-Source: AGHT+IGPvwnGHMEiovh8VAQa9ivd2fvLTCiDTZovipWBmITfYcLHvTnKGEwY9d18d4z6Ra/2K6+yeg== X-Received: by 2002:a17:90b:380c:b0:2ee:edae:780 with SMTP id 98e67ed59e1d1-2ef011fc474mr14791127a91.15.1733381418257; Wed, 04 Dec 2024 22:50:18 -0800 (PST) Received: from darker.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ef31715ba8sm1997649a91.13.2024.12.04.22.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 22:50:17 -0800 (PST) Date: Wed, 4 Dec 2024 22:50:06 -0800 (PST) From: Hugh Dickins To: Andrew Morton cc: Baolin Wang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH hotfix] mm: shmem: fix ShmemHugePages at swapout Message-ID: <5ba477c8-a569-70b5-923e-09ab221af45b@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D38E220011 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: sfbd89tfzx7bnyh86c13pdxj4j1zr3h1 X-HE-Tag: 1733381412-932979 X-HE-Meta: U2FsdGVkX1+FCfIcesz3H8DszJB10uUW9W8yUfqrifYJM/wJSDGsovBzPxN0aFLJf74J3m5kSSNVX6P0UEdmtvoU6CULvlYWty0UCE5qujqnt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RpY3iRz749gW/JuWs71FedR7AJWkRd2M68O+QZF6E+jJ0Ex8h8emLY4333kAXX2gAT16tXyUrx2FibtkCvUb3DemRXzVrv7GuqU9hBJaNdTng/UoOY/7iIJwLsK/vnGa+ZuTD6dBDeS+lSe8R7H7AMD/P4rdIPpFHU1hZ828MKBSEw05ekN1zYaJDw== 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: /proc/meminfo ShmemHugePages has been showing overlarge amounts (more than Shmem) after swapping out THPs: we forgot to update NR_SHMEM_THPS. Add shmem_update_stats(), to avoid repetition, and risk of making that mistake again: the call from shmem_delete_from_page_cache() is the bugfix; the call from shmem_replace_folio() is reassuring, but not really a bugfix (replace corrects misplaced swapin readahead, but huge swapin readahead would be a mistake). Fixes: 809bc86517cc ("mm: shmem: support large folio swap out") Signed-off-by: Hugh Dickins Cc: stable@vger.kernel.org Reviewed-by: Shakeel Butt Reviewed-by: Yosry Ahmed Reviewed-by: Baolin Wang Tested-by: Baolin Wang --- mm/shmem.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index ccb9629a0f70..f6fb053ac50d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -787,6 +787,14 @@ static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +static void shmem_update_stats(struct folio *folio, int nr_pages) +{ + if (folio_test_pmd_mappable(folio)) + __lruvec_stat_mod_folio(folio, NR_SHMEM_THPS, nr_pages); + __lruvec_stat_mod_folio(folio, NR_FILE_PAGES, nr_pages); + __lruvec_stat_mod_folio(folio, NR_SHMEM, nr_pages); +} + /* * Somewhat like filemap_add_folio, but error if expected item has gone. */ @@ -821,10 +829,7 @@ static int shmem_add_to_page_cache(struct folio *folio, xas_store(&xas, folio); if (xas_error(&xas)) goto unlock; - if (folio_test_pmd_mappable(folio)) - __lruvec_stat_mod_folio(folio, NR_SHMEM_THPS, nr); - __lruvec_stat_mod_folio(folio, NR_FILE_PAGES, nr); - __lruvec_stat_mod_folio(folio, NR_SHMEM, nr); + shmem_update_stats(folio, nr); mapping->nrpages += nr; unlock: xas_unlock_irq(&xas); @@ -852,8 +857,7 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap) error = shmem_replace_entry(mapping, folio->index, folio, radswap); folio->mapping = NULL; mapping->nrpages -= nr; - __lruvec_stat_mod_folio(folio, NR_FILE_PAGES, -nr); - __lruvec_stat_mod_folio(folio, NR_SHMEM, -nr); + shmem_update_stats(folio, -nr); xa_unlock_irq(&mapping->i_pages); folio_put_refs(folio, nr); BUG_ON(error); @@ -1969,10 +1973,8 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, } if (!error) { mem_cgroup_replace_folio(old, new); - __lruvec_stat_mod_folio(new, NR_FILE_PAGES, nr_pages); - __lruvec_stat_mod_folio(new, NR_SHMEM, nr_pages); - __lruvec_stat_mod_folio(old, NR_FILE_PAGES, -nr_pages); - __lruvec_stat_mod_folio(old, NR_SHMEM, -nr_pages); + shmem_update_stats(new, nr_pages); + shmem_update_stats(old, -nr_pages); } xa_unlock_irq(&swap_mapping->i_pages);