From patchwork Tue Oct 11 21:56:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vishal Moola (Oracle)" X-Patchwork-Id: 13004459 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 0F8ADC433FE for ; Tue, 11 Oct 2022 21:57:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 042136B0073; Tue, 11 Oct 2022 17:57:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F32E38E0001; Tue, 11 Oct 2022 17:57:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFA0C6B0075; Tue, 11 Oct 2022 17:57:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C43F46B0073 for ; Tue, 11 Oct 2022 17:57:11 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 86BBD120650 for ; Tue, 11 Oct 2022 21:57:11 +0000 (UTC) X-FDA: 80010029862.10.0EF321E Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf24.hostedemail.com (Postfix) with ESMTP id 2C3EF180027 for ; Tue, 11 Oct 2022 21:57:10 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id d7-20020a17090a2a4700b0020d268b1f02so236386pjg.1 for ; Tue, 11 Oct 2022 14:57:10 -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:subject:date :message-id:reply-to; bh=g3WvdRkzSdLVTgj44Ys6XklIheIaxbrqec5BQ0TfTfc=; b=EcEBClDeo6ogTrRId+6TLulSFrp2uvrU+ZkBvLmCm/JAUYaMDshArhrjPjASJyWpjD 0XcrucWAEo5V+aKPBXl9o2biWj7vnOssQnsSa3MUmP8tm/CVyQcYe9op9mTL8+KueHrU Tbee5GWcb3LlXal/kFRUxbtqVWsnEezH5ynVxgLyrJFklrLxr5A7X5K2VR9ZYsaC8CJR Uj0lhF1aJEDuLlR1Sv8JB8Tyw/azUGoAJGDIK44DUxynYCuD/VxMLhPFUWU++voFSkAO OcR/qEjtWfnbPkj/a2JC+TOGNfTKTePy9UoWMZK7rNdFavGeqkGp4Md4exQ4hNbqe2sq wwxw== 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 :subject:date:message-id:reply-to; bh=g3WvdRkzSdLVTgj44Ys6XklIheIaxbrqec5BQ0TfTfc=; b=bx1g71+GBGk+IAmh+FSa3RMh53+VuM8An5We8PQrTa6ou1YOFnyRd/lJhEIa7Z+GIh TuClwg0d3iJoWdLIhz2V5h7rlOcvJCJJ76AFhN002gb8Cg0/70BW7gsKb0mYktxXVbjX v8AeE0DAPuBaBR1ohAbE2EbceGqw26EwJvmxwBs7zk3oM+pE6tYjYLm6XbC007xVPNIn 7gXvrRulotd9BjMRT6+mmofZjaYFykpin6rb9C71I+JO1mKNBQ/BO+OLTtKgt69Vzat3 /2+HKdGCYU7m7N0XxsQwAOYhSekcThI6ss3/tuUrXmwAbL0i+ZZW518b8de0Xqpg0g7k IL3w== X-Gm-Message-State: ACrzQf0mGx1cHoX0y0zLVqTbH1c2SoNe/XuGDKA5JM/FV7XBpHZjne7E +GlSTG57qNn2hw5vTuQYU/4= X-Google-Smtp-Source: AMsMyM6wjMzwhiGk87FX5YgO5U51L5rHNxunbkLzsRulGcSgra54n7TeCV+744ohlWrnCtmZWeJhAg== X-Received: by 2002:a17:903:210d:b0:184:1881:bfe6 with SMTP id o13-20020a170903210d00b001841881bfe6mr2841548ple.80.1665525429934; Tue, 11 Oct 2022 14:57:09 -0700 (PDT) Received: from vmfolio.. (c-76-102-73-225.hsd1.ca.comcast.net. [76.102.73.225]) by smtp.googlemail.com with ESMTPSA id z17-20020a170903019100b0018123556931sm6580371plg.204.2022.10.11.14.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 14:57:09 -0700 (PDT) From: "Vishal Moola (Oracle)" To: akpm@linux-foundation.org Cc: willy@infradead.org, hughd@google.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH 1/4] filemap: find_lock_entries() now updates start offset Date: Tue, 11 Oct 2022 14:56:31 -0700 Message-Id: <20221011215634.478330-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221011215634.478330-1-vishal.moola@gmail.com> References: <20221011215634.478330-1-vishal.moola@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665525431; 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=g3WvdRkzSdLVTgj44Ys6XklIheIaxbrqec5BQ0TfTfc=; b=s4mIpkCZLXreTHo5eaTT6XoSWyR+XQuAbj7daRVXKqCgimPmJdMsHVXOPpSZCV7/zgpocy 4/QEQIb72H3WxbdlvQ12306wj3iU03MBRX1dqecrsZiWw++1V3AoKXlaHvdeMqqS6c0hd3 tOQrqU9MYP+Rnt6dC784hOx59ofOygY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EcEBClDe; spf=pass (imf24.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665525431; a=rsa-sha256; cv=none; b=Pe6rVoz45EN/aaF8nPqbWqfUILlcEGCI96ZL0H2/f1uEZxRVb6CLbJ9JqAEgKu1u4HEDA2 cRzob8nGemA2EUowAMugcI+aM3uDX30a5UScGwZ95UeQMoxKY+iNAfqt7n9GlGvWi7F7zQ 0Adx95fUrtRC0Vn2QbyDB3jFlYaHK+Y= X-Rspam-User: X-Rspamd-Server: rspam11 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EcEBClDe; spf=pass (imf24.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: ew9f94kk57ixbo7sjeap9mikdrma78te X-Rspamd-Queue-Id: 2C3EF180027 X-HE-Tag: 1665525430-315625 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: Initially, find_lock_entries() was being passed in the start offset as a value. That left the calculation of the offset to the callers. This led to complexity in the callers trying to keep track of the index. Now find_lock_entires() takes in a pointer to the start offset and updates the value to be directly after the last entry found. If no entry is found, the offset is not changed. This gets rid of multiple hacky calculations that kept track of the start offset. Signed-off-by: Vishal Moola (Oracle) --- mm/filemap.c | 17 ++++++++++++++--- mm/internal.h | 2 +- mm/shmem.c | 8 ++------ mm/truncate.c | 12 ++++-------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 08341616ae7a..e95500b07ee9 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2084,17 +2084,19 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t start, * locked or folios under writeback. * * Return: The number of entries which were found. + * Also updates @start to be positioned after the last found entry */ -unsigned find_lock_entries(struct address_space *mapping, pgoff_t start, +unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices) { - XA_STATE(xas, &mapping->i_pages, start); + XA_STATE(xas, &mapping->i_pages, *start); + unsigned long nr; struct folio *folio; rcu_read_lock(); while ((folio = find_get_entry(&xas, end, XA_PRESENT))) { if (!xa_is_value(folio)) { - if (folio->index < start) + if (folio->index < *start) goto put; if (folio->index + folio_nr_pages(folio) - 1 > end) goto put; @@ -2116,7 +2118,16 @@ unsigned find_lock_entries(struct address_space *mapping, pgoff_t start, folio_put(folio); } rcu_read_unlock(); + nr = folio_batch_count(fbatch); + + if (nr) { + folio = fbatch->folios[nr - 1]; + nr = folio_nr_pages(folio); + if (folio_test_hugetlb(folio)) + nr = 1; + *start = folio->index + nr; + } return folio_batch_count(fbatch); } diff --git a/mm/internal.h b/mm/internal.h index 6b7ef495b56d..c504ac7267e0 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -106,7 +106,7 @@ static inline void force_page_cache_readahead(struct address_space *mapping, force_page_cache_ra(&ractl, nr_to_read); } -unsigned find_lock_entries(struct address_space *mapping, pgoff_t start, +unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); unsigned find_get_entries(struct address_space *mapping, pgoff_t start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); diff --git a/mm/shmem.c b/mm/shmem.c index 86214d48dd09..ab4f6dfcf6bb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -922,21 +922,18 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio_batch_init(&fbatch); index = start; - while (index < end && find_lock_entries(mapping, index, end - 1, + while (index < end && find_lock_entries(mapping, &index, end - 1, &fbatch, indices)) { for (i = 0; i < folio_batch_count(&fbatch); i++) { folio = fbatch.folios[i]; - index = indices[i]; - if (xa_is_value(folio)) { if (unfalloc) continue; nr_swaps_freed += !shmem_free_swap(mapping, - index, folio); + folio->index, folio); continue; } - index += folio_nr_pages(folio) - 1; if (!unfalloc || !folio_test_uptodate(folio)) truncate_inode_folio(mapping, folio); @@ -945,7 +942,6 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio_batch_remove_exceptionals(&fbatch); folio_batch_release(&fbatch); cond_resched(); - index++; } same_folio = (lstart >> PAGE_SHIFT) == (lend >> PAGE_SHIFT); diff --git a/mm/truncate.c b/mm/truncate.c index c0be77e5c008..b0bd63b2359f 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -361,9 +361,8 @@ void truncate_inode_pages_range(struct address_space *mapping, folio_batch_init(&fbatch); index = start; - while (index < end && find_lock_entries(mapping, index, end - 1, + while (index < end && find_lock_entries(mapping, &index, end - 1, &fbatch, indices)) { - index = indices[folio_batch_count(&fbatch) - 1] + 1; truncate_folio_batch_exceptionals(mapping, &fbatch, indices); for (i = 0; i < folio_batch_count(&fbatch); i++) truncate_cleanup_folio(fbatch.folios[i]); @@ -510,20 +509,18 @@ unsigned long invalidate_mapping_pagevec(struct address_space *mapping, int i; folio_batch_init(&fbatch); - while (find_lock_entries(mapping, index, end, &fbatch, indices)) { + while (find_lock_entries(mapping, &index, end, &fbatch, indices)) { for (i = 0; i < folio_batch_count(&fbatch); i++) { struct folio *folio = fbatch.folios[i]; /* We rely upon deletion not changing folio->index */ - index = indices[i]; if (xa_is_value(folio)) { count += invalidate_exceptional_entry(mapping, - index, - folio); + folio->index, + folio); continue; } - index += folio_nr_pages(folio) - 1; ret = mapping_evict_folio(mapping, folio); folio_unlock(folio); @@ -542,7 +539,6 @@ unsigned long invalidate_mapping_pagevec(struct address_space *mapping, folio_batch_remove_exceptionals(&fbatch); folio_batch_release(&fbatch); cond_resched(); - index++; } return count; } From patchwork Tue Oct 11 21:56:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vishal Moola (Oracle)" X-Patchwork-Id: 13004460 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 F2918C43219 for ; Tue, 11 Oct 2022 21:57:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A545E8E0001; Tue, 11 Oct 2022 17:57:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0278900002; Tue, 11 Oct 2022 17:57:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82E498E0002; Tue, 11 Oct 2022 17:57:12 -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 706AC8E0001 for ; Tue, 11 Oct 2022 17:57:12 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 33E28C0477 for ; Tue, 11 Oct 2022 21:57:12 +0000 (UTC) X-FDA: 80010029904.04.EDE3422 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf10.hostedemail.com (Postfix) with ESMTP id C799BC001E for ; Tue, 11 Oct 2022 21:57:11 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id g8-20020a17090a128800b0020c79f987ceso207948pja.5 for ; Tue, 11 Oct 2022 14:57:11 -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:subject:date :message-id:reply-to; bh=2AXBXWk9KM8i6fKoe7c/6PSVGCSRYeW1GgiDFc8Dazo=; b=RcSCx6GfPgO1zqmEGbdDQcTUwIoMsiDavOa4LQzTIn/Kys1oeo6SjCBVThk33JTJqV lbJEHsFMZ7YTdE6nlgQh0eJxcFSzAqG4mXO8UOH0FDwsbOa2HIBnETyCkzMogatR+KjZ C5hu0sQPVZOOV1U766tB+LuH2Mg5cvwNUcHT2qaELJW4eV5wj8/v7aRQ5McJgFUCt6lL 2GC+XXnttD4uZbATsL6DOkqDgmFtFMH6ir67cYUdZTnN/veUnWCSMWLBjX6lp/NyZ+m9 RiOym3by81erUatbFgimWcCXnDcUnH9AAe8EHyx1Y3JDbKPa7BXFS5ISqh2IKGkwUSmZ hryg== 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 :subject:date:message-id:reply-to; bh=2AXBXWk9KM8i6fKoe7c/6PSVGCSRYeW1GgiDFc8Dazo=; b=tr6MMdGBBufLppcQn/3im0wEMmcOstNnvRap2xCq7VL4lnVdqxF/upukol4X768Lq2 K3z1zhv56M0YrSU7QxdXuunRlA679/c8+DoiAYHJmv0gn3w+2fdqjbkmriAixssu9R2W T8ZUWTuHrQSQ94v2ahaFXqGoSbj2vdPQwlF406Dj0YnImkuJuW0DpfBjlqX9ij1Xyjh4 NuPhmh2ByDYDzMja0wRyUzby8WwJLQEzIZrS7la17rXn1E1Fqq1AGRJNz+jYIJsjzCTH hlLAb+LrO2keShvMJLNSBish+1ApUpk0s9dVZJTmgNUiYGNhpKYbWUSVeX/gmyUbMRiv JJkQ== X-Gm-Message-State: ACrzQf0XkOmuOMogA7JE0kBEndv44MuEHAF4CKveLZa78fBXT8VX93k4 WJ35unO2s9lzav3aEfL16Po= X-Google-Smtp-Source: AMsMyM5iKzVl/ZJYl342ueaPo+/J5AaNlY1YB4giH4BsCeRbJwSLh01n3j9aRW6XYipvoTRiZU04MA== X-Received: by 2002:a17:903:2285:b0:17f:6a39:7097 with SMTP id b5-20020a170903228500b0017f6a397097mr27134374plh.51.1665525430731; Tue, 11 Oct 2022 14:57:10 -0700 (PDT) Received: from vmfolio.. (c-76-102-73-225.hsd1.ca.comcast.net. [76.102.73.225]) by smtp.googlemail.com with ESMTPSA id z17-20020a170903019100b0018123556931sm6580371plg.204.2022.10.11.14.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 14:57:10 -0700 (PDT) From: "Vishal Moola (Oracle)" To: akpm@linux-foundation.org Cc: willy@infradead.org, hughd@google.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH 2/4] filemap: find_get_entries() now updates start offset Date: Tue, 11 Oct 2022 14:56:32 -0700 Message-Id: <20221011215634.478330-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221011215634.478330-1-vishal.moola@gmail.com> References: <20221011215634.478330-1-vishal.moola@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665525431; a=rsa-sha256; cv=none; b=6Nnchi9tFXlUjwJAPgvj8S0NerNv5vJXXcXNKmTfBulPKqnAnLqdBY9Wt7OLHq5va2kwds 26YYNFFtZXDIilxwtroazi5Db6EvxFNWkh2qY8ebc9cyZ++AromWbCFLh50wInB6whsgl/ xOd7rjPRcUB6sTKu1hRB8hHmvl/hXDA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RcSCx6Gf; spf=pass (imf10.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665525431; 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=2AXBXWk9KM8i6fKoe7c/6PSVGCSRYeW1GgiDFc8Dazo=; b=PJIBFbzXwJ2WZC7J5ofV5m3NV3/fKA30QME4LGpWYFdJovW+pfCtlT9tLAKEknGyCclxGW B0NLowpi0lWAUCsF2/6dzD3yhoW5ub4dkNgmxuPDxNravl1b+tmfE4v9B/mDsLfjckYvnk Avsro2jvMd6CffwRUwx2X/DpuJOQoW8= X-Rspam-User: X-Stat-Signature: djwngaqy36bfkur5afxwe8xxku7reisd X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C799BC001E Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RcSCx6Gf; spf=pass (imf10.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1665525431-347144 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: Initially, find_get_entries() was being passed in the start offset as a value. That left the calculation of the offset to the callers. This led to complexity in the callers trying to keep track of the index. Now find_get_entires() takes in a pointer to the start offset and updates the value to be directly after the last entry found. If no entry is found, the offset is not changed. This gets rid of multiple hacky calculations that kept track of the start offset. Signed-off-by: Vishal Moola (Oracle) --- mm/filemap.c | 15 +++++++++++++-- mm/internal.h | 2 +- mm/shmem.c | 11 ++++------- mm/truncate.c | 23 +++++++++-------------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index e95500b07ee9..1b8022c18dc7 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2047,11 +2047,13 @@ static inline struct folio *find_get_entry(struct xa_state *xas, pgoff_t max, * shmem/tmpfs, are included in the returned array. * * Return: The number of entries which were found. + * Also updates @start to be positioned after the last found entry */ -unsigned find_get_entries(struct address_space *mapping, pgoff_t start, +unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices) { - XA_STATE(xas, &mapping->i_pages, start); + XA_STATE(xas, &mapping->i_pages, *start); + unsigned long nr; struct folio *folio; rcu_read_lock(); @@ -2061,7 +2063,16 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t start, break; } rcu_read_unlock(); + nr = folio_batch_count(fbatch); + + if (nr) { + folio = fbatch->folios[nr - 1]; + nr = folio_nr_pages(folio); + if (folio_test_hugetlb(folio)) + nr = 1; + *start = folio->index + nr; + } return folio_batch_count(fbatch); } diff --git a/mm/internal.h b/mm/internal.h index c504ac7267e0..68afdbe7106e 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -108,7 +108,7 @@ static inline void force_page_cache_readahead(struct address_space *mapping, unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); -unsigned find_get_entries(struct address_space *mapping, pgoff_t start, +unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); void filemap_free_folio(struct address_space *mapping, struct folio *folio); int truncate_inode_folio(struct address_space *mapping, struct folio *folio); diff --git a/mm/shmem.c b/mm/shmem.c index ab4f6dfcf6bb..8240e066edfc 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -973,7 +973,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, while (index < end) { cond_resched(); - if (!find_get_entries(mapping, index, end - 1, &fbatch, + if (!find_get_entries(mapping, &index, end - 1, &fbatch, indices)) { /* If all gone or hole-punch or unfalloc, we're done */ if (index == start || end != -1) @@ -985,13 +985,12 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, for (i = 0; i < folio_batch_count(&fbatch); i++) { folio = fbatch.folios[i]; - index = indices[i]; if (xa_is_value(folio)) { if (unfalloc) continue; - if (shmem_free_swap(mapping, index, folio)) { + if (shmem_free_swap(mapping, folio->index, folio)) { /* Swap was replaced by page: retry */ - index--; + index = folio->index; break; } nr_swaps_freed++; @@ -1004,19 +1003,17 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, if (folio_mapping(folio) != mapping) { /* Page was replaced by swap: retry */ folio_unlock(folio); - index--; + index = folio->index; break; } VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio); truncate_inode_folio(mapping, folio); } - index = folio->index + folio_nr_pages(folio) - 1; folio_unlock(folio); } folio_batch_remove_exceptionals(&fbatch); folio_batch_release(&fbatch); - index++; } spin_lock_irq(&info->lock); diff --git a/mm/truncate.c b/mm/truncate.c index b0bd63b2359f..846ddbdb27a4 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -400,7 +400,7 @@ void truncate_inode_pages_range(struct address_space *mapping, index = start; while (index < end) { cond_resched(); - if (!find_get_entries(mapping, index, end - 1, &fbatch, + if (!find_get_entries(mapping, &index, end - 1, &fbatch, indices)) { /* If all gone from start onwards, we're done */ if (index == start) @@ -414,21 +414,18 @@ void truncate_inode_pages_range(struct address_space *mapping, struct folio *folio = fbatch.folios[i]; /* We rely upon deletion not changing page->index */ - index = indices[i]; - if (xa_is_value(folio)) continue; folio_lock(folio); - VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio); + VM_BUG_ON_FOLIO(!folio_contains(folio, folio->index), + folio); folio_wait_writeback(folio); truncate_inode_folio(mapping, folio); folio_unlock(folio); - index = folio_index(folio) + folio_nr_pages(folio) - 1; } truncate_folio_batch_exceptionals(mapping, &fbatch, indices); folio_batch_release(&fbatch); - index++; } } EXPORT_SYMBOL(truncate_inode_pages_range); @@ -637,16 +634,14 @@ int invalidate_inode_pages2_range(struct address_space *mapping, folio_batch_init(&fbatch); index = start; - while (find_get_entries(mapping, index, end, &fbatch, indices)) { + while (find_get_entries(mapping, &index, end, &fbatch, indices)) { for (i = 0; i < folio_batch_count(&fbatch); i++) { struct folio *folio = fbatch.folios[i]; /* We rely upon deletion not changing folio->index */ - index = indices[i]; - if (xa_is_value(folio)) { if (!invalidate_exceptional_entry2(mapping, - index, folio)) + folio->index, folio)) ret = -EBUSY; continue; } @@ -656,13 +651,14 @@ int invalidate_inode_pages2_range(struct address_space *mapping, * If folio is mapped, before taking its lock, * zap the rest of the file in one hit. */ - unmap_mapping_pages(mapping, index, - (1 + end - index), false); + unmap_mapping_pages(mapping, folio->index, + (1 + end - folio->index), false); did_range_unmap = 1; } folio_lock(folio); - VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio); + VM_BUG_ON_FOLIO(!folio_contains(folio, folio->index), + folio); if (folio->mapping != mapping) { folio_unlock(folio); continue; @@ -685,7 +681,6 @@ int invalidate_inode_pages2_range(struct address_space *mapping, folio_batch_remove_exceptionals(&fbatch); folio_batch_release(&fbatch); cond_resched(); - index++; } /* * For DAX we invalidate page tables after invalidating page cache. We From patchwork Tue Oct 11 21:56:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vishal Moola (Oracle)" X-Patchwork-Id: 13004461 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 55739C433FE for ; Tue, 11 Oct 2022 21:57:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72035900003; Tue, 11 Oct 2022 17:57:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CFAF900002; Tue, 11 Oct 2022 17:57:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52159900003; Tue, 11 Oct 2022 17:57:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 40878900002 for ; Tue, 11 Oct 2022 17:57:13 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0063A1407A4 for ; Tue, 11 Oct 2022 21:57:12 +0000 (UTC) X-FDA: 80010029946.30.8BF7B91 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf09.hostedemail.com (Postfix) with ESMTP id A31C3140023 for ; Tue, 11 Oct 2022 21:57:12 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id l1-20020a17090a72c100b0020a6949a66aso245999pjk.1 for ; Tue, 11 Oct 2022 14:57:12 -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:subject:date :message-id:reply-to; bh=yKhqZ9JRxfUHd7ueXHu2hnxQ9xN5WH2xdUaf7T3ps+Y=; b=dur9V8U6avr6eGkxSZVUrKpuSoFFEw3r5SOEyHC0jqIiLFPOMXjVnqgh7rsvGgMJG0 6TfwFx3ajZ6v8lUQK/ljFO4/hzHBOlj0lEA8YLPsPLoLMsoHP29A/dC+cU2vEMpZZocn 36P7QGWbcTaTFZKWn0aSnczlTD0TSNV8ZzkFmr4X43sv9QQyyDXmpPZ5EMtC9Qkwm0bJ 6p5HMmqvoYWgDwaOwECANtWpHQh/a7lu3EwtFJamvh0YiuoQTzM3ebX9CCwtknosf6Hw nS5vPV+oe/1v7IJcBDTtMF4xkb9c6f78WXQ6ap4LAiIdoOPx68WG3gr853+NSp0KOpEu YlKg== 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 :subject:date:message-id:reply-to; bh=yKhqZ9JRxfUHd7ueXHu2hnxQ9xN5WH2xdUaf7T3ps+Y=; b=td4h39VLk+UTVfdoGZAVxSVlhXS8jjxMc6diPRK/Y1wwYSNq1fnLEAGB5rJ1hMvr5H irpo5F4L25ZknxCSCdK52/U/vfV26K8SnnyIXdWYwSPoIdDiL9cFUQlKZGYxj1zk6wCv fjd2b92cIybfN0juZLHP01G0TobpLKVYvkmNER6bLpNOl22FmeydZKtVwN5VHHM8HxUs d2OPr3DyTAuRpdCvac1C7SxmrEtkAGeomHrJ12XLerf3nrZXN8fC6Bh3bfFeiMZL8w4r GDBBeyFJ+M4UoXBpPVF6S6KHTREo+nXIe/praCNudUoMg7OcMr6p7rla4bqOWQZdWGNv 8QTw== X-Gm-Message-State: ACrzQf0MShZN5j0d9ZFjqNT4p+hcFxLbfaps1P9igU7J2F6ftwrEuBtG 2LYYCB8dGturihye8pqWwM2Lvfbx1moEqw== X-Google-Smtp-Source: AMsMyM5nSGmPeX92wxZjVokYJ/kQ1ovTA200qlKORsoRtP5J+yxFeMykTyyDynSg41ww8vRb7zIEkw== X-Received: by 2002:a17:902:e9ca:b0:17f:93b5:5ec8 with SMTP id 10-20020a170902e9ca00b0017f93b55ec8mr26066551plk.59.1665525431654; Tue, 11 Oct 2022 14:57:11 -0700 (PDT) Received: from vmfolio.. (c-76-102-73-225.hsd1.ca.comcast.net. [76.102.73.225]) by smtp.googlemail.com with ESMTPSA id z17-20020a170903019100b0018123556931sm6580371plg.204.2022.10.11.14.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 14:57:11 -0700 (PDT) From: "Vishal Moola (Oracle)" To: akpm@linux-foundation.org Cc: willy@infradead.org, hughd@google.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH 3/4] truncate: Remove indices argument from truncate_folio_batch_exceptionals() Date: Tue, 11 Oct 2022 14:56:33 -0700 Message-Id: <20221011215634.478330-4-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221011215634.478330-1-vishal.moola@gmail.com> References: <20221011215634.478330-1-vishal.moola@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dur9V8U6; spf=pass (imf09.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665525432; a=rsa-sha256; cv=none; b=oGpCyxRTmhHqT9GgbKARTsSUSJmSmx8GC2UnNERLZCZvWt7ChTWihCIh/O+agufHyEnS8l CTLIpMuvs8MlN0uN8K/FcViJUeKHcDiKAXF7fkYNMO66bHJa1N5GfI4IJZLx93UShgnDgd eLQapPjGPWR4uLk4kDewV5FOT7UcTL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665525432; 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=yKhqZ9JRxfUHd7ueXHu2hnxQ9xN5WH2xdUaf7T3ps+Y=; b=CvwAPM7Cy34H7Ple1zMXDCWpZ/nu6JUTT3AOJy/p49ZtQDdVOxSgxF3NfTZ8Ob6CJ7Qute z/hvYCJsoEA4kFoP/OqyyEBWNaKM0JnnzGEB72sBuRPi55fvJ8lowRFwVOmQB8HJ4tDU6r bht1rEu/D+icMJvbXgF4zc88jYpTNvw= X-Rspamd-Server: rspam05 X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dur9V8U6; spf=pass (imf09.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: yirao5ft71shbicipd7nxcn7dyhi8ya9 X-Rspamd-Queue-Id: A31C3140023 X-HE-Tag: 1665525432-164026 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: The indices array is unnecessary. Folios keep track of their xarray indices in the folio->index field which can simply be accessed as needed. This change is in preparation for the removal of the indices arguments of find_get_entries() and find_lock_entries(). Signed-off-by: Vishal Moola (Oracle) --- mm/truncate.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 846ddbdb27a4..4e63d885498a 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -58,7 +58,7 @@ static void clear_shadow_entry(struct address_space *mapping, pgoff_t index, * exceptional entries similar to what folio_batch_remove_exceptionals() does. */ static void truncate_folio_batch_exceptionals(struct address_space *mapping, - struct folio_batch *fbatch, pgoff_t *indices) + struct folio_batch *fbatch) { int i, j; bool dax; @@ -82,7 +82,6 @@ static void truncate_folio_batch_exceptionals(struct address_space *mapping, for (i = j; i < folio_batch_count(fbatch); i++) { struct folio *folio = fbatch->folios[i]; - pgoff_t index = indices[i]; if (!xa_is_value(folio)) { fbatch->folios[j++] = folio; @@ -90,11 +89,11 @@ static void truncate_folio_batch_exceptionals(struct address_space *mapping, } if (unlikely(dax)) { - dax_delete_mapping_entry(mapping, index); + dax_delete_mapping_entry(mapping, folio->index); continue; } - __clear_shadow_entry(mapping, index, folio); + __clear_shadow_entry(mapping, folio->index, folio); } if (!dax) { @@ -363,7 +362,7 @@ void truncate_inode_pages_range(struct address_space *mapping, index = start; while (index < end && find_lock_entries(mapping, &index, end - 1, &fbatch, indices)) { - truncate_folio_batch_exceptionals(mapping, &fbatch, indices); + truncate_folio_batch_exceptionals(mapping, &fbatch); for (i = 0; i < folio_batch_count(&fbatch); i++) truncate_cleanup_folio(fbatch.folios[i]); delete_from_page_cache_batch(mapping, &fbatch); @@ -424,7 +423,7 @@ void truncate_inode_pages_range(struct address_space *mapping, truncate_inode_folio(mapping, folio); folio_unlock(folio); } - truncate_folio_batch_exceptionals(mapping, &fbatch, indices); + truncate_folio_batch_exceptionals(mapping, &fbatch); folio_batch_release(&fbatch); } } From patchwork Tue Oct 11 21:56:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vishal Moola (Oracle)" X-Patchwork-Id: 13004462 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 BE48FC43217 for ; Tue, 11 Oct 2022 21:57:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37509900004; Tue, 11 Oct 2022 17:57:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 325E3900002; Tue, 11 Oct 2022 17:57:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17727900004; Tue, 11 Oct 2022 17:57:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 03068900002 for ; Tue, 11 Oct 2022 17:57:13 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D8FFC1A00DF for ; Tue, 11 Oct 2022 21:57:13 +0000 (UTC) X-FDA: 80010029946.17.A79E3C3 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf28.hostedemail.com (Postfix) with ESMTP id 6925BC002C for ; Tue, 11 Oct 2022 21:57:13 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id v10-20020a17090a634a00b00205e48cf845so212149pjs.4 for ; Tue, 11 Oct 2022 14:57:13 -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:subject:date :message-id:reply-to; bh=hXDbujsutxz3ngIaiJSWN9PnHbyRD3OgFchLZ9JC5Lo=; b=AYlGz70PIZyhQNjM/Pp+kDlhxI0tF4WMQOfLtk/ekNQRgN9Ryg8nV3g6d7Ogp9hFb4 RkFKc7VcBUyFEuKbtWBk7zY+UaP8ogbIUMr5IikoXh6EZt10Bn9RTXbf9klImU9xpiwG OVrarOKuCw2ZiFWChKbD6Jlpb+uuALJpUAegSOOJPrPRUog6y8xBumfw0exi2HOTTuTh MZS44y2LBJvC/jA+mSA8DntE1hWUO7M3xntY8klRbwxceSFR1yDXCloilgbWz/S8Suv2 TWhPwZF1LE1kzT39Kim3Ki6gXy6AeTHGoWppqfPxgNk7GJxrZgGxyFISdjoH/kRbpn6z s0kQ== 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 :subject:date:message-id:reply-to; bh=hXDbujsutxz3ngIaiJSWN9PnHbyRD3OgFchLZ9JC5Lo=; b=tuXAvbHpNDMjFW/2McDwFRgO5EYU2lqv6kuNG1L9zaAynOLUZZMfT+E452rf6/9RG8 7E9UoZa6CAeSf1rj1tKoLBt46XogZOSqLtihrww4nMDOO75s2/o8r79506y4yUzZQbR9 JXpihs2u9t0Gz0RMuMnEIluj0a2HqjJ+rgvF5FPQDSSEiQ0vNGgWlT5dV/D8CHKKwi66 XOwNweTGX62zEz6Ta1yADGaje8PfUTfX89EwGJeu7XSn7E2DWCZAD5tnq8AK5AIyfCKF 7reCZ+j9ajNxucPf5u3d/2Q3WQ5PxgA7zoKZ6orL60NWzlKvvp/FxCF6ljKsOVoE2qac oJjg== X-Gm-Message-State: ACrzQf2gmhNOuJFJk9Epd5pJ0pN67WJCFyd8NTIMy5DU144hFBQavF7M up6/hQrFa5vi0WyWUSiL4CmujYg1fBOK3A== X-Google-Smtp-Source: AMsMyM4lMDBv1ZDaUDkxWrgrJDmvQQx72heA97zHEVahr9/xNPYg8P/qKhBWIIlPosLXZJVP3x8/3A== X-Received: by 2002:a17:902:760d:b0:184:29:8ab8 with SMTP id k13-20020a170902760d00b0018400298ab8mr3405046pll.36.1665525432423; Tue, 11 Oct 2022 14:57:12 -0700 (PDT) Received: from vmfolio.. (c-76-102-73-225.hsd1.ca.comcast.net. [76.102.73.225]) by smtp.googlemail.com with ESMTPSA id z17-20020a170903019100b0018123556931sm6580371plg.204.2022.10.11.14.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 14:57:12 -0700 (PDT) From: "Vishal Moola (Oracle)" To: akpm@linux-foundation.org Cc: willy@infradead.org, hughd@google.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH 4/4] filemap: Remove indices argument from find_lock_entries() and find_get_entries() Date: Tue, 11 Oct 2022 14:56:34 -0700 Message-Id: <20221011215634.478330-5-vishal.moola@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221011215634.478330-1-vishal.moola@gmail.com> References: <20221011215634.478330-1-vishal.moola@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665525433; 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=hXDbujsutxz3ngIaiJSWN9PnHbyRD3OgFchLZ9JC5Lo=; b=3rv9XNVDrbPzbEQ3PEjuVeeahRKTBmGZN5VmUhTrIdPU+1nPcrtosOhBM08aPyKXYYzYlP k8TLMZOL39SNqIzGZ6TxflB21LE6KCAvaIV16KYE7GQUr56Whr27cj+D+5QeXK36rPZcaE PGR1pSlW+jWFHNx9qdnx4DqQ9H0E+V4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AYlGz70P; spf=pass (imf28.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665525433; a=rsa-sha256; cv=none; b=bytx+4AA5ZMFftcFT9fEKMFkZdyA1cAIUyv43TqCUVARjvQqfAtScAZXOi7ULb8Qjbbk5D SxtgNoLMlKgxlP/gPxEyavZgpdMRJQeze2JWX1tA44IKDoSnZXsAjdY9qx281Mo+aab21R UxnfPKnCtbHJIviiTs7YHmaXpe8GoBM= X-Rspam-User: X-Rspamd-Server: rspam11 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AYlGz70P; spf=pass (imf28.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: tw5kc3wt4bzugdxxo681mcmcuos1m8ee X-Rspamd-Queue-Id: 6925BC002C X-HE-Tag: 1665525433-441092 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: The indices array is unnecessary. Folios keep track of their xarray indices in the folio->index field which can simply be accessed as needed. This change removes the indices argument from find_lock_entries() and find_get_entries(). All of the callers are able to remove their indices arrays as well. Signed-off-by: Vishal Moola (Oracle) --- mm/filemap.c | 8 ++------ mm/internal.h | 4 ++-- mm/shmem.c | 6 ++---- mm/truncate.c | 12 ++++-------- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 1b8022c18dc7..1f6be113a214 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2034,7 +2034,6 @@ static inline struct folio *find_get_entry(struct xa_state *xas, pgoff_t max, * @start: The starting page cache index * @end: The final page index (inclusive). * @fbatch: Where the resulting entries are placed. - * @indices: The cache indices corresponding to the entries in @entries * * find_get_entries() will search for and return a batch of entries in * the mapping. The entries are placed in @fbatch. find_get_entries() @@ -2050,7 +2049,7 @@ static inline struct folio *find_get_entry(struct xa_state *xas, pgoff_t max, * Also updates @start to be positioned after the last found entry */ unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, - pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices) + pgoff_t end, struct folio_batch *fbatch) { XA_STATE(xas, &mapping->i_pages, *start); unsigned long nr; @@ -2058,7 +2057,6 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, rcu_read_lock(); while ((folio = find_get_entry(&xas, end, XA_PRESENT)) != NULL) { - indices[fbatch->nr] = xas.xa_index; if (!folio_batch_add(fbatch, folio)) break; } @@ -2082,7 +2080,6 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, * @start: The starting page cache index. * @end: The final page index (inclusive). * @fbatch: Where the resulting entries are placed. - * @indices: The cache indices of the entries in @fbatch. * * find_lock_entries() will return a batch of entries from @mapping. * Swap, shadow and DAX entries are included. Folios are returned @@ -2098,7 +2095,7 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, * Also updates @start to be positioned after the last found entry */ unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, - pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices) + pgoff_t end, struct folio_batch *fbatch) { XA_STATE(xas, &mapping->i_pages, *start); unsigned long nr; @@ -2119,7 +2116,6 @@ unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, VM_BUG_ON_FOLIO(!folio_contains(folio, xas.xa_index), folio); } - indices[fbatch->nr] = xas.xa_index; if (!folio_batch_add(fbatch, folio)) break; continue; diff --git a/mm/internal.h b/mm/internal.h index 68afdbe7106e..db8d5dfa6d68 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -107,9 +107,9 @@ static inline void force_page_cache_readahead(struct address_space *mapping, } unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, - pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); + pgoff_t end, struct folio_batch *fbatch); unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, - pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); + pgoff_t end, struct folio_batch *fbatch); void filemap_free_folio(struct address_space *mapping, struct folio *folio); int truncate_inode_folio(struct address_space *mapping, struct folio *folio); bool truncate_inode_partial_folio(struct folio *folio, loff_t start, diff --git a/mm/shmem.c b/mm/shmem.c index 8240e066edfc..ad6b5adf04ac 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -907,7 +907,6 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, pgoff_t start = (lstart + PAGE_SIZE - 1) >> PAGE_SHIFT; pgoff_t end = (lend + 1) >> PAGE_SHIFT; struct folio_batch fbatch; - pgoff_t indices[PAGEVEC_SIZE]; struct folio *folio; bool same_folio; long nr_swaps_freed = 0; @@ -923,7 +922,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio_batch_init(&fbatch); index = start; while (index < end && find_lock_entries(mapping, &index, end - 1, - &fbatch, indices)) { + &fbatch)) { for (i = 0; i < folio_batch_count(&fbatch); i++) { folio = fbatch.folios[i]; @@ -973,8 +972,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, while (index < end) { cond_resched(); - if (!find_get_entries(mapping, &index, end - 1, &fbatch, - indices)) { + if (!find_get_entries(mapping, &index, end - 1, &fbatch)) { /* If all gone or hole-punch or unfalloc, we're done */ if (index == start || end != -1) break; diff --git a/mm/truncate.c b/mm/truncate.c index 4e63d885498a..9db247a88483 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -332,7 +332,6 @@ void truncate_inode_pages_range(struct address_space *mapping, pgoff_t start; /* inclusive */ pgoff_t end; /* exclusive */ struct folio_batch fbatch; - pgoff_t indices[PAGEVEC_SIZE]; pgoff_t index; int i; struct folio *folio; @@ -361,7 +360,7 @@ void truncate_inode_pages_range(struct address_space *mapping, folio_batch_init(&fbatch); index = start; while (index < end && find_lock_entries(mapping, &index, end - 1, - &fbatch, indices)) { + &fbatch)) { truncate_folio_batch_exceptionals(mapping, &fbatch); for (i = 0; i < folio_batch_count(&fbatch); i++) truncate_cleanup_folio(fbatch.folios[i]); @@ -399,8 +398,7 @@ void truncate_inode_pages_range(struct address_space *mapping, index = start; while (index < end) { cond_resched(); - if (!find_get_entries(mapping, &index, end - 1, &fbatch, - indices)) { + if (!find_get_entries(mapping, &index, end - 1, &fbatch)) { /* If all gone from start onwards, we're done */ if (index == start) break; @@ -497,7 +495,6 @@ EXPORT_SYMBOL(truncate_inode_pages_final); unsigned long invalidate_mapping_pagevec(struct address_space *mapping, pgoff_t start, pgoff_t end, unsigned long *nr_pagevec) { - pgoff_t indices[PAGEVEC_SIZE]; struct folio_batch fbatch; pgoff_t index = start; unsigned long ret; @@ -505,7 +502,7 @@ unsigned long invalidate_mapping_pagevec(struct address_space *mapping, int i; folio_batch_init(&fbatch); - while (find_lock_entries(mapping, &index, end, &fbatch, indices)) { + while (find_lock_entries(mapping, &index, end, &fbatch)) { for (i = 0; i < folio_batch_count(&fbatch); i++) { struct folio *folio = fbatch.folios[i]; @@ -620,7 +617,6 @@ static int folio_launder(struct address_space *mapping, struct folio *folio) int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end) { - pgoff_t indices[PAGEVEC_SIZE]; struct folio_batch fbatch; pgoff_t index; int i; @@ -633,7 +629,7 @@ int invalidate_inode_pages2_range(struct address_space *mapping, folio_batch_init(&fbatch); index = start; - while (find_get_entries(mapping, &index, end, &fbatch, indices)) { + while (find_get_entries(mapping, &index, end, &fbatch)) { for (i = 0; i < folio_batch_count(&fbatch); i++) { struct folio *folio = fbatch.folios[i];