From patchwork Thu Aug 8 15:42:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13757856 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 98ACBC52D7C for ; Thu, 8 Aug 2024 15:42:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B2F56B00F8; Thu, 8 Aug 2024 11:42:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 788BB6B00FA; Thu, 8 Aug 2024 11:42:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6612F6B00F8; Thu, 8 Aug 2024 11:42:44 -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 48EDD6B00F8 for ; Thu, 8 Aug 2024 11:42:44 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E738E1413BF for ; Thu, 8 Aug 2024 15:42:43 +0000 (UTC) X-FDA: 82429495806.21.1ADC53D Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by imf19.hostedemail.com (Postfix) with ESMTP id 1BD3F1A0008 for ; Thu, 8 Aug 2024 15:42:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=0h1A8Oal; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.41 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723131689; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oRSFFXDfNtNVk7lGVeoRIubNta7FSFGwpVVL6fGvxf0=; b=H9ZG2DbONngvWozAWlq2GUvVyJYrXxuW701UPppGYDURf4VJi1Ep1R64MxGAIKDora7P5w RULW/OfHkorzr4yPxeiGnbz2BL2SEQlD5dSa4DyFciVCMr+7F7MBlOwj8+1qwJq4JP+KLn KS7WxdfskJLs0XhyQ8uPxA/bd88uoMk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723131689; a=rsa-sha256; cv=none; b=hqb2SLzBZRWyUBjnNs4KD0XkT4qVgD/P15GJLsFnUl/fqsc5th78mlUrTaaIxOeEqXguEg PWBHU1QsN1Lw/JqQ0GhAY3kqeMhJHRaw5GWoUxqCq0Av2FV4vuQT3DXomHOKGw/Bvv7qcc 2ZTli9NonT/ANpAfOPaV2sMeYTGvvMQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=0h1A8Oal; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.41 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6bb96ef0e96so5964196d6.2 for ; Thu, 08 Aug 2024 08:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723131761; x=1723736561; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=oRSFFXDfNtNVk7lGVeoRIubNta7FSFGwpVVL6fGvxf0=; b=0h1A8OaldduwwMbrHsKqvvkYeYIEg7uU8v56gQzm1ancvzYcWt2s2EZL9djKCVifTc cIFQXkPHJ93l/x8JR+f45ix/gx9u44McltWvYJTIVH9fIYl/U5U7q6XjZ5X7Y5TNvww4 oQiLE7ly5DYO9gyccTqsNddlhVPhPdBpiO+yMlRNzh9TieR1U7yg0rdC6JOOdQQvP0aw 2PvYQgLQt+FcMbwzZ2yvl2Haab2CWJyPLxUXoz8mJdULf/sQqidCYWuL+sZy5YkNMXWT OFV4dVjkTie1xxy00CvF7BtUvb1z19Bi3BIIw0x6QtFwQM3LpYj7UiR/MX5WKIRRDU03 JIag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723131761; x=1723736561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oRSFFXDfNtNVk7lGVeoRIubNta7FSFGwpVVL6fGvxf0=; b=ZeeGCA4p/zxoyYujNT9X+AZYaqhuiv09UEaAjRtQ3cgvebfYfQ7awuMrAurtGuELd9 xwYJ5O7Mioxcnw3BF0mBzcY11D/Xdm6PG+98X0eHSRontbFX+DQ/liV8Ovx0zfPNQOW5 kORO62pqtDe6WcPLI8SXd1uXJd0ChU9zWat6cbahMRk9FTyGB/6mnkg0+I11CTJCJq1B mYC2dZS/MCa0zMVUEx1xGYI/HovCaDYMcGwjgf78TuWO67lyVw337lpmrBtvEuyJgDd6 fV3u0dL37aeevyH99RsaA/jK1wLDJfymPiCsTrdONa//h7H0w0TIwOGGOozIzocvRjmO MrrQ== X-Forwarded-Encrypted: i=1; AJvYcCWAD+D/1/3cNW9sKfJ4Yejx8/JzlTL4H50q089CkYMz6SPr8ksKAGb+rPS5A79R7FrKjUOWMxY1wNt2a6m67rGPgEQ= X-Gm-Message-State: AOJu0Yy4fKw86mDks3sA5M/wC9m/XPK7NU9rIbMW8/WT+3Sl/mmuTKFU 4lxPYLlwgh1HQP7dJcCoFHPmzldnN33VuCqxJ1G3qf0HfaOPLJ5IV4dumkftmjQ= X-Google-Smtp-Source: AGHT+IEedYPnvL6gKHQRQr0wt7cczChz5kQMKQlE59fzWebBtyv5plUCNw68Wg5Sa6xCxlvPXi39qw== X-Received: by 2002:a05:6214:4604:b0:6b9:607e:275e with SMTP id 6a1803df08f44-6bd6bd3263bmr24643256d6.34.1723131761187; Thu, 08 Aug 2024 08:42:41 -0700 (PDT) Received: from soleen.c.googlers.com.com (118.239.150.34.bc.googleusercontent.com. [34.150.239.118]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb9c7b72d9sm67160936d6.60.2024.08.08.08.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 08:42:40 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, cerasuolodomenico@gmail.com, hannes@cmpxchg.org, j.granados@samsung.com, lizhijian@fujitsu.com, muchun.song@linux.dev, nphamcs@gmail.com, pasha.tatashin@soleen.com, rientjes@google.com, rppt@kernel.org, souravpanda@google.com, vbabka@suse.cz, willy@infradead.org, dan.j.williams@intel.com, yi.zhang@redhat.com, alison.schofield@intel.com, david@redhat.com, yosryahmed@google.com Subject: [PATCH v3 1/4] mm: update the memmap stat before page is freed Date: Thu, 8 Aug 2024 15:42:34 +0000 Message-ID: <20240808154237.220029-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240808154237.220029-1-pasha.tatashin@soleen.com> References: <20240808154237.220029-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1BD3F1A0008 X-Stat-Signature: jq6xozr65xt34yszfxygf1sw7gt1thg8 X-Rspam-User: X-HE-Tag: 1723131761-475926 X-HE-Meta: U2FsdGVkX19Uq0GLuNXqrKX9qsfUdwIeNM6UJrrXE1IIN/qcMp14aDi98Yx0UoaR4JFw4u5KNem3Io+zsEOHX9e8OETi9xBVbV3m+K3NQiVfDZaqi4nTNdKMysDcsyvk7VOFl8verPZSHWlgGipDWZG4V5kW/KzBONXoS7+x3ne3oIXnSpEdxsmG87NtCyuUjEuKUXoywRWdoiTZG5b+7cnGMIoCxGfQwR/g1GVIxhXwi8T5wjvZIhEfoN3qVB7KWUHt7tYLGgYwhIDjFug9RxTDu2X37+7vAdkuCs8BrSYghZsUsMXKN5Y7IAq0yzfYbilH4KTEkNYBNNPHM46SLahUPbjNFmZhKJwi8cLT0qmm579MPcYPMzkD+xk1mqdmJtzuSoXUMgctUOBN/+YHZGynxx9xNr9k5ab3gWTPlzWy1tYvgGL8hDsawX41eW6izWUlsQNyICVmKZbn/aIYT+rs/+ptKJPZEgMVvS6pW0KJSvmD+D6XbxiA4SEqlXfaFXReHsW9kbZDXwTm8wHoPVbQ+QthRjqdHR+wSAEAM5r/XiDGVDs8zHOCaeuNM89pGuywl5wMzegTDurgP7i6wDhdc3fXWuyB8Ne+8Q3JuBeYDAgdreR2iZRL4Txwp8eEU2bOV4tq6wB7HIvldZvSww0GUnopkKC9Ht8cuDnmyYvC8vtbaJR34iRPjbMis1NhYkV55hXml7lLrWrLT7hzPLkHIULufEclCzn7fZSccgtd3Rp3VJi7KGBA6fL8o1B0U4I/pBk56agl6c2d8erDeufh9Vp0AlgOtB/2Bagiabn7wyp91X5EdyrOxRWl4tuIo64PwABN/gtt5VFkSy9KhSpWcTGHosccIyFEbqR5VsziOh3D/c5xOO5e4Pdg74yFl24U8M2Hc/mVk26gcf2o0eqaG5qBdMEEUzA91c3zng1iY5wGwx7VTiGk1m9C1vJxjJYq3ryWddWTVsogpE8 8H0SXXQK 6tcznsbRvL98IuCKXd9pTcl3QhIiujtG/DyigEz7zN1w3BIu7mURB6ldXwCCqUiom174AhmIz56FwYx5cgV+mkk2/7+OwAz5xjkk5Vce0PbDFkqw/w41Hr3cJYQw6+1oMO/eumIx1O+RUTLnG3S7yaC3Vqa8yNIc4c85dHNNYAv+VEuwVf7RTGv+qDJYEg/sDCAMbpWA0E2i155ocGFnPHX6NiBeTFTB33ndPkiYlhbye+ROA8CVa36f4u0YKtzdox7jrRY2vBKhdAftcg5iRrEHW/pljfZ1mMfcYDgnTZxeCS5b9Ex6auv+Vs1xr+yQOpBCs7gFo5EVa+jOFEOEcGDNkn/QNPxmEPFgVRVQfBNeinmyxcBD52BiKlilej5dOVFC467b64L/rUF4= 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: It is more logical to update the stat before the page is freed, to avoid use after free scenarios. Fixes: 15995a352474 ("mm: report per-page metadata information") Signed-off-by: Pasha Tatashin Reviewed-by: David Hildenbrand Reviewed-by: Yosry Ahmed Reviewed-by: Fan Ni --- mm/hugetlb_vmemmap.c | 4 ++-- mm/page_ext.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 829112b0a914..fa83a7b38199 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -185,11 +185,11 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, static inline void free_vmemmap_page(struct page *page) { if (PageReserved(page)) { - free_bootmem_page(page); mod_node_page_state(page_pgdat(page), NR_MEMMAP_BOOT, -1); + free_bootmem_page(page); } else { - __free_page(page); mod_node_page_state(page_pgdat(page), NR_MEMMAP, -1); + __free_page(page); } } diff --git a/mm/page_ext.c b/mm/page_ext.c index c191e490c401..962d45eee1f8 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -330,18 +330,18 @@ static void free_page_ext(void *addr) if (is_vmalloc_addr(addr)) { page = vmalloc_to_page(addr); pgdat = page_pgdat(page); + mod_node_page_state(pgdat, NR_MEMMAP, + -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); vfree(addr); } else { page = virt_to_page(addr); pgdat = page_pgdat(page); + mod_node_page_state(pgdat, NR_MEMMAP, + -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); BUG_ON(PageReserved(page)); kmemleak_free(addr); free_pages_exact(addr, table_size); } - - mod_node_page_state(pgdat, NR_MEMMAP, - -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); - } static void __free_page_ext(unsigned long pfn) From patchwork Thu Aug 8 15:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13757857 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 BC2B7C52D7B for ; Thu, 8 Aug 2024 15:42:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0E856B00FA; Thu, 8 Aug 2024 11:42:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F9C06B00FC; Thu, 8 Aug 2024 11:42:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8268E6B00FB; Thu, 8 Aug 2024 11:42:45 -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 633D36B00F9 for ; Thu, 8 Aug 2024 11:42:45 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 20BB5A1515 for ; Thu, 8 Aug 2024 15:42:45 +0000 (UTC) X-FDA: 82429495890.28.72C410D Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf24.hostedemail.com (Postfix) with ESMTP id 63D06180025 for ; Thu, 8 Aug 2024 15:42:43 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=gtpcc572; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723131677; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y3neo5ZpPv5S0nCnjgNJX6IioRmVVyTly9egBg9Jmdk=; b=n2y9bpr+OKfQS3H+8Npbe8u+LNMka/+4bMNp5lknNo/TvU02wFuK3vC9tcwodqfKTSDoWs 9fzR8Io2mxR+uRNIYmz+CAKcZH5g+JIp0w/dS+KV1cTG9plSd+RAM9udobt5y61mL0hy44 yHBH5yjAytho3i5jtmqUTsClefTTXkI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=gtpcc572; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723131677; a=rsa-sha256; cv=none; b=wwNdtlgrYsqSsQqEzD7bk5AfiSKAjTwOkvifWWxM3FWYBop9YRHM3gqMA5kwcZesRUtdiT Zuih8QEKIQU3qJVXYGc27FTC1c+yx1X+H2SRQDyOC+S3c+HpJS+4ATP8SEwQ+VxympsOFo 4PM6SrAbpgK+NzstBc1t4xWVgllmlYQ= Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6bb987d3a98so6228416d6.1 for ; Thu, 08 Aug 2024 08:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723131762; x=1723736562; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=y3neo5ZpPv5S0nCnjgNJX6IioRmVVyTly9egBg9Jmdk=; b=gtpcc572j3mjCd1SDLhDsJVyWDKnZjqVQNGnJveWkDuyLxA20FVNIoSCSnl9Iqm/Kv wGY8beeVfFJMfchDPp0NFKboa9kuDjAL+n5MNv4blemqP9V91uCRs34GZ4mYllorwwmJ BO9JmXWjC8HlmbMjqrBnHRDCARQ0SlPf8/B7f3y/qE/ZDS0J3Zjg9Qx2prwaozZgLWq6 yhnOnGlMTLpNR7EHJ9KZPFDnoU8Vbc6iThGgRU9OkH8Yzb80mKIPWNfr8vT/g8kTYpMq BHsneZ/KDzSHGj8Im1BkzT4WEX6lscZUcwXLXw69w4GOWaV2Cuz7Zo1IwTfnsTfzzWCH ocGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723131762; x=1723736562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y3neo5ZpPv5S0nCnjgNJX6IioRmVVyTly9egBg9Jmdk=; b=Enf7ZFz88m18PajesvyHroNmCfaPcn1yZfEfzfdNqGxf0+nhmEe7u7P3Wvmdfe974O pE78KdVRfsg58wAbTSk7ExR2vXSelBS/OABqPIHT3pIQXKD2B7u/Z670u3U+OggeTrrW bN2JpzYOjEiTpe33VLYJOJfZe72XI+Kylt/+ZBYWERlXlP6KDucrXJuANqKd6+S+wklV QkoUellbkjHZcuhSdUT0nSV8+JsRPtrpGefAOqxlenIO9B6dKfWsXOlYzdbEiuVGilYw IeXpiFKe+Q4tkvQ5acL80NUfIyepaPEM+zwjSjyh3c4s987Yw4RVcPjxu/u/UsLmDJVL 8X2A== X-Forwarded-Encrypted: i=1; AJvYcCVkGSeVukYdlhpNyqBrkyYwGMxQr/YURhWybm5yRSRTIRP6hYmwXM6qiFnNY8bJyIJChpFGLERW2upyxr9oGHJehmA= X-Gm-Message-State: AOJu0Yxd9WE8370iUReQwH6EK6ChDERV55VXceugY+J5Zezdb6H5HViI U2p87kYl8ntcgJtlRFRWwdtiEyCpoOtif+RhXDp4VmzHFReKg5e4zNMU5tR1UY4= X-Google-Smtp-Source: AGHT+IESGfyB5HtXu4zt+BcOgb/gdPZpAEI0Yo2J7Xp64aGcrd7WAVMlzlbxNtl0uyZb/RHkn8qBZg== X-Received: by 2002:a05:6214:3bc5:b0:6b4:4470:81a5 with SMTP id 6a1803df08f44-6bd6bcbb55fmr34927436d6.2.1723131762416; Thu, 08 Aug 2024 08:42:42 -0700 (PDT) Received: from soleen.c.googlers.com.com (118.239.150.34.bc.googleusercontent.com. [34.150.239.118]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb9c7b72d9sm67160936d6.60.2024.08.08.08.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 08:42:41 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, cerasuolodomenico@gmail.com, hannes@cmpxchg.org, j.granados@samsung.com, lizhijian@fujitsu.com, muchun.song@linux.dev, nphamcs@gmail.com, pasha.tatashin@soleen.com, rientjes@google.com, rppt@kernel.org, souravpanda@google.com, vbabka@suse.cz, willy@infradead.org, dan.j.williams@intel.com, yi.zhang@redhat.com, alison.schofield@intel.com, david@redhat.com, yosryahmed@google.com Subject: [PATCH v3 2/4] mm: don't account memmap on failure Date: Thu, 8 Aug 2024 15:42:35 +0000 Message-ID: <20240808154237.220029-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240808154237.220029-1-pasha.tatashin@soleen.com> References: <20240808154237.220029-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 63D06180025 X-Stat-Signature: 199xi791wq7n4toimdc5n6c7p9o6srtn X-Rspam-User: X-HE-Tag: 1723131763-112067 X-HE-Meta: U2FsdGVkX1/RWJL7j5B4tU5Jknd0yApl5MH2miEyG9p16EuHfuwCaT0Yoh0x6ra/GpeJ7JrVZdaD7eg2yadlnVAixSLiPDUm1V8nzBtM9T2Zb4H3zU4uYax4Evcp0aKN5W1uL9P5XvYRKwPcPXnd6pR+JZhxGpau+4Kej0vLgkXqK0p1nCeT4oyMcFqVF5C20kIBvSr6/gsTmaflOo3RTaGu4dVRXcGlJ3hd8KeOZ4lAPUSabdOyHLE6fVdTF8FY+GzkVTJ1WBB8rnqbO7589JkxpVlpEj+5mkrIiW3XORYj2VusPOC//gk7OeGfLBCqF6poauln0pls8PCJSwDx4p8HY000C1J7aX8cDHgT1dwkJ/LhQAZwEtAkqT1maftgceFG/g7NTRuA26n/e462b5wY9fA7A+SxboypLbHukxREjZe+Gut8VcpCk3x/HF+hTOaWx+L2UjXlNfrx9LZ7kAl3PeQeWG6qKRvGIIkswR9Kd/amcdCt9RrnlWnufxzEiZkWpQDAgQBA0/KNv9aKhvdzl7wiDEq7qghvgfWhNV0APWjie6Em4mzpSk8ly9A3DAJJ8ljyali9jeowiBKUYYMNqXgEVGkPMWWTOVKZr0E9YxvQpmzar7KRStYhk8gyLO4gOVa0QpawQ33QqUifrmNhR/Z0z4UyoLplySGE57mFdPTCerlGDL3GnkmL8nEAGfJi55TleIDI/6pZ7wlbptIImak5iIhAHipilDJj9vbSHR/G1d6don2hOFSoASZI+LozGv6eQTAqSNrPDawMQ2Zctsx/nz4YDkMXR7Zwdlp9El8YXepzjiCtLK5OAhIM7EO4AXUXHQNuhT6lWfukGtI9f4fpdCYukXl/EeCzwM9jBjA27+rpbPVcbpZ4+DXm0aHyLlvDypYhomHOPDGVgKhSTtvy3+SrKJL42hwDE591vVlcEECKO6LQ9hiHaWPs504XnlOvm48CU2oycBr jh+t9Aim wX8Iu6x9dmaIclfd5jRt5g7HIjRZ1yjj6lvquAlkXw4ZkUtdR6gnB2IkYQuFgaTx9CHMU7LJGqCtOIGGnp+yS3ONiJKY4EOHvEr3dDjC4ujHOZeo5PmqjGPxdHPMtZfycW/2mi5nJRbGnhBgpYOAzs8fJxJ+A533i78UIaviFSvgGLVqD4NA+7DspArm1Ra4KH1ZGQDSX6aX4sB+I7hwxRtyUUkZbqUlFkz7DUPnuF+fsfPq3pXhoOgF7vxAjGlL6eS1mswGkWvoC7x5FqHLiWualX2u2gBvcTMcX5aAbyPRS1LK03j9vRxO+/5QVRV1QeRJhigBQk7XKzjNvx+uSUIPCQgKQwS3anSuN1GSvjC0xnblOi0JZD8Oqc+uEJaA6ym5z6IsiKy6nDGMO7+3lwCP9NNpq57XskJNqf53ILxtWnRE= 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: When in alloc_vmemmap_page_list() memmap is failed to allocate, do not account, the memory is going to be release at the function exit. Fixes: 15995a352474 ("mm: report per-page metadata information") Signed-off-by: Pasha Tatashin Reviewed-by: Yosry Ahmed Reviewed-by: Fan Ni Acked-by: David Hildenbrand --- mm/hugetlb_vmemmap.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index fa83a7b38199..70027869d844 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -392,13 +392,10 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end, for (i = 0; i < nr_pages; i++) { page = alloc_pages_node(nid, gfp_mask, 0); - if (!page) { - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, i); + if (!page) goto out; - } list_add(&page->lru, list); } - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, nr_pages); return 0; From patchwork Thu Aug 8 15:42:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13757858 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 E188DC52D7B for ; Thu, 8 Aug 2024 15:42:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3209A6B00FB; Thu, 8 Aug 2024 11:42:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 281366B00FC; Thu, 8 Aug 2024 11:42:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1226F6B00FD; Thu, 8 Aug 2024 11:42:47 -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 DF0866B00FB for ; Thu, 8 Aug 2024 11:42:46 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 83B5EC14D5 for ; Thu, 8 Aug 2024 15:42:46 +0000 (UTC) X-FDA: 82429495932.24.BC84965 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf30.hostedemail.com (Postfix) with ESMTP id B030080029 for ; Thu, 8 Aug 2024 15:42:44 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=zhhJm12o; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723131699; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JDFp22AQxyyflK1t03n9dVCi8P6WDfRZ5X/KyWOrQIc=; b=MdCnZFwDdL39nZHGgLtIqzvn0WOPEtIsf6dmzIqEJU6oC2WgfW3N7WmEtKZF0TWbOItDq9 YgEe4/gqIxS2UvknaqbD3whIDawFu1IIApQTl6ZjmpjMJW/kBcAeZ6v5vk5v8vr8/4dRx0 QrzZWEbyaJNPv/IfW7mcRaOjppUFhYg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723131699; a=rsa-sha256; cv=none; b=z0JDgl9MWAbqAarShOo0Mpgy76NLFqnDF6/AFNnX9q6vp1vFAsHeWA3OUFrwVOTq6mo7Ok nAnPouPppthjYcFbTXKOmssD1Ni1LCUzkf8kqwn3EXTGjD7KNOuD0F3/4X9YkHaiSFccz3 TwUCmyHTVrXiPFHZJTLH3jVxz8bNP9g= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=zhhJm12o; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6b7acf213a3so6065126d6.1 for ; Thu, 08 Aug 2024 08:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723131764; x=1723736564; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=JDFp22AQxyyflK1t03n9dVCi8P6WDfRZ5X/KyWOrQIc=; b=zhhJm12oGZtemEv/W+4N2tVaWgASwuRCieax8GuTNbWs1wz3ssX4JCc8ULGBFFKI3v pVAg81cem9MEGYDHEmSedxgMpYQMqOkdbwckqyt3mXo846JqYAe+JOyH0rYmMSkjs+mY WGdGSNxwbaIlM5Ef7AOrhVrxn/5o0ZSqaW74Jm6twZ7Fg2QyMDt/wyFo3wfEsBHZOrQy FwHtA8OxyZ4TqkUobAfXdSDLnzpFRKti0QsIGXw20OBaYtrymSTjmEhMvBMa+wbjCr0P DYGdB49iYgJ/mWjMH0wf0WCFDJsAJ7ITyQ6U8WrnCxIOD4iU0UwsID3acTiEC2Y4DqOF +mJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723131764; x=1723736564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JDFp22AQxyyflK1t03n9dVCi8P6WDfRZ5X/KyWOrQIc=; b=d1w0I1cG+9z/0sEgsicepUdcfBQhBkbXrUUfkMjktmnG0GjM/Ee0vnsXbWP5IKjEeh SH6oGY23+XHXZVLa/7I4ERfGvgD3jb0IqSrA1ZISKZ3PetHQyVzTmM1cgVJklwn2TvOc AHSAqgeTroU5jfsPc7DFpbp/qkjRjo1ZwX3Cp9ePnl/M81cvl++LrgydU4NbCKj8zceS q9WOp9pvpFvE0DhnReP1TUwtPgzJ8Os9vTiINcQhK2WbGopq5SIIXT+Lh8VIC5iXUvIe n+aOftltKwtlYVh0+NVNwsMHFh8oTd19YbAs4MWGfqc1dD2djX5iF/unzlE03ZtOA/xs Avng== X-Forwarded-Encrypted: i=1; AJvYcCW6jZaV73Nf0TxmI4/IPVw1xTfl2//lJuQG6TR91PBsavYduNrqJH1C3q3Ab0NFx7uZqKZUHtEwRbIbnD0TqW6Uxrs= X-Gm-Message-State: AOJu0Yws7oHPGexpzynCi1nOBTlmjeJbO2GgamfUKVccDwhPM5sJTELc 5Fkgnyp+gylOsKmc4Vcp4jXmFqkqQmsm88zEA7EX4P0r+uiGHSN8az+PnTYnStI= X-Google-Smtp-Source: AGHT+IEX9KsTxhX/Ixnu+CrH4K+4EL15weClfV8tgGdVgFqf5/zGrOX8N7XKxkOKw/LPNvKUtrOSaQ== X-Received: by 2002:a05:6214:5d0d:b0:6b5:7e09:970c with SMTP id 6a1803df08f44-6bd6bd227f2mr22276276d6.33.1723131763822; Thu, 08 Aug 2024 08:42:43 -0700 (PDT) Received: from soleen.c.googlers.com.com (118.239.150.34.bc.googleusercontent.com. [34.150.239.118]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb9c7b72d9sm67160936d6.60.2024.08.08.08.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 08:42:42 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, cerasuolodomenico@gmail.com, hannes@cmpxchg.org, j.granados@samsung.com, lizhijian@fujitsu.com, muchun.song@linux.dev, nphamcs@gmail.com, pasha.tatashin@soleen.com, rientjes@google.com, rppt@kernel.org, souravpanda@google.com, vbabka@suse.cz, willy@infradead.org, dan.j.williams@intel.com, yi.zhang@redhat.com, alison.schofield@intel.com, david@redhat.com, yosryahmed@google.com Subject: [PATCH v3 3/4] mm: add system wide stats items category Date: Thu, 8 Aug 2024 15:42:36 +0000 Message-ID: <20240808154237.220029-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240808154237.220029-1-pasha.tatashin@soleen.com> References: <20240808154237.220029-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Stat-Signature: iirmew5opyhrqnn8dxu3kw9jw8jbciwa X-Rspamd-Queue-Id: B030080029 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723131764-104574 X-HE-Meta: U2FsdGVkX1+ehRH4ZZVpOKAeuVpslJF29ZazSPhSAoZ5T6fgQ2ALPIKzGz8znnwyJi4fTT43n+Xn0rtZdWxzXM24xCVS53hSu5Aa5BXQ10B8VcAAqgQVA3+OYnXeMDhkGSl2btOcM5MEcHXp+/xJFnYijodlOtBLPY9HqJdye7geRnMF+JT27v8cGrbbv9yyD3zImCp9yQI2jptBtgqhQ8luoK/xZ1tERxEi5U28/dVw7JlA7zMg/FqYhp3msOz5Qzp+BW0Uqqrcf3e1SNgc1kq5Zd/PtRJ4klADZRX1c9xihKswR1ovE1AaA8DbuhirrlrPhdrveKC/LBJ56ykztzzhtcpxO7b0QcxEtmXIVkSmuECwTfyjTBPckg1q1IDMsjfWOmTDpt/NOpx3B88D5xasPdifRT1ym6xwzcWcXwnKU+eQmtoYaZhRA2TuBP38SZq6G0Zh90dHQksgEdGcbHym50CZ3fyB3Jw5NCzEU2s2u5lCeyPz5zI6mXhLuxIfcWkNDoL1FYp/QHkWtV3ldZlb6xGH1ijFkKQdu5aqa1eOHj/l3GBbV1hw5iVPGW7lao/FnhJd/94ZRWd/D+oaUm3/SWMI0F+YkgRVNrSILt4QIFPy9nyLnzvcyMS3cYgAMRDbQ96YQvC5jU5qjVemFds14nnymLv75gVcDzO+/+vOfGstaWaFoBEFYL/J6nRj8OgRjG9DeMG+TSFTCTETnD08kUCI2W6E6LVs+ltKEILmJY1Xk2SKytceOwUGTRCZtbky01Y9WKuRhjAH6XpOX/LxmDaOjEERdM/Li8n86nryYW6FM7tkKY5dCehW+EzeY5l9HlDU3yeEQeOi8d8j1yUOCvLR98qiDqdr8gVOIiDvoZQ4g42P+2OL22qJd+BBFTcWT5IROJlg3O6Vudui1/oV5WrVD2ZuIZKe92Pfy/FC6r+K3UoJ8QW2q/BxcLA0wCDAPQ5SSz866hL5Nw4 m8NOL0ME PdCQbDLviYd8NTy232QfYcIO/mUFeyuBoRnRQC7siv2qDHMaRlAg6LEH/NDhHGRHtZotLMgeRTn9bGFyajRQNZHrki4Jgw0/+mRxpECC4iaxXNBPys5UC6PR5dKLzvo3TsYhBmV8QWp1W8XzCoexkmOaH99uAVngGwoOywU4WZkGnv3OwyUDivGAgRDHsCH7Epm+LmfhRLiBnmj2DjNF82rVVmaoRJUw7t+PimeGcl3fmmo5RxDyF5KxKCcsPsyxz2qgfuW/kLUDoY+nthI6hDB+BdUpfxbSZDeffx+65vwI/VzTzYD9Wg1Pol2oZQFMIS7iju6PBcZMnH4dEzHbOD7Yirrt/ayh+RA8uIgtero8Aw5M6Cc58VTACLM7yX4RM/+di6yD9awR7RMU= 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/vmstat contains events and stats, events can only grow, but stats can grow and srhink. vmstat has the following: ------------------------- NR_VM_ZONE_STAT_ITEMS: per-zone stats NR_VM_NUMA_EVENT_ITEMS: per-numa events NR_VM_NODE_STAT_ITEMS: per-numa stats NR_VM_WRITEBACK_STAT_ITEMS: system-wide background-writeback and dirty-throttling tresholds. NR_VM_EVENT_ITEMS: system-wide events ------------------------- Rename NR_VM_WRITEBACK_STAT_ITEMS to NR_VM_STAT_ITEMS, to track the system-wide stats, we are going to add per-page metadata stats to this category in the next patch. Also delete unused writeback_stat_name() function. Suggested-by: Yosry Ahmed Signed-off-by: Pasha Tatashin --- include/linux/vmstat.h | 15 ++++----------- mm/vmstat.c | 6 +++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 23cd17942036..9ab4fa5e09b5 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -34,10 +34,11 @@ struct reclaim_stat { unsigned nr_lazyfree_fail; }; -enum writeback_stat_item { +/* Stat data for system wide items */ +enum vm_stat_item { NR_DIRTY_THRESHOLD, NR_DIRTY_BG_THRESHOLD, - NR_VM_WRITEBACK_STAT_ITEMS, + NR_VM_STAT_ITEMS, }; #ifdef CONFIG_VM_EVENT_COUNTERS @@ -514,21 +515,13 @@ static inline const char *lru_list_name(enum lru_list lru) return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_" } -static inline const char *writeback_stat_name(enum writeback_stat_item item) -{ - return vmstat_text[NR_VM_ZONE_STAT_ITEMS + - NR_VM_NUMA_EVENT_ITEMS + - NR_VM_NODE_STAT_ITEMS + - item]; -} - #if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG) static inline const char *vm_event_name(enum vm_event_item item) { return vmstat_text[NR_VM_ZONE_STAT_ITEMS + NR_VM_NUMA_EVENT_ITEMS + NR_VM_NODE_STAT_ITEMS + - NR_VM_WRITEBACK_STAT_ITEMS + + NR_VM_STAT_ITEMS + item]; } #endif /* CONFIG_VM_EVENT_COUNTERS || CONFIG_MEMCG */ diff --git a/mm/vmstat.c b/mm/vmstat.c index 04a1cb6cc636..6f8aa4766f16 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1257,7 +1257,7 @@ const char * const vmstat_text[] = { "pgdemote_khugepaged", "nr_memmap", "nr_memmap_boot", - /* enum writeback_stat_item counters */ + /* system-wide enum vm_stat_item counters */ "nr_dirty_threshold", "nr_dirty_background_threshold", @@ -1790,7 +1790,7 @@ static const struct seq_operations zoneinfo_op = { #define NR_VMSTAT_ITEMS (NR_VM_ZONE_STAT_ITEMS + \ NR_VM_NUMA_EVENT_ITEMS + \ NR_VM_NODE_STAT_ITEMS + \ - NR_VM_WRITEBACK_STAT_ITEMS + \ + NR_VM_STAT_ITEMS + \ (IS_ENABLED(CONFIG_VM_EVENT_COUNTERS) ? \ NR_VM_EVENT_ITEMS : 0)) @@ -1827,7 +1827,7 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos) global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD, v + NR_DIRTY_THRESHOLD); - v += NR_VM_WRITEBACK_STAT_ITEMS; + v += NR_VM_STAT_ITEMS; #ifdef CONFIG_VM_EVENT_COUNTERS all_vm_events(v); From patchwork Thu Aug 8 15:42:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13757859 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 D0BE6C3DA4A for ; Thu, 8 Aug 2024 15:42:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CA796B00FD; Thu, 8 Aug 2024 11:42:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 873AF6B00FE; Thu, 8 Aug 2024 11:42:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A0396B00FF; Thu, 8 Aug 2024 11:42:48 -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 3D3AD6B00FD for ; Thu, 8 Aug 2024 11:42:48 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E9DFB1214A5 for ; Thu, 8 Aug 2024 15:42:47 +0000 (UTC) X-FDA: 82429495974.09.53F2C11 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by imf26.hostedemail.com (Postfix) with ESMTP id 0D786140004 for ; Thu, 8 Aug 2024 15:42:45 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=wMihBT5K; spf=pass (imf26.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.47 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723131700; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wVUhpkOPZqVQX3h1eHDFuE2aZCm6U3+B79UvbkAx6DA=; b=C/AAfwwk5JoI5mG+agVI/LR9GGVa29Vx0ZLz/sCBLzv3rQXCh+ms8GAa30UKJNweBXAwI6 gsp9tuJ0WVhe8/cln1MXAiNf4T1SpPcWPdxfMGESJ6aY92VHrqCKW44ohylzn/01CkScAa YVhFJFtiY0ck9ZzWhgakkiOOWlGZRGQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723131700; a=rsa-sha256; cv=none; b=xuW/ptp88JGs3YN3HxsjH0AbpfAE2uaReoHPT64LdeSLdKPD4qnmMuudFt1eOCGWRevTUH SK0STVo2Ol5SllY4ZXxzoOegsufs1CXyEqyRtZYcZRkIowr/OnqTVisYD3Ao4v49/NxPRt 0txeEVjzyyev5gBjnkO0D/xOyv2EhhA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=wMihBT5K; spf=pass (imf26.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.47 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6b7a4668f1fso6934076d6.3 for ; Thu, 08 Aug 2024 08:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723131765; x=1723736565; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wVUhpkOPZqVQX3h1eHDFuE2aZCm6U3+B79UvbkAx6DA=; b=wMihBT5K4vKRx2qNKC4763OLZfb/UAxpw9hCaqzbJAdqwYU5qgojyB/4zip1k8CBPS gL3paAacLz0rzhCCjWMXqnUxaolPOLkF6B8Sbu/4GVa5wY3SeZdCj7zh2/UiZQehosOu kxqHtvrL1/o0wNXiZRenLoJEhrTe7BuiUjCfAAbtYGv51TnK30opAEeqxKlRfg30Yxv3 nIS828oQm2T+1h+ohvjobnSknSrnNsaxzKc5AeqROQ1xgvlrgtVgX/bDTSfwSm3OCjIH 26i45Hi0nq9ybBPOyDjBQQXl73mpB+1//HGM8DcpgRjSLRe4Hv1cTuURADFOkuPuH0Yx L09g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723131765; x=1723736565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wVUhpkOPZqVQX3h1eHDFuE2aZCm6U3+B79UvbkAx6DA=; b=iMDIiaoleyLBikC79gnYpqymkA576wjYxY0YZQ79SxvGfyXFbkSVftVdjEdOTYze1j PPQo+qWJmnFNgMWq5ua2ImTZhNx3H2rXSolsCPxE9S9mrQbl8iT6oEgSjO9TMqFTq0/F Dfd4lkMGAgyS2B1WRa7uU5/349ifNlO100bxhAOPjgmOK5PL0c9JgVwrcYPgkec+EhN1 slKS4hCjXtlqaTGQg2tUIc3+rE2OV5zc+r6FS1O1J2Wv9TmumzOrWPY8IL6Bto1C9vVh veh3lOKzvx1mFWsDJZHTEG5QHLZT1BLWVyTI+m1cobWvbzrPeVVLljc3cM04pQiyA7YK 5r9A== X-Forwarded-Encrypted: i=1; AJvYcCUg7h2MpsI/2f8cavC0qgkkdcpSjYhqVf6MxcQTe6/VFpq5UjK9zT6H4Mp2BXF+m1XQl9hO3G97QuA3x69+wdcGp8Q= X-Gm-Message-State: AOJu0Yw56GD9TTDsZSWshUE3KrgAqcXJH2ASKU4oJUY85iuW+Q0lNXGF btSpOzN0Xvj4RaGfs7w73DxSHwEVU3C/W6AMAu7/izCVdy52LMxsWNjM1UGltqg= X-Google-Smtp-Source: AGHT+IHuyPvu08+JZDwV+1cdjbraCLK1a/zBKaZNVdpIAi6OHbeRHRlv6moOdjtW9Wgi7xkF2vcdiQ== X-Received: by 2002:a05:6214:2f90:b0:6b9:5b0d:8c9b with SMTP id 6a1803df08f44-6bd6bd53e67mr31343756d6.43.1723131764981; Thu, 08 Aug 2024 08:42:44 -0700 (PDT) Received: from soleen.c.googlers.com.com (118.239.150.34.bc.googleusercontent.com. [34.150.239.118]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb9c7b72d9sm67160936d6.60.2024.08.08.08.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 08:42:44 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, cerasuolodomenico@gmail.com, hannes@cmpxchg.org, j.granados@samsung.com, lizhijian@fujitsu.com, muchun.song@linux.dev, nphamcs@gmail.com, pasha.tatashin@soleen.com, rientjes@google.com, rppt@kernel.org, souravpanda@google.com, vbabka@suse.cz, willy@infradead.org, dan.j.williams@intel.com, yi.zhang@redhat.com, alison.schofield@intel.com, david@redhat.com, yosryahmed@google.com Subject: [PATCH v3 4/4] mm: don't account memmap per-node Date: Thu, 8 Aug 2024 15:42:37 +0000 Message-ID: <20240808154237.220029-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240808154237.220029-1-pasha.tatashin@soleen.com> References: <20240808154237.220029-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Stat-Signature: 5w8symmbnue1ttmruzzkar71z5gjthhw X-Rspamd-Queue-Id: 0D786140004 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723131765-573260 X-HE-Meta: U2FsdGVkX1/DJ26lCcZk/YKj/xnpGbyv+japldmF2x9VhgTXk2sk1YeoxnXSPPrinq79088Z9NdAPiT6fK79YIiQs7fWkdi5KCihJEqhs3+B9cq556bV+ZizSzhyagEA72A/KbVMs0aKeP91pzxKrpsTFMwj9LFpLf8hJMcEie4Z7k1S4nJOUXu0JG9vK5BQy+mg5LMWonb90piGJbdeSFBIcLIjCF99RzRTL8Q5y+Dapraiy/NXmlb7/0x+SOvwBWCEK+5xefcRQnAODuPre16eZ2E/tc0x/l5MgybgSu2/Uo5nAdHxaYfN2EfWQfpmZRwQgL0ZyFWFy2t6M6O8Q/YF8nltRDpSMzS++IZo2Jybv+U38pbdBZJ/aHQOoe3k6Jc/jLFy1yHx/+Lm7Gn+ACZk9UqtNBYkh15+w/Miv7fNfFJw9ryAFLEdKsVJvZXD3JVG680gM8sT3Z/OaIapk0F1t7myLojPxTJ7Wuo6WRjqPL1TItAQRF1VTYmqI9zKLziDopGpQKIHBaFbZr9V2xBEalKv7M/6iE5as9q8QRRNN0fCDJeF9WBf5KkJUq+87qF3TIuXIlkgpVrEkCgzyB165T2w4mJN3Ahcyssf5dIbgwwLqz8guFpR2/Hsf7zUDFJKFVi6H97vl9LTE3qMHi8g2dkSIDCnOtgcjmDD6ZvAeIFwwYAkjreVj/i7AP59LstFGJmp8jURE838NvjZlOb5jN8zyMvLY+mTK8kQJ60/9hrb8hP+knFcCxt1c8INF9rTnbWe3goZePdqQ/MgWMn/XIxJt5fR/w69YOyqEcUrmHu8GiXRw/9BkXXfLbESHJhVH615epS7HkJIVxQDM9FugBLkTtEYgGs8CngbrLae663gtFaBfVIufYbopcrdrRfHso5CvC7FhQiF07jbgsjUeCmV4w3+CMWZKgtqYQkaCS0AHL7mylOxkUkfYFctJ3d2t+AIYVRM0A2BhnH uz/fB6bJ gf4fXV1DSNEOLffFWr0R+st2HOZStjWQUx4dA68RJ1QeTMHLz5IR0gR/LxJQmgrPdHqRLD8F46b8V75YRv9MfP+OkXecA5eBY7zUnA3SiFi8jY8gK+w407DAHIbxpkYGu/xt3/4gopcgf+O1SriVsXkArQy1SAHwry2Ug4YSM6mj2FDEJN/jSzYAw0dmNeYi2EAytspuo0XY9fbnMsW5QZf1mbvovWCvp/Vxw1plCN9PkYv8DvN8ZpNf5UE9Wogn6rw0lEaZ8e5BqCGR4KQyyFjCxmINbl1+puAZUkoIi4vpHzaZ+CtX2lVF1aK5WTRBCgqmVg1e+TbfvU5q8qLqnsKtf+GDXVtV6kHrEu7/iE/meWbk5S6ZWplmSnHw/tA88Cmp8YJqRNh1zROb9ChBcjAPufsQ8T39rSnkxsM+3ssSiwT/CN2KxVWvzmTzqC2t5AcD9fbmEa/Qb4TWUcF/P534T2C5Cp5+4rypUep3sZhU58gak2OXuP2awEA== 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: Currently, when memory is hot-plugged or hot-removed the accounting is done based on the assumption that memmap is allocated from the same node as the hot-plugged/hot-removed memory, which is not always the case. In addition, there are challenges with keeping the node id of the memory that is being remove to the time when memmap accounting is actually performed: since this is done after remove_pfn_range_from_zone(), and also after remove_memory_block_devices(). Meaning that we cannot use pgdat nor walking though memblocks to get the nid. Given all of that, account the memmap overhead system wide instead. For this we are going to be using global atomic counters, but given that memmap size is rarely modified, and normally is only modified either during early boot when there is only one CPU, or under a hotplug global mutex lock, therefore there is no need for per-cpu optimizations. Reported-by: Yi Zhang Closes: https://lore.kernel.org/linux-cxl/CAHj4cs9Ax1=CoJkgBGP_+sNu6-6=6v=_L-ZBZY0bVLD3wUWZQg@mail.gmail.com Reported-by: Alison Schofield Closes: https://lore.kernel.org/linux-mm/Zq0tPd2h6alFz8XF@aschofie-mobl2/#t Fixes: 15995a352474 ("mm: report per-page metadata information") Signed-off-by: Pasha Tatashin --- include/linux/mmzone.h | 2 -- include/linux/vmstat.h | 7 ++++--- mm/hugetlb_vmemmap.c | 8 ++++---- mm/mm_init.c | 3 +-- mm/page_alloc.c | 1 - mm/page_ext.c | 15 +++++--------- mm/sparse-vmemmap.c | 11 ++++------- mm/sparse.c | 5 ++--- mm/vmstat.c | 45 ++++++++++++++++++++---------------------- 9 files changed, 41 insertions(+), 56 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 41458892bc8a..1dc6248feb83 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -220,8 +220,6 @@ enum node_stat_item { PGDEMOTE_KSWAPD, PGDEMOTE_DIRECT, PGDEMOTE_KHUGEPAGED, - NR_MEMMAP, /* page metadata allocated through buddy allocator */ - NR_MEMMAP_BOOT, /* page metadata allocated through boot allocator */ NR_VM_NODE_STAT_ITEMS }; diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 9ab4fa5e09b5..596c050ed492 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -38,6 +38,8 @@ struct reclaim_stat { enum vm_stat_item { NR_DIRTY_THRESHOLD, NR_DIRTY_BG_THRESHOLD, + NR_MEMMAP, /* page metadata allocated through buddy allocator */ + NR_MEMMAP_BOOT, /* page metadata allocated through boot allocator */ NR_VM_STAT_ITEMS, }; @@ -618,7 +620,6 @@ static inline void lruvec_stat_sub_folio(struct folio *folio, lruvec_stat_mod_folio(folio, idx, -folio_nr_pages(folio)); } -void __meminit mod_node_early_perpage_metadata(int nid, long delta); -void __meminit store_early_perpage_metadata(void); - +void mod_memmap_boot(long delta); +void mod_memmap(long delta); #endif /* _LINUX_VMSTAT_H */ diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 70027869d844..60a5faa1f341 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -185,10 +185,10 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, static inline void free_vmemmap_page(struct page *page) { if (PageReserved(page)) { - mod_node_page_state(page_pgdat(page), NR_MEMMAP_BOOT, -1); + mod_memmap_boot(-1); free_bootmem_page(page); } else { - mod_node_page_state(page_pgdat(page), NR_MEMMAP, -1); + mod_memmap(-1); __free_page(page); } } @@ -341,7 +341,7 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, copy_page(page_to_virt(walk.reuse_page), (void *)walk.reuse_addr); list_add(&walk.reuse_page->lru, vmemmap_pages); - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, 1); + mod_memmap(1); } /* @@ -396,7 +396,7 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end, goto out; list_add(&page->lru, list); } - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, nr_pages); + mod_memmap(nr_pages); return 0; out: diff --git a/mm/mm_init.c b/mm/mm_init.c index 75c3bd42799b..29677274e74e 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1623,8 +1623,7 @@ static void __init alloc_node_mem_map(struct pglist_data *pgdat) panic("Failed to allocate %ld bytes for node %d memory map\n", size, pgdat->node_id); pgdat->node_mem_map = map + offset; - mod_node_early_perpage_metadata(pgdat->node_id, - DIV_ROUND_UP(size, PAGE_SIZE)); + mod_memmap_boot(DIV_ROUND_UP(size, PAGE_SIZE)); pr_debug("%s: node %d, pgdat %08lx, node_mem_map %08lx\n", __func__, pgdat->node_id, (unsigned long)pgdat, (unsigned long)pgdat->node_mem_map); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 28f80daf5c04..875d76e8684a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5755,7 +5755,6 @@ void __init setup_per_cpu_pageset(void) for_each_online_pgdat(pgdat) pgdat->per_cpu_nodestats = alloc_percpu(struct per_cpu_nodestat); - store_early_perpage_metadata(); } __meminit void zone_pcp_init(struct zone *zone) diff --git a/mm/page_ext.c b/mm/page_ext.c index 962d45eee1f8..a4b485b39330 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -214,8 +214,7 @@ static int __init alloc_node_page_ext(int nid) return -ENOMEM; NODE_DATA(nid)->node_page_ext = base; total_usage += table_size; - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP_BOOT, - DIV_ROUND_UP(table_size, PAGE_SIZE)); + mod_memmap_boot(DIV_ROUND_UP(table_size, PAGE_SIZE)); return 0; } @@ -275,10 +274,8 @@ static void *__meminit alloc_page_ext(size_t size, int nid) else addr = vzalloc_node(size, nid); - if (addr) { - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, - DIV_ROUND_UP(size, PAGE_SIZE)); - } + if (addr) + mod_memmap(DIV_ROUND_UP(size, PAGE_SIZE)); return addr; } @@ -330,14 +327,12 @@ static void free_page_ext(void *addr) if (is_vmalloc_addr(addr)) { page = vmalloc_to_page(addr); pgdat = page_pgdat(page); - mod_node_page_state(pgdat, NR_MEMMAP, - -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); + mod_memmap(-1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); vfree(addr); } else { page = virt_to_page(addr); pgdat = page_pgdat(page); - mod_node_page_state(pgdat, NR_MEMMAP, - -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); + mod_memmap(-1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); BUG_ON(PageReserved(page)); kmemleak_free(addr); free_pages_exact(addr, table_size); diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 1dda6c53370b..307f6fe83598 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -469,13 +469,10 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn, if (r < 0) return NULL; - if (system_state == SYSTEM_BOOTING) { - mod_node_early_perpage_metadata(nid, DIV_ROUND_UP(end - start, - PAGE_SIZE)); - } else { - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, - DIV_ROUND_UP(end - start, PAGE_SIZE)); - } + if (system_state == SYSTEM_BOOTING) + mod_memmap_boot(DIV_ROUND_UP(end - start, PAGE_SIZE)); + else + mod_memmap(DIV_ROUND_UP(end - start, PAGE_SIZE)); return pfn_to_page(pfn); } diff --git a/mm/sparse.c b/mm/sparse.c index e4b830091d13..9cc80ba1f7c1 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -463,7 +463,7 @@ static void __init sparse_buffer_init(unsigned long size, int nid) sparsemap_buf = memmap_alloc(size, section_map_size(), addr, nid, true); sparsemap_buf_end = sparsemap_buf + size; #ifndef CONFIG_SPARSEMEM_VMEMMAP - mod_node_early_perpage_metadata(nid, DIV_ROUND_UP(size, PAGE_SIZE)); + mod_memmap_boot(DIV_ROUND_UP(size, PAGE_SIZE)); #endif } @@ -643,8 +643,7 @@ static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages, unsigned long start = (unsigned long) pfn_to_page(pfn); unsigned long end = start + nr_pages * sizeof(struct page); - mod_node_page_state(page_pgdat(pfn_to_page(pfn)), NR_MEMMAP, - -1L * (DIV_ROUND_UP(end - start, PAGE_SIZE))); + mod_memmap(-1L * (DIV_ROUND_UP(end - start, PAGE_SIZE))); vmemmap_free(start, end, altmap); } static void free_map_bootmem(struct page *memmap) diff --git a/mm/vmstat.c b/mm/vmstat.c index 6f8aa4766f16..896f9a2ace8a 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1033,6 +1033,23 @@ unsigned long node_page_state(struct pglist_data *pgdat, } #endif +/* + * Count number of pages "struct page" and "struct page_ext" consume. + * nr_memmap_boot: # of pages allocated by boot allocator & not part of MemTotal + * nr_memmap: # of pages that were allocated by buddy allocator + */ +static atomic_long_t nr_memmap_boot, nr_memmap; + +void mod_memmap_boot(long delta) +{ + atomic_long_add(delta, &nr_memmap_boot); +} + +void mod_memmap(long delta) +{ + atomic_long_add(delta, &nr_memmap); +} + #ifdef CONFIG_COMPACTION struct contig_page_info { @@ -1255,11 +1272,11 @@ const char * const vmstat_text[] = { "pgdemote_kswapd", "pgdemote_direct", "pgdemote_khugepaged", - "nr_memmap", - "nr_memmap_boot", /* system-wide enum vm_stat_item counters */ "nr_dirty_threshold", "nr_dirty_background_threshold", + "nr_memmap", + "nr_memmap_boot", #if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG) /* enum vm_event_item counters */ @@ -1827,6 +1844,8 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos) global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD, v + NR_DIRTY_THRESHOLD); + v[NR_MEMMAP_BOOT] = atomic_long_read(&nr_memmap_boot); + v[NR_MEMMAP] = atomic_long_read(&nr_memmap); v += NR_VM_STAT_ITEMS; #ifdef CONFIG_VM_EVENT_COUNTERS @@ -2285,25 +2304,3 @@ static int __init extfrag_debug_init(void) module_init(extfrag_debug_init); #endif - -/* - * Page metadata size (struct page and page_ext) in pages - */ -static unsigned long early_perpage_metadata[MAX_NUMNODES] __meminitdata; - -void __meminit mod_node_early_perpage_metadata(int nid, long delta) -{ - early_perpage_metadata[nid] += delta; -} - -void __meminit store_early_perpage_metadata(void) -{ - int nid; - struct pglist_data *pgdat; - - for_each_online_pgdat(pgdat) { - nid = pgdat->node_id; - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP_BOOT, - early_perpage_metadata[nid]); - } -}