Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp353698pxv; Wed, 14 Jul 2021 05:40:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4T9xaePTunWzm77z19fbxXg2Ae2mu+rVZGym3Zja6DU6snsd3pEIfHYekjeShRpGatRTK X-Received: by 2002:a05:6402:1d4d:: with SMTP id dz13mr13272243edb.67.1626266416758; Wed, 14 Jul 2021 05:40:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626266416; cv=none; d=google.com; s=arc-20160816; b=BpHCsIkinQ4XcMQy5uTeokNXAdEuwSoOrPveXJBdAccKC31UKkY0ctl2AqZkKswTB9 TkNpgxF+0Y5G/u7FoKcL1LIZ4994hIynsin3n9Z7WZnAD1oMbvT0C1yl6FgnBbNwwDDM oeUs5C7JFlyFCcJbyzxmQ3LgXTahJTHylz0SljlsUW99l0UUXZAPsibgkwLGWy+DmcUT hgk/HibNBsTEALgkDwsdyi2N547cBXSDzxlgAbcHOoEcch3iBPHcStObdqXuey1kxWPw EVffS7aSG07zPGouxeaSEbyqaWsUQ+BalHGN5ncvBnI7ErBMpow3ZjLoR7DuhpJF1Dl8 CNCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eRq9jn+wBjnv7jGa0M95hHwE34g9GSDO7CLSV+iQbmM=; b=aWfQvLERpLi9AJUBsKC2duI4g1FqAFk/vae3ASWZ6i37OURj66W41ReSQHPYfovOPO L6lRQF+G8ngkiqnlX3hCLYakGRCXoujg1FPRTHzzI999IwrKJkTCRm3ri/NR3HOstW0o fFvFZxqMzjYx9CXOP34RZ1ciVWU/ytG0v7K4g/XUjq28j4iRLeLQQ50V0VRovBbI6WSA UUUGjrwke7/DFumtTI5R8dm2ZdC0ach/sAISWoCq8fCut9X0WFrstThetxLW3EtLQdRY Nw5/5qSz0pLZEBGnOH62sD/xkHJRbnkf5yH6nAl7EhiNI8dwb8tOoIJUAtqisvqy+vF2 sdLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LdNb1905; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o2si2337681edt.262.2021.07.14.05.39.52; Wed, 14 Jul 2021 05:40:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LdNb1905; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239370AbhGNMkn (ORCPT + 99 others); Wed, 14 Jul 2021 08:40:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:56464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239284AbhGNMkn (ORCPT ); Wed, 14 Jul 2021 08:40:43 -0400 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 used for both FLATMEM and SPARSEMEM cases and will makei memory map zeroing and 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); +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 /* 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); } +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 = memblock_alloc_exact_nid_raw(size, align, min_addr, + MEMBLOCK_ALLOC_ACCESSIBLE, + nid); + else + ptr = 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 = pgdat_end_pfn(pgdat); end = ALIGN(end, MAX_ORDER_NR_PAGES); size = (end - start) * sizeof(struct page); - map = memblock_alloc_node(size, SMP_CACHE_BYTES, - pgdat->node_id); + map = 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(unsigned long pfn, if (map) return map; - map = memblock_alloc_try_nid_raw(size, size, addr, - MEMBLOCK_ALLOC_ACCESSIBLE, nid); + map = memmap_alloc(size, size, addr, nid, false); if (!map) panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d from=%pa\n", __func__, size, PAGE_SIZE, nid, &addr); @@ -490,8 +489,7 @@ static void __init sparse_buffer_init(unsigned long size, 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 = memblock_alloc_exact_nid_raw(size, section_map_size(), - addr, MEMBLOCK_ALLOC_ACCESSIBLE, nid); + sparsemap_buf = memmap_alloc(size, section_map_size(), addr, nid, true); sparsemap_buf_end = sparsemap_buf + size; } -- 2.28.0