Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp425983ybc; Tue, 19 Nov 2019 03:41:55 -0800 (PST) X-Google-Smtp-Source: APXvYqzf+bIFiorP+NkMDDOOZ0onUFWutnl5HlZCq9MdGB06ZEgCZrrNWVzEcZH1ENj0C4jzObZe X-Received: by 2002:adf:979a:: with SMTP id s26mr37442217wrb.92.1574163715294; Tue, 19 Nov 2019 03:41:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574163715; cv=none; d=google.com; s=arc-20160816; b=DpGQmF6r/HZPSBtTQ4d7WiekP6nOsFWMo0tgUhgebxWCn7SgAtdSMe5qj0JXL+Q/Br 9jcJkni7CI/1AtJAmYsYhDnETVfLl1wdCaXdtJPjOcXV8z1j1RzYLkmUzsEi+4KA/GYg pu3JJj0DCQLQl2DU0KvrG7kCl/eMPOB4D7UjuDKpLw80XhZvMiCf+8bLa1UNj3cF80Ju j+e68u3al6PotcY8KFfbDS2fPexm8KEEwahvDzltxhAeDpyJLSuT/01xVPiaOyxovu4W 0WtwnRXAg0xfPSCdA61y6xZyW7l7RPRJYwcm4x82mL/J39r8fQReoIa+OOgTYXDChkZU ZjxQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :dkim-signature; bh=XtH9WCU+QMMrjUxeLM+n4es1zZ2p4ixU1bds8G44OHQ=; b=touTUdrBBVyLxWOxkIfWui4s+IVBcCVLxTiyNjpSneV6MgPRaqiJxwttMLJJZ04kya RfQJ+fKtA+ycHYx5Vt3SsaLwN5eNdU7HVdZgIeA2k5UmxrrP17fTvPqEVB7Egw4VgQSh QLbmSUrd3FEweY8lh32Y59af0cdUM2Y5WwPGE0814MCRS8ILCXOCOChryGp8p5+V+sMj kGvOiuh4aQA1G8MSgn3QfOGSCTji2KZx8QjsZsPuYpwfoiqPX0VkJkmlIZ3NuimvA3r1 K0a8HzhphmdLZC1drMO3kXDWq57Xq7pVZ4AQlwhaLU6J3zoACw1heIydVDy27dwpYzbX PpGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ORBe/pc8"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y31si15803893edb.47.2019.11.19.03.41.31; Tue, 19 Nov 2019 03:41:55 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ORBe/pc8"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727884AbfKSLiQ (ORCPT + 99 others); Tue, 19 Nov 2019 06:38:16 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:51071 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727638AbfKSLiQ (ORCPT ); Tue, 19 Nov 2019 06:38:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574163494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XtH9WCU+QMMrjUxeLM+n4es1zZ2p4ixU1bds8G44OHQ=; b=ORBe/pc8j49nWcZ1btMNJxXzTrGrJvkSEEjJaMcCeaOE9/7KzZZ1J3+AMVYO7PLDeqsMNo pcH2IrnMbS3RWdABU+IuxGBh11Xhs26194MyMHFgD6VKf+jVwbFSvJwBhTHblB/gjS3Y1B PfCo/m4DjMfrsIRy5kXoj7saQi99ezE= 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-10-NNck5YUJN6CeOWTDy4tA8g-1; Tue, 19 Nov 2019 06:38:11 -0500 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 35DEB1883523; Tue, 19 Nov 2019 11:38:10 +0000 (UTC) Received: from [10.36.117.126] (ovpn-117-126.ams2.redhat.com [10.36.117.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2755060251; Tue, 19 Nov 2019 11:38:05 +0000 (UTC) Subject: Re: [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts To: "Michael S. Tsirkin" , linux-kernel@vger.kernel.org Cc: Wei Wang , Khazhismel Kumykov , Jason Wang , virtualization@lists.linux-foundation.org References: <20191119102838.39380-1-mst@redhat.com> <20191119102838.39380-2-mst@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <328b00e2-d2ac-7efb-a3d9-a6e9933d85a8@redhat.com> Date: Tue, 19 Nov 2019 12:38:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <20191119102838.39380-2-mst@redhat.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: NNck5YUJN6CeOWTDy4tA8g-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19.11.19 11:29, 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. >=20 > Signed-off-by: Michael S. Tsirkin > --- > drivers/virtio/virtio_balloon.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) >=20 > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_ball= oon.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 \ > =09(1 << (VIRTIO_BALLOON_HINT_BLOCK_ORDER + PAGE_SHIFT)) > +#define VIRTIO_BALLOON_HINT_BLOCK_PAGES (1 << VIRTIO_BALLOON_HINT_BLOCK_= ORDER) > =20 > #ifdef CONFIG_BALLOON_COMPACTION > static struct vfsmount *balloon_mnt; > @@ -765,11 +766,11 @@ static unsigned long shrink_free_pages(struct virti= o_balloon *vb, > =09unsigned long blocks_to_free, blocks_freed; > =20 > =09pages_to_free =3D round_up(pages_to_free, > -=09=09=09=09 1 << VIRTIO_BALLOON_HINT_BLOCK_ORDER); > -=09blocks_to_free =3D pages_to_free >> VIRTIO_BALLOON_HINT_BLOCK_ORDER; > +=09=09=09=09 VIRTIO_BALLOON_HINT_BLOCK_PAGES); > +=09blocks_to_free =3D pages_to_free / VIRTIO_BALLOON_HINT_BLOCK_PAGES; > =09blocks_freed =3D return_free_pages_to_mm(vb, blocks_to_free); > =20 > -=09return blocks_freed << VIRTIO_BALLOON_HINT_BLOCK_ORDER; > +=09return blocks_freed * VIRTIO_BALLOON_HINT_BLOCK_PAGES; > } > =20 > static unsigned long leak_balloon_pages(struct virtio_balloon *vb, > @@ -825,7 +826,7 @@ static unsigned long virtio_balloon_shrinker_count(st= ruct shrinker *shrinker, > =09unsigned long count; > =20 > =09count =3D vb->num_pages / VIRTIO_BALLOON_PAGES_PER_PAGE; > -=09count +=3D vb->num_free_page_blocks << VIRTIO_BALLOON_HINT_BLOCK_ORDE= R; > +=09count +=3D vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES= ; > =20 > =09return count; > } >=20 Reviewed-by: David Hildenbrand --=20 Thanks, David / dhildenb