Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3342437ybc; Mon, 18 Nov 2019 13:40:29 -0800 (PST) X-Google-Smtp-Source: APXvYqwtQ2zkY0oOnxhxG6HwwYSWIq3N0XiPvjf87IxsTR86f+x+eJKsFFtHxLuIeuywOI8S+KE6 X-Received: by 2002:a17:906:b310:: with SMTP id n16mr29455823ejz.129.1574113229759; Mon, 18 Nov 2019 13:40:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574113229; cv=none; d=google.com; s=arc-20160816; b=fm8ZIraXAC8dIrm825fCPyo+gEKUFO8GK8bNo2k2ZZlXVXhQBJidKPGUSiuVYoRcfC pC5IEDAsd3uYQnQupMfpNvGZFV0IdyCJogZfJ5+UhrGKLqxKw3VY2L65la5mPNqIsHKL ryO2pK44nG8xH4CKsmtKEBtEeACQHWRG4Jc1SghrlqE1M+c6Rtt9aIXREM7mbWE4g/Kz Y4XkfCylTyXHphpnuzNVAu2u2waSjno5syIslpnZY5D/CZA+GuErb2SHyqLL0DuWa0nA j3GJJdINdvvRfEvQpO4DML/j734PEsWqicV7Mnlsmy/Q3lVYNH2iaK0e6S50c6OtoKpG 61NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=R6Acg+jdFVk2p6ATpns4CDctE+Vl9KUjiRKuJA0ei70=; b=Ab4DOEwgedl11xoYMlwdwClzONGPh6bo98+V/KDET833Bn1gNOQT5pjMm4ph3jlz+s kEVgl+PVuxNHhkAPjkhidIaSzIiR6eLgv0NtakKUn32HURa0nBUpmyjgzgoeGNRgrffw oonXRAfFPs9RXsIth4BWVUlfUWSehmhxUPrPipgDEWk2g8DiSWQ3ZlLGwsDswvk1EM5Q gJkLEP3YmgnhQ+tiCmMshDkYI8jiE4UaT0AXxhKPzNz9UGOnu/Q4Uk+vbH97wg1d79nT CXXeZk75RAeXMmIdfED2qa5n2l/02y+7yUR2ziuO3DwqLNn15Nk+ceT7xz0uNAZ4S9Nb DX3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mHQbdyUx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mh1si12440048ejb.221.2019.11.18.13.40.05; Mon, 18 Nov 2019 13:40:29 -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=@google.com header.s=20161025 header.b=mHQbdyUx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726759AbfKRVi4 (ORCPT + 99 others); Mon, 18 Nov 2019 16:38:56 -0500 Received: from mail-pf1-f201.google.com ([209.85.210.201]:53460 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726272AbfKRVi4 (ORCPT ); Mon, 18 Nov 2019 16:38:56 -0500 Received: by mail-pf1-f201.google.com with SMTP id h2so15058028pfr.20 for ; Mon, 18 Nov 2019 13:38:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=R6Acg+jdFVk2p6ATpns4CDctE+Vl9KUjiRKuJA0ei70=; b=mHQbdyUxygyJYLA0wlaa+9zB0wgMSfjizYY7Yt/bxOii/URTraMMYKMOi84x8Dc7Ax jUWvHgud5iiCZ5eDTOZy3J5xy41uNE7QcX9NPBvr8bxtnrBN07DRP+Ec8bBLHn6TSfNr 0xLSAhr2CEd4V0w4ikqMLjmzslN3UMX7mPOf+QOjTX0s214bpeCRmkF6eM94rb2fqxPu uVdOSYCCLZh09m8phPF5WuKhhq0m4J0HXEkOdakp9HyZ9x3h1tD4/gXi7s3SDoUGgQPe bNQA/3Ln21k+ETpuaGRCro++utWdBc9hnJmXPsCO0HRzLGjz+ZIiFRtpZqRRTXTvN9wN DkJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=R6Acg+jdFVk2p6ATpns4CDctE+Vl9KUjiRKuJA0ei70=; b=hMbID6TwyZOMfI5zvJdYrYMi/XMPMknXhLiLG1kXTcBrP1lMEHX8L4WftC+li4Ppu2 dvB7UU7vFyV01lhms5gvylDhwpWfXcx05HS1Oe1goE7YPrqenHRbopUYcndu6RMTjqpt fVn3rbmbW5VAUb1CNnoHTbOhSS0Ahm+lYA3H3j31owMiaANp1APYNFgipqmAb8JMogGG dVChk8VAG/MDjGS66kRceoMAwmQVIeosF1flteKupvPIlcCTz4r9/mJ+Hs7y2hhwGXHi KwFiDcTbV4Z4JhTxKFhg/2u4inSthbyiUjtlAH6WHJyY6owkhxz7X01DHKBtJkjsZGfm Is/Q== X-Gm-Message-State: APjAAAUm4mZLkUYqR0AASt6yi1+vE83Xr+jpa7br5pHr9UXygCroJTwf HfaV+OEswBw6Excy88g/wHASTsAo1LA= X-Received: by 2002:a65:5683:: with SMTP id v3mr1617900pgs.190.1574113133981; Mon, 18 Nov 2019 13:38:53 -0800 (PST) Date: Mon, 18 Nov 2019 13:38:10 -0800 In-Reply-To: Message-Id: <20191118213811.22017-1-khazhy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog Subject: [PATCH 1/2] virtio_balloon: fix pages_to_free calculation From: Khazhismel Kumykov To: mst@redhat.com, jasowang@redhat.com, wei.w.wang@intel.com Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Khazhismel Kumykov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org freed_pages was accumulating total freed pages, but was also subtracted on each iteration from pages_to_free, which could potentially result in attempting to free fewer pages than asked for. This change also makes both freed_pages and pages_to_free in terms of "balloon pages", where they were mismatched before. Fixes: 71994620bb25 ("virtio_balloon: replace oom notifier with shrinker") Cc: Wei Wang Signed-off-by: Khazhismel Kumykov --- drivers/virtio/virtio_balloon.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 226fbb995fb0..7cf9540a40b8 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -782,11 +782,8 @@ static unsigned long shrink_balloon_pages(struct virtio_balloon *vb, * VIRTIO_BALLOON_ARRAY_PFNS_MAX balloon pages, so we call it * multiple times to deflate pages till reaching pages_to_free. */ - while (vb->num_pages && pages_to_free) { - pages_freed += leak_balloon(vb, pages_to_free) / - VIRTIO_BALLOON_PAGES_PER_PAGE; - pages_to_free -= pages_freed; - } + while (vb->num_pages && pages_to_free > pages_freed) + pages_freed += leak_balloon(vb, pages_to_free - pages_freed); update_balloon_size(vb); return pages_freed; -- 2.24.0.432.g9d3f5f5b63-goog