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 X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10678C35DE1 for ; Tue, 25 Feb 2020 14:11:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C24BE21744 for ; Tue, 25 Feb 2020 14:11:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C24BE21744 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5D4616B0006; Tue, 25 Feb 2020 09:11:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 58FB86B0007; Tue, 25 Feb 2020 09:11:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4734B6B0008; Tue, 25 Feb 2020 09:11:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 2DA9A6B0006 for ; Tue, 25 Feb 2020 09:11:38 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D782D141CC for ; Tue, 25 Feb 2020 14:11:37 +0000 (UTC) X-FDA: 76528837434.02.night37_828b5fa66781a X-HE-Tag: night37_828b5fa66781a X-Filterd-Recvd-Size: 6295 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 25 Feb 2020 14:11:36 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id t14so3289980wmi.5 for ; Tue, 25 Feb 2020 06:11:36 -0800 (PST) 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=9llSiqn9QmX37KJecnbve+X+EjpLa4SazqSQQgp9aV4=; b=udVBoAjNaY8JO62rjKxAQc5j0QlkFxMbzFttxWf6X09OQTjW7b41rPq2/9+OQiz7QM /vgVt+aL+k17rtGB4Wr70lbp7zanvVEAOfhJMaoLvQALDu9j0II+X+FD+tBg2I17L3Mw ILBrgjCqfJWPyVmj3p5/p4koifsVWHkrsj1LDhy9WPK/hP5L8cvpO4TQbRbLCq94MR3O mry/mjNzMbXOOypBg0++tFzFmA+cq4OAIpr6KcujQnmdIG2V4Y67K6Gr8VGzVjUimc3d LSRpdaMAr88+UdFTiLtynsrF7ujcLk0zpK7Mm4X0zWO8HEbAGEqUHTj9iq7jbfFOydsU Ukng== X-Gm-Message-State: APjAAAWsscTWJWaEtJdv/x2/Q60eeS1nnG68EK7e/gaOovMKBoqGJA9j 2bdDetsXhqYLdZf/8sjZqbM= X-Google-Smtp-Source: APXvYqzdNFz2/BYLFi72FFgE4SqlwoTvOVPcNUzf0X8k2HDo5fL4XJlZxrMCNKLRmzvrYSwv3huM/w== X-Received: by 2002:a7b:c8c5:: with SMTP id f5mr5368076wml.44.1582639895661; Tue, 25 Feb 2020 06:11:35 -0800 (PST) Received: from localhost (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id v17sm23338678wrt.91.2020.02.25.06.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 06:11:34 -0800 (PST) Date: Tue, 25 Feb 2020 15:11:34 +0100 From: Michal Hocko 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, Andrew Morton , "Michael S . Tsirkin" , Oscar Salvador , Pavel Tatashin , Wei Yang , Dan Williams , Qian Cai Subject: Re: [PATCH RFC v4 08/13] mm/memory_hotplug: Introduce offline_and_remove_memory() Message-ID: <20200225141134.GU22443@dhcp22.suse.cz> References: <20191212171137.13872-1-david@redhat.com> <20191212171137.13872-9-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191212171137.13872-9-david@redhat.com> 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: On Thu 12-12-19 18:11:32, 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 an interface to trigger the "offlining" and the removing in a > single operation - to make sure the memory block cannot get onlined by > user space again before it gets removed. Why does that matter? Is it really likely that the userspace would interfere? What would be the scenario? Or is still mostly about not requiring callers to open code this general patter? > To keep things simple, allow to only work on a single memory block. > > 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 > --- > include/linux/memory_hotplug.h | 1 + > mm/memory_hotplug.c | 35 ++++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index ba0dca6aac6e..586f5c59c291 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -310,6 +310,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 bool is_mem_section_removable(unsigned long pfn, > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index da01453a04e6..d04369e6d3cc 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1825,4 +1825,39 @@ 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 && try_remove_memory(nid, start, size)) > + BUG(); > + unlock_device_hotplug(); > + > + return rc; > +} > +EXPORT_SYMBOL_GPL(offline_and_remove_memory); > #endif /* CONFIG_MEMORY_HOTREMOVE */ > -- > 2.23.0 -- Michal Hocko SUSE Labs