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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16090C433EF for ; Thu, 10 Feb 2022 18:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239935AbiBJSoP (ORCPT ); Thu, 10 Feb 2022 13:44:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbiBJSoN (ORCPT ); Thu, 10 Feb 2022 13:44:13 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA3D3F47 for ; Thu, 10 Feb 2022 10:44:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644518653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=l+XLmNfpk7cwkO7aL9H8IvEkM0xjiYWbU4+0Qm8z5bk=; b=DVXBSe/ggK1kbaQfj7e60oiEIXy9SvWYbr9BkIT1A9EQLF0A84vFdQwkYGOjVmHWbyIi4a cXAxT95gQnuwKV1oUkrJd1GAffnoFVGv2uVKjZJkoOw+Y6SgJrI1AeprF4t0SnVVC4gkWp +4MUxOInfixGzXLYQk+ikSrDM2svtfA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-74t1Cr2mOeWedFW95Lp3Fg-1; Thu, 10 Feb 2022 13:44:07 -0500 X-MC-Unique: 74t1Cr2mOeWedFW95Lp3Fg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A06B92502; Thu, 10 Feb 2022 18:44:06 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 876F27E124; Thu, 10 Feb 2022 18:44:00 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , "Rafael J. Wysocki" , Greg Kroah-Hartman , Michal Hocko , Oscar Salvador Subject: [PATCH v2 0/2] drivers/base/memory: determine and store zone for single-zone memory blocks Date: Thu, 10 Feb 2022 19:43:57 +0100 Message-Id: <20220210184359.235565-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is based on v5.17-rc3 and: * [PATCH v1] drivers/base/memory: add memory block to memory group after registration succeeded [1] * [PATCH v1] drivers/base/node: consolidate node device subsystem initialization in node_dev_init() [2] Which are already in -next via -mm. -- I remember talking to Michal in the past about removing test_pages_in_a_zone(), which we use for: * verifying that a memory block we intend to offline is really only managed by a single zone. We don't support offlining of memory blocks that are managed by multiple zones (e.g., multiple nodes, DMA and DMA32) * exposing that zone to user space via /sys/devices/system/memory/memory*/valid_zones Now that I identified some more cases where test_pages_in_a_zone() might go wrong, and we received an UBSAN report (see patch #3), let's get rid of this PFN walker. So instead of detecting the zone at runtime with test_pages_in_a_zone() by scanning the memmap, let's determine and remember for each memory block if it's managed by a single zone. The stored zone can then be used for the above two cases, avoiding a manual lookup using test_pages_in_a_zone(). This avoids eventually stumbling over uninitialized memmaps in corner cases, especially when ZONE_DEVICE ranges partly fall into memory block (that are responsible for managing System RAM). Handling memory onlining is easy, because we online to exactly one zone. Handling boot memory is more tricky, because we want to avoid scanning all zones of all nodes to detect possible zones that overlap with the physical memory region of interest. Fortunately, we already have code that determines the applicable nodes for a memory block, to create sysfs links -- we'll hook into that. Patch #1 is a simple cleanup I had laying around for a longer time. Patch #2 contains the main logic to remove test_pages_in_a_zone() and further details. v1 -> v2: * Keep returning -EINVAL when we have multiple zones * s/memory_block_set_nid/memory_block_add_nid/ and add proper documentation * Move sanity "single zone" check after "memory hole" check * Minor fixes for spelling mistakes [1] https://lkml.kernel.org/r/20220128144540.153902-1-david@redhat.com [2] https://lkml.kernel.org/r/20220203105212.30385-1-david@redhat.com Cc: Andrew Morton Cc: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman Cc: Michal Hocko Cc: Oscar Salvador David Hildenbrand (2): drivers/base/node: rename link_mem_sections() to register_memory_block_under_node() drivers/base/memory: determine and store zone for single-zone memory blocks drivers/base/memory.c | 101 +++++++++++++++++++++++++++++++-- drivers/base/node.c | 18 +++--- include/linux/memory.h | 12 ++++ include/linux/memory_hotplug.h | 6 +- include/linux/node.h | 16 +++--- mm/memory_hotplug.c | 56 +++++------------- 6 files changed, 139 insertions(+), 70 deletions(-) -- 2.34.1