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=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 8F54AC433DB for ; Wed, 6 Jan 2021 03:51:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3B75D22D04 for ; Wed, 6 Jan 2021 03:51:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B75D22D04 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A58B28D00E3; Tue, 5 Jan 2021 22:51:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A08698D0090; Tue, 5 Jan 2021 22:51:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91E538D00E3; Tue, 5 Jan 2021 22:51:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id 7D1468D0090 for ; Tue, 5 Jan 2021 22:51:18 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4CF911EFF for ; Wed, 6 Jan 2021 03:51:18 +0000 (UTC) X-FDA: 77673975036.16.rock98_4c03557274de Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 29D92100E6903 for ; Wed, 6 Jan 2021 03:51:18 +0000 (UTC) X-HE-Tag: rock98_4c03557274de X-Filterd-Recvd-Size: 9139 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 03:51:17 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id c79so966523pfc.2 for ; Tue, 05 Jan 2021 19:51:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=eXrpMrj6YvsHKIRK9+LKKpoAFDK39SfbfHOXlypYzcY=; b=RvvSRBJL76JHBWv5Iuo5pbFPOkCRGhaqksMZdVAk3yc+voMyPuThBYLQuC1WqBWUet lDoluuYk8qyNnjbsrHBvLEm+r5ZN2NVlldQ0fPVErO5yiDlMCmPqjGCmqn9tdrpDLA1x q93rHGhvbSgH3HGS153bt7sjg5jfKMevbILEiujQKrjlFIw3GWYRTCRimjHBDGQwhNEP agCrtdxYbNowovcXKfSJ5JeVo3g91u/xu6Id0QxxYfihGyldf9ZujfBdQogUtcHYilXo FT9MrM86wlMFkA6n+jzSXjxlnEw74t2HBwgtaQzicWSZNenH4RXpPr8pU0RMB+7h1eQJ T5pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id :mail-followup-to:mime-version:content-disposition:user-agent; bh=eXrpMrj6YvsHKIRK9+LKKpoAFDK39SfbfHOXlypYzcY=; b=nOH7SHUr32U7oCgSCvzoiLnwEB0m1WrMzYNhjNZtG/fMjdhg6VirNyPB64eVyiYtjf TsDDIDxl6PUr/11qtj9HXQAhrG4ssT3J65MmfQsEjTVbm7CNilCBUYLC2t9rvZPCWcLR ZdY4/t1wkyauq3kGd+JN6QfXi1VlY1WcONk582SFM+e5w5FkYqSJ8fpQXMObRC9Vdyz/ cilcjwVM+oR56jEWThL/Zu9qxnFrCV60PBme35v3gIFgVh43lEne4//00J3sDnABTGBS BmQ0WNIEwlU7YkWjQoHZd+cMyeioDBK2pefDbSABSWQDkjm4r6SOKlJ387MDcAhoQxDN hnng== X-Gm-Message-State: AOAM532Iu6kbH6qQWbyWZNYSJE8cdeCZW11pw8gaH1EHyTOAWt8S7swA P2+4qEvGEbwvgp1E8qdCnh8= X-Google-Smtp-Source: ABdhPJxZms0h1r8psnB+l/5ZJpMwdThWyheWb4JvpjFTF2mk3Cpuyqqc/D0VsAYWKcTPmp6zF3+k1g== X-Received: by 2002:aa7:96c9:0:b029:1a3:c274:f717 with SMTP id h9-20020aa796c90000b02901a3c274f717mr2214501pfq.38.1609905076918; Tue, 05 Jan 2021 19:51:16 -0800 (PST) Received: from open-light-1.localdomain (66.98.113.28.16clouds.com. [66.98.113.28]) by smtp.gmail.com with ESMTPSA id g75sm743323pfb.2.2021.01.05.19.51.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jan 2021 19:51:16 -0800 (PST) From: Liang Li X-Google-Original-From: Liang Li Date: Tue, 5 Jan 2021 22:51:13 -0500 To: Alexander Duyck , Mel Gorman , Andrew Morton , Andrea Arcangeli , Dan Williams , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Dave Hansen , Michal Hocko , Liang Li , Liang Li , Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 5/6] virtio-balloon: reporting hugetlb free page to host Message-ID: <20210106035110.GA1170@open-light-1.localdomain> Mail-Followup-To: Alexander Duyck , Mel Gorman , Andrew Morton , Andrea Arcangeli , Dan Williams , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Dave Hansen , Michal Hocko , Liang Li , Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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: Free page reporting only supports buddy pages, it can't report the free pages reserved for hugetlbfs case. On the other hand, hugetlbfs is a good choice for a system with a huge amount of RAM, because it can help to reduce the memory management overhead and improve system performance. This patch add support for reporting free hugepage to host when guest use hugetlbfs. Cc: Alexander Duyck Cc: Mel Gorman Cc: Andrea Arcangeli Cc: Dan Williams Cc: Dave Hansen Cc: David Hildenbrand Cc: Michal Hocko Cc: Andrew Morton Cc: Alex Williamson Cc: Michael S. Tsirkin Cc: Liang Li Signed-off-by: Liang Li --- drivers/virtio/virtio_balloon.c | 55 +++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 684bcc39ef5a..7bd7fcacee8c 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -126,6 +126,10 @@ struct virtio_balloon { /* Free page reporting device */ struct virtqueue *reporting_vq; struct page_reporting_dev_info pr_dev_info; + + /* Free hugepage reporting device */ + struct page_reporting_dev_info hpr_dev_info; + struct mutex mtx_report; }; static const struct virtio_device_id id_table[] = { @@ -173,6 +177,38 @@ static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_i struct virtqueue *vq = vb->reporting_vq; unsigned int unused, err; + mutex_lock(&vb->mtx_report); + /* We should always be able to add these buffers to an empty queue. */ + err = virtqueue_add_inbuf(vq, sg, nents, vb, GFP_NOWAIT | __GFP_NOWARN); + + /* + * In the extremely unlikely case that something has occurred and we + * are able to trigger an error we will simply display a warning + * and exit without actually processing the pages. + */ + if (WARN_ON_ONCE(err)) { + mutex_unlock(&vb->mtx_report); + return err; + } + + virtqueue_kick(vq); + + /* When host has read buffer, this completes via balloon_ack */ + wait_event(vb->acked, virtqueue_get_buf(vq, &unused)); + mutex_unlock(&vb->mtx_report); + + return 0; +} + +static int virtballoon_free_hugepage_report(struct page_reporting_dev_info *hpr_dev_info, + struct scatterlist *sg, unsigned int nents) +{ + struct virtio_balloon *vb = + container_of(hpr_dev_info, struct virtio_balloon, hpr_dev_info); + struct virtqueue *vq = vb->reporting_vq; + unsigned int unused, err; + + mutex_lock(&vb->mtx_report); /* We should always be able to add these buffers to an empty queue. */ err = virtqueue_add_inbuf(vq, sg, nents, vb, GFP_NOWAIT | __GFP_NOWARN); @@ -181,13 +217,16 @@ static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_i * are able to trigger an error we will simply display a warning * and exit without actually processing the pages. */ - if (WARN_ON_ONCE(err)) + if (WARN_ON_ONCE(err)) { + mutex_unlock(&vb->mtx_report); return err; + } virtqueue_kick(vq); /* When host has read buffer, this completes via balloon_ack */ wait_event(vb->acked, virtqueue_get_buf(vq, &unused)); + mutex_unlock(&vb->mtx_report); return 0; } @@ -984,9 +1023,11 @@ static int virtballoon_probe(struct virtio_device *vdev) } vb->pr_dev_info.report = virtballoon_free_page_report; + vb->hpr_dev_info.report = virtballoon_free_hugepage_report; if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) { unsigned int capacity; + mutex_init(&vb->mtx_report); capacity = virtqueue_get_vring_size(vb->reporting_vq); if (capacity < PAGE_REPORTING_CAPACITY) { err = -ENOSPC; @@ -999,6 +1040,14 @@ static int virtballoon_probe(struct virtio_device *vdev) err = page_reporting_register(&vb->pr_dev_info); if (err) goto out_unregister_oom; + + vb->hpr_dev_info.mini_order = MAX_ORDER - 1; + vb->hpr_dev_info.batch_size = 16 * 1024 * 1024; /* 16M */ + vb->hpr_dev_info.delay_jiffies = 2 * HZ; /* 2 seconds */ + err = hugepage_reporting_register(&vb->hpr_dev_info); + if (err) + goto out_unregister_oom; + } virtio_device_ready(vdev); @@ -1051,8 +1100,10 @@ static void virtballoon_remove(struct virtio_device *vdev) { struct virtio_balloon *vb = vdev->priv; - if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) { page_reporting_unregister(&vb->pr_dev_info); + hugepage_reporting_unregister(&vb->hpr_dev_info); + } if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) unregister_oom_notifier(&vb->oom_nb); if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) -- 2.18.2