1212#define Z_EROFS_PCLUSTER_MAX_PAGES (Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE)
1313#define Z_EROFS_INLINE_BVECS 2
1414
15- /*
16- * let's leave a type here in case of introducing
17- * another tagged pointer later.
18- */
19- typedef void * z_erofs_next_pcluster_t ;
20-
2115struct z_erofs_bvec {
2216 struct page * page ;
2317 int offset ;
@@ -48,7 +42,7 @@ struct z_erofs_pcluster {
4842 struct lockref lockref ;
4943
5044 /* A: point to next chained pcluster or TAILs */
51- z_erofs_next_pcluster_t next ;
45+ struct z_erofs_pcluster * next ;
5246
5347 /* I: start block address of this pcluster */
5448 erofs_off_t index ;
@@ -94,12 +88,11 @@ struct z_erofs_pcluster {
9488
9589/* the end of a chain of pclusters */
9690#define Z_EROFS_PCLUSTER_TAIL ((void *) 0x700 + POISON_POINTER_DELTA)
97- #define Z_EROFS_PCLUSTER_NIL (NULL)
9891
9992struct z_erofs_decompressqueue {
10093 struct super_block * sb ;
94+ struct z_erofs_pcluster * head ;
10195 atomic_t pending_bios ;
102- z_erofs_next_pcluster_t head ;
10396
10497 union {
10598 struct completion done ;
@@ -493,8 +486,7 @@ struct z_erofs_decompress_frontend {
493486
494487 struct page * pagepool ;
495488 struct page * candidate_bvpage ;
496- struct z_erofs_pcluster * pcl ;
497- z_erofs_next_pcluster_t owned_head ;
489+ struct z_erofs_pcluster * pcl , * head ;
498490 enum z_erofs_pclustermode mode ;
499491
500492 erofs_off_t headoffset ;
@@ -504,7 +496,7 @@ struct z_erofs_decompress_frontend {
504496};
505497
506498#define DECOMPRESS_FRONTEND_INIT (__i ) { \
507- .inode = __i, .owned_head = Z_EROFS_PCLUSTER_TAIL, \
499+ .inode = __i, .head = Z_EROFS_PCLUSTER_TAIL, \
508500 .mode = Z_EROFS_PCLUSTER_FOLLOWED }
509501
510502static bool z_erofs_should_alloc_cache (struct z_erofs_decompress_frontend * fe )
@@ -752,9 +744,7 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
752744 pcl -> algorithmformat = map -> m_algorithmformat ;
753745 pcl -> length = 0 ;
754746 pcl -> partial = true;
755-
756- /* new pclusters should be claimed as type 1, primary and followed */
757- pcl -> next = fe -> owned_head ;
747+ pcl -> next = fe -> head ;
758748 pcl -> pageofs_out = map -> m_la & ~PAGE_MASK ;
759749 fe -> mode = Z_EROFS_PCLUSTER_FOLLOWED ;
760750
@@ -790,8 +780,7 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
790780 goto err_out ;
791781 }
792782 }
793- fe -> owned_head = & pcl -> next ;
794- fe -> pcl = pcl ;
783+ fe -> head = fe -> pcl = pcl ;
795784 return 0 ;
796785
797786err_out :
@@ -810,7 +799,7 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
810799
811800 DBG_BUGON (fe -> pcl );
812801 /* must be Z_EROFS_PCLUSTER_TAIL or pointed to previous pcluster */
813- DBG_BUGON (fe -> owned_head == Z_EROFS_PCLUSTER_NIL );
802+ DBG_BUGON (! fe -> head );
814803
815804 if (!(map -> m_flags & EROFS_MAP_META )) {
816805 while (1 ) {
@@ -838,10 +827,9 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
838827 if (ret == - EEXIST ) {
839828 mutex_lock (& fe -> pcl -> lock );
840829 /* check if this pcluster hasn't been linked into any chain. */
841- if (cmpxchg (& fe -> pcl -> next , Z_EROFS_PCLUSTER_NIL ,
842- fe -> owned_head ) == Z_EROFS_PCLUSTER_NIL ) {
830+ if (!cmpxchg (& fe -> pcl -> next , NULL , fe -> head )) {
843831 /* .. so it can be attached to our submission chain */
844- fe -> owned_head = & fe -> pcl -> next ;
832+ fe -> head = fe -> pcl ;
845833 fe -> mode = Z_EROFS_PCLUSTER_FOLLOWED ;
846834 } else { /* otherwise, it belongs to an inflight chain */
847835 fe -> mode = Z_EROFS_PCLUSTER_INFLIGHT ;
@@ -1393,7 +1381,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
13931381 pcl -> vcnt = 0 ;
13941382
13951383 /* pcluster lock MUST be taken before the following line */
1396- WRITE_ONCE (pcl -> next , Z_EROFS_PCLUSTER_NIL );
1384+ WRITE_ONCE (pcl -> next , NULL );
13971385 mutex_unlock (& pcl -> lock );
13981386
13991387 if (z_erofs_is_inline_pcluster (pcl ))
@@ -1411,16 +1399,14 @@ static int z_erofs_decompress_queue(const struct z_erofs_decompressqueue *io,
14111399 .pagepool = pagepool ,
14121400 .decompressed_secondary_bvecs =
14131401 LIST_HEAD_INIT (be .decompressed_secondary_bvecs ),
1402+ .pcl = io -> head ,
14141403 };
1415- z_erofs_next_pcluster_t owned = io -> head ;
1404+ struct z_erofs_pcluster * next ;
14161405 int err = io -> eio ? - EIO : 0 ;
14171406
1418- while (owned != Z_EROFS_PCLUSTER_TAIL ) {
1419- DBG_BUGON (owned == Z_EROFS_PCLUSTER_NIL );
1420-
1421- be .pcl = container_of (owned , struct z_erofs_pcluster , next );
1422- owned = READ_ONCE (be .pcl -> next );
1423-
1407+ for (; be .pcl != Z_EROFS_PCLUSTER_TAIL ; be .pcl = next ) {
1408+ DBG_BUGON (!be .pcl );
1409+ next = READ_ONCE (be .pcl -> next );
14241410 err = z_erofs_decompress_pcluster (& be , err ) ?: err ;
14251411 }
14261412 return err ;
@@ -1630,18 +1616,13 @@ enum {
16301616 NR_JOBQUEUES ,
16311617};
16321618
1633- static void move_to_bypass_jobqueue (struct z_erofs_pcluster * pcl ,
1634- z_erofs_next_pcluster_t qtail [] ,
1635- z_erofs_next_pcluster_t owned_head )
1619+ static void z_erofs_move_to_bypass_queue (struct z_erofs_pcluster * pcl ,
1620+ struct z_erofs_pcluster * next ,
1621+ struct z_erofs_pcluster * * qtail [] )
16361622{
1637- z_erofs_next_pcluster_t * const submit_qtail = qtail [JQ_SUBMIT ];
1638- z_erofs_next_pcluster_t * const bypass_qtail = qtail [JQ_BYPASS ];
1639-
16401623 WRITE_ONCE (pcl -> next , Z_EROFS_PCLUSTER_TAIL );
1641-
1642- WRITE_ONCE (* submit_qtail , owned_head );
1643- WRITE_ONCE (* bypass_qtail , & pcl -> next );
1644-
1624+ WRITE_ONCE (* qtail [JQ_SUBMIT ], next );
1625+ WRITE_ONCE (* qtail [JQ_BYPASS ], pcl );
16451626 qtail [JQ_BYPASS ] = & pcl -> next ;
16461627}
16471628
@@ -1676,9 +1657,9 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
16761657{
16771658 struct super_block * sb = f -> inode -> i_sb ;
16781659 struct address_space * mc = MNGD_MAPPING (EROFS_SB (sb ));
1679- z_erofs_next_pcluster_t qtail [NR_JOBQUEUES ];
1660+ struct z_erofs_pcluster * * qtail [NR_JOBQUEUES ];
16801661 struct z_erofs_decompressqueue * q [NR_JOBQUEUES ];
1681- z_erofs_next_pcluster_t owned_head = f -> owned_head ;
1662+ struct z_erofs_pcluster * pcl , * next ;
16821663 /* bio is NULL initially, so no need to initialize last_{index,bdev} */
16831664 erofs_off_t last_pa ;
16841665 unsigned int nr_bios = 0 ;
@@ -1694,22 +1675,19 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
16941675 qtail [JQ_SUBMIT ] = & q [JQ_SUBMIT ]-> head ;
16951676
16961677 /* by default, all need io submission */
1697- q [JQ_SUBMIT ]-> head = owned_head ;
1678+ q [JQ_SUBMIT ]-> head = next = f -> head ;
16981679
16991680 do {
17001681 struct erofs_map_dev mdev ;
1701- struct z_erofs_pcluster * pcl ;
17021682 erofs_off_t cur , end ;
17031683 struct bio_vec bvec ;
17041684 unsigned int i = 0 ;
17051685 bool bypass = true;
17061686
1707- DBG_BUGON (owned_head == Z_EROFS_PCLUSTER_NIL );
1708- pcl = container_of (owned_head , struct z_erofs_pcluster , next );
1709- owned_head = READ_ONCE (pcl -> next );
1710-
1687+ pcl = next ;
1688+ next = READ_ONCE (pcl -> next );
17111689 if (z_erofs_is_inline_pcluster (pcl )) {
1712- move_to_bypass_jobqueue (pcl , qtail , owned_head );
1690+ z_erofs_move_to_bypass_queue (pcl , next , qtail );
17131691 continue ;
17141692 }
17151693
@@ -1781,8 +1759,8 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
17811759 if (!bypass )
17821760 qtail [JQ_SUBMIT ] = & pcl -> next ;
17831761 else
1784- move_to_bypass_jobqueue (pcl , qtail , owned_head );
1785- } while (owned_head != Z_EROFS_PCLUSTER_TAIL );
1762+ z_erofs_move_to_bypass_queue (pcl , next , qtail );
1763+ } while (next != Z_EROFS_PCLUSTER_TAIL );
17861764
17871765 if (bio ) {
17881766 if (erofs_is_fileio_mode (EROFS_SB (sb )))
@@ -1814,7 +1792,7 @@ static int z_erofs_runqueue(struct z_erofs_decompress_frontend *f,
18141792 bool force_fg = z_erofs_is_sync_decompress (sbi , ra_folios );
18151793 int err ;
18161794
1817- if (f -> owned_head == Z_EROFS_PCLUSTER_TAIL )
1795+ if (f -> head == Z_EROFS_PCLUSTER_TAIL )
18181796 return 0 ;
18191797 z_erofs_submit_queue (f , io , & force_fg , !!ra_folios );
18201798
0 commit comments