Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1163694pxp; Wed, 9 Mar 2022 23:11:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvyVbam/ZDt+X3I687BENd8YdXRoEPMx/SVkX4SNhItIRtYQWxUFKp216mdPAApKmGPRn7 X-Received: by 2002:a17:906:174f:b0:6d0:5629:e4be with SMTP id d15-20020a170906174f00b006d05629e4bemr2884788eje.525.1646896308545; Wed, 09 Mar 2022 23:11:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646896308; cv=none; d=google.com; s=arc-20160816; b=0p3xvg4jtG2IvAYjwrqlj1rEEAgjNOvfqZ7jbA0poEBwRLJiYpL+2Vfz0T0Ah04AzP 03I0aInfTNICPUff4yi63u92PNkntDZ7KbZ9t4LTW/yfDwZRTJzutC4josvXRfsEao65 wK9ZSJnIO0esMUPFDBY8OjROhTdzqQtpA2/G/AmC/ObTqOqVmktNqOsohA1CX+hn+jIk 5DZN1T6i9QXFERhpX4iYubeAa1V/DOXtmL6JO7D71OHiQVnNQE+bxLSTAiKxUSvobEKi jSFUiq8rmKhfjKK4iacWgD4GQSGwKrfUsIIyTjdKfACSVJbmy+m4vVQP+lpfIGRppVRw nXfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=kVky6bSOCwyprbnguQSIRSN+jaW6PRxynEGj9oK0yr4=; b=T1s2N8Ij0j9M7Jemv+hWpRlkFbmOY3hE52USv1DDZnd28cHHKRc3Lkq+eXoa04lzqA RW816XTn016smS2oMHBNISKZtMevAVzOlwk3nkrOi6keIRYIVy+aVBImX5nElPJdqmuh Cf2bpfnlpdY81cXvPp0Wk1wQc4KnwzJCoyGpos09Aya2I9nCPys3jYcgBWoWLwe1FSnp jY5J3EQhZUh5/77s00wqZ4fgMKa+u8o65BGLFw3yDngfXbhxUiog9nrjHkfxmHvN9Bc9 /VQGEnWQUaGcaLx/QwkQ+s9RwwykxrtMk9occhMkL3yTiv8TqmVXKW+GjS13OVsyiVED +XnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=gAc0Wsra; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf1-20020a1709077f0100b006da7d7de452si2908529ejc.952.2022.03.09.23.11.25; Wed, 09 Mar 2022 23:11:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=gAc0Wsra; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233550AbiCIUHj (ORCPT + 99 others); Wed, 9 Mar 2022 15:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbiCIUHh (ORCPT ); Wed, 9 Mar 2022 15:07:37 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DF9327CC5 for ; Wed, 9 Mar 2022 12:06:38 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id 514EB1F41CDC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1646856397; bh=upzAnz+AemcOXDgluXZyqh6OsAIdv9e6PtW9m0nL/eY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=gAc0WsraZucHzFdCM5DkNgzQK3fhxUgZGbi3q9C2S0WkfH62pOsS7vE5qTN6asQ8p eFNBCuz7uqtDfjh0K79h7YNLUAY6T6Ga0700BpxFPZiMcFKxpGQOPZKOPl3xF9uy3h MwoWvvnGfTUZg9E+wzjsDD3AOKgqjp20vd+OozepoSgbhSt3MgwBEscof+o+96DjTH 8dNA+xA9OK4KaeNqwvc5TQijt0/npkRPawqTws+CgwlsiffeFl7pBBV5HhoO6Dsflq 3e7HPo5NSfmqYFOu9ubN/OIdAwyka4neXLHb86PqF/xfcQdjLPqPXxM6eF0D0r5ftl gnBZuijXaUiIQ== Message-ID: <05e1fe61-1c29-152f-414b-cd6a44525af0@collabora.com> Date: Wed, 9 Mar 2022 23:06:33 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v1 0/5] Add memory shrinker to VirtIO-GPU DRM driver Content-Language: en-US To: Rob Clark Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny , Tomeu Vizoso , Linux Kernel Mailing List , "open list:VIRTIO GPU DRIVER" , Gustavo Padovan , dri-devel , Dmitry Osipenko , Rob Clark References: <20220308131725.60607-1-dmitry.osipenko@collabora.com> <42facae5-8f2c-9c1f-5144-4ebb99c798bd@collabora.com> From: Dmitry Osipenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/9/22 03:56, Rob Clark wrote: >> If we really can't track madvise state in the guest for dealing with >> host memory pressure, I think the better option is to introduce >> MADV:WILLNEED_REPLACE, ie. something to tell the host kernel that the >> buffer is needed but the previous contents are not (as long as the GPU >> VA remains the same). With this the host could allocate new pages if >> needed, and the guest would not need to wait for a reply from host. > If variant with the memory ballooning will work, then it will be > possible to track the state within guest-only. Let's consider the > simplest variant for now. > > I'll try to implement the balloon driver support in the v2 and will get > back to you. > I looked at the generic balloon driver and looks like this not what we want because: 1. Memory ballooning is primarily about handling memory overcommit situations. I.e. when there are multiple VMs consuming more memory than available in the system. Ballooning allows host to ask guest to give unused pages back to host and host could give pages to other VMs. 2. Memory ballooning operates with guest memory pages only. I.e. each ballooned page is reported to/from host in a form of page's DMA address. 3. There is no direct connection between host's OOM events and the balloon manager. I guess host could watch system's memory pressure and inflate VMs' balloons on low memory, releasing the guest's memory to the system, but apparently this use-case not supported by anyone today, at least I don't see Qemu supporting it. So the virtio-balloon driver isn't very useful for us as-is. One possible solution could be to create something like a new virtio-shrinker device or add shrinker functionality to the virtio-gpu device, allowing host to ask guests to drop shared caches. Host then should become a PSI handler. I think this should be doable in a case of crosvm. In a case of GNU world, it could take a lot of effort to get everything to upstreamable state, at first there is a need to demonstrate real problem being solved by this solution. The other minor issue is that only integrated GPUs may use system's memory and even then they could use a dedicated memory carveout, i.e. releasing VRAM BOs may not help with host's OOM. In case of virgl context we have no clue about where buffers are physically located. On the other hand, in the worst case dropping host caches just won't help with OOM. It's now unclear how we should proceed with the host-side shrinker support. Thoughts? We may start easy and instead of thinking about host-side shrinker, we could make VirtIO-GPU driver to expire cached BOs after a certain timeout. Mesa already uses timeout-based BO caching, but it doesn't have an alarm timer and simply checks expiration when BO is allocated. Should be too much trouble to handle timers within Mesa since it's executed in application context, easier to do it in kernel, like VC4 driver does it for example. This is not good as a proper memory shrinker, but could be good enough in practice.