class SegmentManager

Defined at line 141 of file ../../src/storage/f2fs/segment.h

Public Methods

void SegmentManager (F2fs * fs)

Defined at line 129 of file ../../src/storage/f2fs/segment.cc

void SegmentManager (SuperblockInfo & info)

Defined at line 130 of file ../../src/storage/f2fs/segment.cc

zx::result<uint32_t> GetVictimByDefault (GcType gc_type, CursegType type, AllocMode alloc_mode)

GetVictimByDefault() is called for two purposes:

1) One is to select a victim segment for garbage collection, and

2) the other is to find a dirty segment used for SSR.

For GC, it tries to find a victim segment that might require less cost

to secure free segments among all types of dirty segments.

The gc cost can be calculated in two ways according to GcType.

In case of GcType::kFgGc, it is typically triggered in the middle of user IO path,

and thus it selects a victim with a less valid block count (i.e., GcMode::kGcGreedy)

as it hopes the migration completes more quickly.

In case of GcType::kBgGc, it is triggered at a idle time,

so it uses a cost-benefit method (i.e., GcMode:: kGcCb) rather than kGcGreedy for the victim

selection. kGcCb tries to find a cold segment as a victim as it hopes to mitigate a block

thrashing problem.

Meanwhile, SSR is to reuse invalid blocks for new block allocation, and thus

it uses kGcGreedy to select a dirty segment with more invalid blocks

among the same type of dirty segments as that of the current segment.

If it succeeds in finding an eligible victim, it returns the segment number of the selected

victim. If it fails, it returns ZX_ERR_UNAVAILABLE.

Defined at line 105 of file ../../src/storage/f2fs/gc.cc

void SegmentManager (const SegmentManager & )

Not copyable or moveable

Defined at line 144 of file ../../src/storage/f2fs/segment.h

SegmentManager & operator= (const SegmentManager & )

Defined at line 145 of file ../../src/storage/f2fs/segment.h

void SegmentManager (SegmentManager && )

Defined at line 146 of file ../../src/storage/f2fs/segment.h

SegmentManager & operator= (SegmentManager && )

Defined at line 147 of file ../../src/storage/f2fs/segment.h

void SegmentManager ()

Defined at line 148 of file ../../src/storage/f2fs/segment.h

bool IsValidSegmentNumber (uint32_t segment_number)

Defined at line 172 of file ../../src/storage/f2fs/segment.h

zx_status_t BuildFreeSegmap ()

Defined at line 1469 of file ../../src/storage/f2fs/segment.cc

zx_status_t BuildSegmentManager ()

Defined at line 1598 of file ../../src/storage/f2fs/segment.cc

void DestroySegmentManager ()

Defined at line 1647 of file ../../src/storage/f2fs/segment.cc

const SegmentEntry & GetSegmentEntry (uint32_t segno)

Defined at line 132 of file ../../src/storage/f2fs/segment.cc

void GetSitBitmap (void * dst_addr)

Defined at line 226 of file ../../src/storage/f2fs/segment.cc

bool CompareValidBlocks (uint32_t blocks, uint32_t segno, bool section)

Defined at line 138 of file ../../src/storage/f2fs/segment.cc

uint32_t GetValidBlocks (uint32_t segno, bool section)

Defined at line 143 of file ../../src/storage/f2fs/segment.cc

bool HasNotEnoughFreeSecs (size_t freed_sections, size_t needed_blocks)

It check if there are enough free sections to write a checkpoint pack when adding

|freed_sections| of free sections and |needed_blocks| of dirty data pages.

Defined at line 493 of file ../../src/storage/f2fs/segment.cc

zx::result<> HasEnoughSsrBlocks (size_t needed_blocks)

It check if there are enough blocks to write a checkpoint pack in ssr mode when

adding |needed_blocks| of dirty data pages.

Defined at line 435 of file ../../src/storage/f2fs/segment.cc

uint32_t Utilization ()

Defined at line 322 of file ../../src/storage/f2fs/segment.cc

uint32_t CursegSegno (int type)

Defined at line 336 of file ../../src/storage/f2fs/segment.cc

uint8_t CursegAllocType (int type)

Defined at line 341 of file ../../src/storage/f2fs/segment.cc

uint16_t CursegBlkoff (int type)

Defined at line 346 of file ../../src/storage/f2fs/segment.cc

void CheckBlockCount (uint32_t segno, SitEntry & raw_sit)

Summary block is always treated as invalid block

Defined at line 366 of file ../../src/storage/f2fs/segment.cc

pgoff_t CurrentSitAddr (uint32_t start)

Defined at line 384 of file ../../src/storage/f2fs/segment.cc

pgoff_t NextSitAddr (pgoff_t block_addr)

Defined at line 397 of file ../../src/storage/f2fs/segment.cc

void SetToNextSit (uint32_t start)

Defined at line 407 of file ../../src/storage/f2fs/segment.cc

uint64_t GetMtime ()

Defined at line 416 of file ../../src/storage/f2fs/segment.cc

block_t StartSumBlock ()

Defined at line 421 of file ../../src/storage/f2fs/segment.cc

block_t SumBlkAddr (int base, int type)

Defined at line 426 of file ../../src/storage/f2fs/segment.cc

bool SecUsageCheck (uint32_t secno)

Defined at line 431 of file ../../src/storage/f2fs/segment.cc

bool IsValidBlock (uint32_t segno, uint64_t offset)

Defined at line 202 of file ../../src/storage/f2fs/gc.cc

block_t GetSectionCountForCheckpoint ()

Defined at line 236 of file ../../src/storage/f2fs/segment.cc

block_t PrefreeSegments ()

Defined at line 252 of file ../../src/storage/f2fs/segment.cc

block_t FreeSections ()

Defined at line 247 of file ../../src/storage/f2fs/segment.cc

block_t FreeSegments ()

Defined at line 231 of file ../../src/storage/f2fs/segment.cc

block_t DirtySegments ()

Defined at line 257 of file ../../src/storage/f2fs/segment.cc

block_t ReservedSections ()

Defined at line 267 of file ../../src/storage/f2fs/segment.cc

bool NeedSSR ()

Defined at line 275 of file ../../src/storage/f2fs/segment.cc

bool NeedInplaceUpdate (bool is_dir)

Defined at line 329 of file ../../src/storage/f2fs/segment.cc

void LocateDirtySegment (uint32_t segno, enum DirtyType dirty_type)

Defined at line 505 of file ../../src/storage/f2fs/segment.cc

void RemoveDirtySegment (uint32_t segno, enum DirtyType dirty_type)

Defined at line 531 of file ../../src/storage/f2fs/segment.cc

void LocateDirtySegment (uint32_t segno)

Should not occur error such as ZX_ERR_NO_MEMORY.

Adding dirty entry into seglist is not critical operation.

If a given segment is one of current working segments, it won't be added.

Defined at line 558 of file ../../src/storage/f2fs/segment.cc

void SetPrefreeAsFreeSegments ()

Should call clear_prefree_segments after checkpoint is done.

Defined at line 580 of file ../../src/storage/f2fs/segment.cc

void ClearPrefreeSegments ()

Defined at line 590 of file ../../src/storage/f2fs/segment.cc

void MarkSitEntryDirty (uint32_t segno)

Defined at line 648 of file ../../src/storage/f2fs/segment.cc

void SetSitEntryType (CursegType type, uint32_t segno, bool modified)

Defined at line 656 of file ../../src/storage/f2fs/segment.cc

void UpdateSitEntry (block_t blkaddr, int del)

Defined at line 664 of file ../../src/storage/f2fs/segment.cc

void UpdateInvalidBlocks (int32_t delta, bool is_node)

Defined at line 1649 of file ../../src/storage/f2fs/segment.cc

void RefreshSitEntry (block_t old_blkaddr, block_t new_blkaddr)

Defined at line 715 of file ../../src/storage/f2fs/segment.cc

void InvalidateBlocks (block_t addr)

Defined at line 721 of file ../../src/storage/f2fs/segment.cc

void AddSumEntry (CursegType type, Summary * sum, uint16_t offset)

This function should be resided under the curseg_mutex lock

Defined at line 737 of file ../../src/storage/f2fs/segment.cc

int NpagesForSummaryFlush ()

Calculate the number of current summary pages for writing

Defined at line 743 of file ../../src/storage/f2fs/segment.cc

zx_status_t GetSumPage (uint32_t segno, LockedPage * out)

Caller should put this summary page

Defined at line 770 of file ../../src/storage/f2fs/segment.cc

void WriteSumPage (SummaryBlock * sum_blk, block_t blk_addr)

Defined at line 774 of file ../../src/storage/f2fs/segment.cc

zx_status_t SetSummaryBlock (CursegType type, SummaryCallback callback)

Defined at line 1330 of file ../../src/storage/f2fs/segment.cc

zx_status_t GetSummaryBlock (CursegType type, SummaryCallback callback)

Defined at line 1337 of file ../../src/storage/f2fs/segment.cc

uint32_t CheckPrefreeSegments (int ofs_unit, CursegType type)
void GetNewSegment (uint32_t * newseg, bool new_sec)

Find a new segment from the free segments bitmap to right order

This function should be returned with success, otherwise BUG

TODO: after LFS allocation available, raise out of space event of inspect tree when new segment

cannot be allocated.

Defined at line 785 of file ../../src/storage/f2fs/segment.cc

void ResetCurseg (CursegType type, bool modified)

Defined at line 851 of file ../../src/storage/f2fs/segment.cc

void NewCurseg (CursegType type, bool new_sec)

Allocate a current working segment.

This function always allocates a free segment in LFS manner.

Defined at line 871 of file ../../src/storage/f2fs/segment.cc

void NextFreeBlkoff (CursegInfo * seg, block_t start)

Defined at line 881 of file ../../src/storage/f2fs/segment.cc

void RefreshNextBlkoff (CursegInfo * seg)

If a segment is written by LFS manner, next block offset is just obtained

by increasing the current block offset. However, if a segment is written by

SSR manner, next block offset obtained by calling __next_free_blkoff

Defined at line 895 of file ../../src/storage/f2fs/segment.cc

zx::result<uint32_t> GetGcVictim (GcType gc_type, CursegType type)

Defined at line 197 of file ../../src/storage/f2fs/gc.cc

size_t GetMaxCost (const VictimSelPolicy & policy)

This function calculates the maximum cost for a victim in each GcType

Any segment with a less cost value becomes a victim candidate.

Defined at line 79 of file ../../src/storage/f2fs/gc.cc

VictimSelPolicy GetVictimSelPolicy (GcType gc_type, CursegType type, AllocMode alloc_mode)

This method determines GcMode for GetVictimByDefault

Defined at line 55 of file ../../src/storage/f2fs/gc.cc

uint32_t GetBackgroundVictim ()

Defined at line 89 of file ../../src/storage/f2fs/gc.cc

size_t GetGcCost (uint32_t segno, const VictimSelPolicy & policy)

This method calculates the gc cost for each dirty segment

Defined at line 16 of file ../../src/storage/f2fs/gc.cc

size_t GetCostBenefitRatio (uint32_t segno)

Defined at line 27 of file ../../src/storage/f2fs/gc.cc

zx_status_t DoGarbageCollect (uint32_t segno, GcType gc_type)

Defined at line 208 of file ../../src/storage/f2fs/gc.cc

block_t GetMainAreaStartBlock ()

Defined at line 248 of file ../../src/storage/f2fs/segment.h

CursegInfo * CURSEG_I (CursegType type)

Defined at line 249 of file ../../src/storage/f2fs/segment.h

const CursegInfo * CURSEG_I (CursegType type)

Defined at line 250 of file ../../src/storage/f2fs/segment.h

size_t GetAvailableBlockCountOnCurseg (CursegType type)

Defined at line 253 of file ../../src/storage/f2fs/segment.h

block_t StartBlock (uint32_t segno)

Defined at line 256 of file ../../src/storage/f2fs/segment.h

block_t NextFreeBlkAddr (CursegType type)

Defined at line 259 of file ../../src/storage/f2fs/segment.h

block_t GetSegOffFromSeg0 (block_t blk_addr)

Defined at line 263 of file ../../src/storage/f2fs/segment.h

uint32_t GetSegNoFromSeg0 (block_t blk_addr)

Defined at line 264 of file ../../src/storage/f2fs/segment.h

uint32_t GetSegmentNumber (block_t blk_addr)

Defined at line 267 of file ../../src/storage/f2fs/segment.h

uint32_t GetSecNo (uint32_t segno)

Defined at line 272 of file ../../src/storage/f2fs/segment.h

uint32_t GetZoneNoFromSegNo (uint32_t segno)

Defined at line 273 of file ../../src/storage/f2fs/segment.h

block_t GetSumBlock (uint32_t segno)

Defined at line 276 of file ../../src/storage/f2fs/segment.h

uint32_t SitEntryOffset (uint32_t segno)

Defined at line 277 of file ../../src/storage/f2fs/segment.h

block_t TotalSegs ()

Defined at line 279 of file ../../src/storage/f2fs/segment.h

void DisableFgGc ()

for tests and fsck

Defined at line 322 of file ../../src/storage/f2fs/segment.h

void EnableFgGc ()

Defined at line 323 of file ../../src/storage/f2fs/segment.h

bool CanGc ()

Defined at line 324 of file ../../src/storage/f2fs/segment.h

void SetCurVictimSec (uint32_t secno)

Defined at line 325 of file ../../src/storage/f2fs/segment.h

uint32_t GetCurVictimSec ()

Defined at line 326 of file ../../src/storage/f2fs/segment.h

block_t GetMainSegmentsCount ()

Defined at line 327 of file ../../src/storage/f2fs/segment.h

block_t GetSegmentsCount ()

Defined at line 328 of file ../../src/storage/f2fs/segment.h

SitInfo & GetSitInfo ()

Defined at line 329 of file ../../src/storage/f2fs/segment.h

void SetSitInfo (std::unique_ptr<SitInfo> && info)

Defined at line 330 of file ../../src/storage/f2fs/segment.h

FreeSegmapInfo & GetFreeSegmentInfo ()

Defined at line 333 of file ../../src/storage/f2fs/segment.h

void SetFreeSegmentInfo (std::unique_ptr<FreeSegmapInfo> && info)

Defined at line 334 of file ../../src/storage/f2fs/segment.h

DirtySeglistInfo & GetDirtySegmentInfo ()

Defined at line 337 of file ../../src/storage/f2fs/segment.h

void SetDirtySegmentInfo (std::unique_ptr<DirtySeglistInfo> && info)

Defined at line 338 of file ../../src/storage/f2fs/segment.h

void SetSegmentEntryType (uint32_t target_segno, CursegType type)

Defined at line 341 of file ../../src/storage/f2fs/segment.h

uint32_t GetLastVictim (int mode)

Defined at line 345 of file ../../src/storage/f2fs/segment.h

void SetLastVictim (int mode, uint32_t last_victim)

Defined at line 346 of file ../../src/storage/f2fs/segment.h

void SetSegment0StartBlock (const block_t addr)

Defined at line 349 of file ../../src/storage/f2fs/segment.h

void SetMainAreaStartBlock (const block_t addr)

Defined at line 350 of file ../../src/storage/f2fs/segment.h

void SetSSAreaStartBlock (const block_t addr)

Defined at line 351 of file ../../src/storage/f2fs/segment.h

void SetSegmentsCount (const block_t count)

Defined at line 352 of file ../../src/storage/f2fs/segment.h

void SetMainSegmentsCount (const block_t count)

Defined at line 353 of file ../../src/storage/f2fs/segment.h

void SetReservedSegmentsCount (const block_t count)

Defined at line 354 of file ../../src/storage/f2fs/segment.h

void SetOPSegmentsCount (const block_t count)

Defined at line 355 of file ../../src/storage/f2fs/segment.h

void ChangeCurseg (CursegType type, bool reuse)

This function always allocates a used segment (from dirty seglist) by SSR

manner, so it should recover the existing segment information of valid blocks

Defined at line 905 of file ../../src/storage/f2fs/segment.cc

void AllocateSegmentByDefault (CursegType type, bool force)

Allocate a segment for new block allocations in CURSEG_I(type).

This function is supposed to be successful. Otherwise, BUG.

Defined at line 931 of file ../../src/storage/f2fs/segment.cc

void AllocateNewSegments ()

Defined at line 947 of file ../../src/storage/f2fs/segment.cc

bool HasCursegSpace (CursegType type)

Defined at line 958 of file ../../src/storage/f2fs/segment.cc

block_t GetBlockAddrOnSegment (LockedPage & page, block_t old_blkaddr, Summary * sum, PageType p_type)

Defined at line 963 of file ../../src/storage/f2fs/segment.cc

void RecoverDataPage (Summary & sum, block_t old_blkaddr, block_t new_blkaddr)

Defined at line 1006 of file ../../src/storage/f2fs/segment.cc

zx_status_t ReadCompactedSummaries ()

Defined at line 1047 of file ../../src/storage/f2fs/segment.cc

zx_status_t ReadNormalSummaries (int type)

Defined at line 1101 of file ../../src/storage/f2fs/segment.cc

int RestoreCursegSummaries ()

Defined at line 1177 of file ../../src/storage/f2fs/segment.cc

zx_status_t RestoreNodeSummary (uint32_t segno, SummaryBlock & sum)

Defined at line 1159 of file ../../src/storage/f2fs/segment.cc

void WriteCompactedSummaries (block_t blkaddr)

Defined at line 1195 of file ../../src/storage/f2fs/segment.cc

void WriteNormalSummaries (block_t blkaddr, CursegType type)

Defined at line 1241 of file ../../src/storage/f2fs/segment.cc

void WriteDataSummaries (block_t start_blk)

Defined at line 1257 of file ../../src/storage/f2fs/segment.cc

void WriteNodeSummaries (block_t start_blk)

Defined at line 1265 of file ../../src/storage/f2fs/segment.cc

bool FlushSitsInJournal ()

Defined at line 1311 of file ../../src/storage/f2fs/segment.cc

zx_status_t FlushSitEntries ()

CP calls this function, which flushes SIT entries including SitJournal,

and moves prefree segs to free segs.

Defined at line 1346 of file ../../src/storage/f2fs/segment.cc

Friends

class GcTester
class F2fsFakeDevTestFixture