aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Balsini <balsini@google.com>2023-10-13 20:44:08 +0100
committerAlessio Balsini <balsini@google.com>2023-10-16 10:30:23 +0100
commitb762867192c40b38d3a2f761202cb5eb3170262b (patch)
treee4cf7c7efb0c3a81ccc1035a743a0fc47e91a82d
parent9192aeb5aeeeb18dc4a5bdbfeb31cc9065cefa0f (diff)
downloaddittosuite-b762867192c40b38d3a2f761202cb5eb3170262b.tar.gz
Introduce memory allocation instruction
To bring the system into some memory pressure condition, introduce a new function that allocates memory and loops over the whole memory region to ensure the pages are loaded. Test: manually tested with Zim on Perfetto Bug: 305023314 Change-Id: Idbd189a2d9b59a28362c4d04a8cafdceaffc8648 Signed-off-by: Alessio Balsini <balsini@google.com>
-rw-r--r--example/memory.ditto37
-rw-r--r--include/ditto/memory_allocation.h35
-rw-r--r--schema/benchmark.proto5
-rw-r--r--src/instruction_factory.cpp6
-rw-r--r--src/memory_allocation.cpp39
5 files changed, 122 insertions, 0 deletions
diff --git a/example/memory.ditto b/example/memory.ditto
new file mode 100644
index 0000000..797178f
--- /dev/null
+++ b/example/memory.ditto
@@ -0,0 +1,37 @@
+main: {
+ multithreading: {
+ fork: true,
+ threads: [
+ {
+ name: "Memory"
+ instruction: {
+ mem_alloc: {
+ size: 5000000000
+ }
+ }
+ },
+ {
+ name: "Util"
+ instruction: {
+ cpu_work: {
+ utilization: 0.3,
+ }
+ repeat: 300,
+ period_us: 100000
+ },
+ spawn: 2
+ },
+ {
+ name: "MemGrow"
+ instruction: {
+ mem_alloc: {
+ size: 5000000
+ }
+ repeat: 300,
+ period_us: 100000
+ }
+ }
+ ]
+ }
+}
+global: {}
diff --git a/include/ditto/memory_allocation.h b/include/ditto/memory_allocation.h
new file mode 100644
index 0000000..af32220
--- /dev/null
+++ b/include/ditto/memory_allocation.h
@@ -0,0 +1,35 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma once
+
+#include <ditto/instruction.h>
+
+namespace dittosuite {
+
+class MemoryAllocation : public Instruction {
+ public:
+ inline static const std::string kName = "memory_allocation";
+
+ explicit MemoryAllocation(const Params& params, const uint64_t size);
+ ~MemoryAllocation();
+
+ private:
+ size_t size_;
+ char* allocated_memory_;
+
+ void RunSingle();
+};
+
+} // namespace dittosuite
diff --git a/schema/benchmark.proto b/schema/benchmark.proto
index ef0052e..197c1d7 100644
--- a/schema/benchmark.proto
+++ b/schema/benchmark.proto
@@ -19,6 +19,10 @@ enum AccessMode {
READ_WRITE = 3;
}
+message MemoryAllocate {
+ optional uint64 size = 1;
+}
+
message CpuWork {
oneof type {
uint64 cycles = 1;
@@ -176,6 +180,7 @@ message Instruction {
BinderRequest binder_request = 13;
BinderService binder_service = 14;
CpuWork cpu_work = 16;
+ MemoryAllocate mem_alloc = 17;
};
optional uint64 period_us = 15 [default = 0];
}
diff --git a/src/instruction_factory.cpp b/src/instruction_factory.cpp
index 6d9cead..cef9c1b 100644
--- a/src/instruction_factory.cpp
+++ b/src/instruction_factory.cpp
@@ -27,6 +27,7 @@
#include <ditto/instruction_set.h>
#include <ditto/invalidate_cache.h>
#include <ditto/logger.h>
+#include <ditto/memory_allocation.h>
#include <ditto/multiprocessing.h>
#include <ditto/multithreading.h>
#include <ditto/multithreading_utils.h>
@@ -287,6 +288,11 @@ std::unique_ptr<Instruction> InstructionFactory::CreateFromProtoInstruction(
}
}
}
+ case InstructionType::kMemAlloc: {
+ const auto& options = proto_instruction.mem_alloc();
+ return std::make_unique<MemoryAllocation>(instruction_params, options.size());
+ break;
+ }
case InstructionType::INSTRUCTION_ONEOF_NOT_SET: {
LOGF("Instruction was not set in .ditto file");
}
diff --git a/src/memory_allocation.cpp b/src/memory_allocation.cpp
new file mode 100644
index 0000000..d54c64a
--- /dev/null
+++ b/src/memory_allocation.cpp
@@ -0,0 +1,39 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <ditto/memory_allocation.h>
+
+#include <ditto/logger.h>
+
+#include <unistd.h>
+
+namespace dittosuite {
+
+MemoryAllocation::MemoryAllocation(const Params& params, const uint64_t size)
+ : Instruction(kName, params), size_(size), allocated_memory_(nullptr) {}
+
+MemoryAllocation::~MemoryAllocation() {
+ free(allocated_memory_);
+}
+
+void MemoryAllocation::RunSingle() {
+ int page_size = getpagesize();
+ allocated_memory_ = static_cast<char*>(malloc(size_));
+
+ for (size_t i = 0; i < size_; i += page_size) {
+ allocated_memory_[i] = 1;
+ }
+}
+
+} // namespace dittosuite