Skip to content

Commit edd70ca

Browse files
authored
Improve cgroup hierarchy traversal in managed version (#133692)
In a backporting PR, @jkotas has pointed out that the change being backported has added unnecessary allocation and some complexity. This change fixes it.
1 parent 3c4631e commit edd70ca

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ internal static bool TryGetMemoryLimitV2(string? currentCGroupMemoryPath, string
143143
minLimit = currentLevelLimit;
144144
}
145145
}
146-
if (string.Equals(currentCGroupMemoryPath, cgroupMemoryHierarchyMountPath, StringComparison.Ordinal))
146+
if (currentCGroupMemoryPath == cgroupMemoryHierarchyMountPath)
147147
{
148148
break;
149149
}
@@ -159,12 +159,14 @@ internal static bool TryGetMemoryLimitV2(string? currentCGroupMemoryPath, string
159159

160160
private static bool IsPathAtOrBelowMount(string path, string mount)
161161
{
162-
if (string.Equals(path, mount, StringComparison.Ordinal))
162+
if (!path.StartsWith(mount, StringComparison.Ordinal))
163163
{
164-
return true;
164+
return false;
165165
}
166166

167-
return mount == "/" || path.StartsWith(mount + "/", StringComparison.Ordinal);
167+
return path.Length == mount.Length ||
168+
mount == "/" ||
169+
path[mount.Length] == '/';
168170
}
169171

170172
/// <summary>Tries to parse a memory limit from the specified file.</summary>

0 commit comments

Comments
 (0)