Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp466144ybc; Tue, 19 Nov 2019 04:19:42 -0800 (PST) X-Google-Smtp-Source: APXvYqxS5JnHGv0UzOH8oXRERBgGmIyX6O0TZ3x+0cnAB/muRWPiSNfDatZu7FPh3YQ2AYwK6PXg X-Received: by 2002:a7b:c776:: with SMTP id x22mr5095836wmk.144.1574165982690; Tue, 19 Nov 2019 04:19:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574165982; cv=none; d=google.com; s=arc-20160816; b=mwliypMW6BolZXM92lBRjt2nh+3/FdOftFuJ3xcVG3cfjSqTkgkYKU3g+fAP7yuUlr OTGQJtdUYp6Bnk5J1i6OieXn/SpRG8kJ1PGbxr87hfzGoik3aGIjRRMoKAQFcsympIZW tOw190u1VUH+n8eybmWO/z0T354HnhQwxBQIk+hqY9ooJ+9tKZlmwS+NR1RZb7wnFkMH c4lxOEqolpuP3uf5IKkDD3MAhQe2zj2ecb4AC+oDRXJmCEkK0yZ9AElTbUm1rYLcWHQt 45ZdeYjazhkmoUyJokEVJmLPAVST61CU0xNgVY4D651bCdySqRwg3l7WnZ+MLmL6ND1J B0Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id; bh=PSHTvvbqQ9E0In0y0J0C3UXZovX7te2eGXqB4R+62qI=; b=k9aGzHDRB7V4mQjO61y26AKP7RQ8tyudYLvLE5vHi9+f1KiaPjtbi1+EAGYbYEwL2m eV4FsnrGEN4EkIXHQet5Qfwhd1fPE4XmO++Mz9WNevXRA05qeGxZTGB6fKgsKAYGEFRz LwM5D7csi31Ta/4JNyJpheqFGRoj4EoVmvr/DytHwbseGyFBmt4GNVVp1VKkf/SOMXcr 7xZJ1JVpD8KAE8ePn3NnAJCIjJLY0J9OyjzzoJXPAa55DXFnCZqH1y1LENxWih8vCylo StoaTO1d8otyi8BqrmM/O3rfTe22c5Yu0qpuDOXcjsHDaF1H3GQ5UHzSdedAHdAu10np WrLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si16856161edm.231.2019.11.19.04.19.18; Tue, 19 Nov 2019 04:19:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727797AbfKSMSI (ORCPT + 99 others); Tue, 19 Nov 2019 07:18:08 -0500 Received: from mga05.intel.com ([192.55.52.43]:64330 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725280AbfKSMSI (ORCPT ); Tue, 19 Nov 2019 07:18:08 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Nov 2019 04:18:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,322,1569308400"; d="scan'208";a="209179842" Received: from unknown (HELO [10.239.13.7]) ([10.239.13.7]) by orsmga003.jf.intel.com with ESMTP; 19 Nov 2019 04:18:06 -0800 Message-ID: <5DD3DF17.9050504@intel.com> Date: Tue, 19 Nov 2019 20:24:55 +0800 From: Wei Wang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "Michael S. Tsirkin" , linux-kernel@vger.kernel.org CC: Khazhismel Kumykov , Jason Wang , virtualization@lists.linux-foundation.org Subject: Re: [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts References: <20191119102838.39380-1-mst@redhat.com> <20191119102838.39380-2-mst@redhat.com> In-Reply-To: <20191119102838.39380-2-mst@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/19/2019 06:29 PM, Michael S. Tsirkin wrote: > We managed to get confused about the shift direction at least once. > Let's switch to division/multiplcation instead. Add a number of pages > macro for this purpose. We still keep the order macro around too since > this is what alloc/free pages want. > > Signed-off-by: Michael S. Tsirkin > --- > drivers/virtio/virtio_balloon.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c > index b6a95cd28d9f..dc1ebd638e9b 100644 > --- a/drivers/virtio/virtio_balloon.c > +++ b/drivers/virtio/virtio_balloon.c > @@ -36,6 +36,7 @@ > /* The size of a free page block in bytes */ > #define VIRTIO_BALLOON_HINT_BLOCK_BYTES \ > (1 << (VIRTIO_BALLOON_HINT_BLOCK_ORDER + PAGE_SHIFT)) > +#define VIRTIO_BALLOON_HINT_BLOCK_PAGES (1 << VIRTIO_BALLOON_HINT_BLOCK_ORDER) > > #ifdef CONFIG_BALLOON_COMPACTION > static struct vfsmount *balloon_mnt; > @@ -765,11 +766,11 @@ static unsigned long shrink_free_pages(struct virtio_balloon *vb, > unsigned long blocks_to_free, blocks_freed; > > pages_to_free = round_up(pages_to_free, > - 1 << VIRTIO_BALLOON_HINT_BLOCK_ORDER); > - blocks_to_free = pages_to_free >> VIRTIO_BALLOON_HINT_BLOCK_ORDER; > + VIRTIO_BALLOON_HINT_BLOCK_PAGES); > + blocks_to_free = pages_to_free / VIRTIO_BALLOON_HINT_BLOCK_PAGES; > blocks_freed = return_free_pages_to_mm(vb, blocks_to_free); > > - return blocks_freed << VIRTIO_BALLOON_HINT_BLOCK_ORDER; > + return blocks_freed * VIRTIO_BALLOON_HINT_BLOCK_PAGES; > } > > static unsigned long leak_balloon_pages(struct virtio_balloon *vb, > @@ -825,7 +826,7 @@ static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrinker, > unsigned long count; > > count = vb->num_pages / VIRTIO_BALLOON_PAGES_PER_PAGE; > - count += vb->num_free_page_blocks << VIRTIO_BALLOON_HINT_BLOCK_ORDER; > + count += vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES; > > return count; > } Reviewed-by: Wei Wang Best, Wei