From patchwork Wed Jun 21 16:45:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13287648 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 A3314EB64DC for ; Wed, 21 Jun 2023 16:46:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F78E8D0009; Wed, 21 Jun 2023 12:46:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A8748D0002; Wed, 21 Jun 2023 12:46:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2233D8D0009; Wed, 21 Jun 2023 12:46:06 -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 EC1F28D0005 for ; Wed, 21 Jun 2023 12:46:05 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 97FA4C0927 for ; Wed, 21 Jun 2023 16:46:05 +0000 (UTC) X-FDA: 80927332290.29.4475009 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id BC0C04001F for ; Wed, 21 Jun 2023 16:46:03 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=WBpyN9BX; spf=none (imf17.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=1687365963; 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=yzS6LjqchbTZ4R7rHRoGuy4VZGAEBFE5nqlz2+V2o7A=; b=UgSYQMkSJweI7q9/5RE+vH2xdb14hnWlEmlB2+yLy6Os7cjbVpnuN4qraKE9Dyc/egb2vz OTAKIi5ns6j7Kw7SngO+Rfi1orFR9uXtz8GIstC2pZ8D6s3bHz00SRPcsA/di+z3mghpBb K25vOsIBt7VHM55Jzpw/IZUWzOl646s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687365963; a=rsa-sha256; cv=none; b=RtX9Tr50xkZriWczyZlL6vMKSiAvLr5LoZ9SR5ofugRH9QWmk+G+6tRqOCpVflIk/KTyZR RMDzGu7lNRiYUEJE0XZubBUmhz3wBEQHs4jtRE7N+ApD5H6YMpUpzLv9H1407YU1+b/qsn bf7siv59nJpvOiZt3KqyZWCb9Jd3zwE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=WBpyN9BX; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=yzS6LjqchbTZ4R7rHRoGuy4VZGAEBFE5nqlz2+V2o7A=; b=WBpyN9BXXz0sujrWmftgID2xoV kdlIrjAuPrDvE02NGbEGcLyBZ4Gh5juLzLRwS1aTs/iFXq/1LzJmB5OnGfnoB/gk9TrEijhUjAXEa zfpHDMGrt3LnGpZtYE4JE6eWPWyYdp2X2QggxQXZSI//nfSqIYLKPmLQneg7ai1fOJgcdgv30e8MD nMvTO7EwuTOqP49d04wRvN5Qg/gyTbkAb6jsLtg9q8C+RRUI0bD+XBrJIyUyiEfPwvF9jfze9zMT6 j21Ep+8UpwfWW4NGk2mJombjhn0YtTQ396FgivudfclsdbCqddsGj33hwbEIDLfpb4JolRAADXAQL nT3lFN0g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qC0y1-00EjDo-LH; Wed, 21 Jun 2023 16:46:01 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, Andrew Morton Cc: "Matthew Wilcox (Oracle)" , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 05/13] drm: Convert drm_gem_put_pages() to use a folio_batch Date: Wed, 21 Jun 2023 17:45:49 +0100 Message-Id: <20230621164557.3510324-6-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230621164557.3510324-1-willy@infradead.org> References: <20230621164557.3510324-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: BC0C04001F X-Rspam-User: X-Stat-Signature: 1dc6fw76t31pgwu1zjcthwkjm33f9xpf X-Rspamd-Server: rspam03 X-HE-Tag: 1687365963-916360 X-HE-Meta: U2FsdGVkX18LsqJf3XjiLjLFBYwZrp2UvkIoXgbqMsjPHBYcBwuDg0eAoSuDVdSf1J/ASV893HYQFQ7TpjPYRhgQ53QUhECoIphWiVjdCJYU/Mc5pMrbtiuUIbLt+3BUHN9X5oQ5D1LWl2bMB200CrsDvLxTTZDLhT48FDsLQRqt4HAPjTaUiqmAjTKTSFV5DCfHgT8DMvjTUDZyRFYAGTykGgWteiusoZvlmmhvA4Vg53WaAPo4jMu4uZq5URr45B3a5boaAE5AhifBgqQhEmOTLXXyBmefLnNJ9g7VlmU7wV3a6WQbgtNsLWeEahByFMnndHbPnl8LXHsGBGc1ENBtoSjn6G59XS9iRsfj/j8LzUErfQkHnICiapFHHYiG5WBR/6ayzmaJPbWrKq1dkFFy2JH4bVqeNIU7WrYj7/lniVPpW1HznWjhqYBXI3S33Q2nXqcqHc6q+UT6Ox1nI8/ooAhOWXbXax0veMDOikCnmM06yG5ldYpkk88rsLixgNtW730zW++jYFk3O2V2Ph3MbtOnQNs4QJx86Ed+Rq1I4kyWRViWDT3ZPbkQN68FsHWiULcvnPwZHAPX+5ObNQ6aByt1ZT0kvXEtV4R88+WSwXukm3tIA2exid5h9N+Mb4cy+bpArpoC/BFXoXdWBCevuv9BYoxfBn1eEanowXeBZcdstLnEclzEPBRxP3rkPHevdlSsuQnoJGOCaw1NNQIduoEPf48X4Qw0mgBlYqzAXMzEHI7ptSI7HX4fNrZPaMNumWV2BwiQTuPizXB3OkoHKceGfPsvu0S8PEb0Og7+yoZJD3b4WB3Oj2bHyHvxpsjXISn/SDJeNhQpfeBrppzHBWzZk95DLpACeq4fhpVlNCW61EQmH9IGoAHOVSHaiaZ7AhTwoaP84SIc2FxVgNNpYg+GlO66ZxBWasDzipiO0v3hhj25YVXfCZUqd6CaXZin7VrLxQLhxA4MKnM BeVWo/+m xggt4YWjtWx0/gB9oARC7E8SPKZnNuLrz9quxkFJHPkw3awgUEdeUi9UPpBCZs9V3HcHIQQASiwYJbIdl5Rczd6CPtFicTMJCTPUCTnMSnxgUaBomx8MGg2xPYl7O/sgjU7ymsCmgDKl/O8yQhzxfLx+o/7D0uvhq2TnIMshvt/eLTQJGGB6Uxj/x/iuyWqCL1BRm4MxqXs6yc75m4gwVPWiuYYUk6hasFrGC 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: Remove a few hidden compound_head() calls by converting the returned page to a folio once and using the folio APIs. Signed-off-by: Matthew Wilcox (Oracle) --- drivers/gpu/drm/drm_gem.c | 68 ++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 1a5a2cd0d4ec..78dcae201cc6 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -496,13 +496,13 @@ int drm_gem_create_mmap_offset(struct drm_gem_object *obj) EXPORT_SYMBOL(drm_gem_create_mmap_offset); /* - * Move pages to appropriate lru and release the pagevec, decrementing the - * ref count of those pages. + * Move folios to appropriate lru and release the folios, decrementing the + * ref count of those folios. */ -static void drm_gem_check_release_pagevec(struct pagevec *pvec) +static void drm_gem_check_release_batch(struct folio_batch *fbatch) { - check_move_unevictable_pages(pvec); - __pagevec_release(pvec); + check_move_unevictable_folios(fbatch); + __folio_batch_release(fbatch); cond_resched(); } @@ -534,10 +534,10 @@ static void drm_gem_check_release_pagevec(struct pagevec *pvec) struct page **drm_gem_get_pages(struct drm_gem_object *obj) { struct address_space *mapping; - struct page *p, **pages; - struct pagevec pvec; - int i, npages; - + struct page **pages; + struct folio *folio; + struct folio_batch fbatch; + int i, j, npages; if (WARN_ON(!obj->filp)) return ERR_PTR(-EINVAL); @@ -559,11 +559,14 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj) mapping_set_unevictable(mapping); - for (i = 0; i < npages; i++) { - p = shmem_read_mapping_page(mapping, i); - if (IS_ERR(p)) + i = 0; + while (i < npages) { + folio = shmem_read_folio_gfp(mapping, i, + mapping_gfp_mask(mapping)); + if (IS_ERR(folio)) goto fail; - pages[i] = p; + for (j = 0; j < folio_nr_pages(folio); j++, i++) + pages[i] = folio_file_page(folio, i); /* Make sure shmem keeps __GFP_DMA32 allocated pages in the * correct region during swapin. Note that this requires @@ -571,23 +574,26 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj) * so shmem can relocate pages during swapin if required. */ BUG_ON(mapping_gfp_constraint(mapping, __GFP_DMA32) && - (page_to_pfn(p) >= 0x00100000UL)); + (folio_pfn(folio) >= 0x00100000UL)); } return pages; fail: mapping_clear_unevictable(mapping); - pagevec_init(&pvec); - while (i--) { - if (!pagevec_add(&pvec, pages[i])) - drm_gem_check_release_pagevec(&pvec); + folio_batch_init(&fbatch); + j = 0; + while (j < i) { + struct folio *f = page_folio(pages[j]); + if (!folio_batch_add(&fbatch, f)) + drm_gem_check_release_batch(&fbatch); + j += folio_nr_pages(f); } - if (pagevec_count(&pvec)) - drm_gem_check_release_pagevec(&pvec); + if (fbatch.nr) + drm_gem_check_release_batch(&fbatch); kvfree(pages); - return ERR_CAST(p); + return ERR_CAST(folio); } EXPORT_SYMBOL(drm_gem_get_pages); @@ -603,7 +609,7 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, { int i, npages; struct address_space *mapping; - struct pagevec pvec; + struct folio_batch fbatch; mapping = file_inode(obj->filp)->i_mapping; mapping_clear_unevictable(mapping); @@ -616,23 +622,27 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, npages = obj->size >> PAGE_SHIFT; - pagevec_init(&pvec); + folio_batch_init(&fbatch); for (i = 0; i < npages; i++) { + struct folio *folio; + if (!pages[i]) continue; + folio = page_folio(pages[i]); if (dirty) - set_page_dirty(pages[i]); + folio_mark_dirty(folio); if (accessed) - mark_page_accessed(pages[i]); + folio_mark_accessed(folio); /* Undo the reference we took when populating the table */ - if (!pagevec_add(&pvec, pages[i])) - drm_gem_check_release_pagevec(&pvec); + if (!folio_batch_add(&fbatch, folio)) + drm_gem_check_release_batch(&fbatch); + i += folio_nr_pages(folio) - 1; } - if (pagevec_count(&pvec)) - drm_gem_check_release_pagevec(&pvec); + if (folio_batch_count(&fbatch)) + drm_gem_check_release_batch(&fbatch); kvfree(pages); }