Received: by 2002:a05:6a10:eb0a:0:0:0:0 with SMTP id hx10csp3393300pxb; Tue, 8 Mar 2022 18:22:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGAHozFmO4EGTWPac9iwaQnv9SJomB1qeIP4nOfN4xbxff2/6tNazUi7gdKe8+l1a5WtIU X-Received: by 2002:a17:902:c94a:b0:151:8a66:ee8d with SMTP id i10-20020a170902c94a00b001518a66ee8dmr20472467pla.163.1646792546263; Tue, 08 Mar 2022 18:22:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646792546; cv=none; d=google.com; s=arc-20160816; b=00z+NNjiTtp2M6MZMYYSMUv2Dvv5WkpKaeI8Rt1qRpqwmVhEKjKpA44lnIgVROe27S XwMyoBAgHwM5sFpCp1llpP2eUGqUFXTZC88jYeU+UGxsy4/PaRoGlEITwC9o0eSVgI1F tLBIcBLTyUceuJOu2Ns1tY4/1Utm3PhBh1G6i5kHMKBt+8UMKAhTMX/YQBVIKdub7QGC AK8UvVkJK/m6MiSPN2wmhJMCLVn7ULUL5PAP1W3GS6Fp11dhIVy0SWlEoX+Zio1MJFxI 5xLfchzGuL/PaUMLBdKkFX0GYyopS+qxuY91AOMlMYsB8SVXZeaK0VzZpfvSxIAOkFjJ CWfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wbAfhbFyUGwe2Q5HZ4gVH7hz+BJKhZp/1dIJkpLWrYg=; b=C3k56vbVVTGWtQ1kgzV0pWNWL6Y1MlvTIpLl7/Npv9lm4usOJXflmVx2+3U9SufB40 EbM917sj8/4JCeaahizVsoY/wrcTRhYqmw7Pl753UC68G7DF+FxfsaIGiGjU5rfSvLBb 5ULJVWPz1xwnntWE59uOnMkoVQXV4JpyvBS3UMYjQfI809pPV8xodFqo+NpQx0NGe4Ed Hn4FTlP+CVPSn68kUuQleZwdhCwWGb/FJ4UD7QklGfayr6/k+D+sRZXBsiZgXG83D3qS 0EUYII3/6xtRCNfDs3OorNI3cvOTiAmbG8RHobeRN+1wGYOcYB1KCiOB4C3QN/A1GwAS JfWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oPAjcdMK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d7-20020a056a0010c700b004f72f321f0asi569054pfu.147.2022.03.08.18.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 18:22:26 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oPAjcdMK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7CA603AA4A; Tue, 8 Mar 2022 17:23:19 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbiCIBPI (ORCPT + 99 others); Tue, 8 Mar 2022 20:15:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231284AbiCIBNK (ORCPT ); Tue, 8 Mar 2022 20:13:10 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C00DF15878F for ; Tue, 8 Mar 2022 16:56:16 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id k24so661919wrd.7 for ; Tue, 08 Mar 2022 16:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wbAfhbFyUGwe2Q5HZ4gVH7hz+BJKhZp/1dIJkpLWrYg=; b=oPAjcdMKk2cbLSR0NXJPl2YEmIHZ9WRBbKIrDfh1EAFvaUhr+N8XmHO6RLfSQ4jZIB HH32lTtvocQ3aFw0+L1BvytAwA00qmSTIRhPgYDW5bvxvuSckOReH75dbn6+SKgCti5W 6LF0obtutW0ITI/xSxNCKm5Gt3nBWGqCujHICGD7c/dmBCY4nzn1nk6PbTBurljXT0NE WSuPGbUUGMW1XNsH+d5yNCdaFYBwn+X9XzNrAA8gSYwhbV5P1vbpukFZh6s3Zhx/OJkQ 9AF2wYbYahKsOk8Xj+r1EUjiSfBvGdUh9E5s/TodiCnl4b2GW1PhAWSzW0p4RrC+Ehy2 +/qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wbAfhbFyUGwe2Q5HZ4gVH7hz+BJKhZp/1dIJkpLWrYg=; b=2yG9Z0ODf+lU0o+3IKHSK6vg1cQSigBM0k5NL0BYC0me+bVaARTDEeSK5pSm4wwygO CkykCF+avG9R1y9v3gCFqKi/1MOcUVUqHcr23YJSkNOkaY542XqZB/4hmOMKBQ2UbAok 3SchGHKzfRVCTEsudVOiZ6t43v3VC1rguUxYkdYLCzL2DXnsIg7mB6PP6ul2g2pVe/Mf qBYLKYiOB0CJrXMOhbWLi6EaqyzYSezoGh0kYfqCkB6zOGBBlb54TSpkdRe3hx1+4Edb aUBpisfaAzf3fsH0LhdgMrn9mdMsTyRKXxu7F3DGW63LofdXI9dqK9cWH0i99Noda4n+ vlUw== X-Gm-Message-State: AOAM530ou+ubRqRjI2iWPuRAMGWJZkruxxEB9mcuL4kiCiI1FAKsxSYx sqEgCtZ4ARvqhiMF7FlCSkgmY5WDllMZBbRzb6eLKCJZ X-Received: by 2002:a5d:6344:0:b0:1f0:21ee:9705 with SMTP id b4-20020a5d6344000000b001f021ee9705mr13938132wrw.93.1646787375187; Tue, 08 Mar 2022 16:56:15 -0800 (PST) MIME-Version: 1.0 References: <20220308131725.60607-1-dmitry.osipenko@collabora.com> <42facae5-8f2c-9c1f-5144-4ebb99c798bd@collabora.com> In-Reply-To: <42facae5-8f2c-9c1f-5144-4ebb99c798bd@collabora.com> From: Rob Clark Date: Tue, 8 Mar 2022 16:56:43 -0800 Message-ID: Subject: Re: [PATCH v1 0/5] Add memory shrinker to VirtIO-GPU DRM driver To: Dmitry Osipenko 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Tue, Mar 8, 2022 at 3:36 PM Dmitry Osipenko wrote: > > On 3/9/22 01:24, Rob Clark wrote: > > On Tue, Mar 8, 2022 at 11:28 AM Dmitry Osipenko > > wrote: > >> > >> On 3/8/22 19:29, Rob Clark wrote: > >>> On Tue, Mar 8, 2022 at 5:17 AM Dmitry Osipenko > >>> wrote: > >>>> > >>>> Hello, > >>>> > >>>> This patchset introduces memory shrinker for the VirtIO-GPU DRM driver. > >>>> During OOM, the shrinker will release BOs that are marked as "not needed" > >>>> by userspace using the new madvise IOCTL. The userspace in this case is > >>>> the Mesa VirGL driver, it will mark the cached BOs as "not needed", > >>>> allowing kernel driver to release memory of the cached shmem BOs on lowmem > >>>> situations, preventing OOM kills. > >>> > >>> Will host memory pressure already trigger shrinker in guest? > >> > >> The host memory pressure won't trigger shrinker in guest here. This > >> series will help only with the memory pressure within the guest using a > >> usual "virgl context". > >> > >> Having a host shrinker in a case of "virgl contexts" should be a > >> difficult problem to solve. > > > > Hmm, I think we just need the balloon driver to trigger the shrinker > > in the guest kernel? I suppose a driver like drm/virtio might want to > > differentiate between host and guest pressure (ie. consider only > > objects that have host vs guest storage), but even without that, > > freeing up memory in the guest when host is under memory pressure > > seems worthwhile. Maybe I'm over-simplifying? > > Might be the opposite, i.e. me over-complicating :) The variant with > memory ballooning actually could be good and will work for all kinds of > virtio contexts universally. There will be some back-n-forth between > host and guest, but perhaps it will work okay. Thank you for the suggestion. > > >>> This is > >>> something I'm quite interested in for "virtgpu native contexts" (ie. > >>> native guest driver with new context type sitting on top of virtgpu), > >> > >> In a case of "native contexts" it should be doable, at least I can't see > >> any obvious problems. The madvise invocations could be passed to the > >> host using a new virtio-gpu command by the guest's madvise IOCTL > >> handler, instead-of/in-addition-to handling madvise in the guest's > >> kernel, and that's it. > > > > I think we don't want to do that, because MADV:WILLNEED would be by > > far the most frequent guest<->host synchronous round trip. So from > > that perspective tracking madvise state in guest kernel seems quite > > attractive. > > This is a valid concern. I'd assume that the overhead should be > tolerable, but I don't have any actual perf numbers. jfwiw, MADV:WILLNEED is a *very* hot path for gl drivers, based on some measurements I did a while back with various apps/benchmarks.. easily more than 10x the next most frequent ioctl (for MADV:WONTNEED and MADV:WILLNEED each, so more than 20x combined.. but MADV:WONTNEED can be async). But if the balloon triggering shrinker approach works out, that would be pretty great.. it seems like the easy option and doesn't require adding new host kernel uabi :-) BR, -R > > 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. > > >>> since that isn't using host storage > >> > >> s/host/guest ? > > > > Yes, sorry, I meant that it is not using guest storage. > > Thank you for the clarification.