Changeset 8160e4c0 in mainline


Ignore:
Timestamp:
2024-11-27T13:08:27Z (5 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
40bf2c6
Parents:
bf0a791
git-author:
Miroslav Cimerman <mc@…> (2024-11-27 12:58:10)
git-committer:
Miroslav Cimerman <mc@…> (2024-11-27 13:08:27)
Message:

hr: RAID 4,5: optimize operations with xorbuf

Read block on first iteration directly to
xorbuf. This way one memset and one xor
is saved.

Location:
uspace/srv/bd/hr
Files:
2 edited

Legend:

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

    rbf0a791 r8160e4c0  
    332332
    333333        /* read all other extents in the stripe */
    334         memset(xorbuf, 0, len);
     334        bool first = true;
    335335        for (i = 0; i < vol->dev_no; i++) {
    336                 if (i == bad) {
     336                if (i == bad)
    337337                        continue;
     338
     339                if (first) {
     340                        rc = block_read_direct(vol->extents[i].svc_id, block,
     341                            cnt, xorbuf);
     342                        if (rc != EOK)
     343                                goto end;
     344
     345                        first = false;
    338346                } else {
    339347                        rc = block_read_direct(vol->extents[i].svc_id, block,
     
    341349                        if (rc != EOK)
    342350                                goto end;
     351
    343352                        xor(xorbuf, buf, len);
    344353                }
     
    393402                 * write new parity
    394403                 */
    395                 memset(xorbuf, 0, len);
     404                bool first = true;
    396405                for (i = 1; i < vol->dev_no; i++) {
    397406                        if (i == (size_t)bad)
    398407                                continue;
     408
     409                        if (first) {
     410                                rc = block_read_direct(vol->extents[i].svc_id,
     411                                    ba, cnt, xorbuf);
     412                                if (rc != EOK)
     413                                        goto end;
     414
     415                                first = false;
    399416                        } else {
    400417                                rc = block_read_direct(vol->extents[i].svc_id,
     
    402419                                if (rc != EOK)
    403420                                        goto end;
     421
    404422                                xor(xorbuf, buf, len);
    405423                        }
     
    467485         * XXX: subtract method
    468486         */
    469         memset(xorbuf, 0, len);
     487        bool first = true;
    470488        for (i = 1; i < vol->dev_no; i++) {
    471                 if (i == extent) {
    472                         xor(xorbuf, data, len);
     489                if (first) {
     490                        if (i == extent) {
     491                                memcpy(xorbuf, data, len);
     492                        } else {
     493                                rc = block_read_direct(vol->extents[i].svc_id,
     494                                    block, cnt, xorbuf);
     495                                if (rc != EOK)
     496                                        goto end;
     497                        }
     498
     499                        first = false;
    473500                } else {
    474                         rc = block_read_direct(vol->extents[i].svc_id, block,
    475                             cnt, buf);
    476                         if (rc != EOK)
    477                                 goto end;
    478                         xor(xorbuf, buf, len);
     501                        if (i == extent) {
     502                                xor(xorbuf, data, len);
     503                        } else {
     504                                rc = block_read_direct(vol->extents[i].svc_id,
     505                                    block, cnt, buf);
     506                                if (rc != EOK)
     507                                        goto end;
     508
     509                                xor(xorbuf, buf, len);
     510                        }
    479511                }
    480512        }
  • uspace/srv/bd/hr/raid5.c

    rbf0a791 r8160e4c0  
    329329
    330330        /* read all other extents in the stripe */
    331         memset(xorbuf, 0, len);
     331        bool first = true;
    332332        for (i = 0; i < vol->dev_no; i++) {
    333                 if (i == bad) {
     333                if (i == bad)
    334334                        continue;
     335
     336                if (first) {
     337                        rc = block_read_direct(vol->extents[i].svc_id, block,
     338                            cnt, xorbuf);
     339                        if (rc != EOK)
     340                                goto end;
     341
     342                        first = false;
    335343                } else {
    336344                        rc = block_read_direct(vol->extents[i].svc_id, block,
     
    391399                 * write new parity
    392400                 */
    393                 memset(xorbuf, 0, len);
     401                bool first = true;
    394402                for (i = 1; i < vol->dev_no; i++) {
    395403                        if (i == (size_t)bad)
    396404                                continue;
     405                        if (first) {
     406                                rc = block_read_direct(vol->extents[i].svc_id,
     407                                    ba, cnt, xorbuf);
     408                                if (rc != EOK)
     409                                        goto end;
     410
     411                                first = false;
    397412                        } else {
    398413                                rc = block_read_direct(vol->extents[i].svc_id,
     
    461476        }
    462477
    463         memset(xorbuf, 0, len);
     478        bool first = true;
    464479        for (i = 0; i < vol->dev_no; i++) {
    465480                if (i == p_extent)
    466481                        continue;
    467                 if (i == extent) {
    468                         xor(xorbuf, data, len);
     482
     483                if (first) {
     484                        if (i == extent) {
     485                                memcpy(xorbuf, data, len);
     486                        } else {
     487                                rc = block_read_direct(vol->extents[i].svc_id,
     488                                    block, cnt, xorbuf);
     489                                if (rc != EOK)
     490                                        goto end;
     491                        }
     492
     493                        first = false;
    469494                } else {
    470                         rc = block_read_direct(vol->extents[i].svc_id,
    471                             block, cnt, buf);
    472                         if (rc != EOK)
    473                                 goto end;
    474                         xor(xorbuf, buf, len);
     495                        if (i == extent) {
     496                                xor(xorbuf, data, len);
     497                        } else {
     498                                rc = block_read_direct(vol->extents[i].svc_id,
     499                                    block, cnt, buf);
     500                                if (rc != EOK)
     501                                        goto end;
     502
     503                                xor(xorbuf, buf, len);
     504                        }
    475505                }
    476506        }
     
    690720                        if (i == bad)
    691721                                continue;
    692                         rc = block_read_direct(vol->extents[i].svc_id, ba, cnt,
    693                             buf);
     722                        if (first)
     723                                rc = block_read_direct(vol->extents[i].svc_id,
     724                                    ba, cnt, xorbuf);
     725                        else
     726                                rc = block_read_direct(vol->extents[i].svc_id,
     727                                    ba, cnt, buf);
    694728                        if (rc != EOK) {
    695729                                hr_raid5_handle_extent_error(vol, i, rc);
     
    700734                        }
    701735
    702                         if (first)
    703                                 memcpy(xorbuf, buf, cnt * vol->bsize);
     736                        if (!first)
     737                                xor(xorbuf, buf, cnt * vol->bsize);
    704738                        else
    705                                 xor(xorbuf, buf, cnt * vol->bsize);
    706 
    707                         first = false;
     739                                first = false;
    708740                }
    709741
Note: See TracChangeset for help on using the changeset viewer.