diff --git a/fs_mgr/libsnapshot/partition_cow_creator.cpp b/fs_mgr/libsnapshot/partition_cow_creator.cpp index 7057223bc..5bc7e65f7 100644 --- a/fs_mgr/libsnapshot/partition_cow_creator.cpp +++ b/fs_mgr/libsnapshot/partition_cow_creator.cpp @@ -131,15 +131,28 @@ bool OptimizeSourceCopyOperation(const InstallOperation& operation, InstallOpera return is_optimized; } -void WriteExtent(DmSnapCowSizeCalculator* sc, const chromeos_update_engine::Extent& de, +bool WriteExtent(DmSnapCowSizeCalculator* sc, const chromeos_update_engine::Extent& de, unsigned int sectors_per_block) { const auto block_boundary = de.start_block() + de.num_blocks(); for (auto b = de.start_block(); b < block_boundary; ++b) { for (unsigned int s = 0; s < sectors_per_block; ++s) { - const auto sector_id = b * sectors_per_block + s; + // sector_id = b * sectors_per_block + s; + uint64_t block_start_sector_id; + if (__builtin_mul_overflow(b, sectors_per_block, &block_start_sector_id)) { + LOG(ERROR) << "Integer overflow when calculating sector id (" << b << " * " + << sectors_per_block << ")"; + return false; + } + uint64_t sector_id; + if (__builtin_add_overflow(block_start_sector_id, s, §or_id)) { + LOG(ERROR) << "Integer overflow when calculating sector id (" + << block_start_sector_id << " + " << s << ")"; + return false; + } sc->WriteSector(sector_id); } } + return true; } std::optional PartitionCowCreator::GetCowSize() { @@ -167,7 +180,7 @@ std::optional PartitionCowCreator::GetCowSize() { // Allocate space for extra extents (if any). These extents are those that can be // used for error corrections or to store verity hash trees. for (const auto& de : extra_extents) { - WriteExtent(&sc, de, sectors_per_block); + if (!WriteExtent(&sc, de, sectors_per_block)) return std::nullopt; } if (update == nullptr) return sc.cow_size_bytes(); @@ -182,7 +195,7 @@ std::optional PartitionCowCreator::GetCowSize() { } for (const auto& de : written_op->dst_extents()) { - WriteExtent(&sc, de, sectors_per_block); + if (!WriteExtent(&sc, de, sectors_per_block)) return std::nullopt; } } diff --git a/libprocessgroup/profiles/cgroups.json b/libprocessgroup/profiles/cgroups.json index d013ec858..3e4393df2 100644 --- a/libprocessgroup/profiles/cgroups.json +++ b/libprocessgroup/profiles/cgroups.json @@ -1,5 +1,12 @@ { "Cgroups": [ + { + "Controller": "blkio", + "Path": "/dev/blkio", + "Mode": "0775", + "UID": "system", + "GID": "system" + }, { "Controller": "cpu", "Path": "/dev/cpuctl", @@ -32,12 +39,6 @@ { "Controller": "freezer", "Path": "." - }, - { - "Controller": "io", - "Path": ".", - "NeedsActivation": true, - "Optional": true } ] } diff --git a/libprocessgroup/profiles/task_profiles.json b/libprocessgroup/profiles/task_profiles.json index 12f7b4406..1fc66ba10 100644 --- a/libprocessgroup/profiles/task_profiles.json +++ b/libprocessgroup/profiles/task_profiles.json @@ -76,24 +76,6 @@ "Name": "FreezerState", "Controller": "freezer", "File": "cgroup.freeze" - }, - { - "Name": "BfqWeight", - "Controller": "io", - "File": "blkio.bfq.weight", - "FileV2": "io.bfq.weight" - }, - { - "Name": "CfqGroupIdle", - "Controller": "io", - "File": "blkio.group_idle", - "FileV2": "io.group_idle" - }, - { - "Name": "CfqWeight", - "Controller": "io", - "File": "blkio.weight", - "FileV2": "io.weight" } ], @@ -457,30 +439,11 @@ "Name": "LowIoPriority", "Actions": [ { - "Name": "SetAttribute", + "Name": "JoinCgroup", "Params": { - "Name": "BfqWeight", - "Value": "10", - "Optional": "true" - } - }, - { - "Name": "SetAttribute", - "Params": - { - "Name": "CfqGroupIdle", - "Value": "0", - "Optional": "true" - } - }, - { - "Name": "SetAttribute", - "Params": - { - "Name": "CfqWeight", - "Value": "200", - "Optional": "true" + "Controller": "blkio", + "Path": "background" } } ] @@ -489,30 +452,11 @@ "Name": "NormalIoPriority", "Actions": [ { - "Name": "SetAttribute", + "Name": "JoinCgroup", "Params": { - "Name": "BfqWeight", - "Value": "100", - "Optional": "true" - } - }, - { - "Name": "SetAttribute", - "Params": - { - "Name": "CfqGroupIdle", - "Value": "0", - "Optional": "true" - } - }, - { - "Name": "SetAttribute", - "Params": - { - "Name": "CfqWeight", - "Value": "1000", - "Optional": "true" + "Controller": "blkio", + "Path": "" } } ] @@ -521,30 +465,11 @@ "Name": "HighIoPriority", "Actions": [ { - "Name": "SetAttribute", + "Name": "JoinCgroup", "Params": { - "Name": "BfqWeight", - "Value": "100", - "Optional": "true" - } - }, - { - "Name": "SetAttribute", - "Params": - { - "Name": "CfqGroupIdle", - "Value": "0", - "Optional": "true" - } - }, - { - "Name": "SetAttribute", - "Params": - { - "Name": "CfqWeight", - "Value": "1000", - "Optional": "true" + "Controller": "blkio", + "Path": "" } } ] @@ -553,30 +478,11 @@ "Name": "MaxIoPriority", "Actions": [ { - "Name": "SetAttribute", + "Name": "JoinCgroup", "Params": { - "Name": "BfqWeight", - "Value": "100", - "Optional": "true" - } - }, - { - "Name": "SetAttribute", - "Params": - { - "Name": "CfqGroupIdle", - "Value": "0", - "Optional": "true" - } - }, - { - "Name": "SetAttribute", - "Params": - { - "Name": "CfqWeight", - "Value": "1000", - "Optional": "true" + "Controller": "blkio", + "Path": "" } } ] diff --git a/rootdir/init.rc b/rootdir/init.rc index fb6473666..317f80908 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -219,6 +219,26 @@ on init write /dev/stune/nnapi-hal/schedtune.boost 1 write /dev/stune/nnapi-hal/schedtune.prefer_idle 1 + # Create blkio group and apply initial settings. + # This feature needs kernel to support it, and the + # device's init.rc must actually set the correct values. + mkdir /dev/blkio/background + chown system system /dev/blkio + chown system system /dev/blkio/background + chown system system /dev/blkio/tasks + chown system system /dev/blkio/background/tasks + chown system system /dev/blkio/cgroup.procs + chown system system /dev/blkio/background/cgroup.procs + chmod 0664 /dev/blkio/tasks + chmod 0664 /dev/blkio/background/tasks + chmod 0664 /dev/blkio/cgroup.procs + chmod 0664 /dev/blkio/background/cgroup.procs + write /dev/blkio/blkio.weight 1000 + write /dev/blkio/background/blkio.weight 200 + write /dev/blkio/background/blkio.bfq.weight 10 + write /dev/blkio/blkio.group_idle 0 + write /dev/blkio/background/blkio.group_idle 0 + restorecon_recursive /mnt mount configfs none /config nodev noexec nosuid