@@ -339,19 +339,55 @@ static int nilfs_palloc_delete_entry_block(struct inode *inode, __u64 nr)
339
339
}
340
340
341
341
/**
342
- * nilfs_palloc_block_get_group_desc - get kernel address of a group descriptor
342
+ * nilfs_palloc_group_desc_offset - calculate the byte offset of a group
343
+ * descriptor in the folio containing it
343
344
* @inode: inode of metadata file using this allocator
344
345
* @group: group number
345
- * @bh: buffer head of the buffer storing the group descriptor block
346
- * @kaddr: kernel address mapped for the page including the buffer
346
+ * @bh: buffer head of the group descriptor block
347
+ *
348
+ * Return: Byte offset in the folio of the group descriptor for @group.
347
349
*/
348
- static struct nilfs_palloc_group_desc *
349
- nilfs_palloc_block_get_group_desc (const struct inode * inode ,
350
- unsigned long group ,
351
- const struct buffer_head * bh , void * kaddr )
350
+ static size_t nilfs_palloc_group_desc_offset (const struct inode * inode ,
351
+ unsigned long group ,
352
+ const struct buffer_head * bh )
352
353
{
353
- return (struct nilfs_palloc_group_desc * )(kaddr + bh_offset (bh )) +
354
- group % nilfs_palloc_groups_per_desc_block (inode );
354
+ return offset_in_folio (bh -> b_folio , bh -> b_data ) +
355
+ sizeof (struct nilfs_palloc_group_desc ) *
356
+ (group % nilfs_palloc_groups_per_desc_block (inode ));
357
+ }
358
+
359
+ /**
360
+ * nilfs_palloc_bitmap_offset - calculate the byte offset of a bitmap block
361
+ * in the folio containing it
362
+ * @bh: buffer head of the bitmap block
363
+ *
364
+ * Return: Byte offset in the folio of the bitmap block for @bh.
365
+ */
366
+ static size_t nilfs_palloc_bitmap_offset (const struct buffer_head * bh )
367
+ {
368
+ return offset_in_folio (bh -> b_folio , bh -> b_data );
369
+ }
370
+
371
+ /**
372
+ * nilfs_palloc_entry_offset - calculate the byte offset of an entry in the
373
+ * folio containing it
374
+ * @inode: inode of metadata file using this allocator
375
+ * @nr: serial number of the entry (e.g. inode number)
376
+ * @bh: buffer head of the entry block
377
+ *
378
+ * Return: Byte offset in the folio of the entry @nr.
379
+ */
380
+ size_t nilfs_palloc_entry_offset (const struct inode * inode , __u64 nr ,
381
+ const struct buffer_head * bh )
382
+ {
383
+ unsigned long entry_index_in_group , entry_index_in_block ;
384
+
385
+ nilfs_palloc_group (inode , nr , & entry_index_in_group );
386
+ entry_index_in_block = entry_index_in_group %
387
+ NILFS_MDT (inode )-> mi_entries_per_block ;
388
+
389
+ return offset_in_folio (bh -> b_folio , bh -> b_data ) +
390
+ entry_index_in_block * NILFS_MDT (inode )-> mi_entry_size ;
355
391
}
356
392
357
393
/**
@@ -508,7 +544,7 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *inode,
508
544
struct buffer_head * desc_bh , * bitmap_bh ;
509
545
struct nilfs_palloc_group_desc * desc ;
510
546
unsigned char * bitmap ;
511
- void * desc_kaddr , * bitmap_kaddr ;
547
+ size_t doff , boff ;
512
548
unsigned long group , maxgroup , ngroups ;
513
549
unsigned long group_offset , maxgroup_offset ;
514
550
unsigned long n , entries_per_group ;
@@ -531,30 +567,32 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *inode,
531
567
ret = nilfs_palloc_get_desc_block (inode , group , 1 , & desc_bh );
532
568
if (ret < 0 )
533
569
return ret ;
534
- desc_kaddr = kmap_local_page ( desc_bh -> b_page );
535
- desc = nilfs_palloc_block_get_group_desc (
536
- inode , group , desc_bh , desc_kaddr );
570
+
571
+ doff = nilfs_palloc_group_desc_offset ( inode , group , desc_bh );
572
+ desc = kmap_local_folio ( desc_bh -> b_folio , doff );
537
573
n = nilfs_palloc_rest_groups_in_desc_block (inode , group ,
538
574
maxgroup );
539
- for (j = 0 ; j < n ; j ++ , desc ++ , group ++ , group_offset = 0 ) {
575
+ for (j = 0 ; j < n ; j ++ , group ++ , group_offset = 0 ) {
540
576
lock = nilfs_mdt_bgl_lock (inode , group );
541
- if (nilfs_palloc_group_desc_nfrees (desc , lock ) == 0 )
577
+ if (nilfs_palloc_group_desc_nfrees (& desc [ j ] , lock ) == 0 )
542
578
continue ;
543
579
544
- kunmap_local (desc_kaddr );
580
+ kunmap_local (desc );
545
581
ret = nilfs_palloc_get_bitmap_block (inode , group , 1 ,
546
582
& bitmap_bh );
547
583
if (unlikely (ret < 0 )) {
548
584
brelse (desc_bh );
549
585
return ret ;
550
586
}
551
587
552
- desc_kaddr = kmap_local_page (desc_bh -> b_page );
553
- desc = nilfs_palloc_block_get_group_desc (
554
- inode , group , desc_bh , desc_kaddr );
588
+ /*
589
+ * Re-kmap the folio containing the first (and
590
+ * subsequent) group descriptors.
591
+ */
592
+ desc = kmap_local_folio (desc_bh -> b_folio , doff );
555
593
556
- bitmap_kaddr = kmap_local_page (bitmap_bh -> b_page );
557
- bitmap = bitmap_kaddr + bh_offset (bitmap_bh );
594
+ boff = nilfs_palloc_bitmap_offset (bitmap_bh );
595
+ bitmap = kmap_local_folio (bitmap_bh -> b_folio , boff );
558
596
pos = nilfs_palloc_find_available_slot (
559
597
bitmap , group_offset , entries_per_group , lock ,
560
598
wrap );
@@ -564,14 +602,14 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *inode,
564
602
* beginning, the wrap flag only has an effect on the
565
603
* first search.
566
604
*/
567
- kunmap_local (bitmap_kaddr );
605
+ kunmap_local (bitmap );
568
606
if (pos >= 0 )
569
607
goto found ;
570
608
571
609
brelse (bitmap_bh );
572
610
}
573
611
574
- kunmap_local (desc_kaddr );
612
+ kunmap_local (desc );
575
613
brelse (desc_bh );
576
614
}
577
615
@@ -580,9 +618,9 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *inode,
580
618
581
619
found :
582
620
/* found a free entry */
583
- nilfs_palloc_group_desc_add_entries (desc , lock , -1 );
621
+ nilfs_palloc_group_desc_add_entries (& desc [ j ] , lock , -1 );
584
622
req -> pr_entry_nr = entries_per_group * group + pos ;
585
- kunmap_local (desc_kaddr );
623
+ kunmap_local (desc );
586
624
587
625
req -> pr_desc_bh = desc_bh ;
588
626
req -> pr_bitmap_bh = bitmap_bh ;
@@ -613,18 +651,18 @@ void nilfs_palloc_commit_alloc_entry(struct inode *inode,
613
651
void nilfs_palloc_commit_free_entry (struct inode * inode ,
614
652
struct nilfs_palloc_req * req )
615
653
{
616
- struct nilfs_palloc_group_desc * desc ;
617
654
unsigned long group , group_offset ;
655
+ size_t doff , boff ;
656
+ struct nilfs_palloc_group_desc * desc ;
618
657
unsigned char * bitmap ;
619
- void * desc_kaddr , * bitmap_kaddr ;
620
658
spinlock_t * lock ;
621
659
622
660
group = nilfs_palloc_group (inode , req -> pr_entry_nr , & group_offset );
623
- desc_kaddr = kmap_local_page ( req -> pr_desc_bh -> b_page );
624
- desc = nilfs_palloc_block_get_group_desc ( inode , group ,
625
- req -> pr_desc_bh , desc_kaddr );
626
- bitmap_kaddr = kmap_local_page (req -> pr_bitmap_bh -> b_page );
627
- bitmap = bitmap_kaddr + bh_offset (req -> pr_bitmap_bh );
661
+ doff = nilfs_palloc_group_desc_offset ( inode , group , req -> pr_desc_bh );
662
+ desc = kmap_local_folio ( req -> pr_desc_bh -> b_folio , doff );
663
+
664
+ boff = nilfs_palloc_bitmap_offset (req -> pr_bitmap_bh );
665
+ bitmap = kmap_local_folio (req -> pr_bitmap_bh -> b_folio , boff );
628
666
lock = nilfs_mdt_bgl_lock (inode , group );
629
667
630
668
if (!nilfs_clear_bit_atomic (lock , group_offset , bitmap ))
@@ -635,8 +673,8 @@ void nilfs_palloc_commit_free_entry(struct inode *inode,
635
673
else
636
674
nilfs_palloc_group_desc_add_entries (desc , lock , 1 );
637
675
638
- kunmap_local (bitmap_kaddr );
639
- kunmap_local (desc_kaddr );
676
+ kunmap_local (bitmap );
677
+ kunmap_local (desc );
640
678
641
679
mark_buffer_dirty (req -> pr_desc_bh );
642
680
mark_buffer_dirty (req -> pr_bitmap_bh );
@@ -655,17 +693,17 @@ void nilfs_palloc_abort_alloc_entry(struct inode *inode,
655
693
struct nilfs_palloc_req * req )
656
694
{
657
695
struct nilfs_palloc_group_desc * desc ;
658
- void * desc_kaddr , * bitmap_kaddr ;
696
+ size_t doff , boff ;
659
697
unsigned char * bitmap ;
660
698
unsigned long group , group_offset ;
661
699
spinlock_t * lock ;
662
700
663
701
group = nilfs_palloc_group (inode , req -> pr_entry_nr , & group_offset );
664
- desc_kaddr = kmap_local_page ( req -> pr_desc_bh -> b_page );
665
- desc = nilfs_palloc_block_get_group_desc ( inode , group ,
666
- req -> pr_desc_bh , desc_kaddr );
667
- bitmap_kaddr = kmap_local_page (req -> pr_bitmap_bh -> b_page );
668
- bitmap = bitmap_kaddr + bh_offset (req -> pr_bitmap_bh );
702
+ doff = nilfs_palloc_group_desc_offset ( inode , group , req -> pr_desc_bh );
703
+ desc = kmap_local_folio ( req -> pr_desc_bh -> b_folio , doff );
704
+
705
+ boff = nilfs_palloc_bitmap_offset (req -> pr_bitmap_bh );
706
+ bitmap = kmap_local_folio (req -> pr_bitmap_bh -> b_folio , boff );
669
707
lock = nilfs_mdt_bgl_lock (inode , group );
670
708
671
709
if (!nilfs_clear_bit_atomic (lock , group_offset , bitmap ))
@@ -676,8 +714,8 @@ void nilfs_palloc_abort_alloc_entry(struct inode *inode,
676
714
else
677
715
nilfs_palloc_group_desc_add_entries (desc , lock , 1 );
678
716
679
- kunmap_local (bitmap_kaddr );
680
- kunmap_local (desc_kaddr );
717
+ kunmap_local (bitmap );
718
+ kunmap_local (desc );
681
719
682
720
brelse (req -> pr_bitmap_bh );
683
721
brelse (req -> pr_desc_bh );
@@ -741,7 +779,7 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
741
779
struct buffer_head * desc_bh , * bitmap_bh ;
742
780
struct nilfs_palloc_group_desc * desc ;
743
781
unsigned char * bitmap ;
744
- void * desc_kaddr , * bitmap_kaddr ;
782
+ size_t doff , boff ;
745
783
unsigned long group , group_offset ;
746
784
__u64 group_min_nr , last_nrs [8 ];
747
785
const unsigned long epg = nilfs_palloc_entries_per_group (inode );
@@ -769,8 +807,8 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
769
807
/* Get the first entry number of the group */
770
808
group_min_nr = (__u64 )group * epg ;
771
809
772
- bitmap_kaddr = kmap_local_page (bitmap_bh -> b_page );
773
- bitmap = bitmap_kaddr + bh_offset (bitmap_bh );
810
+ boff = nilfs_palloc_bitmap_offset (bitmap_bh );
811
+ bitmap = kmap_local_folio (bitmap_bh -> b_folio , boff );
774
812
lock = nilfs_mdt_bgl_lock (inode , group );
775
813
776
814
j = i ;
@@ -815,7 +853,7 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
815
853
entry_start = rounddown (group_offset , epb );
816
854
} while (true);
817
855
818
- kunmap_local (bitmap_kaddr );
856
+ kunmap_local (bitmap );
819
857
mark_buffer_dirty (bitmap_bh );
820
858
brelse (bitmap_bh );
821
859
@@ -829,11 +867,10 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
829
867
inode -> i_ino );
830
868
}
831
869
832
- desc_kaddr = kmap_local_page (desc_bh -> b_page );
833
- desc = nilfs_palloc_block_get_group_desc (
834
- inode , group , desc_bh , desc_kaddr );
870
+ doff = nilfs_palloc_group_desc_offset (inode , group , desc_bh );
871
+ desc = kmap_local_folio (desc_bh -> b_folio , doff );
835
872
nfree = nilfs_palloc_group_desc_add_entries (desc , lock , n );
836
- kunmap_local (desc_kaddr );
873
+ kunmap_local (desc );
837
874
mark_buffer_dirty (desc_bh );
838
875
nilfs_mdt_mark_dirty (inode );
839
876
brelse (desc_bh );
0 commit comments