Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp620340ybj; Thu, 7 May 2020 03:48:53 -0700 (PDT) X-Google-Smtp-Source: APiQypJrLkdE8VJJ1AGiWIRHBj8btMVtlxahGQodLp9vvBqwzfU/hQsTaWVyoUzUYT+fUiHPCDVi X-Received: by 2002:a17:906:f251:: with SMTP id gy17mr10544789ejb.369.1588848533637; Thu, 07 May 2020 03:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588848533; cv=none; d=google.com; s=arc-20160816; b=IjNahyktw0zHM9a0xS5YQ0+sXU1mMN/n+D2y/d534eIUy0KHdhnqlUcoofN20go6kW 6eEZ+F5CrATTQcxQWDAzHlIGbuAFnjhO+0TYpOlqcmB/5cWOPGSgpyhuNPoDMRq+3zj1 gJFFwWrjhv82ujs9aoJvRWxr4s5o/FlYuqlWLNtMJioVGUKwAFHYR8y3Xtnf9YTRmaOe 7Bdmigi7525ICvt3ZywOPiF27AvFWg4aSJxHq6D5CGXHMhWu9LRqEe3KsCm7kMbUaJds PYLG+nMCmTpKdJfXYev140lZ4EV/lStRJlIc+EqukB4gTLvqbOKtnqXbJ89AD0GDjmCr d7zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=jwFSP1qKPzAiDWVK6ecZi/lZRSGtCCdB3pW0dxf0VHw=; b=zGzMstpZwgUpWZqUvShKy0M99PtiA5FHHhnCdwGunhkhdj9PomeDIDlYnjT+iX2rtb 71FB4vTLJFMaC9wbaHJipmH4dBQKUeTkOogqa+PDjFQaqRG8qQo28+y/CgIaiOlxDprw ItBwnXi90NN4x9Rj+5fGNHiSlVqWklPl5fzACSF9xpYSz3yMkFXke3ClVsToK4s9Aefc 5LHzpui+hereLS8Qh5EuMV06ovpVZ9WSyK2HTEwNBeIpJ79exZ8GGz1dIgQoYzIb59at M4X4n7QzKNnkxUFpcBe6TKun3nJj1Ny/UjMWrgbtODlHYngbaS9T60QIqP+3JylA/5/P AXyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D0pXP0IU; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id aq1si3194083ejc.344.2020.05.07.03.48.30; Thu, 07 May 2020 03:48:53 -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=@redhat.com header.s=mimecast20190719 header.b=D0pXP0IU; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbgEGKq4 (ORCPT + 99 others); Thu, 7 May 2020 06:46:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60011 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726393AbgEGKq4 (ORCPT ); Thu, 7 May 2020 06:46:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588848414; 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: in-reply-to:in-reply-to:references:references; bh=jwFSP1qKPzAiDWVK6ecZi/lZRSGtCCdB3pW0dxf0VHw=; b=D0pXP0IUIMyXohYPb51/MwOqKX3cwc8P3CtBT1BmWOlAcovCp183l3rbTn1Px4Btyw5R// gNbfNHE5PRtqKcHOKz3qDV2dfoh6wXYpAbT2gtuddFNAXOUazg5TNJzXN041miT2NcPORQ dtQTNv7YqmwPF3o9p+o4GAb5jQ97E2Y= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-52-NbxiJMuVNJKQVEfv9nsKaQ-1; Thu, 07 May 2020 06:46:53 -0400 X-MC-Unique: NbxiJMuVNJKQVEfv9nsKaQ-1 Received: by mail-wr1-f70.google.com with SMTP id 30so3176583wrq.15 for ; Thu, 07 May 2020 03:46:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jwFSP1qKPzAiDWVK6ecZi/lZRSGtCCdB3pW0dxf0VHw=; b=oHFtQ1J1+29vv/d6gAlhqK7/a6fspfhlIr6XGyj97ZExryBlUBh98BpzqO/mv+9Iex LWAp1IHB7z0MnYPXzlwqmKTWmN/B+t56V67VaLqU4XNYrlevbj+5yoM2Nny14v2f00K3 aXvtMcCUv4EUGLjgxKU+2KKLq4/Y6QTJAX1pYHzoXjpZTMKq77Fzl8VAPnmuOPYqh0j2 KQsnk0sGE63StJhL+vKwNcTvZpbvxztlY7/9o7pVTGPzlYtTOsW/tuEp8pA5kAZizNge YYCHl5tnEXfnm1UrkhqdMH2hJWJVrCcQe5UDSviM0Xon7Se/wmH91lufCqY0msGONQZh jV4w== X-Gm-Message-State: AGi0PuYrHC2d5sB9pO/8Xf2Brj7bR4hHLFvsTTU0/yVUEZM3k0rXFovj oi951C/NnZWCnVsYgrAPa/QTQgrhZ6/HG5pLe7mDznXPqGLNzZsF0Nadr4QAcTRr6AHMw41OwjK AnVkH+bU4swgyUWJ2GC7A+wPN X-Received: by 2002:a1c:4b16:: with SMTP id y22mr9704516wma.170.1588848411507; Thu, 07 May 2020 03:46:51 -0700 (PDT) X-Received: by 2002:a1c:4b16:: with SMTP id y22mr9704494wma.170.1588848411214; Thu, 07 May 2020 03:46:51 -0700 (PDT) Received: from redhat.com (bzq-109-66-7-121.red.bezeqint.net. [109.66.7.121]) by smtp.gmail.com with ESMTPSA id v11sm7638062wrv.53.2020.05.07.03.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 03:46:50 -0700 (PDT) Date: Thu, 7 May 2020 06:46:46 -0400 From: "Michael S. Tsirkin" To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , Michal Hocko , Pankaj Gupta , Oscar Salvador , Pavel Tatashin , Wei Yang , Dan Williams , Qian Cai Subject: Re: [PATCH v3 07/15] mm/memory_hotplug: Introduce offline_and_remove_memory() Message-ID: <20200507064558-mutt-send-email-mst@kernel.org> References: <20200507103119.11219-1-david@redhat.com> <20200507103119.11219-8-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200507103119.11219-8-david@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 12:31:11PM +0200, David Hildenbrand wrote: > virtio-mem wants to offline and remove a memory block once it unplugged > all subblocks (e.g., using alloc_contig_range()). Let's provide > an interface to do that from a driver. virtio-mem already supports to > offline partially unplugged memory blocks. Offlining a fully unplugged > memory block will not require to migrate any pages. All unplugged > subblocks are PageOffline() and have a reference count of 0 - so > offlining code will simply skip them. > > All we need is an interface to offline and remove the memory from kernel > module context, where we don't have access to the memory block devices > (esp. find_memory_block() and device_offline()) and the device hotplug > lock. > > To keep things simple, allow to only work on a single memory block. > > Acked-by: Michal Hocko > Tested-by: Pankaj Gupta > Cc: Andrew Morton > Cc: David Hildenbrand > Cc: Oscar Salvador > Cc: Michal Hocko > Cc: Pavel Tatashin > Cc: Wei Yang > Cc: Dan Williams > Cc: Qian Cai > Signed-off-by: David Hildenbrand didn't you lose Andrew Morton's ack here? > --- > include/linux/memory_hotplug.h | 1 + > mm/memory_hotplug.c | 37 ++++++++++++++++++++++++++++++++++ > 2 files changed, 38 insertions(+) I get: error: sha1 information is lacking or useless (mm/memory_hotplug.c). error: could not build fake ancestor which version is this against? Pls post patches on top of some tag in Linus' tree if possible. > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 7dca9cd6076b..d641828e5596 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -318,6 +318,7 @@ extern void try_offline_node(int nid); > extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > extern int remove_memory(int nid, u64 start, u64 size); > extern void __remove_memory(int nid, u64 start, u64 size); > +extern int offline_and_remove_memory(int nid, u64 start, u64 size); > > #else > static inline void try_offline_node(int nid) {} > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 936bfe208a6e..bf1941f02a60 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1748,4 +1748,41 @@ int remove_memory(int nid, u64 start, u64 size) > return rc; > } > EXPORT_SYMBOL_GPL(remove_memory); > + > +/* > + * Try to offline and remove a memory block. Might take a long time to > + * finish in case memory is still in use. Primarily useful for memory devices > + * that logically unplugged all memory (so it's no longer in use) and want to > + * offline + remove the memory block. > + */ > +int offline_and_remove_memory(int nid, u64 start, u64 size) > +{ > + struct memory_block *mem; > + int rc = -EINVAL; > + > + if (!IS_ALIGNED(start, memory_block_size_bytes()) || > + size != memory_block_size_bytes()) > + return rc; > + > + lock_device_hotplug(); > + mem = find_memory_block(__pfn_to_section(PFN_DOWN(start))); > + if (mem) > + rc = device_offline(&mem->dev); > + /* Ignore if the device is already offline. */ > + if (rc > 0) > + rc = 0; > + > + /* > + * In case we succeeded to offline the memory block, remove it. > + * This cannot fail as it cannot get onlined in the meantime. > + */ > + if (!rc) { > + rc = try_remove_memory(nid, start, size); > + WARN_ON_ONCE(rc); > + } > + unlock_device_hotplug(); > + > + return rc; > +} > +EXPORT_SYMBOL_GPL(offline_and_remove_memory); > #endif /* CONFIG_MEMORY_HOTREMOVE */ > -- > 2.25.3