Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp902449ybh; Wed, 15 Jul 2020 19:43:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO1aCgA9bjh3qPgcYFp+mYRTEvz9GXcIQ2oNuG6B+opNOHnb1cjuNcKdT5subjOyi76wYZ X-Received: by 2002:aa7:d142:: with SMTP id r2mr2339124edo.211.1594867385466; Wed, 15 Jul 2020 19:43:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594867385; cv=none; d=google.com; s=arc-20160816; b=W/AcfTHJcSdgTisZPzU9JFRNUijiinTOSiTJirVsBIdkLSMhig6QjFIl/j4T5zWCSj z+GwkBPlJp3utDd8R4E+bNDRbP+eSg82YKYL2PQ8RNiqiP4W3SynvhSQWnCxYm3SnT80 h/i99tyLl+Q5ZH8dCjAuc4GmnEQ197n8H8Oyj6KP7hd6wqu8hzMJDWPGhZP9B34+nY/Z eVyCS8SMD2jyvhlEIjDA4b95eU36dAMmt5vMFOayD3X3/1CrFSb4Yfdd7aYN3mYBu0bH ca76XCU4byw0/gvSLEwjTPqLpRQ+DXdNdF3nN/pcOhKI+XHFUEFkaBISmviVd1OwS7YK H4gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=hxc/5rK77CddEGjrnXT+c2v7vD6n9l4HKPA9Q/ucGH8=; b=S8+nmWV/VDEs5MiJIC/QqJgbv4qS/d8I8S0xcOePJmF3wKrBysMSMlNj1dFM71TGlu AkuPa8eLgWT0TN+zxEus/IFTPYP67McHdWEYv9jVhbyvGIeGmGY4v1XgGuJpd8PdmeHn acwo2B01RQ/mBACKJRblUrtZMmHi1FyrR91uw1dVZ44eWuH9onmltp/i25fTSd7fJYAg lsR1lHBWskzgrfu3CYMTyJUIMX1AoNOJNvToEzsI62HC49e8juuzySEzxjIwC0ZGZaPJ mGWaZFMplpckcJPtZC06WSSAx2ctMEbJi+EIYZngZCAlW1wbU5L1e9JT7o3hTXcnEVAO B0uA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x6si2270786edr.185.2020.07.15.19.42.42; Wed, 15 Jul 2020 19:43:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727768AbgGPCmP (ORCPT + 99 others); Wed, 15 Jul 2020 22:42:15 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:47743 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727105AbgGPCmP (ORCPT ); Wed, 15 Jul 2020 22:42:15 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01419;MF=teawaterz@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0U2rEMt5_1594867319; Received: from localhost(mailfrom:teawaterz@linux.alibaba.com fp:SMTPD_---0U2rEMt5_1594867319) by smtp.aliyun-inc.com(127.0.0.1); Thu, 16 Jul 2020 10:42:09 +0800 From: Hui Zhu To: mst@redhat.com, david@redhat.com, jasowang@redhat.com, akpm@linux-foundation.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org Cc: Hui Zhu Subject: [RFC for Linux v4 0/2] virtio_balloon: Add VIRTIO_BALLOON_F_CONT_PAGES to report continuous pages Date: Thu, 16 Jul 2020 10:41:50 +0800 Message-Id: <1594867315-8626-1-git-send-email-teawater@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The first, second and third version are in [1], [2] and [3]. Code of current version for Linux and qemu is available in [4] and [5]. Update of this version: 1. Report continuous pages will increase the speed. So added deflate continuous pages. 2. According to the comments from David in [6], added 2 new vqs inflate_cont_vq and deflate_cont_vq to report continuous pages with format 32 bits pfn and 32 bits size. Following is the introduction of the function. These patches add VIRTIO_BALLOON_F_CONT_PAGES to virtio_balloon. With this flag, balloon tries to use continuous pages to inflate and deflate. Opening this flag can bring two benefits: 1. Report continuous pages will increase memory report size of each time call tell_host. Then it will increase the speed of balloon inflate and deflate. 2. Host THPs will be splitted when qemu release the page of balloon inflate. Inflate balloon with continuous pages will let QEMU release the pages of same THPs. That will help decrease the splitted THPs number in the host. Following is an example in a VM with 1G memory 1CPU. This test setups an environment that has a lot of fragmentation pages. Then inflate balloon will split the THPs. // This is the THP number before VM execution in the host. // None use THP. cat /proc/meminfo | grep AnonHugePages: AnonHugePages: 0 kB // After VM start, use usemem // (https://git.kernel.org/pub/scm/linux/kernel/git/wfg/vm-scalability.git) // punch-holes function generates 400m fragmentation pages in the guest // kernel. usemem --punch-holes -s -1 800m & // This is the THP number after this command in the host. // Some THP is used by VM because usemem will access 800M memory // in the guest. cat /proc/meminfo | grep AnonHugePages: AnonHugePages: 911360 kB // Connect to the QEMU monitor, setup balloon, and set it size to 600M. (qemu) device_add virtio-balloon-pci,id=balloon1 (qemu) info balloon balloon: actual=1024 (qemu) balloon 600 (qemu) info balloon balloon: actual=600 // This is the THP number after inflate the balloon in the host. cat /proc/meminfo | grep AnonHugePages: AnonHugePages: 88064 kB // Set the size back to 1024M in the QEMU monitor. (qemu) balloon 1024 (qemu) info balloon balloon: actual=1024 // Use usemem to increase the memory usage of QEMU. killall usemem usemem 800m // This is the THP number after this operation. cat /proc/meminfo | grep AnonHugePages: AnonHugePages: 65536 kB Following example change to use continuous pages balloon. The number of splitted THPs is decreased. // This is the THP number before VM execution in the host. // None use THP. cat /proc/meminfo | grep AnonHugePages: AnonHugePages: 0 kB // After VM start, use usemem punch-holes function generates 400M // fragmentation pages in the guest kernel. usemem --punch-holes -s -1 800m & // This is the THP number after this command in the host. // Some THP is used by VM because usemem will access 800M memory // in the guest. cat /proc/meminfo | grep AnonHugePages: AnonHugePages: 911360 kB // Connect to the QEMU monitor, setup balloon, and set it size to 600M. (qemu) device_add virtio-balloon-pci,id=balloon1,cont-pages=on (qemu) info balloon balloon: actual=1024 (qemu) balloon 600 (qemu) info balloon balloon: actual=600 // This is the THP number after inflate the balloon in the host. cat /proc/meminfo | grep AnonHugePages: AnonHugePages: 616448 kB // Set the size back to 1024M in the QEMU monitor. (qemu) balloon 1024 (qemu) info balloon balloon: actual=1024 // Use usemem to increase the memory usage of QEMU. killall usemem usemem 800m // This is the THP number after this operation. cat /proc/meminfo | grep AnonHugePages: AnonHugePages: 907264 kB [1] https://lkml.org/lkml/2020/3/12/144 [2] https://lore.kernel.org/linux-mm/1584893097-12317-1-git-send-email-teawater@gmail.com/ [3] https://lkml.org/lkml/2020/5/12/324 [4] https://github.com/teawater/linux/tree/balloon_conts [5] https://github.com/teawater/qemu/tree/balloon_conts [6] https://lkml.org/lkml/2020/5/13/1211 Hui Zhu (2): virtio_balloon: Add VIRTIO_BALLOON_F_CONT_PAGES and inflate_cont_vq virtio_balloon: Add deflate_cont_vq to deflate continuous pages drivers/virtio/virtio_balloon.c | 180 +++++++++++++++++++++++++++++++----- include/linux/balloon_compaction.h | 12 ++ include/uapi/linux/virtio_balloon.h | 1 mm/balloon_compaction.c | 117 +++++++++++++++++++++-- 4 files changed, 280 insertions(+), 30 deletions(-)