Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3626131ybv; Sun, 16 Feb 2020 01:48:32 -0800 (PST) X-Google-Smtp-Source: APXvYqzSqZ5pq3VNCgsq3fEE9C/4oREaQAvyPiDca7W2PH15SRHaFIltr8rjE9jR55mRyX34EL2L X-Received: by 2002:aca:458:: with SMTP id 85mr7049213oie.56.1581846512177; Sun, 16 Feb 2020 01:48:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581846512; cv=none; d=google.com; s=arc-20160816; b=NeHAcBLv1PxlauguiA1DrgcoOGi025w7EXNfX38itXFvbwZgg75Vn/Vr6BOCFqZMSq bTNnWIuZxeplQ3CVcL0GCvpwe2LHSETT0slmPYboir7+wdDFxQfDenUmx4Fac0kdX1wu 4UIrw43Co7Qh43MjlN0IXfOKJpAFIQ9tYUmqY9ro0L014hgazGaNDocCgWEMrGP1v+8z q/WXn/WCj8vtd852kF3ufuaP1HQd05cmGvKz9qGXOvSF5IX7Prcpz08Mwi1tymFuojHW yhzxNH9qnPzNrKrpokhpDypqLixF+uf71Zdjq1lXX4ntQU+DETS33zfP7gbkJ4RXXrvk Xr2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=3c/WN0m/fSra0TkxvPfDqbPdSXCm+vdA6iOX3UjbCRY=; b=nxYVujKxGEtoa9EUFzreWzM37Wv1zzF1wY+geCAWhpNhjFHweofNAZLN6yspeuFcVM zHwJRxtkfsyLGpprtrBUi0tl1eCAuwQdqtfnw8IFVD/6KR048YLN/40O/ZDYmD95bMTs wd3eBxckahheLLD/67Zx+TdSm6t2IKASf1qpH5RKAaJilZeVscRHZy3JN4bf8AmILWNe FDLvmKLb+JaXAx9tBL6UvuqavOW1u2dWNXxu1E6pxjoK/ZV3raTVaTpWqaKEjsCTEoPn slxAfZJnU+a6kIlrsOYtVTIpzfVEQgmz+fNDHFqN1IUIYP23x5e2CBMpEef58SgNtZwt TLPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Yn1MoOVE; 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 m9si4941422oie.148.2020.02.16.01.48.20; Sun, 16 Feb 2020 01:48:32 -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=Yn1MoOVE; 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 S1726787AbgBPJrW (ORCPT + 99 others); Sun, 16 Feb 2020 04:47:22 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:34098 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725951AbgBPJrW (ORCPT ); Sun, 16 Feb 2020 04:47:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581846440; 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: in-reply-to:in-reply-to:references:references; bh=3c/WN0m/fSra0TkxvPfDqbPdSXCm+vdA6iOX3UjbCRY=; b=Yn1MoOVEGr6lVgT10N4xC6zcG6vNX4qoE0zBN0BFOXdLdqlea5y/Gt94sHPaKYHGbICTlX +60ENbVL1ZOT96+YamgIC4q0mCxKf/sZ9tatB5uVwC28llZFsT5OqvXA4NQ0Ql41l0BrYd zMFlClwjzrA5LeoaOHR9jiWABhvJBZE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-sK3vVnVOPRuUBoSzVRjcjA-1; Sun, 16 Feb 2020 04:47:17 -0500 X-MC-Unique: sK3vVnVOPRuUBoSzVRjcjA-1 Received: by mail-wr1-f71.google.com with SMTP id a12so7059633wrn.19 for ; Sun, 16 Feb 2020 01:47:16 -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=3c/WN0m/fSra0TkxvPfDqbPdSXCm+vdA6iOX3UjbCRY=; b=grJZIng1JtA0PBmgagvc2zux2YJ5kjtqPc6VEASnJC9OYPUii9IDrz8mxkhkOkVzh/ iyGsSSRI7kie3GXcYMf8VqSmS65SUaX3kXfhF+rhn51meNZZqKiUi9p63vRXK9z0ysNh ADl681nf5sJVE3PVYCBuciqa2Mj3JA7o6Jk+3LfBHhHLAxM5Xmh7E3k5XWFUChzeGT9L 6qrrOeAG9/hMFWJHkocyhaJN0qtnLfrkF52mfRy9Oj03FGwTBC3Huy9Mo1SZ6Xn523p3 F2NRRhShNU6FB4IYyaQgffRH9pt6LMTvaUAmasLdWDMGGgKE8RJoHuziUcZd+VMBb8js iW9Q== X-Gm-Message-State: APjAAAW6YZoZDl3d3VXHXecy28mC1N/fZJckAqPBdCUBer+T7LQJ7Sre NAbtNj8t8u/kZ3ivo1+cR6E6xQdbgtKT0Aq1nlaIU10wZ2e0tYYJx36qUNWzA7xA4w4Um8Quje1 4Ns8cuBklg2gp7nf1Hm+ILELC X-Received: by 2002:adf:81c2:: with SMTP id 60mr14899128wra.8.1581846435945; Sun, 16 Feb 2020 01:47:15 -0800 (PST) X-Received: by 2002:adf:81c2:: with SMTP id 60mr14899111wra.8.1581846435739; Sun, 16 Feb 2020 01:47:15 -0800 (PST) Received: from redhat.com (bzq-79-176-28-95.red.bezeqint.net. [79.176.28.95]) by smtp.gmail.com with ESMTPSA id a16sm14989900wrx.87.2020.02.16.01.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2020 01:47:15 -0800 (PST) Date: Sun, 16 Feb 2020 04:47:12 -0500 From: "Michael S. Tsirkin" To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Tyler Sanderson , Wei Wang , Alexander Duyck , David Rientjes , Nadav Amit , Michal Hocko Subject: Re: [PATCH v1 3/3] virtio-balloon: Switch back to OOM handler for VIRTIO_BALLOON_F_DEFLATE_ON_OOM Message-ID: <20200216044641-mutt-send-email-mst@kernel.org> References: <20200205163402.42627-1-david@redhat.com> <20200205163402.42627-4-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 14, 2020 at 10:51:43AM +0100, David Hildenbrand wrote: > On 05.02.20 17:34, David Hildenbrand wrote: > > Commit 71994620bb25 ("virtio_balloon: replace oom notifier with shrinker") > > changed the behavior when deflation happens automatically. Instead of > > deflating when called by the OOM handler, the shrinker is used. > > > > However, the balloon is not simply some slab cache that should be > > shrunk when under memory pressure. The shrinker does not have a concept of > > priorities, so this behavior cannot be configured. > > > > There was a report that this results in undesired side effects when > > inflating the balloon to shrink the page cache. [1] > > "When inflating the balloon against page cache (i.e. no free memory > > remains) vmscan.c will both shrink page cache, but also invoke the > > shrinkers -- including the balloon's shrinker. So the balloon > > driver allocates memory which requires reclaim, vmscan gets this > > memory by shrinking the balloon, and then the driver adds the > > memory back to the balloon. Basically a busy no-op." > > > > The name "deflate on OOM" makes it pretty clear when deflation should > > happen - after other approaches to reclaim memory failed, not while > > reclaiming. This allows to minimize the footprint of a guest - memory > > will only be taken out of the balloon when really needed. > > > > Especially, a drop_slab() will result in the whole balloon getting > > deflated - undesired. While handling it via the OOM handler might not be > > perfect, it keeps existing behavior. If we want a different behavior, then > > we need a new feature bit and document it properly (although, there should > > be a clear use case and the intended effects should be well described). > > > > Keep using the shrinker for VIRTIO_BALLOON_F_FREE_PAGE_HINT, because > > this has no such side effects. Always register the shrinker with > > VIRTIO_BALLOON_F_FREE_PAGE_HINT now. We are always allowed to reuse free > > pages that are still to be processed by the guest. The hypervisor takes > > care of identifying and resolving possible races between processing a > > hinting request and the guest reusing a page. > > > > In contrast to pre commit 71994620bb25 ("virtio_balloon: replace oom > > notifier with shrinker"), don't add a moodule parameter to configure the > > number of pages to deflate on OOM. Can be re-added if really needed. > > Also, pay attention that leak_balloon() returns the number of 4k pages - > > convert it properly in virtio_balloon_oom_notify(). > > > > Note1: using the OOM handler is frowned upon, but it really is what we > > need for this feature. > > > > Note2: without VIRTIO_BALLOON_F_MUST_TELL_HOST (iow, always with QEMU) we > > could actually skip sending deflation requests to our hypervisor, > > making the OOM path *very* simple. Besically freeing pages and > > updating the balloon. If the communication with the host ever > > becomes a problem on this call path. > > > > @Michael, how to proceed with this? > I'd like to see some reports that this helps people. e.g. a tested-by tag. > -- > Thanks, > > David / dhildenb