Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp761475iog; Fri, 24 Jun 2022 13:34:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t0fU/J8gGD/671HOLFH4rT68VeNWF14nxmnEr7buaqrUVMgy+cdHRv1BhVOD34YqaD/Fuu X-Received: by 2002:a17:90a:f3c3:b0:1ec:9f63:1330 with SMTP id ha3-20020a17090af3c300b001ec9f631330mr5957351pjb.165.1656102866491; Fri, 24 Jun 2022 13:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656102866; cv=none; d=google.com; s=arc-20160816; b=SjS+nl1sXdJtvzCd4Q4iQWRVCJVRNTxevD0aGjBcJxCRS/Q6O/mfhrxYuaB+a61R+K LdGgMJ5FhRI44z1dNekMX0aTUO32hQrKFG71VJ75dliceRwoXNBfcwrHaskrx0ONxN4h 91qPbsFqa2yuBg+AvvKYGTQNXZ9uZSraa5zxNJocjT/CKujJwk6qtRFtEqvVoCZWWxVe 6jKfhQrr3XXSB+fikGX6pYkC3wGxozWvQnH/KW1PeYf6QVjFXm8KVLFZ21ufqAB1Qvy7 rTNBB56DR3JVEKe/07cwD3pDd8bJ+OXGwID5N45xRPjyhvXw16ddArl9HIgMrEJsNErK p97g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=aI/Wm30z63oEYhq+jLGxZI/tPMnn/tbFlzZ2xbhv+F4=; b=zNln7yEUboSrOpJkdX1inVcabPrwfIvu+tITKMwrbRC6RwlJZmUciEmfK8uGakNBsM qZlGzJSaNrS5wI93+JRXDNy+2SXiqWPkxltYQronBaJXruFR3jqnlpQCP0FsNqB2pIEu KGFK69DzA9Iswk6Uz9R0pdfQKUcyOCAFezQGy1lSFTwafoXe5vPTOf/PwLgTzYG1RYxA 0pxv4OFxG0yqwMayBoCGmxVc3gSc9tjny3ZYMAtYwNna2pwV3VbKOa2FLGcq3jEJ1t/2 B3NuAWVnDA0W4t68o3uWOBsChZbmXFaMPM0Eb9EurnG9jjD4zsIhcxtTcR45nO3FHD0Y 6o+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=DSfCIl93; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a170903024800b0015ecc946750si141221plh.409.2022.06.24.13.34.11; Fri, 24 Jun 2022 13:34:26 -0700 (PDT) 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=@ffwll.ch header.s=google header.b=DSfCIl93; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbiFXUV7 (ORCPT + 99 others); Fri, 24 Jun 2022 16:21:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbiFXUV5 (ORCPT ); Fri, 24 Jun 2022 16:21:57 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B86B881A2B for ; Fri, 24 Jun 2022 13:21:56 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id g26so6894126ejb.5 for ; Fri, 24 Jun 2022 13:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=aI/Wm30z63oEYhq+jLGxZI/tPMnn/tbFlzZ2xbhv+F4=; b=DSfCIl93ErkZQTmodLqWf6MxjRIpF1ZnQis6V2AmfYLHN/rGtlxKfpfQusYdU3/UoQ cGZ9t8NGw8N1UESLaZQtt9KE8BCcJRvCrZjHW4cY3x/vspkpF+H+OZ9YyYSAm/sR4To9 S80AKWsZyDrPVwQDWYceohfI1JDJJuzPD7o2I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=aI/Wm30z63oEYhq+jLGxZI/tPMnn/tbFlzZ2xbhv+F4=; b=U8b5ex2EvEEHj1zJXKG+OGSfpsNjH/TuLnwBYcXTqxJ7RIJUsxEwnLOVQFH8T4My4U SwJoZcwILqvABmqnKvqQ/67Pq34q7PWNk4COarNiKQhwgmhkUDZ5HnbDEwKhueCCN2NR bxBjbqmGs/KF8fojnTFF62UBntZL7ub3N7OJ+GWjImx08lJ5nuqYZ6RY/PxH/lxciCtI ZQPHuYeakfmSXTRBAkwZ8uNO24TpDRsRboiq7Y+gW5Oo/ftJgsNE2V06rMqtNN3Lu6SN Bkg1PfN1bq6K9tDis/wR4Kj1+jv5+1fTENFAXRhgUuuzpK9W3ljqT0WzyISgdL5JKjcj wO7A== X-Gm-Message-State: AJIora+/e22pcmvL+9oeiaDudYWD0wg2ObyrwZrVLhUk5ORZ6wyZPRC4 G4cM80suyOdMWikl1RrHj56wJA== X-Received: by 2002:a17:906:72d1:b0:722:e714:e9ff with SMTP id m17-20020a17090672d100b00722e714e9ffmr758067ejl.748.1656102115311; Fri, 24 Jun 2022 13:21:55 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id y22-20020a170906559600b00722e7919835sm1623844ejp.111.2022.06.24.13.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jun 2022 13:21:54 -0700 (PDT) Date: Fri, 24 Jun 2022 22:21:52 +0200 From: Daniel Vetter To: Rob Clark Cc: Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Steven Price , Alyssa Rosenzweig , Emil Velikov , Robin Murphy , Qiang Yu , Sumit Semwal , Christian =?iso-8859-1?Q?K=F6nig?= , "Pan, Xinhui" , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Alex Deucher , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Dmitry Osipenko , linux-tegra@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, kernel@collabora.com Subject: Re: [PATCH v6 17/22] drm/shmem-helper: Add generic memory shrinker Message-ID: Mail-Followup-To: Rob Clark , Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Almeida , Gert Wollny , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Steven Price , Alyssa Rosenzweig , Emil Velikov , Robin Murphy , Qiang Yu , Sumit Semwal , Christian =?iso-8859-1?Q?K=F6nig?= , "Pan, Xinhui" , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Alex Deucher , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Dmitry Osipenko , linux-tegra@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, kernel@collabora.com References: <20220526235040.678984-1-dmitry.osipenko@collabora.com> <20220526235040.678984-18-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux phenom 5.10.0-8-amd64 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Sun, Jun 19, 2022 at 10:53:03AM -0700, Rob Clark wrote: > On Thu, May 26, 2022 at 4:55 PM Dmitry Osipenko > wrote: > > + mutex_unlock(&gem_shrinker->lock); > > As I mentioned on other thread, count_objects, being approximate but > lockless and fast is the important thing. Otherwise when you start > hitting the shrinker on many threads, you end up serializing them all, > even if you have no pages to return to the system at that point. Yeah agreed, seems like I was wrong here :-) Atomic counter or something would also be in link the the lru_list stuff. It would be to record this in the kerneldoc for the shrinker structure though, to make sure this is all understood. > > + /* prevent racing with the dma-buf importing/exporting */ > > + if (!mutex_trylock(&gem_shrinker->dev->object_name_lock)) { > > + *lock_contention |= true; > > + goto resv_unlock; > > + } > > I'm not sure this is a good idea to serialize on object_name_lock. > Purgeable buffers should never be shared (imported or exported). So > at best you are avoiding evicting and immediately swapping back in, in > a rare case, at the cost of serializing multiple threads trying to > reclaim pages in parallel. Yeah this sounds really bad. Plus this is a per-device lock, and doing those with trylock means the shrinker will fail to find shrinkable memory way too often. We need to engineer this out somehow. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch