Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1647172pxp; Thu, 17 Mar 2022 13:32:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzX1nCEj9fmW9n/IZFz6ztIbIzoRPu36+5w/xul1SbfShp+CxQVy2cBZKgxQLKbBBkor2dJ X-Received: by 2002:aa7:85d8:0:b0:4f6:8ae9:16a8 with SMTP id z24-20020aa785d8000000b004f68ae916a8mr6704233pfn.15.1647549127740; Thu, 17 Mar 2022 13:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647549127; cv=none; d=google.com; s=arc-20160816; b=T1gX6p73282NC2zBOdKQQSR26CnqRv4CvsRU23Pg9/9HoqTzRcNcX3kWLNFG7e9xQM s9HHBJWKca2UUFyH8VsVuUSGB2VooCjh5POTCleVN1ESQbQXoUb2KPCrpOKnv+vRf7vS pc3IIcM9MN7/G0hLhplzLcM/JewhEA7yYAPI2XS9I95Nrg1N55NgfZPluHYtdNPALW64 OAPQp1V2rpDaRDXWX4Eb1qfyvH8ilV6KMCuJ/wvPkO5UKwEMbYZT9G39Vc+1asPD0qPl 1B0jtv/HU9Hp8ZPCxFG1d601I+pMhbMvwsNAWqv3gwffSO90LCFU5sWVLn3Tzyz8BCql C/2g== 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=SqZutGyhO3JYyEHo9T9tINuDDPfH7lwjqYfTlH6+GEA=; b=t7Q6BkR254oWF8yyGuo3xNG9SaptkBjusnR1Uj/YUUTrNn444yD3vn2Pq2UJ2y2KY8 roOVFtdaKwq6azCUztQgZgms9pcUA51Su+1ucKTpH8ZmlOLLbG6BToApq4LqBNg14Zn0 8aiyydjukLa4G/L3JtC5ZY+VRK4fbL8/KU1F1frOxsoWevk3HnBPW4XIz/LRnK6jPkuO V32muVOlkkOmh3QTS599axi9HIWukM++5a4+0C+xhyKmdhfd5aDEuk1iDla08sl2fDGn hYWM/9IMpECoUFxNQ40lssct76Vpn6Zd59N3QCblPQkKa4UtWTnb0kmt4RlEmv6QLV0l 4CZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lJBtpINq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y30-20020a63181e000000b003816043f08asi1439943pgl.639.2022.03.17.13.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 13:32:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lJBtpINq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 822FC2D6542; Thu, 17 Mar 2022 13:06:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236998AbiCQRpV (ORCPT + 99 others); Thu, 17 Mar 2022 13:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236999AbiCQRpU (ORCPT ); Thu, 17 Mar 2022 13:45:20 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9E3FBD7E4 for ; Thu, 17 Mar 2022 10:44:03 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id DEB1A1F4552B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1647539042; bh=mUMMTYKYpCpUpTWTvn3hhHrvuNHT/8z3r7qyrT17pvA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=lJBtpINq0ld1ylJn0JIcyD6BtNED3KoWz7lRZJ7U60pn0clW6BHz5T84ZrDP2ITIO 3Uv19QN0g4XSrEKLLM1vgdGA3cHcR/wBh41nUgXhNbEPAkm3ndYCf0g6mKqG4eBcDR LgOxRmhCfbKISLiqP6E4PEhiFHW5m4iCGOr5XYcZOFTI+OWtPATMhQPiLhLuxtvvoq 8hU7dLwD5MTqtnJaeqDoktCv9+7KXZ3xzfFWZEhDgQ6SKEEe4ZXHQ/TgaRuqh8Ck8T Ogjin72ZPyE+optlFHhoyqLteqiCZIRYxzj0uhk1cRVWuEno4XCGqeBuxFZlysnPD5 yeWmIV9EijnKg== Message-ID: <37364303-acdc-ec95-9e99-2edbc84c5040@collabora.com> Date: Thu, 17 Mar 2022 20:43:57 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH v2 6/8] drm/shmem-helper: Add generic memory shrinker 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 , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Steven Price , Alyssa Rosenzweig , Linux Kernel Mailing List , "open list:VIRTIO GPU DRIVER" , Gustavo Padovan , dri-devel , Dmitry Osipenko References: <20220314224253.236359-1-dmitry.osipenko@collabora.com> <20220314224253.236359-7-dmitry.osipenko@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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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 3/17/22 19:13, Rob Clark wrote: ... >>>> + /* prevent racing with job submission code paths */ >>>> + if (!dma_resv_trylock(obj->resv)) >>>> + goto shrinker_lock; >>> >>> jfwiw, the trylock here is in the msm code isn't so much for madvise >>> (it is an error to submit jobs that reference DONTNEED objects), but >>> instead for the case of evicting WILLNEED but inactive objects to >>> swap. Ie. in the case that we need to move bo's back in to memory, we >>> don't want to unpin/evict a buffer that is later on the list for the >>> same job.. msm shrinker re-uses the same scan loop for both >>> inactive_dontneed (purge) and inactive_willneed (evict) >> >> I don't see connection between the objects on the shrinker's list and >> the job's BOs. Jobs indeed must not have any objects marked as DONTNEED, >> this case should never happen in practice, but we still need to protect >> from it. > > Hmm, let me try to explain with a simple example.. hopefully this makes sense. > > Say you have a job with two bo's, A and B.. bo A is not backed with > memory (either hasn't been used before or was evicted. Allocating > pages for A triggers shrinker. But B is still on the > inactive_willneed list, however it is already locked (because we don't > want to evict B to obtain backing pages for A). I see now what you're talking about, thanks. My intention of locking the reservations is different since eviction isn't supported by this v2. But we probably will be able to re-use this try_lock for protecting from swapping out job's BOs as well. >>> I suppose using trylock is not technically wrong, and it would be a >>> good idea if the shmem helpers supported eviction as well. But I >>> think in the madvise/purge case if you lose the trylock then there is >>> something else bad going on. >> >> This trylock is intended for protecting job's submission path from >> racing with madvise ioctl invocation followed by immediate purging of >> BOs while job is in a process of submission, i.e. it protects from a >> use-after-free. > > ahh, ok > >> If you'll lose this trylock, then shrinker can't use >> dma_resv_test_signaled() reliably anymore and shrinker may purge BO >> before job had a chance to add fence to the BO's reservation. >> >>> Anyways, from the PoV of minimizing lock contention when under memory >>> pressure, this all looks good to me. >> >> Thank you. I may try to add generic eviction support to the v3. > > eviction is a trickier thing to get right, I wouldn't blame you for > splitting that out into it's own patchset ;-) > > You probably also would want to make it a thing that is opt-in for > drivers using the shmem helpers I had the same thoughts, will see.