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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50568C433EF for ; Thu, 10 Feb 2022 18:44:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B29CA6B0071; Thu, 10 Feb 2022 13:44:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A8C356B0075; Thu, 10 Feb 2022 13:44:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 906966B0078; Thu, 10 Feb 2022 13:44:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id 7C6206B0071 for ; Thu, 10 Feb 2022 13:44:10 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 370358249980 for ; Thu, 10 Feb 2022 18:44:10 +0000 (UTC) X-FDA: 79127745060.22.82D24B6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id B003814000B for ; Thu, 10 Feb 2022 18:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644518649; 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=QGgRMbUP53M5DcRRfi8EtNOidyR0hNXS+RvM6GlMr2HKWjle8zuatUsx6/MCWFgsOdUHLl MeF6xw7QIVE6qNQq4gh5erp1S+WbcuO7a8XyRcplTPyNKig+IEcfkI4tW6cAasy1nshoia JSs564pTE5KwydsL8Rm+3/Fe5WI07zM= 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 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QGgRMbUP; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf09.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Rspamd-Queue-Id: B003814000B X-Stat-Signature: pfnwkixzkrxk7ajc9ubd3h4gihfxcf43 X-Rspamd-Server: rspam07 X-HE-Tag: 1644518649-998125 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: 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 manag= ed 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 o= f this PFN walker. So instead of detecting the zone at runtime with test_pages_in_a_zone() b= y 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 tha= t 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 documentati= on * 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(-) --=20 2.34.1