Skip to content

VMEM file: use file object directly instead of RAM buffer#78

Open
jeanbaptistelab wants to merge 3 commits into
masterfrom
bugfix/MDP-200
Open

VMEM file: use file object directly instead of RAM buffer#78
jeanbaptistelab wants to merge 3 commits into
masterfrom
bugfix/MDP-200

Conversation

@jeanbaptistelab
Copy link
Copy Markdown
Contributor

This reduces artificial RAM requirement for processes using VMEM file objects, at the (relative) expense of speed, but if speed is needed, then VMEM block objects (which offer configurable caching) can be used

This reduces artificail RAM requirement for processes using VMEM file
objects, at the (relative) expense of speed, but if speed is needed,
then VMEM block objects (which offer configurable caching) can be used
Comment thread include/vmem/vmem_file.h Outdated
#if __64BIT__
#define VMEM_FILE_VADDR_INITIALIZER(name_in) \
.vaddr = (uint64_t)vmem_##name_in##_buf
.vaddr = (uint64_t)&vmem_##name_in##_driver
Copy link
Copy Markdown
Contributor Author

@jeanbaptistelab jeanbaptistelab May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see this is going to be an issue: previously, the vaddr was generated by the compiler, and we wouldn't get overlap because each vaddr would be the size of the corresponding allocated static buffer.
I naively use the driver object's address, but depending on the link map, these objects might be placed one after the other in memory, effectively causing overlaps, which will have, let's say, "unintended effects" at runtime :)
I'll try to come up with a solution, but I don't think we can auto-magically solve that one....
Note that though the previous implementation was convenient, it had severe drawbacks when a piece of code serializes the vaddr to reuse it later (across reboots etc): the process address space is not guaranteed to start at the same address for every invocation, this is actually why the VMEM_DEFINE_FILE_VADDR macro was introduced, allowing manual setting the vaddr to values that don't overlap (the "don't overlap" part is currently part of the manual process, a check could be introduced to detect overlaps at run-time, or use our partool process that can detect these overlaps by processing the ELF file)

@johandc
Copy link
Copy Markdown
Contributor

johandc commented May 2, 2026

The concept behind VMEM is to have random access, directly even by peek and poke. The entire file thus needs to live inside virtual memory, and have a full memory or virtual allocation. If you need to open and close file handles and have dynamic access to a file system, it sounds more like its an FTP protocol you are looking for.

Copy link
Copy Markdown
Contributor

@johandc johandc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create another VMEM type if you need to, but dont change default behaviour for VMEM_FILE,

@jeanbaptistelab
Copy link
Copy Markdown
Contributor Author

jeanbaptistelab commented May 4, 2026

@johandc I've now updated this PR to keep the original VMEM file implementation and introduced a new, separate VMEM file vaddr type

@jeanbaptistelab jeanbaptistelab requested a review from johandc May 4, 2026 10:32
@jeanbaptistelab
Copy link
Copy Markdown
Contributor Author

ping ? @troelsjessen @kivkiv12345 @johandc

Copy link
Copy Markdown
Contributor

@troelsjessen troelsjessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation generally seems like a useful extension. I suggest we always set one of the upper bits in the macro when the vaddr is assigned, to avoid that the user accidentally overlaps with a dynamically alloced address allocated to the application.

Image

@jeanbaptistelab
Copy link
Copy Markdown
Contributor Author

The implementation generally seems like a useful extension. I suggest we always set one of the upper bits in the macro when the vaddr is assigned, to avoid that the user accidentally overlaps with a dynamically alloced address allocated to the application.

Image

Something like this @troelsjessen ?
/* We ensure bit 59 is set so that no malloc'ed value will collide with these vaddr */
.vaddr = (1<<59) | (uint64_t)fixed_vaddr, \

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants