From patchwork Tue Sep 8 20:10:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11764369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12386618 for ; Tue, 8 Sep 2020 20:10:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9BB552137B for ; Tue, 8 Sep 2020 20:10:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e7kL1KLP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BB552137B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7F7416B005A; Tue, 8 Sep 2020 16:10:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 782B06B0062; Tue, 8 Sep 2020 16:10:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64ADE6B0068; Tue, 8 Sep 2020 16:10:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0179.hostedemail.com [216.40.44.179]) by kanga.kvack.org (Postfix) with ESMTP id 490D46B005A for ; Tue, 8 Sep 2020 16:10:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0EB531EFD for ; Tue, 8 Sep 2020 20:10:39 +0000 (UTC) X-FDA: 77240986998.26.art49_540bf44270d7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id B67D91804B654 for ; Tue, 8 Sep 2020 20:10:38 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,david@redhat.com,,RULES_HIT:30029:30051:30054,0,RBL:216.205.24.124:@redhat.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04ygmcfrfbfd3jx849bg6a6ut96u6ocundtccy9ocdc6k97yp8ggbqmm6yugmub.78qbxgbekznxh1masu58nryyubpgo4bjmqcnyf9uptisxwzodyz9se13ke3mjqn.6-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: art49_540bf44270d7 X-Filterd-Recvd-Size: 7245 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Sep 2020 20:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599595837; h=from:from: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; bh=c3EXsANyRQfNPWugjklxVXDT/m3en9wKUY4fM1Sf5tA=; b=e7kL1KLPTC0NcQ56BOvHfFkbQJPwH36+0DPCRvptTbit5NPXHvcA7IyAmlIo6SD1WAdjHZ N3SC+qGJLWZoecYsGAWt3Q+N3tLXb26/bs8lfm6rBZmRInvH1agGGIM0fSz9DgVPSpnQwU t3sHBFe+ct0OWZ8l1DzL7gWw40SOXs0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-7-5kkWOmFZP5m0Qe57B5e2tg-1; Tue, 08 Sep 2020 16:10:34 -0400 X-MC-Unique: 5kkWOmFZP5m0Qe57B5e2tg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F25761074667; Tue, 8 Sep 2020 20:10:28 +0000 (UTC) Received: from t480s.redhat.com (ovpn-115-46.ams2.redhat.com [10.36.115.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04EEC5D9E8; Tue, 8 Sep 2020 20:10:13 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, linux-mm@kvack.org, linux-hyperv@vger.kernel.org, xen-devel@lists.xenproject.org, linux-acpi@vger.kernel.org, linux-nvdimm@lists.01.org, linux-s390@vger.kernel.org, Andrew Morton , David Hildenbrand , Anton Blanchard , Ard Biesheuvel , Baoquan He , Benjamin Herrenschmidt , Boris Ostrovsky , Christian Borntraeger , Dan Williams , Dave Jiang , Eric Biederman , Greg Kroah-Hartman , Haiyang Zhang , Heiko Carstens , Jason Gunthorpe , Jason Wang , Juergen Gross , Julien Grall , Kees Cook , "K. Y. Srinivasan" , Len Brown , Leonardo Bras , Libor Pechacek , Michael Ellerman , "Michael S. Tsirkin" , Michal Hocko , Nathan Lynch , "Oliver O'Halloran" , Pankaj Gupta , Paul Mackerras , Pingfan Liu , "Rafael J. Wysocki" , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Stephen Hemminger , Thomas Gleixner , Vasily Gorbik , Vishal Verma , Wei Liu , Wei Yang Subject: [PATCH v2 0/7] mm/memory_hotplug: selective merging of system ram resources Date: Tue, 8 Sep 2020 22:10:05 +0200 Message-Id: <20200908201012.44168-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Rspamd-Queue-Id: B67D91804B654 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: Some add_memory*() users add memory in small, contiguous memory blocks. Examples include virtio-mem, hyper-v balloon, and the XEN balloon. This can quickly result in a lot of memory resources, whereby the actual resource boundaries are not of interest (e.g., it might be relevant for DIMMs, exposed via /proc/iomem to user space). We really want to merge added resources in this scenario where possible. Resources are effectively stored in a list-based tree. Having a lot of resources not only wastes memory, it also makes traversing that tree more expensive, and makes /proc/iomem explode in size (e.g., requiring kexec-tools to manually merge resources when creating a kdump header. The current kexec-tools resource count limit does not allow for more than ~100GB of memory with a memory block size of 128MB on x86-64). Let's allow to selectively merge system ram resources by specifying a new flag for add_memory*(). Patch #5 contains a /proc/iomem example. Only tested with virtio-mem. v1 -> v2: - I had another look at v1 after vacation and didn't like it - it felt like a hack. So I want forward and added a proper flag to add_memory*(), and introduce a clean (non-racy) way to mark System RAM resources mergeable. - "kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED" -- Clean that flag up, felt wrong in the PnP section - "mm/memory_hotplug: prepare passing flags to add_memory() and friends" -- Previously sent in other context - decided to keep Wei's ack - "mm/memory_hotplug: MEMHP_MERGE_RESOURCE to specify merging of System RAM resources" -- Cleaner approach to get the job done by using proper flags and only merging the single, specified resource - "virtio-mem: try to merge system ram resources" "xen/balloon: try to merge system ram resources" "hv_balloon: try to merge system ram resources" -- Use the new flag MEMHP_MERGE_RESOURCE, much cleaner RFC -> v1: - Switch from rather generic "merge_child_mem_resources()" where a resource name has to be specified to "merge_system_ram_resources(). - Smaller comment/documentation/patch description changes/fixes David Hildenbrand (7): kernel/resource: make release_mem_region_adjustable() never fail kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED mm/memory_hotplug: prepare passing flags to add_memory() and friends mm/memory_hotplug: MEMHP_MERGE_RESOURCE to specify merging of System RAM resources virtio-mem: try to merge system ram resources xen/balloon: try to merge system ram resources hv_balloon: try to merge system ram resources arch/powerpc/platforms/powernv/memtrace.c | 2 +- .../platforms/pseries/hotplug-memory.c | 2 +- drivers/acpi/acpi_memhotplug.c | 2 +- drivers/base/memory.c | 2 +- drivers/dax/kmem.c | 2 +- drivers/hv/hv_balloon.c | 2 +- drivers/s390/char/sclp_cmd.c | 2 +- drivers/virtio/virtio_mem.c | 3 +- drivers/xen/balloon.c | 2 +- include/linux/ioport.h | 12 +- include/linux/memory_hotplug.h | 19 ++- kernel/kexec_file.c | 2 +- kernel/resource.c | 109 ++++++++++++++---- mm/memory_hotplug.c | 48 +++----- 14 files changed, 141 insertions(+), 68 deletions(-)