Changeset 978130a in mainline for uspace/srv/bd/hr/raid0.c


Ignore:
Timestamp:
2024-10-28T16:03:24Z (7 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
4dd650a
Parents:
76cd345
Message:

hr: optimize RAID 0, 4, 5 to write whole strip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/hr/raid0.c

    r76cd345 r978130a  
    7474};
    7575
    76 static void raid0_geometry(uint64_t x, hr_volume_t *vol, size_t *extent,
    77     uint64_t *phys_block)
    78 {
    79         uint64_t N = vol->dev_no; /* extents */
    80         uint64_t L = vol->strip_size / vol->bsize; /* size of strip in blocks */
    81 
    82         uint64_t i = (x / L) % N; /* extent */
    83         uint64_t j = (x / L) / N; /* stripe */
    84         uint64_t k = x % L; /* strip offset */
    85 
    86         *extent = i;
    87         *phys_block = j * L + k;
    88 }
    89 
    9076static errno_t hr_raid0_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
    9177{
     
    10692        errno_t rc;
    10793        uint64_t phys_block;
    108         size_t extent, left;
     94        size_t left;
    10995
    11096        if (type == HR_BD_READ || type == HR_BD_WRITE)
     
    116102                return rc;
    117103
     104        uint64_t strip_size = vol->strip_size / vol->bsize; /* in blocks */
     105        uint64_t stripe = ba / strip_size; /* stripe number */
     106        uint64_t extent = stripe % vol->dev_no;
     107        uint64_t ext_stripe = stripe / vol->dev_no; /* stripe level */
     108        uint64_t strip_off = ba % strip_size; /* strip offset */
     109
    118110        fibril_mutex_lock(&vol->lock);
    119111
    120112        left = cnt;
    121113        while (left != 0) {
    122                 raid0_geometry(ba, vol, &extent, &phys_block);
     114                phys_block = ext_stripe * strip_size + strip_off;
     115                cnt = min(left, strip_size - strip_off);
    123116                hr_add_ba_offset(vol, &phys_block);
    124117                switch (type) {
    125118                case HR_BD_SYNC:
    126119                        rc = block_sync_cache(vol->extents[extent].svc_id,
    127                             phys_block, 1);
     120                            phys_block, cnt);
    128121                        break;
    129122                case HR_BD_READ:
    130123                        rc = block_read_direct(vol->extents[extent].svc_id,
    131                             phys_block, 1, data_read);
    132                         data_read = data_read + vol->bsize;
     124                            phys_block, cnt, data_read);
     125                        data_read = (void *) ((uintptr_t) data_read +
     126                            (vol->bsize * cnt));
    133127                        break;
    134128                case HR_BD_WRITE:
    135129                        rc = block_write_direct(vol->extents[extent].svc_id,
    136                             phys_block, 1, data_write);
    137                         data_write = data_write + vol->bsize;
     130                            phys_block, cnt, data_write);
     131                        data_write = (void *) ((uintptr_t) data_write +
     132                            (vol->bsize * cnt));
    138133                        break;
    139134                default:
    140135                        rc = EINVAL;
    141136                }
    142 
    143137                if (rc != EOK)
    144138                        goto error;
    145139
    146                 left--;
    147                 ba++;
     140                left -= cnt;
     141                strip_off = 0;
     142                extent++;
     143                if (extent >= vol->dev_no) {
     144                        ext_stripe++;
     145                        extent = 0;
     146                }
    148147        }
    149148
Note: See TracChangeset for help on using the changeset viewer.