-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make hard memory limit configurable #515
Conversation
7f7c53b
to
84a2e27
Compare
Codecov Report
@@ Coverage Diff @@
## master #515 +/- ##
========================================
Coverage 99.69% 99.69%
========================================
Files 54 54
Lines 17153 17322 +169
========================================
+ Hits 17101 17270 +169
Misses 52 52 |
lib/fizzy/execute.cpp
Outdated
@@ -1229,9 +1230,10 @@ ExecutionResult execute( | |||
uint32_t ret = static_cast<uint32_t>(cur_pages); | |||
try | |||
{ | |||
// TODO use memory_pages_limit passed to instantiate | |||
const size_t memory_max_pages = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we update instance.memory_pages_limit
with the imported max? So execute
would be only concerned with instance.memory_pages_limit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try it
Looks good in general, this is what I meant. |
24616c2
to
8b3c2b8
Compare
auto [memory, memory_limits] = allocate_memory(module.memorysec, imported_memories); | ||
auto [memory, memory_limits] = | ||
allocate_memory(module.memorysec, imported_memories, memory_pages_limit); | ||
if (memory_limits.max.has_value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would add something like:
if (memory_limits.max.has_value()) | |
// If imported memory is used, we need to adjust the memory limit. | |
// Note: allocate_memory ensures this limit is always below memory_pages_limit. | |
if (memory_limits.max.has_value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the comment, but it applies to non-imported memory, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, it is the memory section setting.
m_instances[name] = | ||
fizzy::instantiate(std::move(module), std::move(imports.functions), | ||
std::move(imports.tables), std::move(imports.memories), | ||
std::move(imports.globals), TestMemoryPagesLimit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll actually override the default in #329 too.
9295c81
to
ca23b2f
Compare
lib/fizzy/execute.cpp
Outdated
@@ -173,7 +172,7 @@ std::tuple<table_ptr, Limits> allocate_table( | |||
} | |||
|
|||
std::tuple<bytes_ptr, Limits> allocate_memory(const std::vector<Memory>& module_memories, | |||
const std::vector<ExternalMemory>& imported_memories) | |||
const std::vector<ExternalMemory>& imported_memories, unsigned memory_pages_limit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::vector<ExternalMemory>& imported_memories, unsigned memory_pages_limit) | |
const std::vector<ExternalMemory>& imported_memories, uint32_t memory_pages_limit) |
Always use uint32_t for memory indexing and sizes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is number of pages, the limits sections uses uint32_t
, and we actually use size_t
in multiple places regarding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I made it unsigned
because constants in limits.hpp
are already unsigned
, and also because it's a limit, that we impose ourselves, not related to the sizes in the spec... But now I think it makes sense to make everything uint32_t
lib/fizzy/execute.cpp
Outdated
@@ -677,7 +676,8 @@ std::optional<uint32_t> find_export(const Module& module, ExternalKind kind, std | |||
|
|||
std::unique_ptr<Instance> instantiate(Module module, | |||
std::vector<ExternalFunction> imported_functions, std::vector<ExternalTable> imported_tables, | |||
std::vector<ExternalMemory> imported_memories, std::vector<ExternalGlobal> imported_globals) | |||
std::vector<ExternalMemory> imported_memories, std::vector<ExternalGlobal> imported_globals, | |||
unsigned memory_pages_limit /* = DefaultMemoryPagesLimit */) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsigned memory_pages_limit /* = DefaultMemoryPagesLimit */) | |
unsigned memory_pages_limit /*= DefaultMemoryPagesLimit*/) |
To be consistent with /*unused*/
?
lib/fizzy/limits.hpp
Outdated
@@ -14,8 +14,8 @@ constexpr unsigned PageSize = 65536; | |||
constexpr unsigned MemoryPagesValidationLimit = (4 * 1024 * 1024 * 1024ULL) / PageSize; | |||
static_assert(MemoryPagesValidationLimit == 65536); | |||
|
|||
// Set hard limit of 256MB of memory. | |||
constexpr unsigned MemoryPagesLimit = (256 * 1024 * 1024ULL) / PageSize; | |||
// Set default hard limit of 256MB of memory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Set default hard limit of 256MB of memory. | |
// The default hard limit of the memory size (256MB) as number of pages. |
ca23b2f
to
6b39f2b
Compare
Also use uint32_t for memory size limits.
6b39f2b
to
696a9f2
Compare
Closes #509