From de2ec4a8c3368cbd37597b641a1a7b6c8e10ac26 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 26 Feb 2026 13:13:10 -0500 Subject: [PATCH] ramfs: Rehabilitate AllocationInfo support. At least we won't double-count files now. --- .../file_systems/ramfs/AllocationInfo.cpp | 55 +++++-------------- .../file_systems/ramfs/AllocationInfo.h | 14 ++--- .../kernel/file_systems/ramfs/Attribute.cpp | 4 +- .../file_systems/ramfs/DataContainer.cpp | 13 ++--- .../kernel/file_systems/ramfs/DataContainer.h | 5 +- .../kernel/file_systems/ramfs/File.cpp | 2 +- .../kernel/file_systems/ramfs/Volume.cpp | 2 +- .../kernel/file_systems/ramfs/Volume.h | 2 +- .../file_systems/ramfs/kernel_interface.cpp | 20 +++---- 9 files changed, 40 insertions(+), 77 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.cpp b/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.cpp index f1d510102b..c0bab3f856 100644 --- a/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.cpp @@ -12,7 +12,7 @@ #include "File.h" #include "SymLink.h" -// constructor + AllocationInfo::AllocationInfo() : fNodeTableArraySize(0), fNodeTableVectorSize(0), @@ -30,10 +30,6 @@ AllocationInfo::AllocationInfo() fSymLinkCount(0), fSymLinkSize(0), - fAreaCount(0), - fAreaSize(0), - fBlockCount(0), - fBlockSize(0), fListCount(0), fListSize(0), fOtherCount(0), @@ -43,34 +39,32 @@ AllocationInfo::AllocationInfo() { } -// destructor + AllocationInfo::~AllocationInfo() { } -// AddNodeTableAllocation + void AllocationInfo::AddNodeTableAllocation(size_t arraySize, size_t vectorSize, - size_t elementSize, size_t elementCount) + size_t elementSize, size_t elementCount) { fNodeTableArraySize += arraySize; fNodeTableVectorSize += vectorSize * elementSize; fNodeTableElementCount += elementCount; } -// AddDirectoryEntryTableAllocation + void AllocationInfo::AddDirectoryEntryTableAllocation(size_t arraySize, - size_t vectorSize, - size_t elementSize, - size_t elementCount) + size_t vectorSize, size_t elementSize, size_t elementCount) { fDirectoryEntryTableArraySize += arraySize; fDirectoryEntryTableVectorSize += vectorSize * elementSize; fDirectoryEntryTableElementCount += elementCount; } -// AddAttributeAllocation + void AllocationInfo::AddAttributeAllocation(size_t size) { @@ -78,21 +72,21 @@ AllocationInfo::AddAttributeAllocation(size_t size) fAttributeSize += size; } -// AddDirectoryAllocation + void AllocationInfo::AddDirectoryAllocation() { fDirectoryCount++; } -// AddEntryAllocation + void AllocationInfo::AddEntryAllocation() { fEntryCount++; } -// AddFileAllocation + void AllocationInfo::AddFileAllocation(size_t size) { @@ -100,7 +94,7 @@ AllocationInfo::AddFileAllocation(size_t size) fFileSize += size; } -// AddSymLinkAllocation + void AllocationInfo::AddSymLinkAllocation(size_t size) { @@ -108,23 +102,7 @@ AllocationInfo::AddSymLinkAllocation(size_t size) fSymLinkSize += size; } -// AddAreaAllocation -void -AllocationInfo::AddAreaAllocation(size_t size, size_t count) -{ - fAreaCount += count; - fAreaSize += count * size; -} -// AddBlockAllocation -void -AllocationInfo::AddBlockAllocation(size_t size) -{ - fBlockCount++; - fBlockSize += size; -} - -// AddListAllocation void AllocationInfo::AddListAllocation(size_t capacity, size_t elementSize) { @@ -132,7 +110,7 @@ AllocationInfo::AddListAllocation(size_t capacity, size_t elementSize) fListSize += capacity * elementSize; } -// AddOtherAllocation + void AllocationInfo::AddOtherAllocation(size_t size, size_t count) { @@ -140,7 +118,7 @@ AllocationInfo::AddOtherAllocation(size_t size, size_t count) fOtherSize += size * count; } -// AddStringAllocation + void AllocationInfo::AddStringAllocation(size_t size) { @@ -148,7 +126,7 @@ AllocationInfo::AddStringAllocation(size_t size) fStringSize += size; } -// Dump + void AllocationInfo::Dump() const { @@ -193,10 +171,6 @@ AllocationInfo::Dump() const heapSize += fSymLinkCount * sizeof(SymLink); PRINT(" areas: %9lu, size: %9lu\n", fAreaCount, fAreaSize); - areaCount += fAreaCount; - areaSize += fAreaSize; - - PRINT(" blocks: %9lu, size: %9lu\n", fBlockCount, fBlockSize); PRINT(" lists: %9lu, size: %9lu\n", fListCount, fListSize); heapCount += fListCount; @@ -211,6 +185,5 @@ AllocationInfo::Dump() const heapSize += fStringSize; PRINT("heap: %9lu allocations, size: %9lu\n", heapCount, heapSize); - PRINT("areas: %9lu allocations, size: %9lu\n", areaCount, areaSize); } diff --git a/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.h b/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.h index b0c81cff66..5acabd0442 100644 --- a/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.h +++ b/src/add-ons/kernel/file_systems/ramfs/AllocationInfo.h @@ -5,18 +5,19 @@ #ifndef ALLOCATION_INFO_H #define ALLOCATION_INFO_H + #include + class AllocationInfo { public: AllocationInfo(); ~AllocationInfo(); void AddNodeTableAllocation(size_t arraySize, size_t vectorSize, - size_t elementSize, size_t elementCount); + size_t elementSize, size_t elementCount); void AddDirectoryEntryTableAllocation(size_t arraySize, size_t vectorSize, - size_t elementSize, - size_t elementCount); + size_t elementSize, size_t elementCount); void AddAttributeAllocation(size_t size); void AddDirectoryAllocation(); @@ -24,8 +25,6 @@ public: void AddFileAllocation(size_t size); void AddSymLinkAllocation(size_t size); - void AddAreaAllocation(size_t size, size_t count = 1); - void AddBlockAllocation(size_t size); void AddListAllocation(size_t capacity, size_t elementSize); void AddOtherAllocation(size_t size, size_t count = 1); void AddStringAllocation(size_t size); @@ -49,10 +48,6 @@ private: size_t fSymLinkCount; size_t fSymLinkSize; - size_t fAreaCount; - size_t fAreaSize; - size_t fBlockCount; - size_t fBlockSize; size_t fListCount; size_t fListSize; size_t fOtherCount; @@ -61,4 +56,5 @@ private: size_t fStringSize; }; + #endif // ALLOCATION_INFO_H diff --git a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp index 1ab167a228..dfbdcc6942 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp @@ -149,8 +149,6 @@ Attribute::DetachAttributeIterator(AttributeIterator *iterator) void Attribute::GetAllocationInfo(AllocationInfo &info) { - DataContainer::GetAllocationInfo(info); - info.AddAttributeAllocation(GetSize()); + info.AddAttributeAllocation(DataContainer::GetCommittedSize()); info.AddStringAllocation(fName.GetLength()); } - diff --git a/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp b/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp index 6d34268803..583302e386 100644 --- a/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp @@ -252,14 +252,13 @@ DataContainer::WriteAt(off_t offset, const void *_buffer, size_t size, } -void -DataContainer::GetAllocationInfo(AllocationInfo &info) +off_t +DataContainer::GetCommittedSize() const { - if (_IsCacheMode()) { - info.AddAreaAllocation(fCache->committed_size); - } else { - // ... - } + if (_IsCacheMode()) + return sizeof(VMForVnodeCache) + fCache->committed_size; + else + return fSmallBufferSize; } diff --git a/src/add-ons/kernel/file_systems/ramfs/DataContainer.h b/src/add-ons/kernel/file_systems/ramfs/DataContainer.h index 34b5af9b7a..15d01b2f95 100644 --- a/src/add-ons/kernel/file_systems/ramfs/DataContainer.h +++ b/src/add-ons/kernel/file_systems/ramfs/DataContainer.h @@ -12,7 +12,6 @@ struct vm_page; class VMCache; -class AllocationInfo; class Volume; @@ -27,6 +26,7 @@ public: status_t Resize(off_t newSize); off_t GetSize() const { return fSize; } + off_t GetCommittedSize() const; VMCache* GetCache(struct vnode* vnode); @@ -35,9 +35,6 @@ public: virtual status_t WriteAt(off_t offset, const void *buffer, size_t size, size_t *bytesWritten); - // debugging - void GetAllocationInfo(AllocationInfo &info); - private: inline bool _RequiresCacheMode(size_t size); inline bool _IsCacheMode() const; diff --git a/src/add-ons/kernel/file_systems/ramfs/File.cpp b/src/add-ons/kernel/file_systems/ramfs/File.cpp index ffb021a415..e2960bb52c 100644 --- a/src/add-ons/kernel/file_systems/ramfs/File.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/File.cpp @@ -76,6 +76,6 @@ File::GetSize() const void File::GetAllocationInfo(AllocationInfo &info) { - info.AddFileAllocation(GetSize()); + info.AddFileAllocation(DataContainer::GetCommittedSize()); } diff --git a/src/add-ons/kernel/file_systems/ramfs/Volume.cpp b/src/add-ons/kernel/file_systems/ramfs/Volume.cpp index 4232b0dfc5..67680a00c5 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Volume.cpp @@ -725,7 +725,7 @@ Volume::UpdateLiveQueries(Entry *entry, Node* node, const char *attribute, void -Volume::GetAllocationInfo(AllocationInfo &info) +Volume::GetAllocationInfo(AllocationInfo &info) const { // tables info.AddOtherAllocation(sizeof(NodeTable)); diff --git a/src/add-ons/kernel/file_systems/ramfs/Volume.h b/src/add-ons/kernel/file_systems/ramfs/Volume.h index 42de6c0bf4..cb3f7ab24c 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Volume.h +++ b/src/add-ons/kernel/file_systems/ramfs/Volume.h @@ -154,7 +154,7 @@ public: ino_t NextNodeID() { return fNextNodeID++; } - void GetAllocationInfo(AllocationInfo &info); + void GetAllocationInfo(AllocationInfo &info) const; bigtime_t GetAccessTime() const { return fAccessTime; } diff --git a/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp index 7a0bcef485..b4406e57f7 100644 --- a/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp @@ -300,22 +300,22 @@ ramfs_ioctl(fs_volume* _volume, fs_vnode* /*node*/, void* /*cookie*/, switch (cmd) { case RAMFS_IOCTL_GET_ALLOCATION_INFO: { - if (buffer) { - VolumeReadLocker locker(volume); - if (!locker.IsLocked()) { - AllocationInfo *info = (AllocationInfo*)buffer; - volume->GetAllocationInfo(*info); - } else - SET_ERROR(error, B_ERROR); - } else - SET_ERROR(error, B_BAD_VALUE); + if (buffer == NULL) + RETURN_ERROR(B_BAD_VALUE); + + VolumeReadLocker locker(volume); + if (!locker.IsLocked()) + RETURN_ERROR(B_ERROR); + + AllocationInfo *info = (AllocationInfo*)buffer; + volume->GetAllocationInfo(*info); break; } case RAMFS_IOCTL_DUMP_INDEX: { if (buffer) { VolumeReadLocker locker(volume); - if (!locker.IsLocked()) { + if (locker.IsLocked()) { const char *name = (const char*)buffer; PRINT(" RAMFS_IOCTL_DUMP_INDEX, `%s'\n", name); IndexDirectory *indexDir = volume->GetIndexDirectory();