feat: alloc disk acorrding to avail disk space

This commit is contained in:
Hongze Cheng 2023-10-25 19:44:21 +08:00
parent 3ff331b8b7
commit 25aade1333
1 changed files with 14 additions and 0 deletions

View File

@ -110,7 +110,9 @@ int32_t tfsAllocDiskOnTier(STfsTier *pTier) {
} }
int32_t retId = -1; int32_t retId = -1;
int64_t avail = 0;
for (int32_t id = 0; id < TFS_MAX_DISKS_PER_TIER; ++id) { for (int32_t id = 0; id < TFS_MAX_DISKS_PER_TIER; ++id) {
#if 0 // round-robin
int32_t diskId = (pTier->nextid + id) % pTier->ndisk; int32_t diskId = (pTier->nextid + id) % pTier->ndisk;
STfsDisk *pDisk = pTier->disks[diskId]; STfsDisk *pDisk = pTier->disks[diskId];
@ -126,6 +128,18 @@ int32_t tfsAllocDiskOnTier(STfsTier *pTier) {
terrno = 0; terrno = 0;
pTier->nextid = (diskId + 1) % pTier->ndisk; pTier->nextid = (diskId + 1) % pTier->ndisk;
break; break;
#else // select the disk with the most available space
STfsDisk *pDisk = pTier->disks[id];
if (pDisk == NULL) continue;
if (pDisk->size.avail < tsMinDiskFreeSize) continue;
if (pDisk->size.avail > avail) {
avail = pDisk->size.avail;
retId = id;
terrno = 0;
}
#endif
} }
tfsUnLockTier(pTier); tfsUnLockTier(pTier);