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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 42A1CC38A24 for ; Thu, 7 May 2020 10:46:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D4E1824962 for ; Thu, 7 May 2020 10:46:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A7SQPxuE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4E1824962 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 40BA2900004; Thu, 7 May 2020 06:46:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BD3E900002; Thu, 7 May 2020 06:46:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28337900004; Thu, 7 May 2020 06:46:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 0CC03900002 for ; Thu, 7 May 2020 06:46:56 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CE8E8180AD83B for ; Thu, 7 May 2020 10:46:55 +0000 (UTC) X-FDA: 76789595190.30.cork82_3c73825b20b43 X-HE-Tag: cork82_3c73825b20b43 X-Filterd-Recvd-Size: 7829 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 May 2020 10:46:55 +0000 (UTC) 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TJyDSrGpxcqVnHQrHFSB+jsA9/E+cG6IT3gCbsVH7JI=; b=A7SQPxuEuvhzrRGA/TcEsZZeVsnWqbiPz4FS7TuM5s34V/fwm9+ZLJug9BUXSILAQuzbgT 8pWh/QcaBicLG+Ua2nXELxdgnbLjEuB1JNVqkJZq3FVvxj4rBWAk0nshxnFUUkA1wcz58m T9nYYHatJNrWe+DqP6oblgszSQsE+mM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-753hFB66NquQsWegYYg3hw-1; Thu, 07 May 2020 06:46:53 -0400 X-MC-Unique: 753hFB66NquQsWegYYg3hw-1 Received: by mail-wr1-f71.google.com with SMTP id e14so3168216wrv.11 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=Uu6ij676+1YOXOiU7iHaltmQ+vOApxQpKNBmoFJkZS2fz7YM/0SzlnrkPfCXo9Tji1 Iay7q5/hdAO1c58RWSguxHSB9bJNRunTB+AKMD1rJkXt3b1l8QU+L6j5CNyhcx0ShtYU G8hDlqwgxQC5tKBIDc1yjEWNi6JbsjUKgJP3XnnLHzt6L1CmhQeY7oLWicXgJPmoOQAH 1nu2jFdwV1azgfFVbqTyhsTKdahahJZlRCsaaS7dbjXs+my62iNsHfRtfaiJ9FOwQPKn n11HTwBldKz16hwTvnElPDEcWGJCDTCAX2WWKurHkQyTlaamQxqby5doPrkXIzFGLzeo 8ymQ== X-Gm-Message-State: AGi0PuYWsNyvlDygw50aR/p7DJFj0iW2Q5mcULxkG0xYMwe/8aLGXBrX GIiBmPL3I0DkE44D26N3/cW1r5PViJA7Tg8zgYsxcTg9WQIBim0cBbgrLnystZggh6PQIGxiDBj kqOT00z58yl8= X-Received: by 2002:a1c:4b16:: with SMTP id y22mr9704528wma.170.1588848411511; Thu, 07 May 2020 03:46:51 -0700 (PDT) X-Google-Smtp-Source: APiQypJwkpcsvMDTihRmO/58UI/oBdWetzX3zNTW+RN5tQqtGOSRJ/Ox4DqJrFYHImjL7fq9CHlvYA== 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 In-Reply-To: <20200507103119.11219-8-david@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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, 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. >=20 > 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. >=20 > To keep things simple, allow to only work on a single memory block. >=20 > 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_hotplu= g.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); > =20 > #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) > =09return 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 de= vices > + * that logically unplugged all memory (so it's no longer in use) and wa= nt to > + * offline + remove the memory block. > + */ > +int offline_and_remove_memory(int nid, u64 start, u64 size) > +{ > +=09struct memory_block *mem; > +=09int rc =3D -EINVAL; > + > +=09if (!IS_ALIGNED(start, memory_block_size_bytes()) || > +=09 size !=3D memory_block_size_bytes()) > +=09=09return rc; > + > +=09lock_device_hotplug(); > +=09mem =3D find_memory_block(__pfn_to_section(PFN_DOWN(start))); > +=09if (mem) > +=09=09rc =3D device_offline(&mem->dev); > +=09/* Ignore if the device is already offline. */ > +=09if (rc > 0) > +=09=09rc =3D 0; > + > +=09/* > +=09 * In case we succeeded to offline the memory block, remove it. > +=09 * This cannot fail as it cannot get onlined in the meantime. > +=09 */ > +=09if (!rc) { > +=09=09rc =3D try_remove_memory(nid, start, size); > +=09=09WARN_ON_ONCE(rc); > +=09} > +=09unlock_device_hotplug(); > + > +=09return rc; > +} > +EXPORT_SYMBOL_GPL(offline_and_remove_memory); > #endif /* CONFIG_MEMORY_HOTREMOVE */ > --=20 > 2.25.3