Merge changes Iba59fdc3,I812fccf2 into main

* changes:
  libsnapshot: configure threshold size
  libsnapshot: set thread priority
This commit is contained in:
Daniel Zheng 2024-06-12 18:22:44 +00:00 committed by Gerrit Code Review
commit 8d63f0080a
3 changed files with 19 additions and 6 deletions

View file

@ -577,8 +577,10 @@ bool MergeWorker::Run() {
SNAP_LOG(ERROR) << "Merge terminated early...";
return true;
}
auto merge_thread_priority = android::base::GetUintProperty<uint>(
"ro.virtual_ab.merge_thread_priority", ANDROID_PRIORITY_BACKGROUND);
if (!SetThreadPriority(ANDROID_PRIORITY_BACKGROUND)) {
if (!SetThreadPriority(merge_thread_priority)) {
SNAP_PLOG(ERROR) << "Failed to set thread priority";
}

View file

@ -17,8 +17,10 @@
#include <libsnapshot/cow_format.h>
#include <pthread.h>
#include "android-base/properties.h"
#include "read_worker.h"
#include "snapuserd_core.h"
#include "user-space-merge/worker.h"
#include "utility.h"
namespace android {
@ -259,8 +261,10 @@ bool ReadWorker::Run() {
SNAP_LOG(INFO) << "Processing snapshot I/O requests....";
pthread_setname_np(pthread_self(), "ReadWorker");
auto worker_thread_priority = android::base::GetUintProperty<uint>(
"ro.virtual_ab.worker_thread_priority", ANDROID_PRIORITY_NORMAL);
if (!SetThreadPriority(ANDROID_PRIORITY_NORMAL)) {
if (!SetThreadPriority(worker_thread_priority)) {
SNAP_PLOG(ERROR) << "Failed to set thread priority";
}

View file

@ -20,6 +20,7 @@
#include <android-base/scopeguard.h>
#include <android-base/strings.h>
#include "android-base/properties.h"
#include "snapuserd_core.h"
namespace android {
@ -104,7 +105,9 @@ bool UpdateVerify::VerifyBlocks(const std::string& partition_name,
}
loff_t file_offset = offset;
const uint64_t read_sz = kBlockSizeVerify;
auto verify_block_size = android::base::GetUintProperty<uint>("ro.virtual_ab.verify_block_size",
kBlockSizeVerify);
const uint64_t read_sz = verify_block_size;
void* addr;
ssize_t page_size = getpagesize();
@ -130,7 +133,7 @@ bool UpdateVerify::VerifyBlocks(const std::string& partition_name,
}
bytes_read += to_read;
file_offset += (skip_blocks * kBlockSizeVerify);
file_offset += (skip_blocks * verify_block_size);
if (file_offset >= dev_sz) {
break;
}
@ -184,7 +187,9 @@ bool UpdateVerify::VerifyPartition(const std::string& partition_name,
* latency.
*/
int num_threads = kMinThreadsToVerify;
if (dev_sz > kThresholdSize) {
auto verify_threshold_size = android::base::GetUintProperty<uint>(
"ro.virtual_ab.verify_threshold_size", kThresholdSize);
if (dev_sz > verify_threshold_size) {
num_threads = kMaxThreadsToVerify;
}
@ -192,11 +197,13 @@ bool UpdateVerify::VerifyPartition(const std::string& partition_name,
off_t start_offset = 0;
const int skip_blocks = num_threads;
auto verify_block_size =
android::base::GetUintProperty("ro.virtual_ab.verify_block_size", kBlockSizeVerify);
while (num_threads) {
threads.emplace_back(std::async(std::launch::async, &UpdateVerify::VerifyBlocks, this,
partition_name, dm_block_device, start_offset, skip_blocks,
dev_sz));
start_offset += kBlockSizeVerify;
start_offset += verify_block_size;
num_threads -= 1;
if (start_offset >= dev_sz) {
break;