From patchwork Tue Jun 14 12:02:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 12880959 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 A52F1C43334 for ; Tue, 14 Jun 2022 12:02:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1A2B8D023C; Tue, 14 Jun 2022 08:02:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D980A8D023F; Tue, 14 Jun 2022 08:02:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAB3D8D023C; Tue, 14 Jun 2022 08:02:40 -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 952F28D023D for ; Tue, 14 Jun 2022 08:02:40 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 49C96121705 for ; Tue, 14 Jun 2022 12:02:40 +0000 (UTC) X-FDA: 79576704480.02.6EC3344 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf18.hostedemail.com (Postfix) with ESMTP id 49B251C0086 for ; Tue, 14 Jun 2022 12:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655208157; x=1686744157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GFpQ+/mE/sWJAfnOObzg9+iqOuEtZS5nHGCJB+ROj7k=; b=LGLx92gl00T7oEKRYLDoL/2ZNKfBLRtj0zh33ICgXtbgH80EnCZCT0rs 8NJsuyXTagT0m9V7I6KJoCJZtEB/JJW22gt4/87vf5hnT3F/7yHvdGc2a l+9f+5oHcdtURNjBwT3LTN98fEt3wGvmF7bJ/j+F4PqZxvc9/dDLhaOZK NBMXJCzFaMQxwIZDWiEwf24o+FrlXZUlQojvE74+NiFvDo2eji3HBijjl St/kthJqXAfsfCO0wXYWLKRsYgBv+VPtT5cUi93v7HxZLnZh+9AETV+ZV DmfZvx9nE5o+VAS8FgCNqQolFzMATmqfofAzsqxmsgcfU0XN6lAz4XH8J A==; X-IronPort-AV: E=McAfee;i="6400,9594,10377"; a="279633978" X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="279633978" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 05:02:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="588429901" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 14 Jun 2022 05:02:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 94DE65D3; Tue, 14 Jun 2022 15:02:32 +0300 (EEST) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , Dave Hansen , Mike Rapoport , David Hildenbrand , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv7 03/14] mm: Report unaccepted memory in meminfo Date: Tue, 14 Jun 2022 15:02:20 +0300 Message-Id: <20220614120231.48165-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655208158; a=rsa-sha256; cv=none; b=q/OesI112cfptFdJ4vWSrA7yKAI9zhLV7BTEzNHSiwCvGULszsPnZ11RjrYeZlJP0ID76S XreEXFC5qphbE6lAKk/oKQvwiknpzg0A/1ssuV5/qW/5U+cB4/IUGgR25m5kCt0j160xyM fxTfXkBXahELXzn1orWrnqa8jw92evY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655208158; 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:in-reply-to:references:references:dkim-signature; bh=jL0eKVxAHX2MUtENKfniSWI5GFyZiu7u+0Ge5XWVgqM=; b=3nMhzslknQ6nQ74Lm8jVUWi1QdgfBfs1+ciP5AXB3SNzwaXaPGyTpXLiZuNUpD3rCE1YYM Pqsenysf3sffpqDjqYtxcNxCMKR/c/9MYusWwv6ZeYVseoZx+TGNLusGSYWUS3USdeEX0S WBaW8b7nLOAtFH37q6pFJSH8xC6Efy8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LGLx92gl; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf18.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=kirill.shutemov@linux.intel.com Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LGLx92gl; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf18.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=kirill.shutemov@linux.intel.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 49B251C0086 X-Stat-Signature: cqcetu6jfffsmxcpcegus8nyd79srr8j X-HE-Tag: 1655208156-160255 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: Track amount of unaccepted memory and report it in /proc/meminfo and in node meminfo. Signed-off-by: Kirill A. Shutemov --- drivers/base/node.c | 7 +++++++ fs/proc/meminfo.c | 5 +++++ include/linux/mmzone.h | 1 + mm/page_alloc.c | 9 ++++++++- mm/vmstat.c | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 0ac6376ef7a1..fc7cf4d91eb6 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -446,6 +446,9 @@ static ssize_t node_read_meminfo(struct device *dev, "Node %d ShmemPmdMapped: %8lu kB\n" "Node %d FileHugePages: %8lu kB\n" "Node %d FilePmdMapped: %8lu kB\n" +#endif +#ifdef CONFIG_UNACCEPTED_MEMORY + "Node %d UnacceptedPages: %8lu kB\n" #endif , nid, K(node_page_state(pgdat, NR_FILE_DIRTY)), @@ -474,6 +477,10 @@ static ssize_t node_read_meminfo(struct device *dev, nid, K(node_page_state(pgdat, NR_SHMEM_PMDMAPPED)), nid, K(node_page_state(pgdat, NR_FILE_THPS)), nid, K(node_page_state(pgdat, NR_FILE_PMDMAPPED)) +#endif +#ifdef CONFIG_UNACCEPTED_MEMORY + , + nid, K(node_page_state(pgdat, NR_UNACCEPTED)) #endif ); len += hugetlb_report_node_meminfo(buf, len, nid); diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 6e89f0e2fd20..796544e50365 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -153,6 +153,11 @@ static int meminfo_proc_show(struct seq_file *m, void *v) global_zone_page_state(NR_FREE_CMA_PAGES)); #endif +#ifdef CONFIG_UNACCEPTED_MEMORY + show_val_kb(m, "UnacceptedPages:", + global_node_page_state(NR_UNACCEPTED)); +#endif + hugetlb_report_meminfo(m); arch_report_meminfo(m); diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index aab70355d64f..aa08cd7eaaf5 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -212,6 +212,7 @@ enum node_stat_item { NR_FOLL_PIN_ACQUIRED, /* via: pin_user_page(), gup flag: FOLL_PIN */ NR_FOLL_PIN_RELEASED, /* pages returned via unpin_user_page() */ NR_KERNEL_STACK_KB, /* measured in KiB */ + NR_UNACCEPTED, #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK) NR_KERNEL_SCS_KB, /* measured in KiB */ #endif diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 279c2746aaa8..6316d695a567 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1012,6 +1012,7 @@ static void accept_page(struct page *page, unsigned int order) accept_memory(start, start + (PAGE_SIZE << order)); __ClearPageUnaccepted(page); + mod_node_page_state(page_pgdat(page), NR_UNACCEPTED, -(1 << order)); /* Assert that there is no PageUnaccepted() on tail pages */ if (IS_ENABLED(CONFIG_DEBUG_VM)) { @@ -1063,6 +1064,7 @@ static inline void __free_one_page(struct page *page, struct page *buddy; bool to_tail; bool page_needs_acceptance = false; + int nr_unaccepted = 0; VM_BUG_ON(!zone_is_initialized(zone)); VM_BUG_ON_PAGE(page->flags & PAGE_FLAGS_CHECK_AT_PREP, page); @@ -1076,6 +1078,7 @@ static inline void __free_one_page(struct page *page, if (PageUnaccepted(page)) { page_needs_acceptance = true; + nr_unaccepted += 1 << order; __ClearPageUnaccepted(page); } @@ -1117,6 +1120,7 @@ static inline void __free_one_page(struct page *page, /* Mark page unaccepted if any of merged pages were unaccepted */ if (PageUnaccepted(buddy)) { page_needs_acceptance = true; + nr_unaccepted += 1 << order; __ClearPageUnaccepted(buddy); } @@ -1143,8 +1147,11 @@ static inline void __free_one_page(struct page *page, */ if (!page_needs_acceptance && (fpi_flags & FPI_UNACCEPTED_SLOWPATH)) page_needs_acceptance = page_contains_unaccepted(page, order); - if (page_needs_acceptance) + if (page_needs_acceptance) { __SetPageUnaccepted(page); + __mod_node_page_state(page_pgdat(page), NR_UNACCEPTED, + (1 << order) - nr_unaccepted); + } if (fpi_flags & FPI_TO_TAIL) to_tail = true; diff --git a/mm/vmstat.c b/mm/vmstat.c index 373d2730fcf2..4e12d22f1e04 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1236,6 +1236,7 @@ const char * const vmstat_text[] = { "nr_foll_pin_acquired", "nr_foll_pin_released", "nr_kernel_stack", + "nr_unaccepted", #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK) "nr_shadow_call_stack", #endif