1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2018 HUAWEI, Inc.
4 * https://www.huawei.com/
5 * Copyright (C) 2022 Alibaba Cloud
9 #include <linux/prefetch.h>
11 #include <trace/events/erofs.h>
14 * since pclustersize is variable for big pcluster feature, introduce slab
15 * pools implementation for different pcluster sizes.
17 struct z_erofs_pcluster_slab {
18 struct kmem_cache *slab;
19 unsigned int maxpages;
23 #define _PCLP(n) { .maxpages = n }
25 static struct z_erofs_pcluster_slab pcluster_pool[] __read_mostly = {
26 _PCLP(1), _PCLP(4), _PCLP(16), _PCLP(64), _PCLP(128),
27 _PCLP(Z_EROFS_PCLUSTER_MAX_PAGES)
30 struct z_erofs_bvec_iter {
32 struct z_erofs_bvset *bvset;
36 static struct page *z_erofs_bvec_iter_end(struct z_erofs_bvec_iter *iter)
39 kunmap_local(iter->bvset);
43 static struct page *z_erofs_bvset_flip(struct z_erofs_bvec_iter *iter)
45 unsigned long base = (unsigned long)((struct z_erofs_bvset *)0)->bvec;
46 /* have to access nextpage in advance, otherwise it will be unmapped */
47 struct page *nextpage = iter->bvset->nextpage;
51 oldpage = z_erofs_bvec_iter_end(iter);
52 iter->bvpage = nextpage;
53 iter->bvset = kmap_local_page(nextpage);
54 iter->nr = (PAGE_SIZE - base) / sizeof(struct z_erofs_bvec);
59 static void z_erofs_bvec_iter_begin(struct z_erofs_bvec_iter *iter,
60 struct z_erofs_bvset_inline *bvset,
61 unsigned int bootstrap_nr,
64 *iter = (struct z_erofs_bvec_iter) {
66 .bvset = (struct z_erofs_bvset *)bvset,
69 while (cur > iter->nr) {
71 z_erofs_bvset_flip(iter);
76 static int z_erofs_bvec_enqueue(struct z_erofs_bvec_iter *iter,
77 struct z_erofs_bvec *bvec,
78 struct page **candidate_bvpage)
80 if (iter->cur == iter->nr) {
81 if (!*candidate_bvpage)
84 DBG_BUGON(iter->bvset->nextpage);
85 iter->bvset->nextpage = *candidate_bvpage;
86 z_erofs_bvset_flip(iter);
88 iter->bvset->nextpage = NULL;
89 *candidate_bvpage = NULL;
91 iter->bvset->bvec[iter->cur++] = *bvec;
95 static void z_erofs_bvec_dequeue(struct z_erofs_bvec_iter *iter,
96 struct z_erofs_bvec *bvec,
97 struct page **old_bvpage)
99 if (iter->cur == iter->nr)
100 *old_bvpage = z_erofs_bvset_flip(iter);
103 *bvec = iter->bvset->bvec[iter->cur++];
106 static void z_erofs_destroy_pcluster_pool(void)
110 for (i = 0; i < ARRAY_SIZE(pcluster_pool); ++i) {
111 if (!pcluster_pool[i].slab)
113 kmem_cache_destroy(pcluster_pool[i].slab);
114 pcluster_pool[i].slab = NULL;
118 static int z_erofs_create_pcluster_pool(void)
120 struct z_erofs_pcluster_slab *pcs;
121 struct z_erofs_pcluster *a;
124 for (pcs = pcluster_pool;
125 pcs < pcluster_pool + ARRAY_SIZE(pcluster_pool); ++pcs) {
126 size = struct_size(a, compressed_bvecs, pcs->maxpages);
128 sprintf(pcs->name, "erofs_pcluster-%u", pcs->maxpages);
129 pcs->slab = kmem_cache_create(pcs->name, size, 0,
130 SLAB_RECLAIM_ACCOUNT, NULL);
134 z_erofs_destroy_pcluster_pool();
140 static struct z_erofs_pcluster *z_erofs_alloc_pcluster(unsigned int nrpages)
144 for (i = 0; i < ARRAY_SIZE(pcluster_pool); ++i) {
145 struct z_erofs_pcluster_slab *pcs = pcluster_pool + i;
146 struct z_erofs_pcluster *pcl;
148 if (nrpages > pcs->maxpages)
151 pcl = kmem_cache_zalloc(pcs->slab, GFP_NOFS);
153 return ERR_PTR(-ENOMEM);
154 pcl->pclusterpages = nrpages;
157 return ERR_PTR(-EINVAL);
160 static void z_erofs_free_pcluster(struct z_erofs_pcluster *pcl)
162 unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
165 for (i = 0; i < ARRAY_SIZE(pcluster_pool); ++i) {
166 struct z_erofs_pcluster_slab *pcs = pcluster_pool + i;
168 if (pclusterpages > pcs->maxpages)
171 kmem_cache_free(pcs->slab, pcl);
177 /* how to allocate cached pages for a pcluster */
178 enum z_erofs_cache_alloctype {
179 DONTALLOC, /* don't allocate any cached pages */
181 * try to use cached I/O if page allocation succeeds or fallback
182 * to in-place I/O instead to avoid any direct reclaim.
188 * tagged pointer with 1-bit tag for all compressed pages
189 * tag 0 - the page is just found with an extra page reference
191 typedef tagptr1_t compressed_page_t;
193 #define tag_compressed_page_justfound(page) \
194 tagptr_fold(compressed_page_t, page, 1)
196 static struct workqueue_struct *z_erofs_workqueue __read_mostly;
198 void z_erofs_exit_zip_subsystem(void)
200 destroy_workqueue(z_erofs_workqueue);
201 z_erofs_destroy_pcluster_pool();
204 static inline int z_erofs_init_workqueue(void)
206 const unsigned int onlinecpus = num_possible_cpus();
209 * no need to spawn too many threads, limiting threads could minimum
210 * scheduling overhead, perhaps per-CPU threads should be better?
212 z_erofs_workqueue = alloc_workqueue("erofs_unzipd",
213 WQ_UNBOUND | WQ_HIGHPRI,
214 onlinecpus + onlinecpus / 4);
215 return z_erofs_workqueue ? 0 : -ENOMEM;
218 int __init z_erofs_init_zip_subsystem(void)
220 int err = z_erofs_create_pcluster_pool();
224 err = z_erofs_init_workqueue();
226 z_erofs_destroy_pcluster_pool();
230 enum z_erofs_pclustermode {
231 Z_EROFS_PCLUSTER_INFLIGHT,
233 * The current pclusters was the tail of an exist chain, in addition
234 * that the previous processed chained pclusters are all decided to
235 * be hooked up to it.
236 * A new chain will be created for the remaining pclusters which are
237 * not processed yet, so different from Z_EROFS_PCLUSTER_FOLLOWED,
238 * the next pcluster cannot reuse the whole page safely for inplace I/O
239 * in the following scenario:
240 * ________________________________________________________________
241 * | tail (partial) page | head (partial) page |
242 * | (belongs to the next pcl) | (belongs to the current pcl) |
243 * |_______PCLUSTER_FOLLOWED______|________PCLUSTER_HOOKED__________|
245 Z_EROFS_PCLUSTER_HOOKED,
247 * a weak form of Z_EROFS_PCLUSTER_FOLLOWED, the difference is that it
248 * could be dispatched into bypass queue later due to uptodated managed
249 * pages. All related online pages cannot be reused for inplace I/O (or
250 * bvpage) since it can be directly decoded without I/O submission.
252 Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE,
254 * The current collection has been linked with the owned chain, and
255 * could also be linked with the remaining collections, which means
256 * if the processing page is the tail page of the collection, thus
257 * the current collection can safely use the whole page (since
258 * the previous collection is under control) for in-place I/O, as
260 * ________________________________________________________________
261 * | tail (partial) page | head (partial) page |
262 * | (of the current cl) | (of the previous collection) |
263 * | PCLUSTER_FOLLOWED or | |
264 * |_____PCLUSTER_HOOKED__|___________PCLUSTER_FOLLOWED____________|
266 * [ (*) the above page can be used as inplace I/O. ]
268 Z_EROFS_PCLUSTER_FOLLOWED,
271 struct z_erofs_decompress_frontend {
272 struct inode *const inode;
273 struct erofs_map_blocks map;
274 struct z_erofs_bvec_iter biter;
276 struct page *candidate_bvpage;
277 struct z_erofs_pcluster *pcl, *tailpcl;
278 z_erofs_next_pcluster_t owned_head;
279 enum z_erofs_pclustermode mode;
282 /* used for applying cache strategy on the fly */
284 erofs_off_t headoffset;
286 /* a pointer used to pick up inplace I/O pages */
290 #define DECOMPRESS_FRONTEND_INIT(__i) { \
291 .inode = __i, .owned_head = Z_EROFS_PCLUSTER_TAIL, \
292 .mode = Z_EROFS_PCLUSTER_FOLLOWED, .backmost = true }
294 static void z_erofs_bind_cache(struct z_erofs_decompress_frontend *fe,
295 enum z_erofs_cache_alloctype type,
296 struct page **pagepool)
298 struct address_space *mc = MNGD_MAPPING(EROFS_I_SB(fe->inode));
299 struct z_erofs_pcluster *pcl = fe->pcl;
300 bool standalone = true;
302 * optimistic allocation without direct reclaim since inplace I/O
303 * can be used if low memory otherwise.
305 gfp_t gfp = (mapping_gfp_mask(mc) & ~__GFP_DIRECT_RECLAIM) |
306 __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
309 if (fe->mode < Z_EROFS_PCLUSTER_FOLLOWED)
312 for (i = 0; i < pcl->pclusterpages; ++i) {
315 struct page *newpage = NULL;
317 /* the compressed page was loaded before */
318 if (READ_ONCE(pcl->compressed_bvecs[i].page))
321 page = find_get_page(mc, pcl->obj.index + i);
324 t = tag_compressed_page_justfound(page);
326 /* I/O is needed, no possible to decompress directly */
330 newpage = erofs_allocpage(pagepool, gfp);
333 set_page_private(newpage,
334 Z_EROFS_PREALLOCATED_PAGE);
335 t = tag_compressed_page_justfound(newpage);
337 default: /* DONTALLOC */
342 if (!cmpxchg_relaxed(&pcl->compressed_bvecs[i].page, NULL,
349 erofs_pagepool_add(pagepool, newpage);
353 * don't do inplace I/O if all compressed pages are available in
354 * managed cache since it can be moved to the bypass queue instead.
357 fe->mode = Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE;
360 /* called by erofs_shrinker to get rid of all compressed_pages */
361 int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
362 struct erofs_workgroup *grp)
364 struct z_erofs_pcluster *const pcl =
365 container_of(grp, struct z_erofs_pcluster, obj);
368 DBG_BUGON(z_erofs_is_inline_pcluster(pcl));
370 * refcount of workgroup is now freezed as 1,
371 * therefore no need to worry about available decompression users.
373 for (i = 0; i < pcl->pclusterpages; ++i) {
374 struct page *page = pcl->compressed_bvecs[i].page;
379 /* block other users from reclaiming or migrating the page */
380 if (!trylock_page(page))
383 if (!erofs_page_is_managed(sbi, page))
386 /* barrier is implied in the following 'unlock_page' */
387 WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
388 detach_page_private(page);
394 int erofs_try_to_free_cached_page(struct page *page)
396 struct z_erofs_pcluster *const pcl = (void *)page_private(page);
399 if (!erofs_workgroup_try_to_freeze(&pcl->obj, 1))
403 DBG_BUGON(z_erofs_is_inline_pcluster(pcl));
404 for (i = 0; i < pcl->pclusterpages; ++i) {
405 if (pcl->compressed_bvecs[i].page == page) {
406 WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
411 erofs_workgroup_unfreeze(&pcl->obj, 1);
413 detach_page_private(page);
417 static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe,
418 struct z_erofs_bvec *bvec)
420 struct z_erofs_pcluster *const pcl = fe->pcl;
422 while (fe->icur > 0) {
423 if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page,
425 pcl->compressed_bvecs[fe->icur] = *bvec;
432 /* callers must be with pcluster lock held */
433 static int z_erofs_attach_page(struct z_erofs_decompress_frontend *fe,
434 struct z_erofs_bvec *bvec, bool exclusive)
439 /* give priority for inplaceio to use file pages first */
440 if (z_erofs_try_inplace_io(fe, bvec))
442 /* otherwise, check if it can be used as a bvpage */
443 if (fe->mode >= Z_EROFS_PCLUSTER_FOLLOWED &&
444 !fe->candidate_bvpage)
445 fe->candidate_bvpage = bvec->page;
447 ret = z_erofs_bvec_enqueue(&fe->biter, bvec, &fe->candidate_bvpage);
448 fe->pcl->vcnt += (ret >= 0);
452 static void z_erofs_try_to_claim_pcluster(struct z_erofs_decompress_frontend *f)
454 struct z_erofs_pcluster *pcl = f->pcl;
455 z_erofs_next_pcluster_t *owned_head = &f->owned_head;
457 /* type 1, nil pcluster (this pcluster doesn't belong to any chain.) */
458 if (cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_NIL,
459 *owned_head) == Z_EROFS_PCLUSTER_NIL) {
460 *owned_head = &pcl->next;
461 /* so we can attach this pcluster to our submission chain. */
462 f->mode = Z_EROFS_PCLUSTER_FOLLOWED;
467 * type 2, link to the end of an existing open chain, be careful
468 * that its submission is controlled by the original attached chain.
470 if (*owned_head != &pcl->next && pcl != f->tailpcl &&
471 cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_TAIL,
472 *owned_head) == Z_EROFS_PCLUSTER_TAIL) {
473 *owned_head = Z_EROFS_PCLUSTER_TAIL;
474 f->mode = Z_EROFS_PCLUSTER_HOOKED;
478 /* type 3, it belongs to a chain, but it isn't the end of the chain */
479 f->mode = Z_EROFS_PCLUSTER_INFLIGHT;
482 static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
484 struct erofs_map_blocks *map = &fe->map;
485 bool ztailpacking = map->m_flags & EROFS_MAP_META;
486 struct z_erofs_pcluster *pcl;
487 struct erofs_workgroup *grp;
490 if (!(map->m_flags & EROFS_MAP_ENCODED)) {
492 return -EFSCORRUPTED;
495 /* no available pcluster, let's allocate one */
496 pcl = z_erofs_alloc_pcluster(ztailpacking ? 1 :
497 map->m_plen >> PAGE_SHIFT);
501 atomic_set(&pcl->obj.refcount, 1);
502 pcl->algorithmformat = map->m_algorithmformat;
506 /* new pclusters should be claimed as type 1, primary and followed */
507 pcl->next = fe->owned_head;
508 pcl->pageofs_out = map->m_la & ~PAGE_MASK;
509 fe->mode = Z_EROFS_PCLUSTER_FOLLOWED;
512 * lock all primary followed works before visible to others
513 * and mutex_trylock *never* fails for a new pcluster.
515 mutex_init(&pcl->lock);
516 DBG_BUGON(!mutex_trylock(&pcl->lock));
519 pcl->obj.index = 0; /* which indicates ztailpacking */
520 pcl->pageofs_in = erofs_blkoff(map->m_pa);
521 pcl->tailpacking_size = map->m_plen;
523 pcl->obj.index = map->m_pa >> PAGE_SHIFT;
525 grp = erofs_insert_workgroup(fe->inode->i_sb, &pcl->obj);
531 if (grp != &pcl->obj) {
532 fe->pcl = container_of(grp,
533 struct z_erofs_pcluster, obj);
538 /* used to check tail merging loop due to corrupted images */
539 if (fe->owned_head == Z_EROFS_PCLUSTER_TAIL)
541 fe->owned_head = &pcl->next;
546 mutex_unlock(&pcl->lock);
547 z_erofs_free_pcluster(pcl);
551 static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe)
553 struct erofs_map_blocks *map = &fe->map;
554 struct erofs_workgroup *grp = NULL;
559 /* must be Z_EROFS_PCLUSTER_TAIL or pointed to previous pcluster */
560 DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_NIL);
561 DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_TAIL_CLOSED);
563 if (!(map->m_flags & EROFS_MAP_META)) {
564 grp = erofs_find_workgroup(fe->inode->i_sb,
565 map->m_pa >> PAGE_SHIFT);
566 } else if ((map->m_pa & ~PAGE_MASK) + map->m_plen > PAGE_SIZE) {
568 return -EFSCORRUPTED;
572 fe->pcl = container_of(grp, struct z_erofs_pcluster, obj);
575 ret = z_erofs_register_pcluster(fe);
578 if (ret == -EEXIST) {
579 mutex_lock(&fe->pcl->lock);
580 /* used to check tail merging loop due to corrupted images */
581 if (fe->owned_head == Z_EROFS_PCLUSTER_TAIL)
582 fe->tailpcl = fe->pcl;
584 z_erofs_try_to_claim_pcluster(fe);
588 z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
589 Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
590 /* since file-backed online pages are traversed in reverse order */
591 fe->icur = z_erofs_pclusterpages(fe->pcl);
596 * keep in mind that no referenced pclusters will be freed
597 * only after a RCU grace period.
599 static void z_erofs_rcu_callback(struct rcu_head *head)
601 z_erofs_free_pcluster(container_of(head,
602 struct z_erofs_pcluster, rcu));
605 void erofs_workgroup_free_rcu(struct erofs_workgroup *grp)
607 struct z_erofs_pcluster *const pcl =
608 container_of(grp, struct z_erofs_pcluster, obj);
610 call_rcu(&pcl->rcu, z_erofs_rcu_callback);
613 static bool z_erofs_collector_end(struct z_erofs_decompress_frontend *fe)
615 struct z_erofs_pcluster *pcl = fe->pcl;
620 z_erofs_bvec_iter_end(&fe->biter);
621 mutex_unlock(&pcl->lock);
623 if (fe->candidate_bvpage) {
624 DBG_BUGON(z_erofs_is_shortlived_page(fe->candidate_bvpage));
625 fe->candidate_bvpage = NULL;
629 * if all pending pages are added, don't hold its reference
630 * any longer if the pcluster isn't hosted by ourselves.
632 if (fe->mode < Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE)
633 erofs_workgroup_put(&pcl->obj);
639 static bool should_alloc_managed_pages(struct z_erofs_decompress_frontend *fe,
640 unsigned int cachestrategy,
643 if (cachestrategy <= EROFS_ZIP_CACHE_DISABLED)
649 return cachestrategy >= EROFS_ZIP_CACHE_READAROUND &&
653 static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
654 struct page *page, struct page **pagepool)
656 struct inode *const inode = fe->inode;
657 struct erofs_sb_info *const sbi = EROFS_I_SB(inode);
658 struct erofs_map_blocks *const map = &fe->map;
659 const loff_t offset = page_offset(page);
660 bool tight = true, exclusive;
662 enum z_erofs_cache_alloctype cache_strategy;
663 unsigned int cur, end, spiltted;
666 /* register locked file pages as online pages in pack */
667 z_erofs_onlinepage_init(page);
674 if (offset + cur < map->m_la ||
675 offset + cur >= map->m_la + map->m_llen) {
676 erofs_dbg("out-of-range map @ pos %llu", offset + cur);
678 if (z_erofs_collector_end(fe))
679 fe->backmost = false;
680 map->m_la = offset + cur;
682 err = z_erofs_map_blocks_iter(inode, map, 0);
688 /* didn't get a valid pcluster previously (very rare) */
691 if (!(map->m_flags & EROFS_MAP_MAPPED))
694 err = z_erofs_collector_begin(fe);
698 if (z_erofs_is_inline_pcluster(fe->pcl)) {
701 mp = erofs_read_metabuf(&fe->map.buf, inode->i_sb,
702 erofs_blknr(map->m_pa), EROFS_NO_KMAP);
705 erofs_err(inode->i_sb,
706 "failed to get inline page, err %d", err);
709 get_page(fe->map.buf.page);
710 WRITE_ONCE(fe->pcl->compressed_bvecs[0].page,
712 fe->mode = Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE;
714 /* bind cache first when cached decompression is preferred */
715 if (should_alloc_managed_pages(fe, sbi->opt.cache_strategy,
717 cache_strategy = TRYALLOC;
719 cache_strategy = DONTALLOC;
721 z_erofs_bind_cache(fe, cache_strategy, pagepool);
725 * Ensure the current partial page belongs to this submit chain rather
726 * than other concurrent submit chains or the noio(bypass) chain since
727 * those chains are handled asynchronously thus the page cannot be used
728 * for inplace I/O or bvpage (should be processed in a strict order.)
730 tight &= (fe->mode >= Z_EROFS_PCLUSTER_HOOKED &&
731 fe->mode != Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE);
733 cur = end - min_t(unsigned int, offset + end - map->m_la, end);
734 if (!(map->m_flags & EROFS_MAP_MAPPED)) {
735 zero_user_segment(page, cur, end);
739 exclusive = (!cur && (!spiltted || tight));
741 tight &= (fe->mode >= Z_EROFS_PCLUSTER_FOLLOWED);
744 err = z_erofs_attach_page(fe, &((struct z_erofs_bvec) {
746 .offset = offset - map->m_la,
749 /* should allocate an additional short-lived page for bvset */
750 if (err == -EAGAIN && !fe->candidate_bvpage) {
751 fe->candidate_bvpage = alloc_page(GFP_NOFS | __GFP_NOFAIL);
752 set_page_private(fe->candidate_bvpage,
753 Z_EROFS_SHORTLIVED_PAGE);
758 DBG_BUGON(err == -EAGAIN && fe->candidate_bvpage);
762 z_erofs_onlinepage_split(page);
763 /* bump up the number of spiltted parts of a page */
765 if (fe->pcl->pageofs_out != (map->m_la & ~PAGE_MASK))
766 fe->pcl->multibases = true;
768 if ((map->m_flags & EROFS_MAP_FULL_MAPPED) &&
769 fe->pcl->length == map->m_llen)
770 fe->pcl->partial = false;
771 if (fe->pcl->length < offset + end - map->m_la) {
772 fe->pcl->length = offset + end - map->m_la;
773 fe->pcl->pageofs_out = map->m_la & ~PAGE_MASK;
776 /* shorten the remaining extent to update progress */
777 map->m_llen = offset + cur - map->m_la;
778 map->m_flags &= ~EROFS_MAP_FULL_MAPPED;
786 z_erofs_page_mark_eio(page);
787 z_erofs_onlinepage_endio(page);
789 erofs_dbg("%s, finish page: %pK spiltted: %u map->m_llen %llu",
790 __func__, page, spiltted, map->m_llen);
794 static bool z_erofs_get_sync_decompress_policy(struct erofs_sb_info *sbi,
795 unsigned int readahead_pages)
797 /* auto: enable for read_folio, disable for readahead */
798 if ((sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO) &&
802 if ((sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_FORCE_ON) &&
803 (readahead_pages <= sbi->opt.max_sync_decompress_pages))
809 static bool z_erofs_page_is_invalidated(struct page *page)
811 return !page->mapping && !z_erofs_is_shortlived_page(page);
814 struct z_erofs_decompress_backend {
815 struct page *onstack_pages[Z_EROFS_ONSTACK_PAGES];
816 struct super_block *sb;
817 struct z_erofs_pcluster *pcl;
819 /* pages with the longest decompressed length for deduplication */
820 struct page **decompressed_pages;
821 /* pages to keep the compressed data */
822 struct page **compressed_pages;
824 struct list_head decompressed_secondary_bvecs;
825 struct page **pagepool;
826 unsigned int onstack_used, nr_pages;
829 struct z_erofs_bvec_item {
830 struct z_erofs_bvec bvec;
831 struct list_head list;
834 static void z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend *be,
835 struct z_erofs_bvec *bvec)
837 struct z_erofs_bvec_item *item;
839 if (!((bvec->offset + be->pcl->pageofs_out) & ~PAGE_MASK)) {
841 struct page *oldpage;
843 pgnr = (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT;
844 DBG_BUGON(pgnr >= be->nr_pages);
845 oldpage = be->decompressed_pages[pgnr];
846 be->decompressed_pages[pgnr] = bvec->page;
852 /* (cold path) one pcluster is requested multiple times */
853 item = kmalloc(sizeof(*item), GFP_KERNEL | __GFP_NOFAIL);
855 list_add(&item->list, &be->decompressed_secondary_bvecs);
858 static void z_erofs_fill_other_copies(struct z_erofs_decompress_backend *be,
861 unsigned int off0 = be->pcl->pageofs_out;
862 struct list_head *p, *n;
864 list_for_each_safe(p, n, &be->decompressed_secondary_bvecs) {
865 struct z_erofs_bvec_item *bvi;
866 unsigned int end, cur;
869 bvi = container_of(p, struct z_erofs_bvec_item, list);
870 cur = bvi->bvec.offset < 0 ? -bvi->bvec.offset : 0;
871 end = min_t(unsigned int, be->pcl->length - bvi->bvec.offset,
873 dst = kmap_local_page(bvi->bvec.page);
875 unsigned int pgnr, scur, len;
877 pgnr = (bvi->bvec.offset + cur + off0) >> PAGE_SHIFT;
878 DBG_BUGON(pgnr >= be->nr_pages);
880 scur = bvi->bvec.offset + cur -
881 ((pgnr << PAGE_SHIFT) - off0);
882 len = min_t(unsigned int, end - cur, PAGE_SIZE - scur);
883 if (!be->decompressed_pages[pgnr]) {
888 src = kmap_local_page(be->decompressed_pages[pgnr]);
889 memcpy(dst + cur, src + scur, len);
895 z_erofs_page_mark_eio(bvi->bvec.page);
896 z_erofs_onlinepage_endio(bvi->bvec.page);
902 static void z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be)
904 struct z_erofs_pcluster *pcl = be->pcl;
905 struct z_erofs_bvec_iter biter;
906 struct page *old_bvpage;
909 z_erofs_bvec_iter_begin(&biter, &pcl->bvset, Z_EROFS_INLINE_BVECS, 0);
910 for (i = 0; i < pcl->vcnt; ++i) {
911 struct z_erofs_bvec bvec;
913 z_erofs_bvec_dequeue(&biter, &bvec, &old_bvpage);
916 z_erofs_put_shortlivedpage(be->pagepool, old_bvpage);
918 DBG_BUGON(z_erofs_page_is_invalidated(bvec.page));
919 z_erofs_do_decompressed_bvec(be, &bvec);
922 old_bvpage = z_erofs_bvec_iter_end(&biter);
924 z_erofs_put_shortlivedpage(be->pagepool, old_bvpage);
927 static int z_erofs_parse_in_bvecs(struct z_erofs_decompress_backend *be,
930 struct z_erofs_pcluster *pcl = be->pcl;
931 unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
935 for (i = 0; i < pclusterpages; ++i) {
936 struct z_erofs_bvec *bvec = &pcl->compressed_bvecs[i];
937 struct page *page = bvec->page;
939 /* compressed pages ought to be present before decompressing */
944 be->compressed_pages[i] = page;
946 if (z_erofs_is_inline_pcluster(pcl)) {
947 if (!PageUptodate(page))
952 DBG_BUGON(z_erofs_page_is_invalidated(page));
953 if (!z_erofs_is_shortlived_page(page)) {
954 if (erofs_page_is_managed(EROFS_SB(be->sb), page)) {
955 if (!PageUptodate(page))
959 z_erofs_do_decompressed_bvec(be, bvec);
969 static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
972 struct erofs_sb_info *const sbi = EROFS_SB(be->sb);
973 struct z_erofs_pcluster *pcl = be->pcl;
974 unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
975 unsigned int i, inputsize;
980 mutex_lock(&pcl->lock);
981 be->nr_pages = PAGE_ALIGN(pcl->length + pcl->pageofs_out) >> PAGE_SHIFT;
983 /* allocate (de)compressed page arrays if cannot be kept on stack */
984 be->decompressed_pages = NULL;
985 be->compressed_pages = NULL;
986 be->onstack_used = 0;
987 if (be->nr_pages <= Z_EROFS_ONSTACK_PAGES) {
988 be->decompressed_pages = be->onstack_pages;
989 be->onstack_used = be->nr_pages;
990 memset(be->decompressed_pages, 0,
991 sizeof(struct page *) * be->nr_pages);
994 if (pclusterpages + be->onstack_used <= Z_EROFS_ONSTACK_PAGES)
995 be->compressed_pages = be->onstack_pages + be->onstack_used;
997 if (!be->decompressed_pages)
998 be->decompressed_pages =
999 kvcalloc(be->nr_pages, sizeof(struct page *),
1000 GFP_KERNEL | __GFP_NOFAIL);
1001 if (!be->compressed_pages)
1002 be->compressed_pages =
1003 kvcalloc(pclusterpages, sizeof(struct page *),
1004 GFP_KERNEL | __GFP_NOFAIL);
1006 z_erofs_parse_out_bvecs(be);
1007 err2 = z_erofs_parse_in_bvecs(be, &overlapped);
1013 if (z_erofs_is_inline_pcluster(pcl))
1014 inputsize = pcl->tailpacking_size;
1016 inputsize = pclusterpages * PAGE_SIZE;
1018 err = z_erofs_decompress(&(struct z_erofs_decompress_req) {
1020 .in = be->compressed_pages,
1021 .out = be->decompressed_pages,
1022 .pageofs_in = pcl->pageofs_in,
1023 .pageofs_out = pcl->pageofs_out,
1024 .inputsize = inputsize,
1025 .outputsize = pcl->length,
1026 .alg = pcl->algorithmformat,
1027 .inplace_io = overlapped,
1028 .partial_decoding = pcl->partial,
1029 .fillgaps = pcl->multibases,
1033 /* must handle all compressed pages before actual file pages */
1034 if (z_erofs_is_inline_pcluster(pcl)) {
1035 page = pcl->compressed_bvecs[0].page;
1036 WRITE_ONCE(pcl->compressed_bvecs[0].page, NULL);
1039 for (i = 0; i < pclusterpages; ++i) {
1040 page = pcl->compressed_bvecs[i].page;
1042 if (erofs_page_is_managed(sbi, page))
1045 /* recycle all individual short-lived pages */
1046 (void)z_erofs_put_shortlivedpage(be->pagepool, page);
1047 WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
1050 if (be->compressed_pages < be->onstack_pages ||
1051 be->compressed_pages >= be->onstack_pages + Z_EROFS_ONSTACK_PAGES)
1052 kvfree(be->compressed_pages);
1053 z_erofs_fill_other_copies(be, err);
1055 for (i = 0; i < be->nr_pages; ++i) {
1056 page = be->decompressed_pages[i];
1060 DBG_BUGON(z_erofs_page_is_invalidated(page));
1062 /* recycle all individual short-lived pages */
1063 if (z_erofs_put_shortlivedpage(be->pagepool, page))
1066 z_erofs_page_mark_eio(page);
1067 z_erofs_onlinepage_endio(page);
1070 if (be->decompressed_pages != be->onstack_pages)
1071 kvfree(be->decompressed_pages);
1074 pcl->partial = true;
1075 pcl->multibases = false;
1076 pcl->bvset.nextpage = NULL;
1079 /* pcluster lock MUST be taken before the following line */
1080 WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_NIL);
1081 mutex_unlock(&pcl->lock);
1085 static void z_erofs_decompress_queue(const struct z_erofs_decompressqueue *io,
1086 struct page **pagepool)
1088 struct z_erofs_decompress_backend be = {
1090 .pagepool = pagepool,
1091 .decompressed_secondary_bvecs =
1092 LIST_HEAD_INIT(be.decompressed_secondary_bvecs),
1094 z_erofs_next_pcluster_t owned = io->head;
1096 while (owned != Z_EROFS_PCLUSTER_TAIL_CLOSED) {
1097 /* impossible that 'owned' equals Z_EROFS_WORK_TPTR_TAIL */
1098 DBG_BUGON(owned == Z_EROFS_PCLUSTER_TAIL);
1099 /* impossible that 'owned' equals Z_EROFS_PCLUSTER_NIL */
1100 DBG_BUGON(owned == Z_EROFS_PCLUSTER_NIL);
1102 be.pcl = container_of(owned, struct z_erofs_pcluster, next);
1103 owned = READ_ONCE(be.pcl->next);
1105 z_erofs_decompress_pcluster(&be, io->eio ? -EIO : 0);
1106 erofs_workgroup_put(&be.pcl->obj);
1110 static void z_erofs_decompressqueue_work(struct work_struct *work)
1112 struct z_erofs_decompressqueue *bgq =
1113 container_of(work, struct z_erofs_decompressqueue, u.work);
1114 struct page *pagepool = NULL;
1116 DBG_BUGON(bgq->head == Z_EROFS_PCLUSTER_TAIL_CLOSED);
1117 z_erofs_decompress_queue(bgq, &pagepool);
1119 erofs_release_pages(&pagepool);
1123 static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,
1124 bool sync, int bios)
1126 struct erofs_sb_info *const sbi = EROFS_SB(io->sb);
1128 /* wake up the caller thread for sync decompression */
1130 if (!atomic_add_return(bios, &io->pending_bios))
1131 complete(&io->u.done);
1135 if (atomic_add_return(bios, &io->pending_bios))
1137 /* Use workqueue and sync decompression for atomic contexts only */
1138 if (in_atomic() || irqs_disabled()) {
1139 queue_work(z_erofs_workqueue, &io->u.work);
1140 /* enable sync decompression for readahead */
1141 if (sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
1142 sbi->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_ON;
1145 z_erofs_decompressqueue_work(&io->u.work);
1148 static struct page *pickup_page_for_submission(struct z_erofs_pcluster *pcl,
1150 struct page **pagepool,
1151 struct address_space *mc)
1153 const pgoff_t index = pcl->obj.index;
1154 gfp_t gfp = mapping_gfp_mask(mc);
1155 bool tocache = false;
1157 struct address_space *mapping;
1158 struct page *oldpage, *page;
1160 compressed_page_t t;
1164 page = READ_ONCE(pcl->compressed_bvecs[nr].page);
1170 /* process the target tagged pointer */
1171 t = tagptr_init(compressed_page_t, page);
1172 justfound = tagptr_unfold_tags(t);
1173 page = tagptr_unfold_ptr(t);
1176 * preallocated cached pages, which is used to avoid direct reclaim
1177 * otherwise, it will go inplace I/O path instead.
1179 if (page->private == Z_EROFS_PREALLOCATED_PAGE) {
1180 WRITE_ONCE(pcl->compressed_bvecs[nr].page, page);
1181 set_page_private(page, 0);
1185 mapping = READ_ONCE(page->mapping);
1188 * file-backed online pages in plcuster are all locked steady,
1189 * therefore it is impossible for `mapping' to be NULL.
1191 if (mapping && mapping != mc)
1192 /* ought to be unmanaged pages */
1195 /* directly return for shortlived page as well */
1196 if (z_erofs_is_shortlived_page(page))
1201 /* only true if page reclaim goes wrong, should never happen */
1202 DBG_BUGON(justfound && PagePrivate(page));
1204 /* the page is still in manage cache */
1205 if (page->mapping == mc) {
1206 WRITE_ONCE(pcl->compressed_bvecs[nr].page, page);
1208 if (!PagePrivate(page)) {
1210 * impossible to be !PagePrivate(page) for
1211 * the current restriction as well if
1212 * the page is already in compressed_bvecs[].
1214 DBG_BUGON(!justfound);
1217 set_page_private(page, (unsigned long)pcl);
1218 SetPagePrivate(page);
1221 /* no need to submit io if it is already up-to-date */
1222 if (PageUptodate(page)) {
1230 * the managed page has been truncated, it's unsafe to
1231 * reuse this one, let's allocate a new cache-managed page.
1233 DBG_BUGON(page->mapping);
1234 DBG_BUGON(!justfound);
1240 page = erofs_allocpage(pagepool, gfp | __GFP_NOFAIL);
1241 if (oldpage != cmpxchg(&pcl->compressed_bvecs[nr].page,
1243 erofs_pagepool_add(pagepool, page);
1248 if (!tocache || add_to_page_cache_lru(page, mc, index + nr, gfp)) {
1249 /* turn into temporary page if fails (1 ref) */
1250 set_page_private(page, Z_EROFS_SHORTLIVED_PAGE);
1253 attach_page_private(page, pcl);
1254 /* drop a refcount added by allocpage (then we have 2 refs here) */
1257 out: /* the only exit (for tracing and debugging) */
1261 static struct z_erofs_decompressqueue *
1262 jobqueue_init(struct super_block *sb,
1263 struct z_erofs_decompressqueue *fgq, bool *fg)
1265 struct z_erofs_decompressqueue *q;
1268 q = kvzalloc(sizeof(*q), GFP_KERNEL | __GFP_NOWARN);
1273 INIT_WORK(&q->u.work, z_erofs_decompressqueue_work);
1277 init_completion(&fgq->u.done);
1278 atomic_set(&fgq->pending_bios, 0);
1282 q->head = Z_EROFS_PCLUSTER_TAIL_CLOSED;
1286 /* define decompression jobqueue types */
1293 static void *jobqueueset_init(struct super_block *sb,
1294 struct z_erofs_decompressqueue *q[],
1295 struct z_erofs_decompressqueue *fgq, bool *fg)
1298 * if managed cache is enabled, bypass jobqueue is needed,
1299 * no need to read from device for all pclusters in this queue.
1301 q[JQ_BYPASS] = jobqueue_init(sb, fgq + JQ_BYPASS, NULL);
1302 q[JQ_SUBMIT] = jobqueue_init(sb, fgq + JQ_SUBMIT, fg);
1304 return tagptr_cast_ptr(tagptr_fold(tagptr1_t, q[JQ_SUBMIT], *fg));
1307 static void move_to_bypass_jobqueue(struct z_erofs_pcluster *pcl,
1308 z_erofs_next_pcluster_t qtail[],
1309 z_erofs_next_pcluster_t owned_head)
1311 z_erofs_next_pcluster_t *const submit_qtail = qtail[JQ_SUBMIT];
1312 z_erofs_next_pcluster_t *const bypass_qtail = qtail[JQ_BYPASS];
1314 DBG_BUGON(owned_head == Z_EROFS_PCLUSTER_TAIL_CLOSED);
1315 if (owned_head == Z_EROFS_PCLUSTER_TAIL)
1316 owned_head = Z_EROFS_PCLUSTER_TAIL_CLOSED;
1318 WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_TAIL_CLOSED);
1320 WRITE_ONCE(*submit_qtail, owned_head);
1321 WRITE_ONCE(*bypass_qtail, &pcl->next);
1323 qtail[JQ_BYPASS] = &pcl->next;
1326 static void z_erofs_decompressqueue_endio(struct bio *bio)
1328 tagptr1_t t = tagptr_init(tagptr1_t, bio->bi_private);
1329 struct z_erofs_decompressqueue *q = tagptr_unfold_ptr(t);
1330 blk_status_t err = bio->bi_status;
1331 struct bio_vec *bvec;
1332 struct bvec_iter_all iter_all;
1334 bio_for_each_segment_all(bvec, bio, iter_all) {
1335 struct page *page = bvec->bv_page;
1337 DBG_BUGON(PageUptodate(page));
1338 DBG_BUGON(z_erofs_page_is_invalidated(page));
1340 if (erofs_page_is_managed(EROFS_SB(q->sb), page)) {
1342 SetPageUptodate(page);
1348 z_erofs_decompress_kickoff(q, tagptr_unfold_tags(t), -1);
1352 static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
1353 struct page **pagepool,
1354 struct z_erofs_decompressqueue *fgq,
1357 struct super_block *sb = f->inode->i_sb;
1358 struct address_space *mc = MNGD_MAPPING(EROFS_SB(sb));
1359 z_erofs_next_pcluster_t qtail[NR_JOBQUEUES];
1360 struct z_erofs_decompressqueue *q[NR_JOBQUEUES];
1362 z_erofs_next_pcluster_t owned_head = f->owned_head;
1363 /* bio is NULL initially, so no need to initialize last_{index,bdev} */
1365 struct block_device *last_bdev;
1366 unsigned int nr_bios = 0;
1367 struct bio *bio = NULL;
1369 bi_private = jobqueueset_init(sb, q, fgq, force_fg);
1370 qtail[JQ_BYPASS] = &q[JQ_BYPASS]->head;
1371 qtail[JQ_SUBMIT] = &q[JQ_SUBMIT]->head;
1373 /* by default, all need io submission */
1374 q[JQ_SUBMIT]->head = owned_head;
1377 struct erofs_map_dev mdev;
1378 struct z_erofs_pcluster *pcl;
1383 /* no possible 'owned_head' equals the following */
1384 DBG_BUGON(owned_head == Z_EROFS_PCLUSTER_TAIL_CLOSED);
1385 DBG_BUGON(owned_head == Z_EROFS_PCLUSTER_NIL);
1387 pcl = container_of(owned_head, struct z_erofs_pcluster, next);
1389 /* close the main owned chain at first */
1390 owned_head = cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_TAIL,
1391 Z_EROFS_PCLUSTER_TAIL_CLOSED);
1392 if (z_erofs_is_inline_pcluster(pcl)) {
1393 move_to_bypass_jobqueue(pcl, qtail, owned_head);
1397 /* no device id here, thus it will always succeed */
1398 mdev = (struct erofs_map_dev) {
1399 .m_pa = blknr_to_addr(pcl->obj.index),
1401 (void)erofs_map_dev(sb, &mdev);
1403 cur = erofs_blknr(mdev.m_pa);
1404 end = cur + pcl->pclusterpages;
1409 page = pickup_page_for_submission(pcl, i++, pagepool,
1414 if (bio && (cur != last_index + 1 ||
1415 last_bdev != mdev.m_bdev)) {
1422 bio = bio_alloc(mdev.m_bdev, BIO_MAX_VECS,
1423 REQ_OP_READ, GFP_NOIO);
1424 bio->bi_end_io = z_erofs_decompressqueue_endio;
1426 last_bdev = mdev.m_bdev;
1427 bio->bi_iter.bi_sector = (sector_t)cur <<
1428 LOG_SECTORS_PER_BLOCK;
1429 bio->bi_private = bi_private;
1431 bio->bi_opf |= REQ_RAHEAD;
1435 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE)
1436 goto submit_bio_retry;
1440 } while (++cur < end);
1443 qtail[JQ_SUBMIT] = &pcl->next;
1445 move_to_bypass_jobqueue(pcl, qtail, owned_head);
1446 } while (owned_head != Z_EROFS_PCLUSTER_TAIL);
1452 * although background is preferred, no one is pending for submission.
1453 * don't issue workqueue for decompression but drop it directly instead.
1455 if (!*force_fg && !nr_bios) {
1456 kvfree(q[JQ_SUBMIT]);
1459 z_erofs_decompress_kickoff(q[JQ_SUBMIT], *force_fg, nr_bios);
1462 static void z_erofs_runqueue(struct z_erofs_decompress_frontend *f,
1463 struct page **pagepool, bool force_fg)
1465 struct z_erofs_decompressqueue io[NR_JOBQUEUES];
1467 if (f->owned_head == Z_EROFS_PCLUSTER_TAIL)
1469 z_erofs_submit_queue(f, pagepool, io, &force_fg);
1471 /* handle bypass queue (no i/o pclusters) immediately */
1472 z_erofs_decompress_queue(&io[JQ_BYPASS], pagepool);
1477 /* wait until all bios are completed */
1478 wait_for_completion_io(&io[JQ_SUBMIT].u.done);
1480 /* handle synchronous decompress queue in the caller context */
1481 z_erofs_decompress_queue(&io[JQ_SUBMIT], pagepool);
1485 * Since partial uptodate is still unimplemented for now, we have to use
1486 * approximate readmore strategies as a start.
1488 static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,
1489 struct readahead_control *rac,
1491 struct page **pagepool,
1494 struct inode *inode = f->inode;
1495 struct erofs_map_blocks *map = &f->map;
1501 err = z_erofs_map_blocks_iter(inode, map,
1502 EROFS_GET_BLOCKS_READMORE);
1506 /* expend ra for the trailing edge if readahead */
1508 loff_t newstart = readahead_pos(rac);
1510 cur = round_up(map->m_la + map->m_llen, PAGE_SIZE);
1511 readahead_expand(rac, newstart, cur - newstart);
1514 end = round_up(end, PAGE_SIZE);
1516 end = round_up(map->m_la, PAGE_SIZE);
1522 cur = map->m_la + map->m_llen - 1;
1523 while (cur >= end) {
1524 pgoff_t index = cur >> PAGE_SHIFT;
1527 page = erofs_grab_cache_page_nowait(inode->i_mapping, index);
1529 if (PageUptodate(page)) {
1532 err = z_erofs_do_read_page(f, page, pagepool);
1534 erofs_err(inode->i_sb,
1535 "readmore error at page %lu @ nid %llu",
1536 index, EROFS_I(inode)->nid);
1541 if (cur < PAGE_SIZE)
1543 cur = (index << PAGE_SHIFT) - 1;
1547 static int z_erofs_read_folio(struct file *file, struct folio *folio)
1549 struct page *page = &folio->page;
1550 struct inode *const inode = page->mapping->host;
1551 struct erofs_sb_info *const sbi = EROFS_I_SB(inode);
1552 struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
1553 struct page *pagepool = NULL;
1556 trace_erofs_readpage(page, false);
1557 f.headoffset = (erofs_off_t)page->index << PAGE_SHIFT;
1559 z_erofs_pcluster_readmore(&f, NULL, f.headoffset + PAGE_SIZE - 1,
1561 err = z_erofs_do_read_page(&f, page, &pagepool);
1562 z_erofs_pcluster_readmore(&f, NULL, 0, &pagepool, false);
1564 (void)z_erofs_collector_end(&f);
1566 /* if some compressed cluster ready, need submit them anyway */
1567 z_erofs_runqueue(&f, &pagepool,
1568 z_erofs_get_sync_decompress_policy(sbi, 0));
1571 erofs_err(inode->i_sb, "failed to read, err [%d]", err);
1573 erofs_put_metabuf(&f.map.buf);
1574 erofs_release_pages(&pagepool);
1578 static void z_erofs_readahead(struct readahead_control *rac)
1580 struct inode *const inode = rac->mapping->host;
1581 struct erofs_sb_info *const sbi = EROFS_I_SB(inode);
1582 struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
1583 struct page *pagepool = NULL, *head = NULL, *page;
1584 unsigned int nr_pages;
1587 f.headoffset = readahead_pos(rac);
1589 z_erofs_pcluster_readmore(&f, rac, f.headoffset +
1590 readahead_length(rac) - 1, &pagepool, true);
1591 nr_pages = readahead_count(rac);
1592 trace_erofs_readpages(inode, readahead_index(rac), nr_pages, false);
1594 while ((page = readahead_page(rac))) {
1595 set_page_private(page, (unsigned long)head);
1600 struct page *page = head;
1603 /* traversal in reverse order */
1604 head = (void *)page_private(page);
1606 err = z_erofs_do_read_page(&f, page, &pagepool);
1608 erofs_err(inode->i_sb,
1609 "readahead error at page %lu @ nid %llu",
1610 page->index, EROFS_I(inode)->nid);
1613 z_erofs_pcluster_readmore(&f, rac, 0, &pagepool, false);
1614 (void)z_erofs_collector_end(&f);
1616 z_erofs_runqueue(&f, &pagepool,
1617 z_erofs_get_sync_decompress_policy(sbi, nr_pages));
1618 erofs_put_metabuf(&f.map.buf);
1619 erofs_release_pages(&pagepool);
1622 const struct address_space_operations z_erofs_aops = {
1623 .read_folio = z_erofs_read_folio,
1624 .readahead = z_erofs_readahead,