AK: Rename KB, MB, GB to KiB, MiB, GiB

The SI prefixes "k", "M", "G" mean "10^3", "10^6", "10^9".
The IEC prefixes "Ki", "Mi", "Gi" mean "2^10", "2^20", "2^30".

Let's use the correct name, at least in code.

Only changes the name of the constants, no other behavior change.
This commit is contained in:
Nico Weber 2020-08-15 13:55:00 -04:00 committed by Andreas Kling
parent a68650a7b4
commit 430b265cd4
31 changed files with 69 additions and 69 deletions

View file

@ -39,13 +39,13 @@ static String number_string_with_one_decimal(float number, const char* suffix)
static String human_readable_size(size_t size)
{
if (size < 1 * KB)
if (size < 1 * KiB)
return String::format("%zu bytes", size);
if (size < 1 * MB)
return number_string_with_one_decimal((float)size / (float)KB, "KB");
if (size < 1 * GB)
return number_string_with_one_decimal((float)size / (float)MB, "MB");
return number_string_with_one_decimal((float)size / (float)GB, "GB");
if (size < 1 * MiB)
return number_string_with_one_decimal((float)size / (float)KiB, "KB");
if (size < 1 * GiB)
return number_string_with_one_decimal((float)size / (float)MiB, "MB");
return number_string_with_one_decimal((float)size / (float)GiB, "GB");
}
}

View file

@ -74,9 +74,9 @@ typedef __PTRDIFF_TYPE__ __ptrdiff_t;
typedef Conditional<sizeof(void*) == 8, u64, u32>::Type FlatPtr;
constexpr unsigned KB = 1024;
constexpr unsigned MB = KB * KB;
constexpr unsigned GB = KB * KB * KB;
constexpr unsigned KiB = 1024;
constexpr unsigned MiB = KiB * KiB;
constexpr unsigned GiB = KiB * KiB * KiB;
namespace std {
typedef decltype(nullptr) nullptr_t;

View file

@ -31,7 +31,7 @@
#include <LibAudio/WavLoader.h>
#include <LibCore/Timer.h>
#define PLAYBACK_MANAGER_BUFFER_SIZE 64 * KB
#define PLAYBACK_MANAGER_BUFFER_SIZE 64 * KiB
#define PLAYBACK_MANAGER_RATE 44100
class PlaybackManager final {

View file

@ -63,13 +63,13 @@
static String human_readable_size(u32 size)
{
if (size < (64 * KB))
if (size < (64 * KiB))
return String::format("%u", size);
if (size < MB)
return String::format("%u KB", size / KB);
if (size < GB)
return String::format("%u MB", size / MB);
return String::format("%u GB", size / GB);
if (size < MiB)
return String::format("%u KB", size / KiB);
if (size < GiB)
return String::format("%u MB", size / MiB);
return String::format("%u GB", size / GiB);
}
static NonnullRefPtr<GUI::Widget> build_file_systems_tab();

View file

@ -54,7 +54,7 @@
namespace UserspaceEmulator {
static constexpr u32 stack_location = 0x10000000;
static constexpr size_t stack_size = 64 * KB;
static constexpr size_t stack_size = 64 * KiB;
static Emulator* s_the;

View file

@ -355,7 +355,7 @@ struct SC_create_thread_params {
// ... ok, if you say so posix. Guess we get to lie to people about guard page size
unsigned int m_guard_page_size = 0; // Rounded up to PAGE_SIZE
unsigned int m_reported_guard_page_size = 0; // The lie we tell callers
unsigned int m_stack_size = 4 * MB; // Default PTHREAD_STACK_MIN
unsigned int m_stack_size = 4 * MiB; // Default PTHREAD_STACK_MIN
Userspace<void*> m_stack_location; // nullptr means any, o.w. process virtual address
};

View file

@ -34,7 +34,7 @@ namespace Kernel {
MappedROM map_bios()
{
MappedROM mapping;
mapping.size = 128 * KB;
mapping.size = 128 * KiB;
mapping.paddr = PhysicalAddress(0xe0000);
mapping.region = MM.allocate_kernel_region(mapping.paddr, PAGE_ROUND_UP(mapping.size), {}, Region::Access::Read);
return mapping;

View file

@ -837,7 +837,7 @@ KResult Plan9FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEnt
}
u64 offset = 0;
u32 count = fs().adjust_buffer_size(8 * MB);
u32 count = fs().adjust_buffer_size(8 * MiB);
while (true) {
Plan9FS::Message message { fs(), Plan9FS::Message::Type::Treaddir };

View file

@ -105,7 +105,7 @@ private:
Atomic<u32> m_next_fid { 1 };
ProtocolVersion m_remote_protocol_version { ProtocolVersion::v9P2000 };
size_t m_max_message_size { 4 * KB };
size_t m_max_message_size { 4 * KiB };
Lock m_send_lock { "Plan9FS send" };
Atomic<bool> m_someone_is_reading { false };

View file

@ -128,10 +128,10 @@ void for_each_allocator(Callback callback)
void slab_alloc_init()
{
s_slab_allocator_16.init(128 * KB);
s_slab_allocator_32.init(128 * KB);
s_slab_allocator_64.init(512 * KB);
s_slab_allocator_128.init(512 * KB);
s_slab_allocator_16.init(128 * KiB);
s_slab_allocator_32.init(128 * KiB);
s_slab_allocator_64.init(512 * KiB);
s_slab_allocator_128.init(512 * KiB);
}
void* slab_alloc(size_t slab_size)

View file

@ -48,12 +48,12 @@ struct AllocationHeader {
u8 data[0];
};
#define BASE_PHYSICAL (0xc0000000 + (4 * MB))
#define BASE_PHYSICAL (0xc0000000 + (4 * MiB))
#define CHUNK_SIZE 32
#define POOL_SIZE (3 * MB)
#define POOL_SIZE (3 * MiB)
#define ETERNAL_BASE_PHYSICAL (0xc0000000 + (2 * MB))
#define ETERNAL_RANGE_SIZE (2 * MB)
#define ETERNAL_BASE_PHYSICAL (0xc0000000 + (2 * MiB))
#define ETERNAL_RANGE_SIZE (2 * MiB)
static u8 alloc_map[POOL_SIZE / CHUNK_SIZE / 8];

View file

@ -45,7 +45,7 @@ KBuffer KBufferBuilder::build()
}
KBufferBuilder::KBufferBuilder()
: m_buffer(KBuffer::create_with_size(4 * MB, Region::Access::Read | Region::Access::Write))
: m_buffer(KBuffer::create_with_size(4 * MiB, Region::Access::Read | Region::Access::Write))
{
}

View file

@ -105,7 +105,7 @@ void NetworkTask_main()
return packet_size;
};
size_t buffer_size = 64 * KB;
size_t buffer_size = 64 * KiB;
auto buffer_region = MM.allocate_kernel_region(buffer_size, "Kernel Packet Buffer", Region::Access::Read | Region::Access::Write, false, true);
auto buffer = (u8*)buffer_region->vaddr().get();

View file

@ -33,7 +33,7 @@
namespace Kernel {
PerformanceEventBuffer::PerformanceEventBuffer()
: m_buffer(KBuffer::create_with_size(4 * MB))
: m_buffer(KBuffer::create_with_size(4 * MiB))
{
}

View file

@ -64,7 +64,7 @@ void start(Process& process)
s_pid = process.pid();
if (!s_profiling_buffer) {
s_profiling_buffer = RefPtr<KBufferImpl>(KBuffer::create_with_size(8 * MB).impl()).leak_ref();
s_profiling_buffer = RefPtr<KBufferImpl>(KBuffer::create_with_size(8 * MiB).impl()).leak_ref();
s_profiling_buffer->region().commit();
s_slot_count = s_profiling_buffer->size() / sizeof(Sample);
}

View file

@ -512,7 +512,7 @@ public:
}
static constexpr u32 default_kernel_stack_size = 65536;
static constexpr u32 default_userspace_stack_size = 4 * MB;
static constexpr u32 default_userspace_stack_size = 4 * MiB;
ThreadTracer* tracer() { return m_tracer.ptr(); }
void start_tracing_from(ProcessID tracer);

View file

@ -101,8 +101,8 @@ void MemoryManager::parse_memory_map()
if (mmap->type != MULTIBOOT_MEMORY_AVAILABLE)
continue;
// FIXME: Maybe make use of stuff below the 1MB mark?
if (mmap->addr < (1 * MB))
// FIXME: Maybe make use of stuff below the 1MiB mark?
if (mmap->addr < (1 * MiB))
continue;
if ((mmap->addr + mmap->len) > 0xffffffff)
@ -131,9 +131,9 @@ void MemoryManager::parse_memory_map()
for (size_t page_base = mmap->addr; page_base < (mmap->addr + mmap->len); page_base += PAGE_SIZE) {
auto addr = PhysicalAddress(page_base);
if (page_base < 7 * MB) {
if (page_base < 7 * MiB) {
// nothing
} else if (page_base >= 7 * MB && page_base < 8 * MB) {
} else if (page_base >= 7 * MiB && page_base < 8 * MiB) {
if (region.is_null() || !region_is_super || region->upper().offset(PAGE_SIZE) != addr) {
m_super_physical_regions.append(PhysicalRegion::create(addr, addr));
region = m_super_physical_regions.last();

View file

@ -80,7 +80,7 @@ PageDirectory::PageDirectory(Process& process, const RangeAllocator* parent_rang
if (parent_range_allocator) {
m_range_allocator.initialize_from_parent(*parent_range_allocator);
} else {
size_t random_offset = (get_fast_random<u8>() % 32 * MB) & PAGE_MASK;
size_t random_offset = (get_fast_random<u8>() % 32 * MiB) & PAGE_MASK;
u32 base = userspace_range_base + random_offset;
m_range_allocator.initialize_with_range(VirtualAddress(base), userspace_range_ceiling - base);
}
@ -102,7 +102,7 @@ PageDirectory::PageDirectory(Process& process, const RangeAllocator* parent_rang
MM.unquickmap_page();
}
// Clone bottom 2 MB of mappings from kernel_page_directory
// Clone bottom 2 MiB of mappings from kernel_page_directory
PageDirectoryEntry buffer;
auto* kernel_pd = MM.quickmap_pd(MM.kernel_page_directory(), 0);
memcpy(&buffer, kernel_pd, sizeof(PageDirectoryEntry));

View file

@ -44,7 +44,7 @@ public:
bool has_error() const { return !m_error_string.is_null(); }
const char* error_string() { return m_error_string.characters(); }
RefPtr<Buffer> get_more_samples(size_t max_bytes_to_read_from_input = 128 * KB);
RefPtr<Buffer> get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB);
void reset();
void seek(const int position);

View file

@ -73,7 +73,7 @@ static bool s_profiling = false;
static unsigned short size_classes[] = { 8, 16, 32, 64, 128, 252, 508, 1016, 2036, 4090, 8188, 16376, 32756, 0 };
static constexpr size_t num_size_classes = sizeof(size_classes) / sizeof(unsigned short);
constexpr size_t block_size = 64 * KB;
constexpr size_t block_size = 64 * KiB;
constexpr size_t block_mask = ~(block_size - 1);
struct CommonHeader {

View file

@ -109,7 +109,7 @@ void Job::on_socket_connected()
ASSERT(m_state == State::InBody || m_state == State::Finished);
read_while_data_available([&] {
auto read_size = 64 * KB;
auto read_size = 64 * KiB;
auto payload = receive(read_size);
if (!payload) {

View file

@ -1206,7 +1206,7 @@ JPGImageDecoderPlugin::JPGImageDecoderPlugin(const u8* data, size_t size)
m_context = make<JPGLoadingContext>();
m_context->data = data;
m_context->data_size = size;
m_context->huffman_stream.stream.ensure_capacity(50 * KB);
m_context->huffman_stream.stream.ensure_capacity(50 * KiB);
}
JPGImageDecoderPlugin::~JPGImageDecoderPlugin()

View file

@ -173,7 +173,7 @@ void Job::on_socket_connected()
ASSERT(can_read());
read_while_data_available([&] {
auto read_size = 64 * KB;
auto read_size = 64 * KiB;
if (m_current_chunk_remaining_size.has_value()) {
read_chunk_size:;
auto remaining = m_current_chunk_remaining_size.value();

View file

@ -34,7 +34,7 @@ namespace JS {
class HeapBlock {
public:
static constexpr size_t block_size = 16 * KB;
static constexpr size_t block_size = 16 * KiB;
static NonnullOwnPtr<HeapBlock> create_with_cell_size(Heap&, size_t);
void operator delete(void*);

View file

@ -44,9 +44,9 @@ namespace {
using PthreadAttrImpl = Syscall::SC_create_thread_params;
} // end anonymous namespace
constexpr size_t required_stack_alignment = 4 * MB;
constexpr size_t required_stack_alignment = 4 * MiB;
constexpr size_t highest_reasonable_guard_size = 32 * PAGE_SIZE;
constexpr size_t highest_reasonable_stack_size = 8 * MB; // That's the default in Ubuntu?
constexpr size_t highest_reasonable_stack_size = 8 * MiB; // That's the default in Ubuntu?
extern "C" {

View file

@ -80,7 +80,7 @@ private:
float total_memory = allocated + available;
float memory = (float)allocated / total_memory;
m_history.enqueue(memory);
m_tooltip = String::format("Memory: %.1f MiB of %.1f MiB in use",(float)allocated / MB, total_memory / MB);
m_tooltip = String::format("Memory: %.1f MiB of %.1f MiB in use", (float)allocated / MiB, total_memory / MiB);
break;
}
default:

View file

@ -69,7 +69,7 @@ int main()
printf("Success! Evil pointer: %p\n", ptr);
u8* base = &ptr[128 * MB];
u8* base = &ptr[128 * MiB];
uintptr_t g_processes = *(uintptr_t*)&base[0x1b51c4];
printf("base = %p\n", base);

View file

@ -58,13 +58,13 @@ static String number_string_with_one_decimal(float number, const char* suffix)
static String human_readable_size(size_t size)
{
if (size < 1 * KB)
if (size < 1 * KiB)
return String::number(size);
if (size < 1 * MB)
return number_string_with_one_decimal((float)size / (float)KB, "K");
if (size < 1 * GB)
return number_string_with_one_decimal((float)size / (float)MB, "M");
return number_string_with_one_decimal((float)size / (float)GB, "G");
if (size < 1 * MiB)
return number_string_with_one_decimal((float)size / (float)KiB, "K");
if (size < 1 * GiB)
return number_string_with_one_decimal((float)size / (float)MiB, "M");
return number_string_with_one_decimal((float)size / (float)GiB, "G");
}
int main(int argc, char** argv)

View file

@ -40,12 +40,12 @@
static String si_bytes(unsigned bytes)
{
if (bytes >= GB)
return String::format("%fGiB", (double)bytes / (double)GB);
if (bytes >= MB)
return String::format("%fMiB", (double)bytes / (double)MB);
if (bytes >= KB)
return String::format("%fkiB", (double)bytes / (double)KB);
if (bytes >= GiB)
return String::format("%fGiB", (double)bytes / (double)GiB);
if (bytes >= MiB)
return String::format("%fMiB", (double)bytes / (double)MiB);
if (bytes >= KiB)
return String::format("%fkiB", (double)bytes / (double)KiB);
return String::format("%dB", bytes);
}

View file

@ -241,13 +241,13 @@ static String number_string_with_one_decimal(float number, const char* suffix)
static String human_readable_size(size_t size)
{
if (size < 1 * KB)
if (size < 1 * KiB)
return String::number(size);
if (size < 1 * MB)
return number_string_with_one_decimal((float)size / (float)KB, "K");
if (size < 1 * GB)
return number_string_with_one_decimal((float)size / (float)MB, "M");
return number_string_with_one_decimal((float)size / (float)GB, "G");
if (size < 1 * MiB)
return number_string_with_one_decimal((float)size / (float)KiB, "K");
if (size < 1 * GiB)
return number_string_with_one_decimal((float)size / (float)MiB, "M");
return number_string_with_one_decimal((float)size / (float)GiB, "G");
}
static bool print_filesystem_object(const String& path, const String& name, const struct stat& st)

View file

@ -156,7 +156,7 @@ static bool unpack_file_for_central_directory_index(off_t central_directory_inde
int main(int argc, char** argv)
{
const char* path;
int map_size_limit = 32 * MB;
int map_size_limit = 32 * MiB;
Core::ArgsParser args_parser;
args_parser.add_option(map_size_limit, "Maximum chunk size to map", "map-size-limit", 0, "size");