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=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 A2081C433DF for ; Mon, 12 Oct 2020 12:54:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3D32621D7F for ; Mon, 12 Oct 2020 12:54:52 +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="fOXtX1TJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D32621D7F 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 CDE33940010; Mon, 12 Oct 2020 08:54:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C69AE94000C; Mon, 12 Oct 2020 08:54:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B303E940010; Mon, 12 Oct 2020 08:54:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id 8344994000C for ; Mon, 12 Oct 2020 08:54:51 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1D5AD1EE6 for ; Mon, 12 Oct 2020 12:54:51 +0000 (UTC) X-FDA: 77363267982.27.pipe90_0a17fe5271fa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id EBDA33D663 for ; Mon, 12 Oct 2020 12:54:50 +0000 (UTC) X-HE-Tag: pipe90_0a17fe5271fa X-Filterd-Recvd-Size: 5766 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Mon, 12 Oct 2020 12:54:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602507289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GqBRdrN+rzKtjpl2XrHaqNhvixrxohgsDeDRZkVA61Y=; b=fOXtX1TJ46/PmUN8Yyvhhu2z9QrldkvpZUR53+GajQ8TdQ6vtQWi31nZX/yEgQi41UB9bD /bjIAKslbTeYrxAG/azhiiyer5r8wJXTZpdY1rmgbaxqqYF4uwJgEYk10U8j6nilfiZDzB 2sjGWX77OuMvaki7gjlUcW3z0xScYu8= 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-447-T30Fq8AONu2AuXWUt9jDqA-1; Mon, 12 Oct 2020 08:54:47 -0400 X-MC-Unique: T30Fq8AONu2AuXWUt9jDqA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 40C4E1800D4A; Mon, 12 Oct 2020 12:54:46 +0000 (UTC) Received: from t480s.redhat.com (ovpn-113-251.ams2.redhat.com [10.36.113.251]) by smtp.corp.redhat.com (Postfix) with ESMTP id 009C060C13; Mon, 12 Oct 2020 12:54:35 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Jason Wang , Pankaj Gupta Subject: [PATCH v1 09/29] virtio-mem: don't always trigger the workqueue when offlining memory Date: Mon, 12 Oct 2020 14:53:03 +0200 Message-Id: <20201012125323.17509-10-david@redhat.com> In-Reply-To: <20201012125323.17509-1-david@redhat.com> References: <20201012125323.17509-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable 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: Let's trigger from offlining code when we're not allowed to touch online memory. Handle the other case (memmap possibly freeing up another memory block) when actually removing memory. When removing via virtio_mem_remove(), virtio_mem_retry() is a NOP and safe to use. While at it, move retry handling when offlining out of virtio_mem_notify_offline(), to share it with Device Block Mode (DBM) soon. Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 40 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 5c93f8a65eba..8ea00f0b2ecd 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -158,6 +158,7 @@ static DEFINE_MUTEX(virtio_mem_mutex); static LIST_HEAD(virtio_mem_devices); =20 static void virtio_mem_online_page_cb(struct page *page, unsigned int or= der); +static void virtio_mem_retry(struct virtio_mem *vm); =20 /* * Register a virtio-mem device so it will be considered for the online_= page @@ -435,9 +436,17 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, = unsigned long mb_id) static int virtio_mem_mb_remove(struct virtio_mem *vm, unsigned long mb_= id) { const uint64_t addr =3D virtio_mem_mb_id_to_phys(mb_id); + int rc; =20 dev_dbg(&vm->vdev->dev, "removing memory block: %lu\n", mb_id); - return remove_memory(vm->nid, addr, memory_block_size_bytes()); + rc =3D remove_memory(vm->nid, addr, memory_block_size_bytes()); + if (!rc) + /* + * We might have freed up memory we can now unplug, retry + * immediately instead of waiting. + */ + virtio_mem_retry(vm); + return rc; } =20 /* @@ -452,11 +461,19 @@ static int virtio_mem_mb_offline_and_remove(struct = virtio_mem *vm, unsigned long mb_id) { const uint64_t addr =3D virtio_mem_mb_id_to_phys(mb_id); + int rc; =20 dev_dbg(&vm->vdev->dev, "offlining and removing memory block: %lu\n", mb_id); - return offline_and_remove_memory(vm->nid, addr, - memory_block_size_bytes()); + rc =3D offline_and_remove_memory(vm->nid, addr, + memory_block_size_bytes()); + if (!rc) + /* + * We might have freed up memory we can now unplug, retry + * immediately instead of waiting. + */ + virtio_mem_retry(vm); + return rc; } =20 /* @@ -534,15 +551,6 @@ static void virtio_mem_notify_offline(struct virtio_= mem *vm, BUG(); break; } - - /* - * Trigger the workqueue, maybe we can now unplug memory. Also, - * when we offline and remove a memory block, this will re-trigger - * us immediately - which is often nice because the removal of - * the memory block (e.g., memmap) might have freed up memory - * on other memory blocks we manage. - */ - virtio_mem_retry(vm); } =20 static void virtio_mem_notify_online(struct virtio_mem *vm, unsigned lon= g mb_id) @@ -679,6 +687,14 @@ static int virtio_mem_memory_notifier_cb(struct noti= fier_block *nb, break; case MEM_OFFLINE: virtio_mem_notify_offline(vm, mb_id); + + /* + * Trigger the workqueue. Now that we have some offline memory, + * maybe we can handle pending unplug requests. + */ + if (!unplug_online) + virtio_mem_retry(vm); + vm->hotplug_active =3D false; mutex_unlock(&vm->hotplug_mutex); break; --=20 2.26.2