From a98a4515457a47295ade7d25affdea3b67079842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 27 Jan 2004 02:37:29 +0000 Subject: [PATCH] Added a small test application that uses the same allocation group algorithm as (our) BFS, so that you can play with it. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6340 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/bfs/mkbfs/Jamfile | 7 +- .../bfs/mkbfs/allocationGroups.cpp | 70 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/tests/add-ons/kernel/file_systems/bfs/mkbfs/allocationGroups.cpp diff --git a/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/Jamfile b/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/Jamfile index b69c7aa2a3..a186042e83 100644 --- a/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/Jamfile +++ b/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/Jamfile @@ -20,8 +20,7 @@ UsePrivateHeaders [ FDirName kernel util ] ; SubDirC++Flags $(defines) -fno-exceptions -fno-rtti $(malloc_debug_flags) ; } -SimpleTest mkbfs - : +SimpleTest mkbfs : mkbfs.cpp cache.c @@ -36,6 +35,10 @@ SimpleTest mkbfs : ; +SimpleTest allocationGroups : + allocationGroups.cpp + ; + # Tell Jam where to find these sources SEARCH on [ FGristFiles Volume.cpp BPlusTree.cpp Inode.cpp Index.cpp Query.cpp Journal.cpp diff --git a/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/allocationGroups.cpp b/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/allocationGroups.cpp new file mode 100644 index 0000000000..1f46f9953a --- /dev/null +++ b/src/tests/add-ons/kernel/file_systems/bfs/mkbfs/allocationGroups.cpp @@ -0,0 +1,70 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include + +#include +#include +#include +#include + + +static const uint32 kDesiredAllocationGroups = 56; + + +int +main(int argc, char **argv) +{ + if (argc != 3 || !isdigit(argv[1][0]) || !isdigit(argv[2][0])) { + const char *name = strrchr(argv[0], '/'); + name = name ? name + 1 : argv[0]; + + fprintf(stderr, "usage: %s \n", name); + return -1; + } + + off_t numBlocks = atoll(argv[1]); + uint32 blockSize = (uint32)atol(argv[2]); + + if (blockSize != 1024 && blockSize != 2048 && blockSize != 4096 && blockSize != 8192) { + fprintf(stderr, "valid values for are: 1024, 2048, 4096, 8192\n"); + return -1; + } + + uint32 blocks_per_ag = 1; + uint32 ag_shift = 13; + uint32 num_ags = 0; + + uint32 bitsPerBlock = blockSize << 3; + off_t bitmapBlocks = (numBlocks + bitsPerBlock - 1) / bitsPerBlock; + for (uint32 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 + + while (true) { + num_ags = bitmapBlocks / blocks_per_ag; + if (num_ags > kDesiredAllocationGroups) { + if (ag_shift == 16) + break; + + ag_shift++; + blocks_per_ag++; + } else + break; + } + + printf("bitmap blocks = %Ld\n", bitmapBlocks); + printf("allocation groups = %lu\n", num_ags); + printf("shift = %lu (%lu)\n", ag_shift, 1UL << ag_shift); + printf("blocks per group = %lu\n", blocks_per_ag); + + return 0; +} +