From patchwork Wed Aug 24 00:40:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12952762 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BA9AC3F6B0 for ; Wed, 24 Aug 2022 00:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230482AbiHXAms (ORCPT ); Tue, 23 Aug 2022 20:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbiHXAmq (ORCPT ); Tue, 23 Aug 2022 20:42:46 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0712B85F83; Tue, 23 Aug 2022 17:42:46 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id x14-20020a17090a8a8e00b001fb61a71d99so3695905pjn.2; Tue, 23 Aug 2022 17:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=roEOVbMBkZrS+KI85Bv7B/f0yshSydvUYCZY5utraVI=; b=axPR5zKGK6FMyTGxARPaldWKtH7yyljRt5bxFzpIGOUfrlF7+RCqumQ03cEhG8/mnR J4GdPGyiCvAQhoAR+VLKPErEwrHdTZsicE16ytnlwYQC02ac3i+UQjMzYcmQIFuv/BMe VgRpVk3yOG3Oy3AZRKq/NOkyFrGYzVAkxud7JOndBVhOysDfedJ46ou8jKoLkOzWVSgf pDQocPOwVQwzE8SHXCGvsWfYeASm9P85dA+4okdbCpu5deeBfX1oQrUBBZ9l1pzTJVYb pkqTdg7JukSeYz9o6engmowTMsgXeGTtX4InuI3CCb2A33IllR6xneDSV1xMPMPp4lfn iWgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=roEOVbMBkZrS+KI85Bv7B/f0yshSydvUYCZY5utraVI=; b=mLsfCpKHt6vi3QggqiqSEil3CoIdfZcNzBBUFgi9bP471+DJKXMfXTAZP2VcT7RWxY CzKRVTfAGIL1I0ZWnz+YGTUVIpZFdMygBMlmFl7/j1CiVRLSt3o8jRMj0LhAOVCas7C0 PMI9m1GRPwZAPLtv2oPBsyXrO0z3WygnhMgoMEbWG92/leo+MSEJ88K8gw11PYZ/ZShe ZSwBRCGUCPn0CUklRPPcmpbVyR1V7xzdXqMSkISo0jYgM/mA0KuVfpddSwZAHSwwze9V 31Lau78e4iVP/YhN/GTcmzAtHLGRShYGH7PE+J+/Cfek7m2MHaPZhMLxGDkXUxLJPsGe gMUA== X-Gm-Message-State: ACgBeo0VBvH63BTrXf80qOBmtzf1FzLy/4qudUInQjFwX/Ni1aiJMNFD FaF8/p0TZkeUE63aBthPeeNF2LnaxsMDJm7Z X-Google-Smtp-Source: AA6agR53GLH+fjC3PReEZrs7TBuuMUHLeMC2vLgvCj3RocZFLBaunRfuKN28TqxGevtAj9YnYzCjZw== X-Received: by 2002:a17:90b:3a92:b0:1fb:23f3:f218 with SMTP id om18-20020a17090b3a9200b001fb23f3f218mr5576811pjb.102.1661301765225; Tue, 23 Aug 2022 17:42:45 -0700 (PDT) Received: from vmfolio.. (c-73-189-111-8.hsd1.ca.comcast.net. [73.189.111.8]) by smtp.googlemail.com with ESMTPSA id ij5-20020a170902ab4500b0016dd667d511sm11063319plb.252.2022.08.23.17.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 17:42:44 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH v3 1/7] filemap: Add filemap_get_folios_contig() Date: Tue, 23 Aug 2022 17:40:17 -0700 Message-Id: <20220824004023.77310-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220824004023.77310-1-vishal.moola@gmail.com> References: <20220824004023.77310-1-vishal.moola@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This function is meant to replace find_get_pages_contig(). Unlike find_get_pages_contig(), filemap_get_folios_contig() no longer takes in a target number of pages to find - It returns up to 15 contiguous folios. To be more consistent with filemap_get_folios(), filemap_get_folios_contig() now also updates the start index passed in, and takes an end index. Signed-off-by: Vishal Moola (Oracle) --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 73 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index cc9adbaddb59..951936a2be1d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -720,6 +720,8 @@ static inline struct page *find_subpage(struct page *head, pgoff_t index) unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); +unsigned filemap_get_folios_contig(struct address_space *mapping, + pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start, unsigned int nr_pages, struct page **pages); unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index, diff --git a/mm/filemap.c b/mm/filemap.c index 8ccb868c3d95..8167bcc96e37 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2196,6 +2196,79 @@ bool folio_more_pages(struct folio *folio, pgoff_t index, pgoff_t max) return index < folio->index + folio_nr_pages(folio) - 1; } +/** + * filemap_get_folios_contig - Get a batch of contiguous folios + * @mapping: The address_space to search + * @start: The starting page index + * @end: The final page index (inclusive) + * @fbatch: The batch to fill + * + * filemap_get_folios_contig() works exactly like filemap_get_folios(), + * except the returned folios are guaranteed to be contiguous. This may + * not return all contiguous folios if the batch gets filled up. + * + * Return: The number of folios found. + * Also update @start to be positioned for traversal of the next folio. + */ + +unsigned filemap_get_folios_contig(struct address_space *mapping, + pgoff_t *start, pgoff_t end, struct folio_batch *fbatch) +{ + XA_STATE(xas, &mapping->i_pages, *start); + unsigned long nr; + struct folio *folio; + + rcu_read_lock(); + + for (folio = xas_load(&xas); folio && xas.xa_index <= end; + folio = xas_next(&xas)) { + if (xas_retry(&xas, folio)) + continue; + /* + * If the entry has been swapped out, we can stop looking. + * No current caller is looking for DAX entries. + */ + if (xa_is_value(folio)) + goto update_start; + + if (!folio_try_get_rcu(folio)) + goto retry; + + if (unlikely(folio != xas_reload(&xas))) + goto put_folio; + + if (!folio_batch_add(fbatch, folio)) { + nr = folio_nr_pages(folio); + + if (folio_test_hugetlb(folio)) + nr = 1; + *start = folio->index + nr; + goto out; + } + continue; +put_folio: + folio_put(folio); + +retry: + xas_reset(&xas); + } + +update_start: + nr = folio_batch_count(fbatch); + + if (nr) { + folio = fbatch->folios[nr - 1]; + if (folio_test_hugetlb(folio)) + *start = folio->index + 1; + else + *start = folio->index + folio_nr_pages(folio); + } +out: + rcu_read_unlock(); + return folio_batch_count(fbatch); +} +EXPORT_SYMBOL(filemap_get_folios_contig); + /** * find_get_pages_contig - gang contiguous pagecache lookup * @mapping: The address_space to search From patchwork Wed Aug 24 00:40:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12952763 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B969C38142 for ; Wed, 24 Aug 2022 00:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229759AbiHXAmu (ORCPT ); Tue, 23 Aug 2022 20:42:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230475AbiHXAms (ORCPT ); Tue, 23 Aug 2022 20:42:48 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C49D185FB5; Tue, 23 Aug 2022 17:42:47 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id 67so6811441pfv.2; Tue, 23 Aug 2022 17:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=7skDaFS+wO3x7T1TXAuYW/BptQcipesiqb0XDCtUEEw=; b=eHdJm85W11mqHe7iSlXRQz2ygLqKExb3lA40z8uFuGfbXq3WXeGy9DXultohRdLawo 7Qd4RYcqXdiOD1jVazkFWrVfbcEpZLkLKiYEbbVNpAP6i1Nd7Enztpw0rco/HtfAgelS yXfeHGXyD3xjvUoNPjR0C5NtRVGRp7UlscxmNBTFPWt1x2OwLuMcANfed4zmLsZjT/45 2+zuuS+rYfMhq3rXHITdzud7s/woaEpElOxkAQsM6OVktlhuI4CydOja6ok5+Q7WCPNx 7UYV6GrwTNA8j6aGb/1ATFVVL0qJDsULOKYgFWsLu62kFPJLVN89ECVXY93Qo3YIHNjG RWfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=7skDaFS+wO3x7T1TXAuYW/BptQcipesiqb0XDCtUEEw=; b=BRY0yZ1pRE+beGrrw3k7cjBTjIihwSXPiH2LRODQAGHyKQdwxVBogAQVryWcmIsERs LnEdnphPT2U0B/UxT7jB/qBPNxgLo+XHvKgO6JZQ2tz0qi0Yxt9FjnmZowsnYt91f1+H mdrQ+3pKfWlL+nYWYzZiXrWd1mVyuLdD1HdZ9CpoLWmGwKC0KahTFH3qP26ya/e4mObe 5KO3Q0yNHRF/y/bnwF5JKe4RoNz3MRIclWLyca3Qae2pztaaEx2D1RKxBCvh7iFmwLDO b4z01Evi4BgQHkKM6MyNJ/aBP8jctoRjsCzgm8LmgtXGYYWg+RwnJjcBro0H6wQO/XQ9 /FFA== X-Gm-Message-State: ACgBeo3NNR4Yxy1yaG3EpNMCVoLvRVvm8KEtYdHKOry1CL9ZzYw+Qu5n ZQ3DzhuHijhHrbzAWn0ybCcESNsXnK1fmOdC X-Google-Smtp-Source: AA6agR5Q1Wli3z1uHbV2YZ/D6eEz/caJjcTDDqR90x6WtSvY1gRmMDL8bMOFSbjugWK/cuKV+GsHyw== X-Received: by 2002:aa7:9084:0:b0:535:ed0c:f401 with SMTP id i4-20020aa79084000000b00535ed0cf401mr25266450pfa.48.1661301767013; Tue, 23 Aug 2022 17:42:47 -0700 (PDT) Received: from vmfolio.. (c-73-189-111-8.hsd1.ca.comcast.net. [73.189.111.8]) by smtp.googlemail.com with ESMTPSA id ij5-20020a170902ab4500b0016dd667d511sm11063319plb.252.2022.08.23.17.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 17:42:46 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" , David Sterba Subject: [PATCH v3 2/7] btrfs: Convert __process_pages_contig() to use filemap_get_folios_contig() Date: Tue, 23 Aug 2022 17:40:18 -0700 Message-Id: <20220824004023.77310-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220824004023.77310-1-vishal.moola@gmail.com> References: <20220824004023.77310-1-vishal.moola@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Convert to use folios throughout. This is in preparation for the removal of find_get_pages_contig(). Now also supports large folios. Since we may receive more than nr_pages pages, nr_pages may underflow. Since nr_pages > 0 is equivalent to index <= end_index, we replaced it with this check instead. Acked-by: David Sterba Signed-off-by: Vishal Moola (Oracle) --- fs/btrfs/extent_io.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 8f6b544ae616..f16929bc531b 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1882,9 +1882,8 @@ static int __process_pages_contig(struct address_space *mapping, pgoff_t start_index = start >> PAGE_SHIFT; pgoff_t end_index = end >> PAGE_SHIFT; pgoff_t index = start_index; - unsigned long nr_pages = end_index - start_index + 1; unsigned long pages_processed = 0; - struct page *pages[16]; + struct folio_batch fbatch; int err = 0; int i; @@ -1893,16 +1892,17 @@ static int __process_pages_contig(struct address_space *mapping, ASSERT(processed_end && *processed_end == start); } - if ((page_ops & PAGE_SET_ERROR) && nr_pages > 0) + if ((page_ops & PAGE_SET_ERROR) && start_index <= end_index) mapping_set_error(mapping, -EIO); - while (nr_pages > 0) { - int found_pages; + folio_batch_init(&fbatch); + while (index <= end_index) { + int found_folios; + + found_folios = filemap_get_folios_contig(mapping, &index, + end_index, &fbatch); - found_pages = find_get_pages_contig(mapping, index, - min_t(unsigned long, - nr_pages, ARRAY_SIZE(pages)), pages); - if (found_pages == 0) { + if (found_folios == 0) { /* * Only if we're going to lock these pages, we can find * nothing at @index. @@ -1912,23 +1912,20 @@ static int __process_pages_contig(struct address_space *mapping, goto out; } - for (i = 0; i < found_pages; i++) { + for (i = 0; i < found_folios; i++) { int process_ret; - + struct folio *folio = fbatch.folios[i]; process_ret = process_one_page(fs_info, mapping, - pages[i], locked_page, page_ops, + &folio->page, locked_page, page_ops, start, end); if (process_ret < 0) { - for (; i < found_pages; i++) - put_page(pages[i]); err = -EAGAIN; + folio_batch_release(&fbatch); goto out; } - put_page(pages[i]); - pages_processed++; + pages_processed += folio_nr_pages(folio); } - nr_pages -= found_pages; - index += found_pages; + folio_batch_release(&fbatch); cond_resched(); } out: From patchwork Wed Aug 24 00:40:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12952764 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52E7DC38145 for ; Wed, 24 Aug 2022 00:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbiHXAmz (ORCPT ); Tue, 23 Aug 2022 20:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbiHXAmu (ORCPT ); Tue, 23 Aug 2022 20:42:50 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E6086044; Tue, 23 Aug 2022 17:42:49 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id s31-20020a17090a2f2200b001faaf9d92easo18829866pjd.3; Tue, 23 Aug 2022 17:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=qAIZUZ0pgScRmQa0duFh/+V4CGm9o36zgCrAtR/Z4DI=; b=oI3O32y9Nc1raAftWQD45HU0GA4593iugYPxYzJPeePQFlHLBee2vueXj2ulohnlGD 0apI5Vd2fXUvaSfIfbhGlpXWV8qX5pAShMjdTMdoMsZPlf0qnMkxYf0Mt7om59P/zn0D nkf6+QPwhFNNcbPSMmPiebGNWB5Fyut9TU52gVuzsPb0lqdPHa06BWertBwZr/3AkyLF 6G3GMlyy5cWyGBlHl/U/aIJUlygwCrZndzi8pl6TFqpKdhcY0snfUl3PeC/zdS/Z90cK XGmdiXzwyIPV20FBVatPpV4QZVBMlp43v26aUh+bcTSoSOOt++Szi9rUHP6iiXXqbfVr Ntuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=qAIZUZ0pgScRmQa0duFh/+V4CGm9o36zgCrAtR/Z4DI=; b=arjb2gi4oHi9W4mZKS3hcPYcLkXlPYfgBBDuofSjGJ2gnN3K8RN1Uvc9xyK6a2VVsK rubBLFN+Ston/wzfMwQAcOidYwP4/gfhSfRdSxuUpzyhL8hgsvZw9T8fJYsoW0hyCDUR +AiFHH2hRCHtE+xNjdVS98qARKlyRHFRnyeA+gbAqGakOfacemqnTitbZp+gOtVHH6xK ke0C+aQfjG+D4Bk26iC8vevDLjRcn0K0ggJPh7JL09J/bf5mjhj2Q62SeCCcT+CH6Szl x8TrJdkyWT/ye8G6C2i4Y+wDoated1+sPVPcRD1hlRvg2NxEJ3Ayo8YUd8wwS932pIFc 6eAw== X-Gm-Message-State: ACgBeo2pMkgTy7GLLOstbL3kbYfYeCkXYr3p03TIKANTt7fqrDCAXJuV K4P4HMCfyENmYY+kloitVpVDS4CyN58GQ54u X-Google-Smtp-Source: AA6agR5llaHTn279DIwEZUeEMnW3NXj8vtX5ysX6JUk/8qA8xgTynGzMRCc6FPq/y4eEsBnNCo1oEQ== X-Received: by 2002:a17:903:22c6:b0:172:cad9:403 with SMTP id y6-20020a17090322c600b00172cad90403mr19905404plg.123.1661301768634; Tue, 23 Aug 2022 17:42:48 -0700 (PDT) Received: from vmfolio.. (c-73-189-111-8.hsd1.ca.comcast.net. [73.189.111.8]) by smtp.googlemail.com with ESMTPSA id ij5-20020a170902ab4500b0016dd667d511sm11063319plb.252.2022.08.23.17.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 17:42:48 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" , David Sterba Subject: [PATCH v3 3/7] btrfs: Convert end_compressed_writeback() to use filemap_get_folios() Date: Tue, 23 Aug 2022 17:40:19 -0700 Message-Id: <20220824004023.77310-4-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220824004023.77310-1-vishal.moola@gmail.com> References: <20220824004023.77310-1-vishal.moola@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Converted function to use folios throughout. This is in preparation for the removal of find_get_pages_contig(). Now also supports large folios. Since we may receive more than nr_pages pages, nr_pages may underflow. Since nr_pages > 0 is equivalent to index <= end_index, we replaced it with this check instead. Also this function does not care about the pages being contiguous so we can just use filemap_get_folios() to be more efficient. Acked-by: David Sterba Signed-off-by: Vishal Moola (Oracle) --- fs/btrfs/compression.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index f4564f32f6d9..e0f8839cdd94 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -339,8 +340,7 @@ static noinline void end_compressed_writeback(struct inode *inode, struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); unsigned long index = cb->start >> PAGE_SHIFT; unsigned long end_index = (cb->start + cb->len - 1) >> PAGE_SHIFT; - struct page *pages[16]; - unsigned long nr_pages = end_index - index + 1; + struct folio_batch fbatch; const int errno = blk_status_to_errno(cb->status); int i; int ret; @@ -348,24 +348,23 @@ static noinline void end_compressed_writeback(struct inode *inode, if (errno) mapping_set_error(inode->i_mapping, errno); - while (nr_pages > 0) { - ret = find_get_pages_contig(inode->i_mapping, index, - min_t(unsigned long, - nr_pages, ARRAY_SIZE(pages)), pages); - if (ret == 0) { - nr_pages -= 1; - index += 1; - continue; - } + folio_batch_init(&fbatch); + while (index <= end_index) { + ret = filemap_get_folios(inode->i_mapping, &index, end_index, + &fbatch); + + if (ret == 0) + return; + for (i = 0; i < ret; i++) { + struct folio *folio = fbatch.folios[i]; + if (errno) - SetPageError(pages[i]); - btrfs_page_clamp_clear_writeback(fs_info, pages[i], + folio_set_error(folio); + btrfs_page_clamp_clear_writeback(fs_info, &folio->page, cb->start, cb->len); - put_page(pages[i]); } - nr_pages -= ret; - index += ret; + folio_batch_release(&fbatch); } /* the inode may be gone now */ } From patchwork Wed Aug 24 00:40:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12952766 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 614F1C32793 for ; Wed, 24 Aug 2022 00:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232034AbiHXAnA (ORCPT ); Tue, 23 Aug 2022 20:43:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbiHXAmy (ORCPT ); Tue, 23 Aug 2022 20:42:54 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF5186078; Tue, 23 Aug 2022 17:42:50 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id c2so14298513plo.3; Tue, 23 Aug 2022 17:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=fsvLs3dxCPx9IBTgjKC5zI8Z7kYUASZBA4STFA8FapY=; b=kl5Ynp+b/qJi5XM2umHjmSQHEkTDDMvpacUO50PPBjgNqBHxyxqWoXIUMOfjvHAJG3 oTGpKYfRiQ2GATQsJK0r9x42oinbboBr24fMIoK5LkiCM+8rQCJpZ15JcqKG+SzzWWdV /ChBcvv2dcdg92KmuvoNdeZZDzs+3KpmPPVT3ALy0+KQgopUCBZSq4NP89tr0HGtT/0V RP+TGfuY37/5Cg37DKL/cYxkJQRHYkhYRtyap5srPgo9RhQ9HCuU/cMf42hMXoTI+xfi de7hAL1mVJQ5y0T8dbCMF93yPMTrknbk2/3R/gCW32MNC4js0B9AaAgywAg9xISbM646 tVJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=fsvLs3dxCPx9IBTgjKC5zI8Z7kYUASZBA4STFA8FapY=; b=bA0Ik7P0lpGj3j4xCwXPh0r2c4qXjLbtNSt8ZzMClZG9jkuCS6bvqdzivVhDT68brv bowvid55SgQrW6vRILITnX0uX9ST94zrgOJobR4aKi1Vo9p0SW/t+clez404wmobhybc eCh8JRnikYG3sE8CFiXBKnzfWBw7/7kH4ru880tFGrT7kg8MGzOGoZpJLkQoxRkD4vuC goa+KCv6mDlHwjVvJET86N273i6mcXLDhPvgd8wdUXZ2nyFfCGXycHsX/GgR4LvekA3P drQbd+BoT+wRnV5ECqh7m4eXOGy9EBafjk1qDoIJKCnPwS6KBs0GNCfqeuIACJcjXROy tIKA== X-Gm-Message-State: ACgBeo0AJr6dyvNSc5G9l7cGeYtLBLIba69ErPDIVUoncWU0BsLyTFbz KvxSBaiyxRqHSsnLXNnAK3FIrMk2kUW/ZHhz X-Google-Smtp-Source: AA6agR6J0l1eMiiv5vUNrdo/CN/+qTnn+dZoNKOj6OE1MQuDAUmCobIy9S2J7jrjIr9Qw3KkvqcoFw== X-Received: by 2002:a17:90b:1d02:b0:1fb:77df:2c6 with SMTP id on2-20020a17090b1d0200b001fb77df02c6mr2391864pjb.102.1661301769897; Tue, 23 Aug 2022 17:42:49 -0700 (PDT) Received: from vmfolio.. (c-73-189-111-8.hsd1.ca.comcast.net. [73.189.111.8]) by smtp.googlemail.com with ESMTPSA id ij5-20020a170902ab4500b0016dd667d511sm11063319plb.252.2022.08.23.17.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 17:42:49 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" , David Sterba Subject: [PATCH v3 4/7] btrfs: Convert process_page_range() to use filemap_get_folios_contig() Date: Tue, 23 Aug 2022 17:40:20 -0700 Message-Id: <20220824004023.77310-5-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220824004023.77310-1-vishal.moola@gmail.com> References: <20220824004023.77310-1-vishal.moola@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Converted function to use folios throughout. This is in preparation for the removal of find_get_pages_contig(). Now also supports large folios. Since we may receive more than nr_pages pages, nr_pages may underflow. Since nr_pages > 0 is equivalent to index <= end_index, we replaced it with this check instead. Also minor comment renaming for consistency in subpage. Acked-by: David Sterba Signed-off-by: Vishal Moola (Oracle) --- fs/btrfs/subpage.c | 2 +- fs/btrfs/tests/extent-io-tests.c | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c index a105b291444f..6418c38c4b30 100644 --- a/fs/btrfs/subpage.c +++ b/fs/btrfs/subpage.c @@ -337,7 +337,7 @@ bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_info, * * Even with 0 returned, the page still need extra check to make sure * it's really the correct page, as the caller is using - * find_get_pages_contig(), which can race with page invalidating. + * filemap_get_folios_contig(), which can race with page invalidating. */ int btrfs_page_start_writer_lock(const struct btrfs_fs_info *fs_info, struct page *page, u64 start, u32 len) diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c index a232b15b8021..26b0c99f54b8 100644 --- a/fs/btrfs/tests/extent-io-tests.c +++ b/fs/btrfs/tests/extent-io-tests.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -20,39 +21,40 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end, unsigned long flags) { int ret; - struct page *pages[16]; + struct folio_batch fbatch; unsigned long index = start >> PAGE_SHIFT; unsigned long end_index = end >> PAGE_SHIFT; - unsigned long nr_pages = end_index - index + 1; int i; int count = 0; int loops = 0; - while (nr_pages > 0) { - ret = find_get_pages_contig(inode->i_mapping, index, - min_t(unsigned long, nr_pages, - ARRAY_SIZE(pages)), pages); + folio_batch_init(&fbatch); + + while (index <= end_index) { + ret = filemap_get_folios_contig(inode->i_mapping, &index, + end_index, &fbatch); for (i = 0; i < ret; i++) { + struct folio *folio = fbatch.folios[i]; + if (flags & PROCESS_TEST_LOCKED && - !PageLocked(pages[i])) + !folio_test_locked(folio)) count++; - if (flags & PROCESS_UNLOCK && PageLocked(pages[i])) - unlock_page(pages[i]); - put_page(pages[i]); + if (flags & PROCESS_UNLOCK && folio_test_locked(folio)) + folio_unlock(folio); if (flags & PROCESS_RELEASE) - put_page(pages[i]); + folio_put(folio); } - nr_pages -= ret; - index += ret; + folio_batch_release(&fbatch); cond_resched(); loops++; if (loops > 100000) { printk(KERN_ERR - "stuck in a loop, start %llu, end %llu, nr_pages %lu, ret %d\n", - start, end, nr_pages, ret); + "stuck in a loop, start %llu, end %llu, ret %d\n", + start, end, ret); break; } } + return count; } From patchwork Wed Aug 24 00:40:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12952765 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAEE3C38142 for ; Wed, 24 Aug 2022 00:43:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231918AbiHXAm7 (ORCPT ); Tue, 23 Aug 2022 20:42:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231492AbiHXAmy (ORCPT ); Tue, 23 Aug 2022 20:42:54 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E6E8861D4; Tue, 23 Aug 2022 17:42:51 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id g129so11680896pfb.8; Tue, 23 Aug 2022 17:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=KyMLiEXuqe6oMgJlOPUNT684cH6jPO08N05OJyEa5MI=; b=JXzLL8UAMMTyqxQPGNwR9rod7kTLexta+9ZdxunA7mrxp0SsVejkQaJC5Bmil85eaD jH1a6u8Qw8HCxqsOCfUc6dXwabaWbL1o3EKqezvzeM4nqchYD0Zj+Nmw3zXtu6Ivc5f1 EmVyKyYwbbK3AEFq5jQHeUtGYTArf4JfFOUDCmZx6nsXZ5aoClbLow/COO51EDjyteN0 Z5h2uy3b6bEdUihA/HT+I9Z7cRXmvPNXWmft999iQHIXvE2GFKctDA5u/QCN3Gs/WtGS mygT/DoUY6gHw3/Bu1+ryrseK5gWZjTBlO4ZKmPq4oIHx6urSYB5Io7e8qe2QSPRV7El NI5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=KyMLiEXuqe6oMgJlOPUNT684cH6jPO08N05OJyEa5MI=; b=IoiTr604QBuKUqdCNQkK18I7Q83akzdtn5jq72MV0xVE98SQ5VNGYOjtd/zh+tJXKj 4QkXFq5f+voJhQycUwCEV/fKEk74c6kdPOzSoTRq8IEmIZRZc20ElnkpCome8CpnyKNR 2YxqXCyW6uwq8S+y9oVR45/7js6WCDSnOr9pZK7Qi3JzEZfCvZE8q4Aqxpwo1yIQTKM/ D4bSqdIhAhdP2VeLY92IYlJWJ4fDEDn1+9asVFod2keWIBPKlL1RTZXaftObgzHJtSJq 792Rvu65Vw/WZOVjSYG7BYOfKxpGlRRE8NoPQC0wqxJPvovboIMqXq0afcWvUryI9okJ hLKg== X-Gm-Message-State: ACgBeo0rP+MD/xxTnNkKYbi+YrkxwolRLO4DgXKDb+wJskt5Pirzu5iX ccClrrwY7izE5vzT1voIJ57YBg9W1Hf7grmp X-Google-Smtp-Source: AA6agR7ZhhuWt7Z3orz6dRd2bYxDUpCPJIMRmnwoYYc0vK/g3DtqDkZxoGhhEptFnPNqDJqxc/NxIg== X-Received: by 2002:aa7:8887:0:b0:536:a411:40d0 with SMTP id z7-20020aa78887000000b00536a41140d0mr11726341pfe.46.1661301771045; Tue, 23 Aug 2022 17:42:51 -0700 (PDT) Received: from vmfolio.. (c-73-189-111-8.hsd1.ca.comcast.net. [73.189.111.8]) by smtp.googlemail.com with ESMTPSA id ij5-20020a170902ab4500b0016dd667d511sm11063319plb.252.2022.08.23.17.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 17:42:50 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH v3 5/7] nilfs2: Convert nilfs_find_uncommited_extent() to use filemap_get_folios_contig() Date: Tue, 23 Aug 2022 17:40:21 -0700 Message-Id: <20220824004023.77310-6-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220824004023.77310-1-vishal.moola@gmail.com> References: <20220824004023.77310-1-vishal.moola@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Converted function to use folios throughout. This is in preparation for the removal of find_get_pages_contig(). Now also supports large folios. Also cleaned up an unnecessary if statement - pvec.pages[0]->index > index will always evaluate to false, and filemap_get_folios_contig() returns 0 if there is no folio found at index. Signed-off-by: Vishal Moola (Oracle) Acked-by: Ryusuke Konishi --- fs/nilfs2/page.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c index 3267e96c256c..39b7eea2642a 100644 --- a/fs/nilfs2/page.c +++ b/fs/nilfs2/page.c @@ -480,41 +480,36 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode, sector_t start_blk, sector_t *blkoff) { - unsigned int i; + unsigned int i, nr_folios; pgoff_t index; - unsigned int nblocks_in_page; unsigned long length = 0; - sector_t b; - struct pagevec pvec; - struct page *page; + struct folio_batch fbatch; + struct folio *folio; if (inode->i_mapping->nrpages == 0) return 0; index = start_blk >> (PAGE_SHIFT - inode->i_blkbits); - nblocks_in_page = 1U << (PAGE_SHIFT - inode->i_blkbits); - pagevec_init(&pvec); + folio_batch_init(&fbatch); repeat: - pvec.nr = find_get_pages_contig(inode->i_mapping, index, PAGEVEC_SIZE, - pvec.pages); - if (pvec.nr == 0) + nr_folios = filemap_get_folios_contig(inode->i_mapping, &index, ULONG_MAX, + &fbatch); + if (nr_folios == 0) return length; - if (length > 0 && pvec.pages[0]->index > index) - goto out; - - b = pvec.pages[0]->index << (PAGE_SHIFT - inode->i_blkbits); i = 0; do { - page = pvec.pages[i]; + folio = fbatch.folios[i]; - lock_page(page); - if (page_has_buffers(page)) { + folio_lock(folio); + if (folio_buffers(folio)) { struct buffer_head *bh, *head; + sector_t b; - bh = head = page_buffers(page); + b = folio->index << (PAGE_SHIFT - inode->i_blkbits); + bh = head = folio_buffers(folio); do { if (b < start_blk) continue; @@ -529,21 +524,17 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode, } else { if (length > 0) goto out_locked; - - b += nblocks_in_page; } - unlock_page(page); + folio_unlock(folio); - } while (++i < pagevec_count(&pvec)); + } while (++i < nr_folios); - index = page->index + 1; - pagevec_release(&pvec); + folio_batch_release(&fbatch); cond_resched(); goto repeat; out_locked: - unlock_page(page); -out: - pagevec_release(&pvec); + folio_unlock(folio); + folio_batch_release(&fbatch); return length; } From patchwork Wed Aug 24 00:40:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12952767 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18420C32793 for ; Wed, 24 Aug 2022 00:43:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbiHXAnD (ORCPT ); Tue, 23 Aug 2022 20:43:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231516AbiHXAmy (ORCPT ); Tue, 23 Aug 2022 20:42:54 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57A5A861FB; Tue, 23 Aug 2022 17:42:53 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id io24so993013plb.1; Tue, 23 Aug 2022 17:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=uj5rrWVo2hhIgeuvVD0w6VogaYUvVvctXUbaYlCVCAo=; b=ojG9SQPgHrXaANCUaSiNdwQENvFe0haF1bqg2TNsX0PZ4L89+S9oEqG3x9mSHNOmCX fEkkxL5MmF2Z+NoSCrF7uNfE6LOSdRvjC+VTS7SYmQu5M4NnGKBD9B5TiVgrFjDzCruf ANQMTXrR9WRRE/NMOxIWTzrUPOQwD6wcQDRW7d/A3HQruAY8Q/LFHBCLjO+NulfdW0ej OG6BFSK5Hgghaq2RPMGKBYCZxcxHmlqEO0Kwmibm4qoLBH+INxAubDUtJqb670NJ+JN/ WmfukncGRHe3XrC+vSmdtg51xSWy2Eoaktuu073lH25G+RTwB0r8uRdzZPr4xNjjFfn5 aEjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=uj5rrWVo2hhIgeuvVD0w6VogaYUvVvctXUbaYlCVCAo=; b=3I1DUeXQc+AuvvsT2UdB1Q+k63u4/SGMDV5l04jAgzaUhiGMHpmtpdCXofPlsHJ7Ab J/pa3A2xZ/GHCPTvXbSsgxclQfSo5Gs00ubkKJJMZrzaQZ6eYT3cPFiZ6WmBvmFe0Y3e ReX5ZTLT7+egGfZOXXPlgmphFhM4GJ5J7ccz5lD6jVBP+dCJ1OcLySdSZQUtkSIHRR9t V/GUO2Irx+ht48B/16LWuo5UW1jqltyyeZJ0fH6NGZbcvLj4fLx9D4lAn+V4rT969sHB 33sCxwurDcIvdnyFPKx0c7c9LEJ8rRjTtcEa0jI3sfffx2m7RHvl0sxadgYGxw5EviSN GslQ== X-Gm-Message-State: ACgBeo20m0cXw7mBw99KhvNV075cEnLFWP67YUtT9YmXZ9ROAx9T/pUB ZZD0zz6ci4sGIl29aFE/pdVyUYQ8ypxB7Q4m X-Google-Smtp-Source: AA6agR4QKpwL6R2zyk4XY3/XZMQUNveYTQy+QnagYV81kICTpxGmHkiP0SGAa0ajiEmDjO3dLDXJ2Q== X-Received: by 2002:a17:902:7b87:b0:172:8ae9:2015 with SMTP id w7-20020a1709027b8700b001728ae92015mr26859761pll.112.1661301772273; Tue, 23 Aug 2022 17:42:52 -0700 (PDT) Received: from vmfolio.. (c-73-189-111-8.hsd1.ca.comcast.net. [73.189.111.8]) by smtp.googlemail.com with ESMTPSA id ij5-20020a170902ab4500b0016dd667d511sm11063319plb.252.2022.08.23.17.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 17:42:51 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH v3 6/7] ramfs: Convert ramfs_nommu_get_unmapped_area() to use filemap_get_folios_contig() Date: Tue, 23 Aug 2022 17:40:22 -0700 Message-Id: <20220824004023.77310-7-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220824004023.77310-1-vishal.moola@gmail.com> References: <20220824004023.77310-1-vishal.moola@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Converted to use folios throughout. This is in preparation for the removal for find_get_pages_contig(). Now also supports large folios. The initial version of this function set the page_address to be returned after finishing all the checks. Since folio_batches have a maximum of 15 folios, the function had to be modified to support getting and checking up to lpages, 15 pages at a time while still returning the initial page address. Now the function sets ret as soon as the first batch arrives, and updates it only if a check fails. The physical adjacency check utilizes the page frame numbers. The page frame number of each folio must be nr_pages away from the first folio. Signed-off-by: Vishal Moola (Oracle) --- --- fs/ramfs/file-nommu.c | 50 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c index ba3525ccc27e..cb240eac5036 100644 --- a/fs/ramfs/file-nommu.c +++ b/fs/ramfs/file-nommu.c @@ -203,9 +203,9 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { - unsigned long maxpages, lpages, nr, loop, ret; + unsigned long maxpages, lpages, nr_folios, loop, ret, nr_pages, pfn; struct inode *inode = file_inode(file); - struct page **pages = NULL, **ptr, *page; + struct folio_batch fbatch; loff_t isize; /* the mapping mustn't extend beyond the EOF */ @@ -221,31 +221,39 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file, goto out; /* gang-find the pages */ - pages = kcalloc(lpages, sizeof(struct page *), GFP_KERNEL); - if (!pages) - goto out_free; - - nr = find_get_pages_contig(inode->i_mapping, pgoff, lpages, pages); - if (nr != lpages) - goto out_free_pages; /* leave if some pages were missing */ + folio_batch_init(&fbatch); + nr_pages = 0; +repeat: + nr_folios = filemap_get_folios_contig(inode->i_mapping, &pgoff, + ULONG_MAX, &fbatch); + if (!nr_folios) { + ret = -ENOSYS; + return ret; + } + if (ret == -ENOSYS) { + ret = (unsigned long) folio_address(fbatch.folios[0]); + pfn = folio_pfn(fbatch.folios[0]); + } /* check the pages for physical adjacency */ - ptr = pages; - page = *ptr++; - page++; - for (loop = lpages; loop > 1; loop--) - if (*ptr++ != page++) - goto out_free_pages; + for (loop = 0; loop < nr_folios; loop++) { + if (pfn + nr_pages != folio_pfn(fbatch.folios[loop])) { + ret = -ENOSYS; + goto out_free; /* leave if not physical adjacent */ + } + nr_pages += folio_nr_pages(fbatch.folios[loop]); + if (nr_pages >= lpages) + goto out_free; /* successfully found desired pages*/ + } + if (nr_pages < lpages) { + folio_batch_release(&fbatch); + goto repeat; /* loop if pages are missing */ + } /* okay - all conditions fulfilled */ - ret = (unsigned long) page_address(pages[0]); -out_free_pages: - ptr = pages; - for (loop = nr; loop > 0; loop--) - put_page(*ptr++); out_free: - kfree(pages); + folio_batch_release(&fbatch); out: return ret; } From patchwork Wed Aug 24 00:40:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 12952768 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C94D8C38142 for ; Wed, 24 Aug 2022 00:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232432AbiHXAnF (ORCPT ); Tue, 23 Aug 2022 20:43:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231597AbiHXAmz (ORCPT ); Tue, 23 Aug 2022 20:42:55 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4563E8670D; Tue, 23 Aug 2022 17:42:54 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id o14-20020a17090a0a0e00b001fabfd3369cso16326163pjo.5; Tue, 23 Aug 2022 17:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=/CfNnOMJk6G65551bZckVmJ3kjJ/k4Yc+qvoAg65GHU=; b=G8TXZ41ypzXH2ZGDemwUIRnrhlgVru1aOFOrt11RUGeOxYD2OEbjqjcKoGK6qHOJi9 MbtYizKOZFfhZwL8kE8b9i9Vda56q1LheWpsm8zBqVGawexnK256o4cNnjDR2yR0RNj1 jWmHonngeuWnuopR3tvKa2pkmlrs5Pvf+FehXXpbrFYiVp5TramRl4P9BVFicecGfqZH 7P5r07WqQCaO+01g7WRirRh4lfh0/bgOArCv3maqdBcWCfoaSptp5Y2zL01c+FWlMUrG VMAMO5V/XsqnEjfd4gfoDT7FqrQQU9iEiOVlcQ7iQkIuLOAklkrQAyE4dm4arHMjJXHc ptNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=/CfNnOMJk6G65551bZckVmJ3kjJ/k4Yc+qvoAg65GHU=; b=rWnHl09JEFu2ZUGBehDWRZ5p5UW9zfY0o8HmeyhhXIuu4vAKjhgtSEvvJ72QAPho4T q724JQsBgOUf7b4CxDvqj03nTXX3ZoBf6JdnSUtlyQa8Uyg+EzcPdED/6CDJ1G3idQjV n610irLHnsxnh95FsvXZHeXKa3A6KnMmevij5Qf7GO/rCwss4BE4rt6K7vY3VT+7v6fY 56eQlto9sINx7OgnTPfN/Youcb7BLkYidfFTkwT6udh2SD7g48RETQQ4ijFa+LP/GuCw PQLVcuYRs8C0GY66RDQ5Em0re3+OvJ8+58KJOxSdfX/1m5XC9JdPFjnYe2msspDAx5MC ODyQ== X-Gm-Message-State: ACgBeo2xZSjyGsCI3u2iEypefd7DPESZF21saFNt5lOJicfpYUKyEXyS PYclF368eAE6pKwf9SFP3xXXi/f/PdEg51Ot X-Google-Smtp-Source: AA6agR5WT/40tN+ZgWF8O3r0YRQFSvwdr0HcxJVpLFddbFnLr3FgL+4iWeI2l6ZXe1RaOMtfOyIiEw== X-Received: by 2002:a17:902:bd41:b0:172:74c9:2a08 with SMTP id b1-20020a170902bd4100b0017274c92a08mr26498900plx.9.1661301773430; Tue, 23 Aug 2022 17:42:53 -0700 (PDT) Received: from vmfolio.. (c-73-189-111-8.hsd1.ca.comcast.net. [73.189.111.8]) by smtp.googlemail.com with ESMTPSA id ij5-20020a170902ab4500b0016dd667d511sm11063319plb.252.2022.08.23.17.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 17:42:52 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH v3 7/7] filemap: Remove find_get_pages_contig() Date: Tue, 23 Aug 2022 17:40:23 -0700 Message-Id: <20220824004023.77310-8-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220824004023.77310-1-vishal.moola@gmail.com> References: <20220824004023.77310-1-vishal.moola@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org All callers of find_get_pages_contig() have been removed, so it is no longer needed. Signed-off-by: Vishal Moola (Oracle) --- include/linux/pagemap.h | 2 -- mm/filemap.c | 60 ----------------------------------------- 2 files changed, 62 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 951936a2be1d..a04a645b64e9 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -722,8 +722,6 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); unsigned filemap_get_folios_contig(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); -unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start, - unsigned int nr_pages, struct page **pages); unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index, pgoff_t end, xa_mark_t tag, unsigned int nr_pages, struct page **pages); diff --git a/mm/filemap.c b/mm/filemap.c index 8167bcc96e37..af5a4b5f866d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2269,66 +2269,6 @@ unsigned filemap_get_folios_contig(struct address_space *mapping, } EXPORT_SYMBOL(filemap_get_folios_contig); -/** - * find_get_pages_contig - gang contiguous pagecache lookup - * @mapping: The address_space to search - * @index: The starting page index - * @nr_pages: The maximum number of pages - * @pages: Where the resulting pages are placed - * - * find_get_pages_contig() works exactly like find_get_pages_range(), - * except that the returned number of pages are guaranteed to be - * contiguous. - * - * Return: the number of pages which were found. - */ -unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, - unsigned int nr_pages, struct page **pages) -{ - XA_STATE(xas, &mapping->i_pages, index); - struct folio *folio; - unsigned int ret = 0; - - if (unlikely(!nr_pages)) - return 0; - - rcu_read_lock(); - for (folio = xas_load(&xas); folio; folio = xas_next(&xas)) { - if (xas_retry(&xas, folio)) - continue; - /* - * If the entry has been swapped out, we can stop looking. - * No current caller is looking for DAX entries. - */ - if (xa_is_value(folio)) - break; - - if (!folio_try_get_rcu(folio)) - goto retry; - - if (unlikely(folio != xas_reload(&xas))) - goto put_page; - -again: - pages[ret] = folio_file_page(folio, xas.xa_index); - if (++ret == nr_pages) - break; - if (folio_more_pages(folio, xas.xa_index, ULONG_MAX)) { - xas.xa_index++; - folio_ref_inc(folio); - goto again; - } - continue; -put_page: - folio_put(folio); -retry: - xas_reset(&xas); - } - rcu_read_unlock(); - return ret; -} -EXPORT_SYMBOL(find_get_pages_contig); - /** * find_get_pages_range_tag - Find and return head pages matching @tag. * @mapping: the address_space to search