From patchwork Sat Oct 5 20:01:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13823462 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 F4106CFB42B for ; Sat, 5 Oct 2024 20:01:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A9436B0324; Sat, 5 Oct 2024 16:01:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 707A46B0325; Sat, 5 Oct 2024 16:01:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CF5D6B0326; Sat, 5 Oct 2024 16:01:41 -0400 (EDT) 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 269776B0324 for ; Sat, 5 Oct 2024 16:01:41 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 40A6F140AF3 for ; Sat, 5 Oct 2024 20:01:37 +0000 (UTC) X-FDA: 82640618634.04.97A0558 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 92F99A0019 for ; Sat, 5 Oct 2024 20:01:35 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=mQz8xSsV; dmarc=none; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728158398; a=rsa-sha256; cv=none; b=085V5J2PbCN+N5Jgjo4B6aygQiaVoeaLvBcFYIvUiwPK5+mATVoQ+/YwtHnkrkwCYT7dhk qo8Sz2PuiVLhXzW+XgZhJwmBmKx3K9IDmrxQybsTtVKPmvwZvCDDTbYag82Sj8IDSVUIlo 38ji9KfjHxJErMVS7iDQQF+Sole1Iuo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=mQz8xSsV; dmarc=none; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728158398; 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=qAUhcutSpNzHMfGoUnNFYBLH5l/c9SO2zzfu+lWTDuI=; b=ShxRE6mymBR3SGXzMJ5p6AedHv/Wr9bHNtQCBIrsq7mmePwR08fj12isazrkGuREAhuROh MCWeTUyHPsrlZLw8GcJWWmDNrDLrq7VZHL4i5NmsD5CMbOl3Xx1DmMeE97nPZ7Byd4TKdz VkwdSQ7oRxzgoJekQXH9+KUcvFadJG0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=qAUhcutSpNzHMfGoUnNFYBLH5l/c9SO2zzfu+lWTDuI=; b=mQz8xSsVKTGmDN7cUKnCM65RcM xCth5Gw4chwTaQnL1tN1MQlskHo0Tzjf19bo3kgnSbTbhGDTDhuqWt07EGG8UdK3RzLHD+b8Opp0U iJjWeBb3wZXyeBY5N7ZGuJP/SykUcl1qsggE/3uj10DH6xe9QIMP7bk3upA3qeWeZrBfoqWDqA+pn 4kHHrlnnJTHiaAufNnGqXhcNqXRTzvrq6yJdQsNTo2pw8oUKH2ZinwWPMHMpni3XnhmJSkBloPbCt brjRVz7z7qfsauX4igBstgSGPxCkoREYddmAFFPzDwGWclHou50OI0hjAQjChg+XUyuYbZks7zhc4 StN4zcxA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sxAxw-0000000DYZk-41HX; Sat, 05 Oct 2024 20:01:24 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 5/7] bootmem: Stop using page->index Date: Sat, 5 Oct 2024 21:01:16 +0100 Message-ID: <20241005200121.3231142-6-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241005200121.3231142-1-willy@infradead.org> References: <20241005200121.3231142-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 92F99A0019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: pk9m6nrfwm5bhaeta9p4qu4srojrop87 X-HE-Tag: 1728158495-994419 X-HE-Meta: U2FsdGVkX19ZRXmAmCwSHyygF/wgfgTlrEP6fBXJoK4kOoH4IOunuj7oh23tT6V+uU+Mr4AEgz82homB8Y/uheeZf/tVLfOIFNtzsaYU7uWS/ISe53R+2Rx8YHCG6ROpt0fNsBmEyJ8p0pbwqo07W74vF+DZNdEGVR/LePIB4I4mziHRkd5R6OfNuxKg6Td/uHGFVpW9eZJg2eVljzziIZtQ0lI268Ba48FJ9C9fZDn0niYJU7FVATacn3803vN/lyfte/Ip6k1qX94n6mCdBdYvv6C2f8TSb56rWE+I1ICOR8vaM2FoTgYpmCZsPGEU3ilYlpt0bKFPHQcvCxBE46aAyt8vJ8SgUtA45FBWPH19oRYf+o71L/CIAJY3XZp+dLs89OpIFiwQMDV0BiK0Wi7f2EbWOnSTVX9D87aO6OeJRF5xQLnV0+0klmiKz3r9Jw12T+/d0twvwg1pRRC35Lq1v21pA46Eo/7LcqXGqpINNjBF8I+HQ2AedthUlJxmsy9942d1yjzCAI0tCYbFQbcp3rPKQi8aFPCXUey32wq15xwvAb79qJe2Z85DY3D0WMizoOHtSwErclWhuwlccZn7vsZgrWSdnuuDCD+nD/7yxJwNVLVl6DRC7sy27ESm/78XyEx/AHlfJqbTTql0UDl/b95CPN7PFOlrhXg5ApGJ4qn5KgRZ4ESzwWshq7qn5WgQpjmtmSnaW0m8G+KLbQxrjA3TPO+IxV5zCXDNthuClHUaBgICako3VRS1JE90ZFs5kP3kM28SP/HdbkH76EhICAKf2V5JCnxp9hkSbiLSF/vuNQe0OmW2UC2/4/YWuMMS6ok66KIlW6Rvjxy49cMfjpGQxed1gifYA1bbj2jh4mClsEd5QcUl8pHsqd57GiOZAeCuYRgz1d7PLwHFc6HV9ZLE0D5ySe+xfMM6dQQy4mwTqx1QxJQ9PQ7sjvbrbThomfHiWHbssGkO8Vd l3gYJspo AKt8pwU0WUfT2XWTn9zT8rgBjYQ/rvi3FgRh3D39/rwV6FHvdn+mTKNJOR6gmPk5Yy0qg3S8qWEo3VOphDmuDeHJe/9+vEu4eFwW8htyGYewCokpx0UlZ6oWe5Kyg2M39ZAFmIYWFbweZA/i5Qgm/E/X3JHPrMCGfzKZSelIrky+Id/hG1+UF7RGsYxqjS7QHPfPhv+BdvPZ6er7IFbSt5ZEFkWphw7sdGVZ9Ez8FRLYat20= 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: Encode the type into the bottom four bits of page->private and the info into the remaining bits. Also turn the bootmem type into a named enum. Signed-off-by: Matthew Wilcox (Oracle) Reported-by: kernel test robot Signed-off-by: Andrew Morton --- arch/x86/mm/init_64.c | 9 ++++----- include/linux/bootmem_info.h | 25 +++++++++++++++++-------- mm/bootmem_info.c | 11 ++++++----- mm/sparse.c | 8 ++++---- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index ff253648706f..4d5fde324136 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -987,13 +987,12 @@ int arch_add_memory(int nid, u64 start, u64 size, static void __meminit free_pagetable(struct page *page, int order) { - unsigned long magic; - unsigned int nr_pages = 1 << order; - /* bootmem page has reserved flag */ if (PageReserved(page)) { - magic = page->index; - if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) { + enum bootmem_type type = bootmem_type(page); + unsigned long nr_pages = 1 << order; + + if (type == SECTION_INFO || type == MIX_SECTION_INFO) { while (nr_pages--) put_page_bootmem(page++); } else diff --git a/include/linux/bootmem_info.h b/include/linux/bootmem_info.h index cffa38a73618..e2fe5de93dcc 100644 --- a/include/linux/bootmem_info.h +++ b/include/linux/bootmem_info.h @@ -6,11 +6,10 @@ #include /* - * Types for free bootmem stored in page->lru.next. These have to be in - * some random range in unsigned long space for debugging purposes. + * Types for free bootmem stored in the low bits of page->private. */ -enum { - MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 12, +enum bootmem_type { + MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 1, SECTION_INFO = MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE, MIX_SECTION_INFO, NODE_INFO, @@ -21,9 +20,19 @@ enum { void __init register_page_bootmem_info_node(struct pglist_data *pgdat); void get_page_bootmem(unsigned long info, struct page *page, - unsigned long type); + enum bootmem_type type); void put_page_bootmem(struct page *page); +static inline enum bootmem_type bootmem_type(const struct page *page) +{ + return (unsigned long)page->private & 0xf; +} + +static inline unsigned long bootmem_info(const struct page *page) +{ + return (unsigned long)page->private >> 4; +} + /* * Any memory allocated via the memblock allocator and not via the * buddy will be marked reserved already in the memmap. For those @@ -31,7 +40,7 @@ void put_page_bootmem(struct page *page); */ static inline void free_bootmem_page(struct page *page) { - unsigned long magic = page->index; + enum bootmem_type type = bootmem_type(page); /* * The reserve_bootmem_region sets the reserved flag on bootmem @@ -39,7 +48,7 @@ static inline void free_bootmem_page(struct page *page) */ VM_BUG_ON_PAGE(page_ref_count(page) != 2, page); - if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) + if (type == SECTION_INFO || type == MIX_SECTION_INFO) put_page_bootmem(page); else VM_BUG_ON_PAGE(1, page); @@ -54,7 +63,7 @@ static inline void put_page_bootmem(struct page *page) } static inline void get_page_bootmem(unsigned long info, struct page *page, - unsigned long type) + enum bootmem_type type) { } diff --git a/mm/bootmem_info.c b/mm/bootmem_info.c index fa7cb0c87c03..95f288169a38 100644 --- a/mm/bootmem_info.c +++ b/mm/bootmem_info.c @@ -14,23 +14,24 @@ #include #include -void get_page_bootmem(unsigned long info, struct page *page, unsigned long type) +void get_page_bootmem(unsigned long info, struct page *page, + enum bootmem_type type) { - page->index = type; + BUG_ON(type > 0xf); + BUG_ON(info > (ULONG_MAX >> 4)); SetPagePrivate(page); - set_page_private(page, info); + set_page_private(page, info << 4 | type); page_ref_inc(page); } void put_page_bootmem(struct page *page) { - unsigned long type = page->index; + enum bootmem_type type = bootmem_type(page); BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE || type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE); if (page_ref_dec_return(page) == 1) { - page->index = 0; ClearPagePrivate(page); set_page_private(page, 0); INIT_LIST_HEAD(&page->lru); diff --git a/mm/sparse.c b/mm/sparse.c index dc38539f8560..6ba5354cf2e1 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -720,19 +720,19 @@ static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages, static void free_map_bootmem(struct page *memmap) { unsigned long maps_section_nr, removing_section_nr, i; - unsigned long magic, nr_pages; + unsigned long type, nr_pages; struct page *page = virt_to_page(memmap); nr_pages = PAGE_ALIGN(PAGES_PER_SECTION * sizeof(struct page)) >> PAGE_SHIFT; for (i = 0; i < nr_pages; i++, page++) { - magic = page->index; + type = bootmem_type(page); - BUG_ON(magic == NODE_INFO); + BUG_ON(type == NODE_INFO); maps_section_nr = pfn_to_section_nr(page_to_pfn(page)); - removing_section_nr = page_private(page); + removing_section_nr = bootmem_info(page); /* * When this function is called, the removing section is