Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp356106ybc; Tue, 19 Nov 2019 02:31:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwV1JkSyoOnZ72AX7tXtjwe9vmHNy2HdAJPg70cfZACFqo/znRbwll6O1EctbZ7HlXmRnAK X-Received: by 2002:a17:906:f24d:: with SMTP id gy13mr33958000ejb.159.1574159472425; Tue, 19 Nov 2019 02:31:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574159472; cv=none; d=google.com; s=arc-20160816; b=fk5IgoQIml6CxXW12w3TWdqtG5ZAUlCDrO6NSvpM492yZuA+rggj6B+Bimiaro509g MSAYhzsN/olYktt2he05l6v+TyXdwCK3V6ORbKYhQjls6uMm45saEUFDKBuhQ9O+h5/D fOi102G21V9Z/r2pT4hBPKCC10BH0Gp1ll34P5HLnyFTohOMrX5uGO6+1Y8OLDdSBjhu Lt+8m4MFHy4icEN9QNafeFyTmCZgHe5Bo1vdRmN4n3v/ZboyEiufrW8EITG1TLyvl4Nk KE94lwSIHCFbsKGgcJpubIwQ2WQe8pDJZH5wmiiS8o8lqZZxFUvSQQW/JdREsvD1Rxqj 3TBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:in-reply-to:mime-version:references :message-id:subject:cc:to:from:date:dkim-signature; bh=77amoXDxo8ofz+4ayGx8uiP5lWMJfYYOQ/k+hO5dXpA=; b=pot3Q/nR4l2urb88lcGeLPz9CdzRE+H5JVlxCg1T+bHzrDJlLCEF1jsKhy/Ox2O/V4 tvQbQMRPasQhn6sDinPdCdk1uxg8NbxezRg41z9ugfpoTSEvjjbIj93ZYKgv1wlSiyxn 5JlsH2/B+WjYhgXeS5KcS7h6TpmfTpQCw5ueSxq16XQabG/PSQ5k//INAppRxTe9Oxdt kG0rx40soHc1MRG2d9Vd9e0pSu3Se1mRGb7rqgSlzEJkzWXy5yGqUX8R8Jk/XTxTtaTS DeUG+iAypqY9JG/58xnfo0yK1OI2fYnCW0sAZBClsxng0x8yhmxnsv8/0gDusuR0eD5f vcdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CTaweVDN; 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 f2si13793935ejd.369.2019.11.19.02.30.48; Tue, 19 Nov 2019 02:31:12 -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=CTaweVDN; 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 S1727372AbfKSK3k (ORCPT + 99 others); Tue, 19 Nov 2019 05:29:40 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:55816 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725798AbfKSK3j (ORCPT ); Tue, 19 Nov 2019 05:29:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574159378; 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=77amoXDxo8ofz+4ayGx8uiP5lWMJfYYOQ/k+hO5dXpA=; b=CTaweVDNvdcygOtIZ6x90agqgt39ZvpLSByq9H9GIw78IWyEDhRnsM2R4+F8yRBEXbTMt1 4HUtYjZ1Dx+4kfda1uTLk7Y42pwZ3jcJimLmyePI7z1Ll6VZtS9I4EhuwAaF0KPUHusNtD AanEDnHCpOgLXx0hZFKTB5sIzcfM4Hk= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-74-hhj45PCUOXyHnjMS93OjHA-1; Tue, 19 Nov 2019 05:29:37 -0500 Received: by mail-qt1-f197.google.com with SMTP id v92so14290020qtd.18 for ; Tue, 19 Nov 2019 02:29:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7Tg+D+F/fAw3zm3TLDKDFrbW/cPHm7unwaXfVwzos8E=; b=Kp9Rpfksl9BX2k2LQ9F+3eoX1L5R6JTpUN8FyiBvDWI9pVuYlj9Aavd4pziso7U7gv 5Z929ny8WyfaBwdizTPARtWW4yDapJ7d74bCQu6066/Q9qArWdNT7xbT3MkXtDFi8slX 3XRELRh/eUARd1KVqsXehrLarQs6H9SX33nUO/++uhuTcARHhEV6FONXuo42K8lul43q hhfsGEPNPk3gk30kVJZr2hAFGkxLp7+6QyxqFunkaX7sJfiztGJBkuH/7PDS2q3JApme E/6YyKwVnx0APVikVuWy0EaJjIIO9nAON4D0cX8ojESWBckBu4mt1r1yP/v3ZhMSZ32l 4zvA== X-Gm-Message-State: APjAAAUFwfW/LlNm2mDb9rphcJHHtJasL95fGeKH1lm7eMJ4Kddw5cH2 uKSfXaHDAih3TVSqqo288MdsDHxULD1jkI5QG8EybLwAR2QT2DTlSBQ5yNVWIuXl5gbDYBugNef S6SmiijabAmm9n1qOnPVJimuQ X-Received: by 2002:ac8:6f7c:: with SMTP id u28mr31779263qtv.273.1574159376666; Tue, 19 Nov 2019 02:29:36 -0800 (PST) X-Received: by 2002:ac8:6f7c:: with SMTP id u28mr31779255qtv.273.1574159376524; Tue, 19 Nov 2019 02:29:36 -0800 (PST) Received: from redhat.com (bzq-79-176-6-42.red.bezeqint.net. [79.176.6.42]) by smtp.gmail.com with ESMTPSA id m65sm11670564qte.54.2019.11.19.02.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2019 02:29:35 -0800 (PST) Date: Tue, 19 Nov 2019 05:29:31 -0500 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Wei Wang , Khazhismel Kumykov , Jason Wang , virtualization@lists.linux-foundation.org Subject: [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts Message-ID: <20191119102838.39380-2-mst@redhat.com> References: <20191119102838.39380-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20191119102838.39380-1-mst@redhat.com> X-Mailer: git-send-email 2.22.0.678.g13338e74b8 X-Mutt-Fcc: =sent X-MC-Unique: hhj45PCUOXyHnjMS93OjHA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_balloo= n.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_OR= DER) =20 #ifdef CONFIG_BALLOON_COMPACTION static struct vfsmount *balloon_mnt; @@ -765,11 +766,11 @@ static unsigned long shrink_free_pages(struct virtio_= 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(stru= ct 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_ORDER; +=09count +=3D vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES; =20 =09return count; } --=20 MST