From patchwork Wed Apr 2 15:00:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4072C3601A for ; Wed, 2 Apr 2025 15:00:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32A5C280003; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DA54280001; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B95C280007; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CB6A8280003 for ; Wed, 2 Apr 2025 11:00:10 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8A064ADBC6 for ; Wed, 2 Apr 2025 15:00:11 +0000 (UTC) X-FDA: 83289414222.07.074CBC8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 41DC314000D for ; Wed, 2 Apr 2025 15:00:09 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Rgpmie3P; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606010; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HxorfBgE1Uv1byaGENr7pDp1WuWnctNAqk3G3c3CU84=; b=iAB6FVNJ1ZJ6ofjKSL9nEi0Gp1DVbv5ythHJWHrJmOtolhFVYaL0VxhPgH5ev6u9aIjXFZ 2yY9MYN1SvMKDNzZG+G7l6D2hGvm0KxLtD1K/PS/rMjsdSNDsa/JpBeWcpwA6ra2h1kF+j J+ON5OE750jWwwKNU+6o1WkbRDhiq/c= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Rgpmie3P; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606010; a=rsa-sha256; cv=none; b=L980fOXI3s14O5JGjkRT1DFnGYf64pDmWvTEXsM8srjac9BDkNbuk5YHLpgJtr0VvqP7aa h2ieTWMRzPgWahDqauPprB34pwqwVsqaCKIYBk+tCB1pjta6ImYhwGEHlDMeeDojhC+Z3u vW1+UyirnPUsw887JAo2NzekdikpKT8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=HxorfBgE1Uv1byaGENr7pDp1WuWnctNAqk3G3c3CU84=; b=Rgpmie3PxYC1mfYW3w8XJdLFLM 68IZm5NGrCaClZqC3nKJYdIKGsB9h3JMsYOLPPY8ATYR0OcEt13uXZk9CS0jPSa/6/OEnVSnp+edn JtxL3K6k/cAaAPnIWeuw6+iwIVR25bAFZBbxqjronOrOtc8H5iobhcWmrZQdGWb2o0JqDsgecbGEB HfdWvIXKNnyRerhjAo32CuQy3pHoEKaBz0FHeCA9ZaSmapfUsfM+zxb2hRq+btwmZYOlie2LnekjW vQoPBKxXlold4/4j1Yc7w9yTYhuj1kWqrWw/hO7N07E6HYSJUOZHneXcoL9DAx1IweKyALy4yV8tG M75fmUIw==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gsR-2QUj; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 6/9] i915: Use writeback_iter() Date: Wed, 2 Apr 2025 16:00:00 +0100 Message-ID: <20250402150005.2309458-7-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 41DC314000D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: wdc1rjy63aw1z6nuwerxrx8a94otrusa X-HE-Tag: 1743606009-393146 X-HE-Meta: U2FsdGVkX18Ow5jtX/JFpN+R2cj/fft3kBhFoh6XtlAh3CUKuSJpiKkGC+oNXA7++cWFji6ooaof0h1Bn7X5rZVuNUBE1We1gBql+KVC/E5K1TrbaqChTRmn4j1zQ2lhu0cNdPp8Txh/AGDjfr8llCx+I99pEcR3OwX3/iyLgoopV/4SW40JEE5LEA5v2SkiKZO+jt5F/E4U+9OZ7DtRdkgEpyBB7uF+3gmCPB/wEMHml/0m4SCZSH48DRqhBk7mj2HgGyqBmt5om7lkIbJ7HjYSAQYuYoOWcuyJrNisqqo4/QH41XocrzUX6kIUCQQoBVDiq1WtvxyKykjNU/B4BdwKSX0g92aEkE6ZYgxbUPdqDPyThXRyxmWNqx235yt76MEszw/p1UM/C8xGgj5ijZ5R73Khn0hUtQjgyuSAJ3CMo06O4G4ECYek87w6g5IWe6Vhnws2CUU42ejnbayG6SWFW+A3HaYerkjvoQGLyiTvPmhf8m/EWyuVAPs4wQYwNBumELdh2qYZH2rujZ/HPwFEAjy8tlFkkVa7VFpYGL6MMPN2hnEsm7t8t4rS52XLeoqvjK9W8qB0bUz8ArRj0dVKnQqEg34tXHEBcdwCTLLtHsYouPC69mZB+SliP3xKdkmbYCQUWvUy/zcqrA5+MEvrDLKJ6EmKXvGF301LIdcFhtHmMGO241kxrYYOcQ1sEYDAlevbSl4uGXY+z07BPZAs6MTboKGBKS5nQUnPCyVSBQVH7yigcdvY9+4pImIyEd8RW5U7QT4hqhpP61/6fOprUL+mnJTifFrt5458BWWjBUZo11G+OPge3zC7RfS+qy+cbdiCS6M7vO9xyeheL7TCL96RKLXWsC2Ci2e8sa6KYcDtDLeIWZj6DNmfFW4ne5xZechEZpRod0RrR4XH6xRpk6YGKqvArtGhRPKEIUiPhZI+qvce6HG5yCK/lEXcWovi5cOzOKtRI1FRFc/ tXIeuRMI Ikedp/kEWDRjetPyfBZ569k3UsqQsh3dMpzcIgAMvvxz9WuQp31ZaijtAZTANAg7Bc8GsZ4qZoKtvFSW+Iah2ToCjj3DeltiOx4KuUymk+siU/1PA44SRnXKVUxE7GxehmN1Bo+CI8GhSEip20ap0JdJSX3aGIVR1ARChmFsQfq5EQtr7Z6LfwzSlff3P0kZRZsCqpwnaITyYB5VKOyNFQjZCZXs0oGBCPmXVLx9S0HU0Qwa0r0I6rXSnOstZLG8s5NVOsiTHGzpzfvJZhnz4oLs56tSs8QfTr8Qy X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Convert from an inefficient loop to the standard writeback iterator. Signed-off-by: Matthew Wilcox (Oracle) --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 32 ++++++----------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index ae3343c81a64..5e784db9f315 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -305,36 +305,20 @@ void __shmem_writeback(size_t size, struct address_space *mapping) .range_end = LLONG_MAX, .for_reclaim = 1, }; - unsigned long i; + struct folio *folio = NULL; + int error = 0; /* * Leave mmapings intact (GTT will have been revoked on unbinding, - * leaving only CPU mmapings around) and add those pages to the LRU + * leaving only CPU mmapings around) and add those folios to the LRU * instead of invoking writeback so they are aged and paged out * as normal. */ - - /* Begin writeback on each dirty page */ - for (i = 0; i < size >> PAGE_SHIFT; i++) { - struct page *page; - - page = find_lock_page(mapping, i); - if (!page) - continue; - - if (!page_mapped(page) && clear_page_dirty_for_io(page)) { - int ret; - - SetPageReclaim(page); - ret = mapping->a_ops->writepage(page, &wbc); - if (!PageWriteback(page)) - ClearPageReclaim(page); - if (!ret) - goto put; - } - unlock_page(page); -put: - put_page(page); + while ((folio = writeback_iter(mapping, &wbc, folio, &error))) { + if (folio_mapped(folio)) + folio_redirty_for_writepage(&wbc, folio); + else + error = shmem_writeout(folio, &wbc); } }