From d61e7f330adeafe99e1ea163d212d34279217d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 27 Jan 2004 02:26:22 +0000 Subject: [PATCH] Wrote a simple algorithm to create appropriate allocation group values for newly initialized disks. Should work for all sizes :-) Documented a bit what good values actually mean. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6339 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/bfs/Volume.cpp | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Volume.cpp b/src/add-ons/kernel/file_systems/bfs/Volume.cpp index 10b7d496d7..d0cc491839 100644 --- a/src/add-ons/kernel/file_systems/bfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Volume.cpp @@ -21,6 +21,18 @@ #include +static const int32 kDesiredAllocationGroups = 56; + // This is the number of allocation groups that will be tried + // to be given for newly initialized disks. + // That's only relevant for smaller disks, though, since any + // of today's disk sizes already reach the maximum length + // of an allocation group (65536 blocks). + // It seems to create appropriate numbers for smaller disks + // with this setting, though (i.e. you can create a 400 MB + // file on a 1 GB disk without the need for double indirect + // blocks). + + class DeviceOpener { public: DeviceOpener(const char *device, int mode); @@ -172,11 +184,34 @@ disk_super_block::Initialize(const char *diskName, off_t numBlocks, uint32 block num_blocks = numBlocks; used_blocks = 0; - // ToDo: set allocation group stuff for real (this is hardcoded for a 10 MB file)!!! + // Get the minimum ag_shift (that's determined by the block size) blocks_per_ag = 1; - num_ags = 2; ag_shift = 13; + + int32 bitsPerBlock = blockSize << 3; + off_t bitmapBlocks = (numBlocks + bitsPerBlock - 1) / bitsPerBlock; + + for (int32 i = 8192; i < bitsPerBlock; i *= 2) { + ag_shift++; + } + + // Many allocation groups help applying allocation policies, but if + // they are too small, we will need to many block_runs to cover large + // files (see above to get an explanation of the kDesiredAllocationGroups + // constant). + + while (true) { + num_ags = bitmapBlocks / blocks_per_ag; + if (num_ags > kDesiredAllocationGroups) { + if (ag_shift == 16) + break; + + ag_shift++; + blocks_per_ag++; + } else + break; + } }