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 2165AC43457 for ; Mon, 12 Oct 2020 12:55:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9E0BD21BE5 for ; Mon, 12 Oct 2020 12:55:24 +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="eBBceP4t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E0BD21BE5 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 2CC2F940011; Mon, 12 Oct 2020 08:55:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22C9C940007; Mon, 12 Oct 2020 08:55:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F7F9940011; Mon, 12 Oct 2020 08:55:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id D07F7940007 for ; Mon, 12 Oct 2020 08:55:23 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 678A83623 for ; Mon, 12 Oct 2020 12:55:23 +0000 (UTC) X-FDA: 77363269326.13.root85_110f1a6271fa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 43BF818140B69 for ; Mon, 12 Oct 2020 12:55:23 +0000 (UTC) X-HE-Tag: root85_110f1a6271fa X-Filterd-Recvd-Size: 4476 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Mon, 12 Oct 2020 12:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602507322; 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=Nfx3E1E8CtjMuP9lMG33p0/a9KgSIqjdfK7bGnmRDXs=; b=eBBceP4tpN6lIsBhu2GnDydiR1Ud9iOTgAXczLNcJ6hLWrRtdzFXqyRxJwec33sE7ZPk9C JMDydK1Fv72ccEQvxifJyBxWFxjKNGSK0qvxO3hefoK11kGOW9u1sBOTJ0uXfKHOs5/pal vHz/QE9oUKbQAHy/Ku5Hd4JbzdyLK0Y= 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-518-OQI5yNW_MnGAQ8K74Zdxcg-1; Mon, 12 Oct 2020 08:55:20 -0400 X-MC-Unique: OQI5yNW_MnGAQ8K74Zdxcg-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 866281005E5D; Mon, 12 Oct 2020 12:55:19 +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 DF04E60C07; Mon, 12 Oct 2020 12:55:14 +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 14/29] virtio-mem: retry fake-offlining via alloc_contig_range() on ZONE_MOVABLE Date: Mon, 12 Oct 2020 14:53:08 +0200 Message-Id: <20201012125323.17509-15-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: ZONE_MOVABLE is supposed to give some guarantees, yet, alloc_contig_range() isn't prepared to properly deal with some racy cases properly (e.g., temporary page pinning when exiting processed, PCP)= . Retry 5 times for now. There is certainly room for improvement in the future. Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index a2124892e510..faeb759687fe 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -823,19 +823,34 @@ static void virtio_mem_fake_online(unsigned long pf= n, unsigned long nr_pages) */ static int virtio_mem_fake_offline(unsigned long pfn, unsigned long nr_p= ages) { - int rc; + const bool is_movable =3D zone_idx(page_zone(pfn_to_page(pfn))) =3D=3D + ZONE_MOVABLE; + int rc, retry_count; =20 - rc =3D alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_MOVABLE, - GFP_KERNEL); - if (rc =3D=3D -ENOMEM) - /* whoops, out of memory */ - return rc; - if (rc) - return -EBUSY; + /* + * TODO: We want an alloc_contig_range() mode that tries to allocate + * harder (e.g., dealing with temporarily pinned pages, PCP), especiall= y + * with ZONE_MOVABLE. So for now, retry a couple of times with + * ZONE_MOVABLE before giving up - because that zone is supposed to giv= e + * some guarantees. + */ + for (retry_count =3D 0; retry_count < 5; retry_count++) { + rc =3D alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_MOVABLE, + GFP_KERNEL); + if (rc =3D=3D -ENOMEM) + /* whoops, out of memory */ + return rc; + else if (rc && !is_movable) + break; + else if (rc) + continue; =20 - virtio_mem_set_fake_offline(pfn, nr_pages, true); - adjust_managed_page_count(pfn_to_page(pfn), -nr_pages); - return 0; + virtio_mem_set_fake_offline(pfn, nr_pages, true); + adjust_managed_page_count(pfn_to_page(pfn), -nr_pages); + return 0; + } + + return -EBUSY; } =20 /* --=20 2.26.2