From patchwork Thu Aug 8 21:34: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: 13758209 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AD2D1494CF for ; Thu, 8 Aug 2024 21:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723152882; cv=none; b=W6QqX0YBHHUwfgAD1QmY3tyquuI7OHdQRzzhlRJWu9wMUnZCSypsO8kNCSIHaqDlSQ8EwgTa56iT3iQugvRh1wdYsl2N7BDt4wms1/Uj+ZSXIBT1DZz3/A/mT7j7G1VfThsC/PAWXGEHsYmNPo23JWuz7nrJl7EBYMtRobgr3GQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723152882; c=relaxed/simple; bh=RJOegQUHcv+I33+qU7btWGqlaiXtgvR83VFZU3SBof8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FgypjC9ohqNMiKsUJkMwrwvdqgGne8VlhWJ28zR/8bJowYKoIKrgsSCyv0QsG1caaxtB05XpQ20/3nOqFYuJTQHDpZFd6xSdj88cG14qCYcZeue4FpS4xWfvkkmqgysPvcUC1PW3yzaOT92UouAaB+jv+Q7R62QHxfxKvPvCmDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=cnCtS0Zm; arc=none smtp.client-ip=209.85.219.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="cnCtS0Zm" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6b7a3b75133so8968906d6.2 for ; Thu, 08 Aug 2024 14:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723152880; x=1723757680; darn=vger.kernel.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=2Zfyh9sb1bnT5AOZDmCrIADGqpbj2HcF73SygbadHf0=; b=cnCtS0ZmTiSzbgaSkNEWrOvGHnFxDvqWb1z6xsgziztfOAHoaKJHUH8X9N3Q5nLBB5 w5eS9IFhV/llUsmPlDfq4yq/o2qTccRklbsfMOt38/B0/SCNVEfne8YwIIua4OTnpWM+ d7XjnW/t2ncjwyugvoc8AXJ3OkJzBe/4RPNlT92htq+BgHri5nMSNlqBmf9mL7JftlOH nCkrM63w4qbqD5Ra9XObHc7by7wnGTU41XQVM/TvzcNriZWQksPc57+AxNaHCHpA+Gbx KjczxmiUa5waHNYeZTcoz+BQDQnL+44o9yDFBU2RPgK8Dgi1OrIK8K7wRGzEduzySAKV z/iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723152880; x=1723757680; 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=2Zfyh9sb1bnT5AOZDmCrIADGqpbj2HcF73SygbadHf0=; b=MKNQ6TlEGNn9Slq2ySUuX2pqJA+WWU5qXHUVBLLws/O8yfSo1pVWZEBSRVkMme161a haO7zqu0iAXYW5dOJZYT5SepxT5+ZSOtPwjg2OKydYpafQc8/NJNjxrU1xfDPAzZJdmT PnnXeEorzbeVJ6MN8VeMPbAwN2105XdhqOsvf6pIhNkRVH/tk88RrF6AjtTNOUB+WJbm pHE2X5T9wdLM9Tja///KcfiuGWMZ1A6r73ZSvAgKu4RmzQhqUl+i3fRvfIq0UgHl3H1t WexkVj89PTJ9Z9GxLlt8OMkfLNlL9AoDDiN6efYwShFvVPKvJxKCxVKyEQF0l8GvodCA 2KpA== X-Forwarded-Encrypted: i=1; AJvYcCVLT9b5SoGZ1LL48ziEfR1nU4yL+iRc2a3mkEJEqELg73AtZ1Xwhs16tJyZVif7t5O4OqN6YydnByByXYKKyIU4ZHXhEER0LOKZ X-Gm-Message-State: AOJu0YyC/H3x6VkMLDiO3ZcWilvS3U7j/8/ercBC1eBVGqVKy1v5BzjM TuVvCgbc61MJfugY5l0iJu1mNmAvtdDORHsBZBaV/n7KmgUgG/471btsJiO/4UU= X-Google-Smtp-Source: AGHT+IEYrhxVpzTUFHMNv2JCMahxEtnVaIB4zBU/Fd+nkSIIYgPtSTnsyB+XCR6jRJ7P++5L69WPeQ== X-Received: by 2002:a05:6214:2b99:b0:6b7:a87b:e9b9 with SMTP id 6a1803df08f44-6bd6bda461fmr32485766d6.48.1723152880168; Thu, 08 Aug 2024 14:34:40 -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-6bb9c762bd1sm70205026d6.29.2024.08.08.14.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 14:34:39 -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 v4 1/3] mm: don't account memmap on failure Date: Thu, 8 Aug 2024 21:34:34 +0000 Message-ID: <20240808213437.682006-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240808213437.682006-1-pasha.tatashin@soleen.com> References: <20240808213437.682006-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When we fail to allocate the mmemmap in alloc_vmemmap_page_list(), do not account any already-allocated pages: we're going to free all them before we return from the function. Fixes: 15995a352474 ("mm: report per-page metadata information") Signed-off-by: Pasha Tatashin Reviewed-by: Fan Ni Reviewed-by: Yosry Ahmed 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 829112b0a914..4f51e0596197 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 21:34: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: 13758211 Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4175C13BACC for ; Thu, 8 Aug 2024 21:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723152885; cv=none; b=FBmLGL2vmU5selBY5CT+Ka+P5YG3TVeucc7o/X27vL2uegnFXXRRcCqHbaQ29DyDuEu04lKVpf5CO1l40hZtwbqCCrwriCCdLMTe8ukKh4W7C3ek/GJe7CU7jUxDMKbr/KDh6GWIbgWIfCQUSDxUQ/WYdYd96ttZctY3UQdB3YM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723152885; c=relaxed/simple; bh=LPymHoA6qtomFJj9prs4W/8rrsULUAMfwn30gfK801o=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSeh0dridhqVFde65CGaKHBqOkfeG+g4graJEa89slbKOZ2ZOxNk5T/gHoITjiV7z/EnVgwntN8LwN/ckbPlO+MkfEaJ/IFspmfCOSOZlWZY0NWqsXrgr71ZYoBSbTXxXd7XQm74bUXLCbFloXfnHTP0eZk0w5IopTqLDSo0kos= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=R659dDfm; arc=none smtp.client-ip=209.85.222.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="R659dDfm" Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-831a5b7d250so494212241.3 for ; Thu, 08 Aug 2024 14:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723152881; x=1723757681; darn=vger.kernel.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=+YmoLJUzKwh05YDZkUnFH4Q03LnbmDmhfqr83K75cyk=; b=R659dDfmPHqrWs0s7iDXfuSm+V9j/3GmFB5pzAoEjBSgAV6VHaigwehiQ2lbpnU7UZ biS0xUioOK8jJq0a7QDiUz8N5LNdHECjYX+1RO6agHi/uvQwMutK4TPsO9pA1zWCwdNH 14eI2AcLYWHYIQIWSicK/Ehra8cgJjACZS/imhFcNPhYhD2sWPVK2oxDCTg4U+emvVKw /rQ82Gw6vOlTvWs5FCnuQz183HaoTUAHWn1L2bNqVGp9zPFSBS6Xz3ibmQE4WDnX18OG 70tSDrhG0qiZEU1J28Cye9drvsqtljLW5nojdEAQLgNAgYYuSjAy7CpjTa0iiD1IUkvI hIWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723152881; x=1723757681; 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=+YmoLJUzKwh05YDZkUnFH4Q03LnbmDmhfqr83K75cyk=; b=l7SeBLiJtreKDt3sG50LnQneNwxP6OM+cpN3x8ysfE422o7ddA/K+Q/LBBuTMK5hiV YWI/XVwFbUFAlPr3/D6yZwpScHoDzv9YpVbEGFVQml2pR6Maf8d87AdIEQcxrdGqvsAr ELBX0Bt88fpJ7F+NEzTRTtUm1Dq6gbU/+lodGghUW32Bs425FRWbldNQWPxxMR+Rewci qHtNOhiwZDb6HiKMW+z+q9WOiCjWWGweyNo/gftQ6kcgo5B/sGyJ/XsWOSVcp07aXhUa H/lqIcLWUJ0wO38R/yH9FcDc0o9bm8Ue7q1geVXxlCwPjBhZz1ddN+bnT80OTBZuTVoq iDEQ== X-Forwarded-Encrypted: i=1; AJvYcCVZjgnlZTgM23RQOP5XwBTRCG6tJBUFGFkfPAdjjZ82dG2BrLHbaDTj50uSgy+IuRtjvI+4YI98guI4jqsHtjb3X1q/Jq2L4tA3 X-Gm-Message-State: AOJu0Yy54pNAR7DBEXnTxLJknEwq6uUXDlVH+AfItUNqGbzpkG5mRC7n 1LKRVuhpuKxqm3lP49qpZ7ommwAvaZ6R+fUSOwFalKXPEY2F36FJrSRjOmKhivk= X-Google-Smtp-Source: AGHT+IE4Qv1sn/qov17GIXusF8ykKagazq0LzzEpnGG7EXiIsWLtpNSrGNRu3rLDOXEBkRSnwDDAyA== X-Received: by 2002:a05:6102:2acb:b0:492:ab05:8d6e with SMTP id ada2fe7eead31-495c5b38e89mr3764112137.3.1723152880951; Thu, 08 Aug 2024 14:34:40 -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-6bb9c762bd1sm70205026d6.29.2024.08.08.14.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 14:34: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 v4 2/3] mm: add system wide stats items category Date: Thu, 8 Aug 2024 21:34:35 +0000 Message-ID: <20240808213437.682006-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240808213437.682006-1-pasha.tatashin@soleen.com> References: <20240808213437.682006-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 /proc/vmstat contains events and stats, events can only grow, but stats can grow and shrink. 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 Acked-by: David Hildenbrand --- 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 21:34: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: 13758210 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 578171474A2 for ; Thu, 8 Aug 2024 21:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723152885; cv=none; b=fZBMW/SLZBMVPi2pCb48+rqrSufRjRV9TiRqSfGoJ+0+dWmZNYLGX2VV6vY6eOS7CuyHGrmcG9mGvjSZ4A4H+8sPJ+7ymMZyDkXpISIl53f/ElZBuz5amAORKWpLthx4VldG3t009G6vyn+QG+Y1CThF/bzTGglYWDqmx30ld70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723152885; c=relaxed/simple; bh=X4oPsEgbStyOQlGPDzpddY9mdkuyWhoRbtbcyQSgws4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MdQmELZU5bhGjZ/S5JDbMFiExahe9JFmM1BSW65x45Cy3JjMNAQbJXkXP2UiSHAG3lx1KSj6eKJ9rSInlzoyCbAN3507mu/eTUfHgWuHsUZq0w3Dswyrp1D6VqH7kJhrPwWXmUudMnS6fHt9buqA8z8dygSUoNRCrSBoTj10ccI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=Vbzzo964; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="Vbzzo964" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6b78c980981so7993586d6.2 for ; Thu, 08 Aug 2024 14:34:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723152882; x=1723757682; darn=vger.kernel.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=kWOlhfAfce+9LYenfYKmrvC1/DBShQ3awKUGjH/tW0o=; b=Vbzzo964q7Upkc3fuEubOr7wXeMTqUZ/mvPp8Wj9WeWjwv2UeeWtekde4zTpt2IlMN WKzauK7YyCyE+B3kKGybJkqIIQ6DoMN6F6vbzhqagjxLcbnSgtl3JfLNKYINNOX66LwQ Ln3A0OvHjqQYvfEs8QJj4x9uaCZlN7xAfi2oqiJecoSt09LMAKMxHpYVSntal/WTwoHc 9Lts1ouXpeFzHXzXlqmNBpKURZzYpHh4HTHMa/PRlx63EToECwEkh02LuS8wh8HEQzba LWoxgq9tcI+uFZDCPEt8v4MeCxHH/FC70tnqjYAPoNgGLsEVkM1Q3xiKB0qDYUwm2Z7k Cgyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723152882; x=1723757682; 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=kWOlhfAfce+9LYenfYKmrvC1/DBShQ3awKUGjH/tW0o=; b=c2p+iOA+hxC5EgKR77hWCMoiWM+aGO3n8KD9ak4dIDOppCemYnBromGLWlW0lXethY vKZoL6BwLYe9UWzYkuG58U7oqlXNta4zSQKJHj+grbNEw+PuWy9rMeh5IuHlyjcRJb3V NLmF7UNpOkmhHhXSFz/0MBYIqvcQi9I8L81Y60uVqqGTKc0BTuTkF/QaA3pNwJgWsZMA nhm06OHSAI2H701M/dXVksMwFe7UfinpQB/a83ME8YbaOz+7H4kIpBk/hMpvPd8cvwJH 4elcdHcFn6EJdYQIZbELu3KJgPtyKyidBIRv8B/yQavOtvfnFofuu1GPMU4qRLSTbgwh 24gw== X-Forwarded-Encrypted: i=1; AJvYcCXQkUgPx9rSQ1xLcaphwDuMIN5NGq/viod/5i+sEqIzj0/7Ovc7Zux7Js1behgOjCgT2aplW4jurp1L/9eC8+SJJdGNbKEBGnnC X-Gm-Message-State: AOJu0YxxI1qWwTsvZVAe/v/OE4xnBCxUL80Cazb9ctQlZ4D9PEL26soa VZpr6HOorOmA+55SRqvkOSC971bd8y6S1dExbeORHNo/T/FPHAnNHcWYJgy2W/s= X-Google-Smtp-Source: AGHT+IFiuKAoaUv/Ru7WO2pjfXBkX2yVU/zNkZyXTPPVKMhOqrJp0xprvwJzwpRKdYdERrxf3hNSpg== X-Received: by 2002:a05:6214:2f05:b0:6b5:e60c:76dc with SMTP id 6a1803df08f44-6bd6bce96famr48503556d6.19.1723152882071; Thu, 08 Aug 2024 14:34: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-6bb9c762bd1sm70205026d6.29.2024.08.08.14.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 14:34: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 v4 3/3] mm: don't account memmap per-node Date: Thu, 8 Aug 2024 21:34:36 +0000 Message-ID: <20240808213437.682006-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240808213437.682006-1-pasha.tatashin@soleen.com> References: <20240808213437.682006-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix invalid access to pgdat during hot-remove operation: ndctl users reported a GPF when trying to destroy a namespace: $ ndctl destroy-namespace all -r all -f Segmentation fault dmesg: Oops: general protection fault, probably for non-canonical address 0xdffffc0000005650: 0000 [#1] PREEMPT SMP KASAN PTI KASAN: probably user-memory-access in range [0x000000000002b280-0x000000000002b287] CPU: 26 UID: 0 PID: 1868 Comm: ndctl Not tainted 6.11.0-rc1 #1 Hardware name: Dell Inc. PowerEdge R640/08HT8T, BIOS 2.20.1 09/13/2023 RIP: 0010:mod_node_page_state+0x2a/0x110 cxl-test users report a GPF when trying to unload the test module: $ modrpobe -r cxl-test dmesg BUG: unable to handle page fault for address: 0000000000004200 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: Oops: 0000 [#1] PREEMPT SMP PTI CPU: 0 UID: 0 PID: 1076 Comm: modprobe Tainted: G O N 6.11.0-rc1 #197 Tainted: [O]=OOT_MODULE, [N]=TEST Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/15 RIP: 0010:mod_node_page_state+0x6/0x90 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. Also, while we are here rename nr_memmap to nr_memmap_pages, and nr_memmap_boot to nr_memmap_boot_pages to be self explanatory that the units are in page count. 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 Tested-by: Dan Williams Acked-by: David Hildenbrand --- 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 | 18 ++++------------- mm/sparse-vmemmap.c | 11 ++++------- mm/sparse.c | 5 ++--- mm/vmstat.c | 45 ++++++++++++++++++++---------------------- 9 files changed, 40 insertions(+), 60 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 4f51e0596197..60a5faa1f341 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)) { + mod_memmap_boot(-1); free_bootmem_page(page); - mod_node_page_state(page_pgdat(page), NR_MEMMAP_BOOT, -1); } else { + mod_memmap(-1); __free_page(page); - mod_node_page_state(page_pgdat(page), NR_MEMMAP, -1); } } @@ -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 c191e490c401..c9419f6abfa0 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; } @@ -323,25 +320,18 @@ static void free_page_ext(void *addr) { size_t table_size; struct page *page; - struct pglist_data *pgdat; table_size = page_ext_size * PAGES_PER_SECTION; + mod_memmap(-1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); if (is_vmalloc_addr(addr)) { - page = vmalloc_to_page(addr); - pgdat = page_pgdat(page); vfree(addr); } else { page = virt_to_page(addr); - pgdat = page_pgdat(page); 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) 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..ad82c1bf0e63 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_pages", + "nr_memmap_boot_pages", #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]); - } -}