From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96A53C11F66 for ; Wed, 14 Jul 2021 12:37:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 39275613B7 for ; Wed, 14 Jul 2021 12:37:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39275613B7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 617966B008C; Wed, 14 Jul 2021 08:37:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C74E6B0092; Wed, 14 Jul 2021 08:37:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4424D6B0095; Wed, 14 Jul 2021 08:37:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 22AFC6B008C for ; Wed, 14 Jul 2021 08:37:54 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 077348047A35 for ; Wed, 14 Jul 2021 12:37:53 +0000 (UTC) X-FDA: 78361145226.19.8A91E52 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf18.hostedemail.com (Postfix) with ESMTP id 9A00D4002091 for ; Wed, 14 Jul 2021 12:37:52 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 4B2AE613B0; Wed, 14 Jul 2021 12:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626266271; bh=d2immekSgHA4d0HzzgQ0U4J8/emUzkNR9p4b5EVUXL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LdNb1905cVXkyWPv+c6YlXvxZxMs2zNeW6VJwG5o1+XeehmArs7qSfeYmGehpnhVO 83PizuHhvC0jjqJzCyrrzIRayAOhyz8x7eINjhLT5XhAn+L7RXbtkfTFLv5oqzYKdJ Rz48GwUgRfZyUQOb0NWU0Tic49LXstBbJ6mMK5ELN1sx/JzmwKXuFLl0N8jVc6OyYt ceHwJcxqBr/Exhg2uBeLf0dMEi7M0IfSNjMpRdtx6EGH1gnP8NNIg0up8zyIrVTyOv T4VooaMbx16Uvq4EfK8oLiwPGZyl6/Xjhulmm6AdFCldbMFqWkg+u59Mnov8YFFccJ B/YMexS3gTj0g== From: Mike Rapoport To: Andrew Morton Cc: Michal Simek , Mike Rapoport , Mike Rapoport , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/4] mm: introduce memmap_alloc() to unify memory map allocation Date: Wed, 14 Jul 2021 15:37:38 +0300 Message-Id: <20210714123739.16493-4-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210714123739.16493-1-rppt@kernel.org> References: <20210714123739.16493-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9A00D4002091 X-Stat-Signature: 3ys4zxdk58to8mkueq5p45nobzexmw6w Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LdNb1905; spf=pass (imf18.hostedemail.com: domain of rppt@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1626266272-978366 Content-Transfer-Encoding: quoted-printable 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: From: Mike Rapoport There are several places that allocate memory for the memory map: alloc_node_mem_map() for FLATMEM, sparse_buffer_init() and __populate_section_memmap() for SPARSEMEM. The memory allocated in the FLATMEM case is zeroed and it is never poisoned, regardless of CONFIG_PAGE_POISON setting. The memory allocated in the SPARSEMEM cases is not zeroed and it is implicitly poisoned inside memblock if CONFIG_PAGE_POISON is set. Introduce memmap_alloc() wrapper for memblock allocators that will be use= d for both FLATMEM and SPARSEMEM cases and will makei memory map zeroing an= d poisoning consistent for different memory models. Signed-off-by: Mike Rapoport --- mm/internal.h | 4 ++++ mm/page_alloc.c | 24 ++++++++++++++++++++++-- mm/sparse.c | 6 ++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 31ff935b2547..57e28261a3b1 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -211,6 +211,10 @@ extern void zone_pcp_reset(struct zone *zone); extern void zone_pcp_disable(struct zone *zone); extern void zone_pcp_enable(struct zone *zone); =20 +extern void *memmap_alloc(phys_addr_t size, phys_addr_t align, + phys_addr_t min_addr, + int nid, bool exact_nid); + #if defined CONFIG_COMPACTION || defined CONFIG_CMA =20 /* diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 878d7af4403d..b82e55006894 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6730,6 +6730,26 @@ static void __init memmap_init(void) init_unavailable_range(hole_pfn, end_pfn, zone_id, nid); } =20 +void __init *memmap_alloc(phys_addr_t size, phys_addr_t align, + phys_addr_t min_addr, int nid, bool exact_nid) +{ + void *ptr; + + if (exact_nid) + ptr =3D memblock_alloc_exact_nid_raw(size, align, min_addr, + MEMBLOCK_ALLOC_ACCESSIBLE, + nid); + else + ptr =3D memblock_alloc_try_nid_raw(size, align, min_addr, + MEMBLOCK_ALLOC_ACCESSIBLE, + nid); + + if (ptr && size > 0) + page_init_poison(ptr, size); + + return ptr; +} + static int zone_batchsize(struct zone *zone) { #ifdef CONFIG_MMU @@ -7501,8 +7521,8 @@ static void __ref alloc_node_mem_map(struct pglist_= data *pgdat) end =3D pgdat_end_pfn(pgdat); end =3D ALIGN(end, MAX_ORDER_NR_PAGES); size =3D (end - start) * sizeof(struct page); - map =3D memblock_alloc_node(size, SMP_CACHE_BYTES, - pgdat->node_id); + map =3D memmap_alloc(size, SMP_CACHE_BYTES, MEMBLOCK_LOW_LIMIT, + pgdat->node_id, false); if (!map) panic("Failed to allocate %ld bytes for node %d memory map\n", size, pgdat->node_id); diff --git a/mm/sparse.c b/mm/sparse.c index 6326cdf36c4f..a5fad244ac5f 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -462,8 +462,7 @@ struct page __init *__populate_section_memmap(unsigne= d long pfn, if (map) return map; =20 - map =3D memblock_alloc_try_nid_raw(size, size, addr, - MEMBLOCK_ALLOC_ACCESSIBLE, nid); + map =3D memmap_alloc(size, size, addr, nid, false); if (!map) panic("%s: Failed to allocate %lu bytes align=3D0x%lx nid=3D%d from=3D= %pa\n", __func__, size, PAGE_SIZE, nid, &addr); @@ -490,8 +489,7 @@ static void __init sparse_buffer_init(unsigned long s= ize, int nid) * and we want it to be properly aligned to the section size - this is * especially the case for VMEMMAP which maps memmap to PMDs */ - sparsemap_buf =3D memblock_alloc_exact_nid_raw(size, section_map_size()= , - addr, MEMBLOCK_ALLOC_ACCESSIBLE, nid); + sparsemap_buf =3D memmap_alloc(size, section_map_size(), addr, nid, tru= e); sparsemap_buf_end =3D sparsemap_buf + size; } =20 --=20 2.28.0