Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1825574rdb; Tue, 3 Oct 2023 02:01:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaVOJtDptBspiJx6yxflvEKbv3frQqIr2WeYXOXV2sh884rfb0fe+2Cw8uyt4Bh3qVeg+w X-Received: by 2002:a05:6358:7204:b0:133:4ce:4e8c with SMTP id h4-20020a056358720400b0013304ce4e8cmr17913504rwa.29.1696323682374; Tue, 03 Oct 2023 02:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696323682; cv=none; d=google.com; s=arc-20160816; b=OaA1tSjzadSBkalEevtgiOI9bYsAnBmRjg2hGW+y3nwFwM/tlDCsyO5x5ODwiVRmvR Op7PrMsnBpJ+IkT+k7ppQsJ6dYbzsFqonBxstOtyXsbdN0Ho9RYQCUej08unSWoYy1BX TRdLHGWXofSrKFfo8QfasidTRKOj5mC/vwuu3deQ4ivm9+4XYK6Cc74SGVQtrJeXoQ/1 gj4JUF3ejr0wgykTyDA70OQGyZbmSFZwvljuPGl2dEg4EcvjwYhXlSVXFCcJkOef6QsR ZIYZ7sEHdc9kYtTZevJYgtSDzVku07jr0cUbuifFJkwWuTm18Z67TcDvrQIC8nWn1Rke baHw== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=cz+EiXUsye0wIxDopFOv/pe974hmcorHT+utSlV+S1k=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=p/KFnJwURqhXchg/vMOjq7JzIoef/K9JkA3AdNdnsoX3hgyIEXkzZR1C3t02QQLDyP lAuyhm0o2iDbqawL/stFvrwP6ou0jILrq8VgmqKh/qi5gFVyjItxYuTMwf+3uzOeszOx rJRkVlCGDTBFc11uEbwgJbSVNG3hAX0vh75EIbJxZwE+REPK9+ZQRqHjWMiuoNIv8BdI kwM0iKU23rMWWL0Pw7ZoI2ppjAggW8Y0eSCVUhvM2zFVLF6IJpIi8ae3y9tllMzcRwVD VbyZSg71IUqAqN1/Ji+sko0b0CEbix4DZrwquRMmZY5BpAxlzDCr1AB5fvLWpDKw2WpW 2ygA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lqsfHalC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id fj2-20020a056a003a0200b0068e3f550763si1082356pfb.101.2023.10.03.02.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 02:01:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lqsfHalC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1B2868089840; Tue, 3 Oct 2023 02:01:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239299AbjJCJBE (ORCPT + 99 others); Tue, 3 Oct 2023 05:01:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbjJCJBD (ORCPT ); Tue, 3 Oct 2023 05:01:03 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63CEAAF for ; Tue, 3 Oct 2023 02:01:00 -0700 (PDT) Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 447B26607079; Tue, 3 Oct 2023 10:00:58 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1696323658; bh=cvW64htWBwkbZa50ehWwGHppuYY384nnu1olxbLOfrc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lqsfHalCz/aFw0YXCDQqUQrDpgV1BVfV9FUbldI+Vn06NWEt0/oE9DpNqCi0NV613 Zzv5Ow+cc+O3QQG7+dqsPgK2Aot/H30/KoH3vPb9vjhzuEJh4D+bKBtTI4Krngkx2B SNf1Z9OpJPONNAcaDwMAmFLV8DVRYz1JAhoR8bCLY/x6oT4TVyTvLrnOhBkYzQ0HWj YurT6ILG14bLcU57gj5zKdhPt2SBMXYXJB3tNEcbpIVIHQFmRpf5o+GB9Ym8FK5F17 W6i4ktGWuDT6mJrDi4sQ2oAsxFIRaLMiFA6TDg3GFrMOjpf9qaeiqs7TPqSlvLn21r 203pqcOgXn6bQ== Date: Tue, 3 Oct 2023 11:00:55 +0200 From: Boris Brezillon To: Dmitry Osipenko Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Christian =?UTF-8?B?S8O2bmln?= , Qiang Yu , Steven Price , Emma Anholt , Melissa Wen , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v17 13/18] drm/shmem-helper: Add memory shrinker Message-ID: <20231003110055.346fd94c@collabora.com> In-Reply-To: References: <20230914232721.408581-1-dmitry.osipenko@collabora.com> <20230914232721.408581-14-dmitry.osipenko@collabora.com> <20230915104633.0d5c3932@collabora.com> <454c464e-4534-7ec3-6d38-49b7df83c7be@collabora.com> <20230926093517.11a172ad@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 03 Oct 2023 02:01:20 -0700 (PDT) Hello Dmitry, On Tue, 3 Oct 2023 03:31:32 +0300 Dmitry Osipenko wrote: > On 9/26/23 10:35, Boris Brezillon wrote: > >>>> + __drm_gem_shmem_release_pages(shmem); > >>> Make sure you drop the implicit pages_use_count ref the sgt had, this > >>> way you can still tie the necessity to drop the pages to sgt != NULL in > >>> drm_gem_shmem_free(). > >> This will require further refcnt re-initialization when pages are > >> restored if it's dropped to zero. I don't see how this will improve > >> anything. > > Sorry to disagree, but I do think it matters to have a clear ownership > > model, and if I look at the code (drm_gem_shmem_get_pages_sgt_locked()), > > the sgt clearly owns a reference to the pages it points to. > > It creates too much unnecessary trouble because, again, pages_use_count > can't drop to zero easily. Not saying pages_use_count should drop to zero, I'm just saying the reference that was owned by the sgt should be released when this sgt is freed, no matter if this sgt destruction is triggered by a GEM eviction, or because the GEM object is freed entirely. > Shrinker doesn't own the refcnt and not > allowed to touch it. I'm not asking the shrinker to own a reference on the pages either. It's really the sgt that owns this reference. > The pages_use_count is then used by things like > mmap() and etc that use get_pages(), which can be invoked for evicted GEM. Yes, and I still have a hard time seeing how this interferes with what I'm suggesting to be honest. > > I'd prefer to keep refcounting as is, don't see how to implement your > suggestion. Can you be more specific? I don't really see what the problem is with decrementing pages_use_count when you free the sgt (eviction), and re-incrementing it when the sgt is restored (swapin). Regards, Boris