Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3015332pxp; Tue, 8 Mar 2022 06:19:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzORr+lktsRIE07q9f8/12mm15FcxHaQ8s1k8EYcbg3LXarKBcUl8EWhzr7zEJg6TrKHFGC X-Received: by 2002:a17:907:9626:b0:6da:6c6f:9825 with SMTP id gb38-20020a170907962600b006da6c6f9825mr13379642ejc.600.1646749141285; Tue, 08 Mar 2022 06:19:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646749141; cv=none; d=google.com; s=arc-20160816; b=lFYkC0hgTIvg1W7MygYP4Kzix7PyFqcCKyKLU+tJt4TsPTOWlmVv9MTb40R5CSS1Ez C0ZbMip64Kp5WD8HG5FIEIP1Xl9U3W0qat8XhDxnZkrA9TEfKAze3kxl1IYwCZBc0R6U r/sHwthgBQxygItAXEe8xqHG+QSQiE9NNKR6LcA050Tg+JhKFkx7HcztBusDWohFBDpw aGzpIaZSyo0JoFOncCG/IZ6+7U/imOt8TZzNT9Og0+tXcgIspR5KpOKYOVl4k//VK06b KsFfd8dpssLcedRcgf7MPT7eLNqirGOSMFBcXdqEKEw1CFcATJRe1G0eFOFbGfd2ZN1G SdPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=OEeRk2TKGoFzKfzODdA9yH0UVt0tIerQ9tpy3ZsAcuU=; b=FPU8JGh1UPgAhhvvxwKY4FnE0D59RB44mtl/qk0JC0uleS7ym188sO/nvZTa+5hOpm G/tckhq+dEpqbvY+4nztRl9eYKiDMjdzIpwCQWB4atJXuvH3svAOeWvtfqekx6PTa5Zp HHj1FKfJ0SBc1spGvmhP8fnVLsJTgX8fVtNWcqudIucrcUnqzyn3Deu70SJMh7qoM2s6 0ocnCENnaOwdRu5exdJUtW9H4fSq5nH5NmCycPn1kF+sKpMCSI+dNlkufhy87wt8VBED rh/naa9jkMDwlDFC2jzFoR2EfvWafRBTqKIh368rsP19TkRVOwdAeoNi4kX/YkEaIWk3 SRJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HKfueVRL; 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 o20-20020a170906975400b006da7ac0f190si9716348ejy.933.2022.03.08.06.18.36; Tue, 08 Mar 2022 06:19:01 -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=HKfueVRL; 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 S1347095AbiCHNSo (ORCPT + 99 others); Tue, 8 Mar 2022 08:18:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234318AbiCHNSk (ORCPT ); Tue, 8 Mar 2022 08:18:40 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6A3465CC for ; Tue, 8 Mar 2022 05:17:39 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id A43E61F44049 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1646745457; bh=zcqcE7dIUc7tx7i1KnnMTJpX/TOVNA/MHpX4Pjw5exg=; h=From:To:Cc:Subject:Date:From; b=HKfueVRLzYyO7heYtKq0P/VcD/mvjVk9O+tlsnYuUALjo1FEabj4WwLBiVWL4Av90 uVcDFyMWpNldyoeq/D1suqnKq1P0WFuhcj4bj5KWotnShNHJdaomZzegK+sgxLzaGh UPRHSrtVQqZMvjiaJ2+DHew1T80/308r6GFNpQpATODJcrO2YO63bZNR+t3o3YBD4c m7uy3eScR6qnPupk0ewJL2RF8oj9M2lV0b5ZxjCdUfhs1RYJ8zSS6EnScZRIidZXTR ASbl241baqqO2DnpZ4AHIJIvPbrifE/YXG8iUN/PnlBTF1gPVJ3Fi63Luk8a4YanB3 JOs7NFZaib1bA== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Gustavo Padovan , Daniel Stone , Tomeu Vizoso , virtualization@lists.linux-foundation.org, Dmitry Osipenko Subject: [PATCH v1 0/5] Add memory shrinker to VirtIO-GPU DRM driver Date: Tue, 8 Mar 2022 16:17:20 +0300 Message-Id: <20220308131725.60607-1-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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. This patchset includes couple fixes for problems I found while was working on the shrinker, it also includes prerequisite DMA API usage improvement needed by the shrinker. The Mesa and IGT patches will be kept on hold until this kernel series will be approved and applied. This patchset was tested using Qemu and crosvm, including both cases of IOMMU off/on. Mesa: https://gitlab.freedesktop.org/digetx/mesa/-/commits/virgl-madvise IGT: https://gitlab.freedesktop.org/digetx/igt-gpu-tools/-/tree/virtio-madvise Dmitry Osipenko (5): drm/virtio: Correct drm_gem_shmem_get_sg_table() error handling drm/virtio: Check whether transferred 2D BO is shmem drm/virtio: Unlock GEM reservations in error code path drm/virtio: Improve DMA API usage for shmem BOs drm/virtio: Add memory shrinker drivers/gpu/drm/virtio/Makefile | 3 +- drivers/gpu/drm/virtio/virtgpu_drv.c | 22 +++- drivers/gpu/drm/virtio/virtgpu_drv.h | 31 ++++- drivers/gpu/drm/virtio/virtgpu_gem.c | 84 ++++++++++++ drivers/gpu/drm/virtio/virtgpu_gem_shrinker.c | 124 ++++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_ioctl.c | 37 ++++++ drivers/gpu/drm/virtio/virtgpu_kms.c | 17 ++- drivers/gpu/drm/virtio/virtgpu_object.c | 63 +++------ drivers/gpu/drm/virtio/virtgpu_plane.c | 17 ++- drivers/gpu/drm/virtio/virtgpu_vq.c | 30 +++-- include/uapi/drm/virtgpu_drm.h | 14 ++ 11 files changed, 373 insertions(+), 69 deletions(-) create mode 100644 drivers/gpu/drm/virtio/virtgpu_gem_shrinker.c -- 2.35.1