From patchwork Tue Oct 17 05:44:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13424456 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 2CCAECDB474 for ; Tue, 17 Oct 2023 05:45:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEB9F8D00F4; Tue, 17 Oct 2023 01:45:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9C6A8D00DE; Tue, 17 Oct 2023 01:45:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A639A8D00F4; Tue, 17 Oct 2023 01:45:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 955558D00DE for ; Tue, 17 Oct 2023 01:45:10 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6E7F8120AFA for ; Tue, 17 Oct 2023 05:45:10 +0000 (UTC) X-FDA: 81353865180.07.C19B159 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by imf09.hostedemail.com (Postfix) with ESMTP id 4BC90140008 for ; Tue, 17 Oct 2023 05:45:08 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=btV7KmiJ; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of vishal.l.verma@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697521508; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=rFTh9hdLSAYhZGtwq78intqjdrGyBl5gU9oDISScxwk=; b=EKkfFl0gRgjDPnIEDp3qub7xv6n002lcFlGtXdTHC9S/u14L6wXtYOvbAH/9c8v7m3tBJD SCP7RrJYpq6TfUdZUbQFo5i7DuOKU6lACcBo3fWn6Ou8G1oerTdaJVfa008OVxhTXSYmxX 63ZCPG4JzreOdZIHIwHMcgMEadAI+rQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=btV7KmiJ; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of vishal.l.verma@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697521508; a=rsa-sha256; cv=none; b=7E/V9pVJ8NJgAtcnj5Pnfg8vyzH1HRK3PQIUxwFfCnQGItzBuBvVSn6e1Zlf7r80L2CCCU YxNY23Bqj5vTodj8CBPlgZWl+armcw+jFgiIFipL513XmpbJqMhe4MNQYMk9htkgkqFJo4 OL6Tewh+zGbXGKH2hasqa83AcnalHQQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697521508; x=1729057508; h=from:subject:date:message-id:mime-version: content-transfer-encoding:to:cc; bh=D2q85RkwugIFb5ErxqlgU3WLAEq5xCEwZ4AKsbq/LHM=; b=btV7KmiJ0y9O2Mg1cYVmROB8/y2rcjsBkwSj77T6aEP1G0elcYmFylR/ 3rPFArWQt3TFuLbRZ5jjI3bbVdNI3CwazKuVadI5dGnJCdZQlvObA6U84 en1coQDF0uU71f/W08j7/+3Oj1544H3/CFo5PkgovPh2aIncB09/ETMWY 75veEuLTnQw9U2DjVnTxLHWIprIYgWVroT7uwLTk5wX8uy3jn/736cPBS cL0jGX0yg0ad5rxxO4R3jETwre/Frchn5iSE6oxSgAGUM0SbsrqfEZLbP lMUbafEXsvsH2LJe7xNVosNCEmwOqtP4TSnl7S0mDU2velb3a2YRdwFeP A==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="384580744" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="384580744" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 22:45:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="879693918" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="879693918" Received: from mjwirth-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.209.151.162]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 22:45:00 -0700 From: Vishal Verma Subject: [PATCH v6 0/3] mm: use memmap_on_memory semantics for dax/kmem Date: Mon, 16 Oct 2023 23:44:54 -0600 Message-Id: <20231016-vv-kmem_memmap-v6-0-078f0d3c0371@intel.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAFYfLmUC/3XOy07EMAwF0F8ZZU1Q3k1Y8R8IITd1aEQfo2aIQ KP+O55ZUNGKhRfX0rn2lRVcMhb2dLqyBWsueZ4ouIcTiz1M78hzR5kpobRwUvNa+ceI4xvNCGd ujdfRd8KoJjBCLRTk7QJT7IlNn8NAy/OCKX/dr7y8Uu5zuczL9/1olbftv/1VcsGT6zBEB0lF9 5ynCw6PcR7ZraqqjTdKHLgi7n3bAbTahKD3XG/cC3ngmrgRDgNAss6HPTcbD8ofuCHuUmp0wmh lgD23v1wKYQ/cEgdrOhm8TAL+PL+u6w9QU2covQEAAA== To: Andrew Morton , David Hildenbrand , Oscar Salvador , Dan Williams , Dave Jiang Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Huang Ying , Dave Hansen , "Aneesh Kumar K.V" , Michal Hocko , Jonathan Cameron , Jeff Moyer , Vishal Verma , Jonathan Cameron X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4668; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=D2q85RkwugIFb5ErxqlgU3WLAEq5xCEwZ4AKsbq/LHM=; b=owGbwMvMwCXGf25diOft7jLG02pJDKl68pEKMU+LNeWDPF1K7pYs2eC89+dCgaITj6ZWLevbt zZ1gpd+RykLgxgXg6yYIsvfPR8Zj8ltz+cJTHCEmcPKBDKEgYtTACaSG8PI8ETpm+Z+0z/O+x8f 2FCWtrh28/FEyX+NvkKcb1tuun5gjmD4n1FWn8v0TMSkpvZ0HoP/w2s6VY4sljyuwt9vzLQIKNd iBAA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4BC90140008 X-Stat-Signature: mbdp41izdjgt4gkw61u36eakpyayjj8w X-HE-Tag: 1697521508-30881 X-HE-Meta: U2FsdGVkX1/gCq/3k5MyZM90Td7lQ1N0LcmWSRYplYJtjVbUuCyMo9cXTUmTzkic8twvFzoMZ+LJhF/v4NHH/IQpopxQMeQYNkf1uvukiz6r26BG7l2j4Zf/ny+jDCeGziFM2ttyD9VefFXeTfBcHnPAV9qIA9ME8n/JFiL7Qk3Lu3dVTQQyhC4hoB2cYmilTgi4ThpUJiZL3Ow/hduwlH1yCbbrnCXshxdK7w2Q9Qktplqn6rxzjanCpk5yRYyhnr6hQEc5O3sMAJalRLrQIoJOPdlsb92Qq3ohs0CSZH1av9gU3mnEuZGLx6BGnRHe7mxi+GtGBgoSVQg6uCwfwUG172T2qMAyyNSRjkKYTnh1V7hcn5EOEh1sWEgHK/NIAOrCXZZDH2D32Ez6WD4I84RxyXq+VVW0Ubc2Oz+KUsHYzBQusHOQ94K5pf44N8pFcutBE21ZHCirzTKzs3yIaCP2asnpE4CwyJg5qgpqeT30AKml9+mo/ZtC7ISnmgWYcU8GKAU2T30HqOxJ23dWHUGvDlSHhwaaV9SuStsnqqF/gpwvvhAYuDeZtcYYkRLFaNqD482tkkgox5EQs0U2W/Ql//kkNYehOHNBziYE8vHCQwrpwjHCkElHg/FdL/RKhB3bnmGU7T912OMYLOcEE2FCQ6kIYsH3I+5Ho7lams+SmKeL9ecRKqAfnGmUYjpqPJ6uLUPoaFDPb36wl5irBsmbe3rfBFTf08IJgw85NpM2ktRejJMNzPHRc3IeNjZJfo/H6qPdAQRIcE3s8MeGw1q0l2M1rFh50KK70VhPQCAcumZSLD485i8eA4Z6Tpb9Igb+HKkysk+7LeO1G+syXYJDzHXVG04oqJjK/mfVwzUtVXDVMmyahERACejVCyZUOLjoVRgnrSuCeJzGWDeDnf/SRLVb2FBkl1O3F9nelD0x2ojkXNY/w6M0w70Er5D+0tKTqMXyO+Z3gsP3YX6 bE8EJBPe HfAu3u/7qN4DZzyTzWY1OBpgIp/mzd618dXFwO/BOxxm2nnrJsD53j4XY0YIIytCzKbKGLyRZQRN/yLWWh66GpNMd085YXUw45pgLLqxjqT1c+laUKkQVVfJ8GRiZM4VIpBHH+v935fl163+3F1RJ/KQQLP0YBMeqxxAPHt0XOqxRys44/8PyVtLk4OUSakPk6WdvHAD/bGXAn6E1M3FcGg6L80dIaSSnjHslWy7BmnUTAPkvvNxs6+llhDy+wvNAvjzDRDH4gAlPk1nQqpKHBSG9Ogw8cIzyB/uhOe/mHylxO8w= 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: The dax/kmem driver can potentially hot-add large amounts of memory originating from CXL memory expanders, or NVDIMMs, or other 'device memories'. There is a chance there isn't enough regular system memory available to fit the memmap for this new memory. It's therefore desirable, if all other conditions are met, for the kmem managed memory to place its memmap on the newly added memory itself. The main hurdle for accomplishing this for kmem is that memmap_on_memory can only be done if the memory being added is equal to the size of one memblock. To overcome this, allow the hotplug code to split an add_memory() request into memblock-sized chunks, and try_remove_memory() to also expect and handle such a scenario. Patch 1 teaches the memory_hotplug code to allow for splitting add_memory() and remove_memory() requests over memblock sized chunks. Patch 2 adds a sysfs control for the kmem driver that would allow an opt-out of using memmap_on_memory for the memory being added. Signed-off-by: Vishal Verma --- Changes in v6: - Add a prep patch to replace an open coded kmemdup in add_memory_resource() (Dan Williams) - Fix ordering of firmware_map_remove w.r.t taking the hotplug lock (David Hildenbrand) - Remove unused 'nid' variable, and a stray whitespace (David Hildenbrand) - Clean up and simplify the altmap vs non-altmap paths for try_remove_memory (David Hildenbrand) - Add a note to the changelog in patch 1 linking to the PUD mappings proposal (David Hildenbrand) - Remove the new sysfs ABI from the kmem/dax drivers until ABI documentation for /sys/bus/dax can be established (will split this out into a separate patchset) (Dan Williams) - Link to v5: https://lore.kernel.org/r/20231005-vv-kmem_memmap-v5-0-a54d1981f0a3@intel.com Changes in v5: - Separate out per-memblock operations from per memory block operations in try_remove_memory(), and rename the inner function appropriately. This does expand the scope of the memory hotplug lock to include remove_memory_block_devices(), but the alternative was to drop the lock in the inner function separately for each iteration, and then re-acquire it in try_remove_memory() creating a small window where the lock isn't held. (David Hildenbrand) - Remove unnecessary rc check from the memmap_on_memory_store sysfs helper in patch 2 (Dan Carpenter) - Link to v4: https://lore.kernel.org/r/20230928-vv-kmem_memmap-v4-0-6ff73fec519a@intel.com Changes in v4: - Rebase to Aneesh's PPC64 memmap_on_memory series v8 [2]. - Tweak a goto / error path in add_memory_create_devices() (Jonathan) - Retain the old behavior for dax devices, only default to memmap_on_memory for CXL (Jonathan) - Link to v3: https://lore.kernel.org/r/20230801-vv-kmem_memmap-v3-0-406e9aaf5689@intel.com [2]: https://lore.kernel.org/linux-mm/20230808091501.287660-1-aneesh.kumar@linux.ibm.com Changes in v3: - Rebase on Aneesh's patches [1] - Drop Patch 1 - it is not needed since [1] allows for dynamic setting of the memmap_on_memory param (David) - Link to v2: https://lore.kernel.org/r/20230720-vv-kmem_memmap-v2-0-88bdaab34993@intel.com [1]: https://lore.kernel.org/r/20230801044116.10674-1-aneesh.kumar@linux.ibm.com Changes in v2: - Drop the patch to create an override path for the memmap_on_memory module param (David) - Move the chunking into memory_hotplug.c so that any caller of add_memory() can request this behavior. (David) - Handle remove_memory() too. (David, Ying) - Add a sysfs control in the kmem driver for memmap_on_memory semantics (David, Jonathan) - Add a #else case to define mhp_supports_memmap_on_memory() if CONFIG_MEMORY_HOTPLUG is unset. (0day report) - Link to v1: https://lore.kernel.org/r/20230613-vv-kmem_memmap-v1-0-f6de9c6af2c6@intel.com --- Vishal Verma (3): mm/memory_hotplug: replace an open-coded kmemdup() in add_memory_resource() mm/memory_hotplug: split memmap_on_memory requests across memblocks dax/kmem: allow kmem to add memory with memmap_on_memory drivers/dax/bus.h | 1 + drivers/dax/dax-private.h | 1 + drivers/dax/bus.c | 3 + drivers/dax/cxl.c | 1 + drivers/dax/hmem/hmem.c | 1 + drivers/dax/kmem.c | 8 +- drivers/dax/pmem.c | 1 + mm/memory_hotplug.c | 214 ++++++++++++++++++++++++++++++++-------------- 8 files changed, 163 insertions(+), 67 deletions(-) --- base-commit: 25b5b1a0646c3d39e1d885e27c10be1c9e202bf2 change-id: 20230613-vv-kmem_memmap-5483c8d04279 Best regards,