2023-09-16 05:17:09

by Pankaj Raghav (Samsung)

[permalink] [raw]
Subject: [RFC 04/23] filemap: set the order of the index in page_cache_delete_batch()

From: Luis Chamberlain <[email protected]>

Similar to page_cache_delete(), call xas_set_order for non-hugetlb pages
while deleting an entry from the page cache. Also put BUG_ON if the
order of the folio is less than the mapping min_order.

Signed-off-by: Luis Chamberlain <[email protected]>
---
mm/filemap.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/mm/filemap.c b/mm/filemap.c
index b1ce63143df5..2c47729dc8b0 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -126,6 +126,7 @@
static void page_cache_delete(struct address_space *mapping,
struct folio *folio, void *shadow)
{
+ unsigned int min_order = mapping_min_folio_order(mapping);
XA_STATE(xas, &mapping->i_pages, folio->index);
long nr = 1;

@@ -134,6 +135,7 @@ static void page_cache_delete(struct address_space *mapping,
xas_set_order(&xas, folio->index, folio_order(folio));
nr = folio_nr_pages(folio);

+ VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio);
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);

xas_store(&xas, shadow);
@@ -276,6 +278,7 @@ void filemap_remove_folio(struct folio *folio)
static void page_cache_delete_batch(struct address_space *mapping,
struct folio_batch *fbatch)
{
+ unsigned int min_order = mapping_min_folio_order(mapping);
XA_STATE(xas, &mapping->i_pages, fbatch->folios[0]->index);
long total_pages = 0;
int i = 0;
@@ -304,6 +307,11 @@ static void page_cache_delete_batch(struct address_space *mapping,

WARN_ON_ONCE(!folio_test_locked(folio));

+ /* hugetlb pages are represented by a single entry in the xarray */
+ if (!folio_test_hugetlb(folio)) {
+ VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio);
+ xas_set_order(&xas, folio->index, folio_order(folio));
+ }
folio->mapping = NULL;
/* Leave folio->index set: truncation lookup relies on it */

--
2.40.1