You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/03/01 23:28:29 UTC
[1/4] mesos git commit: Modified `NetClsHandleManager` to take a
range of secondary handles.
Repository: mesos
Updated Branches:
refs/heads/master a1a9cd593 -> 4f59f9804
Modified `NetClsHandleManager` to take a range of secondary handles.
The `alloc`, `free` and `reserve` methods of `NetClsHandleManager` can
now work with a specified range of secondary handles instead of assuming
that the entire 64K space of secondary handles is available for use.
Review: https://reviews.apache.org/r/43914/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/10760c3f
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/10760c3f
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/10760c3f
Branch: refs/heads/master
Commit: 10760c3f06eb1b6f0cd4514c115dcd87e42fefcf
Parents: a1a9cd5
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Tue Mar 1 14:26:31 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Mar 1 14:27:38 2016 -0800
----------------------------------------------------------------------
.../mesos/isolators/cgroups/net_cls.cpp | 76 ++++++++++++++------
.../mesos/isolators/cgroups/net_cls.hpp | 17 +++--
2 files changed, 69 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/10760c3f/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
index f05cd55..8f5e841 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
@@ -70,6 +70,21 @@ ostream& operator<<(ostream& stream, const NetClsHandle& obj)
}
+NetClsHandleManager::NetClsHandleManager(
+ const IntervalSet<uint32_t>& _primaries,
+ const IntervalSet<uint32_t>& _secondaries)
+ : primaries(_primaries),
+ secondaries(_secondaries)
+{
+ if (secondaries.empty()) {
+ // Default range [1,0xffff].
+ secondaries +=
+ (Bound<uint32_t>::closed(1),
+ Bound<uint32_t>::closed(0xffff));
+ }
+};
+
+
// For each primary handle, we maintain a bitmap to keep track of
// allocated and free secondary handles. To find a free secondary
// handle we scan the bitmap from the first element till we find a
@@ -105,8 +120,14 @@ Try<NetClsHandle> NetClsHandleManager::alloc(
}
if (!used.contains(primary)) {
- // NOTE: We never use 0 as a secondary handle, so mark it used.
- used[primary].set(0);
+ used[primary].set(); // Set all handles.
+
+ foreach (const Interval<uint32_t>& handles, secondaries) {
+ for (size_t secondary = handles.lower();
+ secondary < handles.upper(); secondary++) {
+ used[primary].reset(secondary);
+ }
+ }
} else if (used[primary].all()) {
return Error(
"No free handles remaining for primary handle " +
@@ -114,11 +135,11 @@ Try<NetClsHandle> NetClsHandleManager::alloc(
}
// At least one secondary handle is free for this primary handle.
- for (size_t count = 1; count < used[primary].size(); count++) {
- if (!used[primary].test(count)) {
- used[primary].set(count);
+ for (size_t secondary = 1; secondary < used[primary].size(); secondary++) {
+ if (!used[primary].test(secondary)) {
+ used[primary].set(secondary);
- return NetClsHandle(primary, count);
+ return NetClsHandle(primary, secondary);
}
}
@@ -134,13 +155,21 @@ Try<Nothing> NetClsHandleManager::reserve(const NetClsHandle& handle)
" not present in primary handle range");
}
- if (handle.secondary == 0) {
- return Error("0 is an invalid secondary handle");
+ if (!secondaries.contains(handle.secondary)) {
+ return Error(
+ "Secondary handle " + hexify(handle.secondary) +
+ " not present in secondary handle range ");
}
if (!used.contains(handle.primary)) {
- // NOTE: We never use 0 as a secondary handle, so mark it used.
- used[handle.primary].set(0);
+ used[handle.primary].set(); // Set all handles.
+
+ foreach (const Interval<uint32_t>& handles, secondaries) {
+ for (size_t secondary = handles.lower();
+ secondary < handles.upper(); secondary++) {
+ used[handle.primary].reset(secondary);
+ }
+ }
}
if (used[handle.primary].test(handle.secondary)) {
@@ -164,8 +193,10 @@ Try<Nothing> NetClsHandleManager::free(const NetClsHandle& handle)
" not present in primary handle range");
}
- if (handle.secondary == 0) {
- return Error("0 is an invalid secondary handle");
+ if (!secondaries.contains(handle.secondary)) {
+ return Error(
+ "Secondary handle " + hexify(handle.secondary) +
+ " not present in secondary handle range ");
}
if (!used.contains(handle.primary)) {
@@ -195,8 +226,10 @@ Try<bool> NetClsHandleManager::isUsed(const NetClsHandle& handle)
" is not within the primary's range");
}
- if (handle.secondary == 0) {
- return Error("Secondary handle is 0");
+ if (!secondaries.contains(handle.secondary)) {
+ return Error(
+ "Secondary handle " + hexify(handle.secondary) +
+ " not present in secondary handle range");
}
if (!used.contains(handle.primary)) {
@@ -240,7 +273,8 @@ Try<Isolator*> CgroupsNetClsIsolatorProcess::create(const Flags& flags)
}
}
- IntervalSet<uint16_t> primaries;
+ IntervalSet<uint32_t> primaries;
+ IntervalSet<uint32_t> secondaries;
if (flags.cgroups_net_cls_primary_handle.isSome()) {
Try<uint16_t> primary = numify<uint16_t>(
@@ -254,15 +288,16 @@ Try<Isolator*> CgroupsNetClsIsolatorProcess::create(const Flags& flags)
}
primaries +=
- (Bound<uint16_t>::closed(primary.get()),
- Bound<uint16_t>::closed(primary.get()));
+ (Bound<uint32_t>::closed(primary.get()),
+ Bound<uint32_t>::closed(primary.get()));
}
process::Owned<MesosIsolatorProcess> process(
new CgroupsNetClsIsolatorProcess(
flags,
hierarchy.get(),
- primaries));
+ primaries,
+ secondaries));
return new MesosIsolator(process);
}
@@ -271,12 +306,13 @@ Try<Isolator*> CgroupsNetClsIsolatorProcess::create(const Flags& flags)
CgroupsNetClsIsolatorProcess::CgroupsNetClsIsolatorProcess(
const Flags& _flags,
const string& _hierarchy,
- const IntervalSet<uint16_t>& primaries)
+ const IntervalSet<uint32_t>& primaries,
+ const IntervalSet<uint32_t>& secondaries)
: flags(_flags),
hierarchy(_hierarchy)
{
if (!primaries.empty()) {
- handleManager = NetClsHandleManager(primaries);
+ handleManager = NetClsHandleManager(primaries, secondaries);
}
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/10760c3f/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
index acd61e6..d7592cf 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
@@ -88,8 +88,9 @@ std::ostream& operator<<(std::ostream& stream, const NetClsHandle& obj);
class NetClsHandleManager
{
public:
- NetClsHandleManager(const IntervalSet<uint16_t>& _primaries)
- : primaries(_primaries) {};
+ NetClsHandleManager(
+ const IntervalSet<uint32_t>& _primaries,
+ const IntervalSet<uint32_t>& _secondaries = IntervalSet<uint32_t>());
~NetClsHandleManager() {};
@@ -107,7 +108,14 @@ private:
// The key to this hashmap is the 16-bit primary handle.
hashmap<uint16_t, std::bitset<0x10000>> used;
- IntervalSet<uint16_t> primaries;
+ // NOTE: Though the primary and secondary handles are 16 bit, we
+ // cannot use an `IntervalSet` specialization of type `uint16_t`
+ // since the intervals are stored in right openf format -- [x,y) --
+ // and setting the type to `uint16_t` would lead to overflow errors.
+ // For e.g., we would not be able to store the range [0xffff,0xffff]
+ // in `IntervalSet<uint16_t>` due to overflow error.
+ IntervalSet<uint32_t> primaries;
+ IntervalSet<uint32_t> secondaries;
};
@@ -170,7 +178,8 @@ private:
CgroupsNetClsIsolatorProcess(
const Flags& _flags,
const std::string& _hierarchy,
- const IntervalSet<uint16_t>& primaries);
+ const IntervalSet<uint32_t>& primaries,
+ const IntervalSet<uint32_t>& secondaries);
process::Future<Nothing> _cleanup(
const ContainerID& containerId);
[4/4] mesos git commit: Modified testcase to test
`--cgroups_net_cls_secondary_handles` flag.
Posted by ji...@apache.org.
Modified testcase to test `--cgroups_net_cls_secondary_handles` flag.
Review: https://reviews.apache.org/r/43916/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4f59f980
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4f59f980
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4f59f980
Branch: refs/heads/master
Commit: 4f59f9804961b16a747471f65660fe4084cee0bc
Parents: db26aef
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Tue Mar 1 14:28:16 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Mar 1 14:28:16 2016 -0800
----------------------------------------------------------------------
src/tests/containerizer/isolator_tests.cpp | 59 ++++++++++++++++++++-----
1 file changed, 47 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4f59f980/src/tests/containerizer/isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/isolator_tests.cpp b/src/tests/containerizer/isolator_tests.cpp
index 7b257de..342037c 100644
--- a/src/tests/containerizer/isolator_tests.cpp
+++ b/src/tests/containerizer/isolator_tests.cpp
@@ -382,9 +382,9 @@ class NetClsHandleManagerTest : public testing::Test {};
// and free secondary handles from a range of primary handles.
TEST_F(NetClsHandleManagerTest, AllocateFreeHandles)
{
- NetClsHandleManager manager(IntervalSet<uint16_t>(
- (Bound<uint16_t>::closed(0x0002),
- Bound<uint16_t>::closed(0x0003))));
+ NetClsHandleManager manager(IntervalSet<uint32_t>(
+ (Bound<uint32_t>::closed(0x0002),
+ Bound<uint32_t>::closed(0x0003))));
Try<NetClsHandle> handle = manager.alloc(0x0003);
ASSERT_SOME(handle);
@@ -401,9 +401,9 @@ TEST_F(NetClsHandleManagerTest, AllocateFreeHandles)
// handles results in an error.
TEST_F(NetClsHandleManagerTest, AllocateInvalidPrimary)
{
- NetClsHandleManager manager(IntervalSet<uint16_t>(
- (Bound<uint16_t>::closed(0x0002),
- Bound<uint16_t>::closed(0x0003))));
+ NetClsHandleManager manager(IntervalSet<uint32_t>(
+ (Bound<uint32_t>::closed(0x0002),
+ Bound<uint32_t>::closed(0x0003))));
ASSERT_ERROR(manager.alloc(0x0001));
}
@@ -413,9 +413,9 @@ TEST_F(NetClsHandleManagerTest, AllocateInvalidPrimary)
// handle so that they won't be allocated out later.
TEST_F(NetClsHandleManagerTest, ReserveHandles)
{
- NetClsHandleManager manager(IntervalSet<uint16_t>(
- (Bound<uint16_t>::closed(0x0002),
- Bound<uint16_t>::closed(0x0003))));
+ NetClsHandleManager manager(IntervalSet<uint32_t>(
+ (Bound<uint32_t>::closed(0x0002),
+ Bound<uint32_t>::closed(0x0003))));
NetClsHandle handle(0x0003, 0xffff);
@@ -423,6 +423,39 @@ TEST_F(NetClsHandleManagerTest, ReserveHandles)
EXPECT_SOME_TRUE(manager.isUsed(handle));
}
+
+
+// Tests that secondary handles are allocated only from a given range,
+// when the range is specified.
+TEST_F(NetClsHandleManagerTest, SecondaryHandleRange)
+{
+ NetClsHandleManager manager(
+ IntervalSet<uint32_t>(
+ (Bound<uint32_t>::closed(0x0002),
+ Bound<uint32_t>::closed(0x0003))),
+ IntervalSet<uint32_t>(
+ (Bound<uint32_t>::closed(0xffff),
+ Bound<uint32_t>::closed(0xffff))));
+
+ Try<NetClsHandle> handle = manager.alloc(0x0003);
+ ASSERT_SOME(handle);
+
+ EXPECT_SOME_TRUE(manager.isUsed(handle.get()));
+
+ // Try allocating another handle. This should fail, since we don't
+ // have any more secondary handles left.
+ EXPECT_ERROR(manager.alloc(0x0003));
+
+ ASSERT_SOME(manager.free(handle.get()));
+
+ ASSERT_SOME(manager.reserve(handle.get()));
+
+ EXPECT_SOME_TRUE(manager.isUsed(handle.get()));
+
+ // Make sure you cannot reserve a secondary handle that is out of
+ // range.
+ EXPECT_ERROR(manager.reserve(NetClsHandle(0x0003, 0x0001)));
+}
#endif // __linux__
@@ -944,6 +977,7 @@ TEST_F(NetClsIsolatorTest, ROOT_CGROUPS_NetClsIsolate)
slave::Flags flags = CreateSlaveFlags();
flags.isolation = "cgroups/net_cls";
flags.cgroups_net_cls_primary_handle = stringify(primary);
+ flags.cgroups_net_cls_secondary_handles = "0xffff,0xffff";
Fetcher fetcher;
@@ -1021,8 +1055,8 @@ TEST_F(NetClsIsolatorTest, ROOT_CGROUPS_NetClsIsolate)
// `--cgroup_net_cls_primary_handle`.
EXPECT_EQ(primary, (classid.get() & 0xffff0000) >> 16);
- // Make sure the secondary handle is non-zero.
- EXPECT_NE(0u, classid.get() & 0xffff);
+ // Make sure the secondary handle is 0xffff.
+ EXPECT_EQ(0xffffu, classid.get() & 0xffff);
}
// Isolator cleanup test: Killing the task should cleanup the cgroup
@@ -1063,6 +1097,7 @@ TEST_F(NetClsIsolatorTest, ROOT_CGROUPS_ContainerStatus)
slave::Flags flags = CreateSlaveFlags();
flags.isolation = "cgroups/net_cls";
flags.cgroups_net_cls_primary_handle = stringify(0x0012);
+ flags.cgroups_net_cls_secondary_handles = "0x0011,0x0012";
Fetcher fetcher;
@@ -1126,7 +1161,7 @@ TEST_F(NetClsIsolatorTest, ROOT_CGROUPS_ContainerStatus)
// Check the primary and the secondary handle.
EXPECT_EQ(0x0012u, classid >> 16);
- EXPECT_NE(0u, classid & 0xffff);
+ EXPECT_EQ(0x0011u, classid & 0xffff);
driver.stop();
driver.join();
[2/4] mesos git commit: Introduced the
`--cgroups_net_cls_secondary_handles` flag in the agent.
Posted by ji...@apache.org.
Introduced the `--cgroups_net_cls_secondary_handles` flag in the agent.
Review: https://reviews.apache.org/r/43915/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c91d2999
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c91d2999
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c91d2999
Branch: refs/heads/master
Commit: c91d29996bafad04ac0b3ceb2d251a88f9b2c5eb
Parents: 10760c3
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Tue Mar 1 14:27:50 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Mar 1 14:27:50 2016 -0800
----------------------------------------------------------------------
.../mesos/isolators/cgroups/net_cls.cpp | 45 ++++++++++++++++++++
src/slave/flags.cpp | 6 +++
src/slave/flags.hpp | 1 +
3 files changed, 52 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/c91d2999/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
index 8f5e841..e886f7e 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
@@ -276,6 +276,7 @@ Try<Isolator*> CgroupsNetClsIsolatorProcess::create(const Flags& flags)
IntervalSet<uint32_t> primaries;
IntervalSet<uint32_t> secondaries;
+ // Primary handle.
if (flags.cgroups_net_cls_primary_handle.isSome()) {
Try<uint16_t> primary = numify<uint16_t>(
flags.cgroups_net_cls_primary_handle.get());
@@ -290,6 +291,50 @@ Try<Isolator*> CgroupsNetClsIsolatorProcess::create(const Flags& flags)
primaries +=
(Bound<uint32_t>::closed(primary.get()),
Bound<uint32_t>::closed(primary.get()));
+
+ // Range of valid secondary handles.
+ if (flags.cgroups_net_cls_secondary_handles.isSome()) {
+ vector<string> range =
+ strings::tokenize(flags.cgroups_net_cls_secondary_handles.get(), ",");
+
+ if (range.size() != 2) {
+ return Error(
+ "Failed to parse the range of secondary handles " +
+ flags.cgroups_net_cls_secondary_handles.get() +
+ " set in flag --cgroups_net_cls_secondary_handles");
+ }
+
+ Try<uint16_t> lower = numify<uint16_t>(range[0]);
+ if (lower.isError()) {
+ return Error(
+ "Failed to parse the lower bound of range of secondary handles" +
+ flags.cgroups_net_cls_secondary_handles.get() +
+ " set in flag --cgroups_net_cls_secondary_handles");
+ }
+
+ if (lower.get() == 0) {
+ return Error("The secondary handle has to be a non-zero value.");
+ }
+
+ Try<uint16_t> upper = numify<uint16_t>(range[1]);
+ if (upper.isError()) {
+ return Error(
+ "Failed to parse the upper bound of range of secondary handles" +
+ flags.cgroups_net_cls_secondary_handles.get() +
+ " set in flag --cgroups_net_cls_secondary_handles");
+ }
+
+ secondaries +=
+ (Bound<uint32_t>::closed(lower.get()),
+ Bound<uint32_t>::closed(upper.get()));
+
+ if (secondaries.empty()) {
+ return Error(
+ "Secondary handle range specified " +
+ flags.cgroups_net_cls_secondary_handles.get() +
+ ", in flag --cgroups_net_cls_secondary_handles, is an empty set");
+ }
+ }
}
process::Owned<MesosIsolatorProcess> process(
http://git-wip-us.apache.org/repos/asf/mesos/blob/c91d2999/src/slave/flags.cpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.cpp b/src/slave/flags.cpp
index b0bf3d5..6e3fd69 100644
--- a/src/slave/flags.cpp
+++ b/src/slave/flags.cpp
@@ -346,6 +346,12 @@ mesos::internal::slave::Flags::Flags()
"A non-zero, 16-bit handle of the form `0xAAAA`. This will be \n"
"used as the primary handle for the net_cls cgroup.");
+ add(&Flags::cgroups_net_cls_secondary_handles,
+ "cgroups_net_cls_secondary_handles",
+ "A range of the form 0xAAAA,0xBBBB, specifying the valid secondary\n"
+ "handles that can be used with the primary handle. This will take\n"
+ "effect only when the `--cgroups_net_cls_primary_handle is set.");
+
add(&Flags::slave_subsystems,
"slave_subsystems",
"List of comma-separated cgroup subsystems to run the slave binary\n"
http://git-wip-us.apache.org/repos/asf/mesos/blob/c91d2999/src/slave/flags.hpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.hpp b/src/slave/flags.hpp
index c079321..feb095d 100644
--- a/src/slave/flags.hpp
+++ b/src/slave/flags.hpp
@@ -88,6 +88,7 @@ public:
bool cgroups_limit_swap;
bool cgroups_cpu_enable_pids_and_tids_count;
Option<std::string> cgroups_net_cls_primary_handle;
+ Option<std::string> cgroups_net_cls_secondary_handles;
Option<std::string> slave_subsystems;
Option<std::string> perf_events;
Duration perf_interval;
[3/4] mesos git commit: Added the flag
--cgroups_net_cls_secondary_handles to documentation.
Posted by ji...@apache.org.
Added the flag --cgroups_net_cls_secondary_handles to documentation.
Review: https://reviews.apache.org/r/44182/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/db26aef9
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/db26aef9
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/db26aef9
Branch: refs/heads/master
Commit: db26aef954753da615ea43d40834c4f06c875484
Parents: c91d299
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Tue Mar 1 14:28:04 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Mar 1 14:28:04 2016 -0800
----------------------------------------------------------------------
docs/configuration.md | 10 ++++++++++
1 file changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/db26aef9/docs/configuration.md
----------------------------------------------------------------------
diff --git a/docs/configuration.md b/docs/configuration.md
index 4ecc461..a56d02b 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -927,6 +927,16 @@ the primary handle for the net_cls cgroup.
</tr>
<tr>
<td>
+ --cgroups_net_cls_secondary_handles
+ </td>
+ <td>
+A range of the form 0xAAAA,0xBBBB, specifying the valid secondary
+handles that can be used with the primary handle. This will take
+effect only when the <code>--cgroups_net_cls_primary_handle</code> is set.
+ </td>
+</tr>
+<tr>
+ <td>
--cgroups_root=VALUE
</td>
<td>