* [LTP] [PATCH] memcg_use_hierarchy_test.sh: skip setting use_hierarchy if not available
@ 2020-09-11 9:21 Chen Hanxiao
2020-09-17 5:21 ` Yang Xu
0 siblings, 1 reply; 6+ messages in thread
From: Chen Hanxiao @ 2020-09-11 9:21 UTC (permalink / raw)
To: ltp
The precondition of this case is that we can disable use_hierarchy.
But some distributions such as CentOS 8 had enabled it in root
cgroup and hard to disabled.
As [1] describe:
NOTE1: Enabling/disabling will fail if either the cgroup already has other
cgroups created below it, or if the parent cgroup has use_hierarchy
enabled.
We should check the precondition before testing.
[1] https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
Signed-off-by: Chen Hanxiao <chenhx.fnst@cn.fujitsu.com>
---
.../controllers/memcg/functional/memcg_lib.sh | 25 +++++++++++++++----
.../functional/memcg_use_hierarchy_test.sh | 12 +++++++--
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
index 22ef4f5e2..4f99c6f59 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
@@ -491,6 +491,10 @@ cleanup_test()
orig_memory_use_hierarchy=""
fi
+ if [ -n "$root_memory_use_hierarchy" ];then
+ root_memory_use_hierarchy=""
+ fi
+
killall -9 memcg_process 2>/dev/null
wait
@@ -514,16 +518,27 @@ setup_test()
# while there are distributions (RHEL7U0Beta for example) that sets
# it to 1.
orig_memory_use_hierarchy=$(cat /dev/memcg/memory.use_hierarchy)
+ MEMCGROUP_PATH="/sys/fs/cgroup/memory"
+ if [ -e "$MEMCGROUP_PATH" ];then
+ root_memory_use_hierarchy=$(cat "$MEMCGROUP_PATH/memory.use_hierarchy")
+ fi
+
if [ -z "$orig_memory_use_hierarchy" ];then
tst_resm TINFO "cat /dev/memcg/memory.use_hierarchy failed"
elif [ "$orig_memory_use_hierarchy" = "0" ];then
orig_memory_use_hierarchy=""
else
- echo 0 > /dev/memcg/memory.use_hierarchy
- if [ $? -ne 0 ];then
- tst_resm TINFO "set /dev/memcg/memory.use_hierarchy" \
- "to 0 failed"
- fi
+ if [ "$root_memory_use_hierarchy" = "1" ]; then
+ tst_resm TINFO "root cgroup has use_hierarchy enabled, " \
+ "can't set /dev/memcg/memory.use_hierarchy to 0"
+ export root_memory_use_hierarchy
+ else
+ echo 0 > /dev/memcg/memory.use_hierarchy
+ if [ $? -ne 0 ];then
+ tst_resm TINFO "set /dev/memcg/memory.use_hierarchy" \
+ "to 0 failed"
+ fi
+ fi
fi
ROD mkdir "/dev/memcg/$TEST_ID"
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
index 4cf6b9fc2..1439b6352 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
@@ -34,7 +34,9 @@ TST_TOTAL=3
# test if one of the ancestors goes over its limit, the proces will be killed
testcase_1()
{
- echo 1 > memory.use_hierarchy
+ if [ "$root_memory_use_hierarchy" != "1" ]; then
+ echo 1 > memory.use_hierarchy
+ fi
echo $PAGESIZE > memory.limit_in_bytes
mkdir subgroup
@@ -48,6 +50,10 @@ testcase_1()
# test Enabling will fail if the cgroup already has other cgroups
testcase_2()
{
+ if [ "$root_memory_use_hierarchy" = "1" ]; then
+ tst_resm TCONF "root cgroup has use_hierarchy enabled, skip"
+ return
+ fi
mkdir subgroup
EXPECT_FAIL echo 1 \> memory.use_hierarchy
@@ -57,7 +63,9 @@ testcase_2()
# test disabling will fail if the parent cgroup has enabled hierarchy.
testcase_3()
{
- echo 1 > memory.use_hierarchy
+ if [ "$root_memory_use_hierarchy" != "1" ]; then
+ echo 1 > memory.use_hierarchy
+ fi
mkdir subgroup
EXPECT_FAIL echo 0 \> subgroup/memory.use_hierarchy
--
2.26.0.windows.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH] memcg_use_hierarchy_test.sh: skip setting use_hierarchy if not available
2020-09-11 9:21 [LTP] [PATCH] memcg_use_hierarchy_test.sh: skip setting use_hierarchy if not available Chen Hanxiao
@ 2020-09-17 5:21 ` Yang Xu
2020-09-21 10:53 ` [LTP] 答复: " Chen, Hanxiao
0 siblings, 1 reply; 6+ messages in thread
From: Yang Xu @ 2020-09-17 5:21 UTC (permalink / raw)
To: ltp
Hi hanxiao
> The precondition of this case is that we can disable use_hierarchy.
> But some distributions such as CentOS 8 had enabled it in root
> cgroup and hard to disabled.
>
> As [1] describe:
> NOTE1: Enabling/disabling will fail if either the cgroup already has other
> cgroups created below it, or if the parent cgroup has use_hierarchy
> enabled.
>
> We should check the precondition before testing.
>
> [1] https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
>
> Signed-off-by: Chen Hanxiao <chenhx.fnst@cn.fujitsu.com>
> ---
> .../controllers/memcg/functional/memcg_lib.sh | 25 +++++++++++++++----
> .../functional/memcg_use_hierarchy_test.sh | 12 +++++++--
> 2 files changed, 30 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
> index 22ef4f5e2..4f99c6f59 100755
> --- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
> +++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
> @@ -491,6 +491,10 @@ cleanup_test()
> orig_memory_use_hierarchy=""
> fi
>
> + if [ -n "$root_memory_use_hierarchy" ];then
> + root_memory_use_hierarchy=""
> + fi
> +
> killall -9 memcg_process 2>/dev/null
> wait
>
> @@ -514,16 +518,27 @@ setup_test()
> # while there are distributions (RHEL7U0Beta for example) that sets
> # it to 1.
> orig_memory_use_hierarchy=$(cat /dev/memcg/memory.use_hierarchy)
> + MEMCGROUP_PATH="/sys/fs/cgroup/memory"
> + if [ -e "$MEMCGROUP_PATH" ];then
> + root_memory_use_hierarchy=$(cat "$MEMCGROUP_PATH/memory.use_hierarchy")
> + fi
> +
> if [ -z "$orig_memory_use_hierarchy" ];then
> tst_resm TINFO "cat /dev/memcg/memory.use_hierarchy failed"
> elif [ "$orig_memory_use_hierarchy" = "0" ];then
> orig_memory_use_hierarchy=""
> else
> - echo 0 > /dev/memcg/memory.use_hierarchy
> - if [ $? -ne 0 ];then
> - tst_resm TINFO "set /dev/memcg/memory.use_hierarchy" \
> - "to 0 failed"
> - fi
> + if [ "$root_memory_use_hierarchy" = "1" ]; then
> + tst_resm TINFO "root cgroup has use_hierarchy enabled, " \
> + "can't set /dev/memcg/memory.use_hierarchy to 0"
> + export root_memory_use_hierarchy
> + else
> + echo 0 > /dev/memcg/memory.use_hierarchy
> + if [ $? -ne 0 ];then
> + tst_resm TINFO "set /dev/memcg/memory.use_hierarchy" \
> + "to 0 failed"
> + fi
> + fi
I test this patch on centos7 and testcase2 skips. On centos7(without
installing docker), /sys/fs/cgroup/memory/memory.use_hierarchy value is
equal to 1 and I still can disable value for
/dev/memcg/memory.use_hierarchy.
So why not directly use /dev/memcg/memory.use_hierarchy value to judge
in testcase after setting 0.
Best Regards
Yang Xu
> fi
>
> ROD mkdir "/dev/memcg/$TEST_ID"
> diff --git a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
> index 4cf6b9fc2..1439b6352 100755
> --- a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
> +++ b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
> @@ -34,7 +34,9 @@ TST_TOTAL=3
> # test if one of the ancestors goes over its limit, the proces will be killed
> testcase_1()
> {
> - echo 1 > memory.use_hierarchy
> + if [ "$root_memory_use_hierarchy" != "1" ]; then
> + echo 1 > memory.use_hierarchy
> + fi
> echo $PAGESIZE > memory.limit_in_bytes
>
> mkdir subgroup
> @@ -48,6 +50,10 @@ testcase_1()
> # test Enabling will fail if the cgroup already has other cgroups
> testcase_2()
> {
> + if [ "$root_memory_use_hierarchy" = "1" ]; then
> + tst_resm TCONF "root cgroup has use_hierarchy enabled, skip"
> + return
> + fi
> mkdir subgroup
> EXPECT_FAIL echo 1 \> memory.use_hierarchy
>
> @@ -57,7 +63,9 @@ testcase_2()
> # test disabling will fail if the parent cgroup has enabled hierarchy.
> testcase_3()
> {
> - echo 1 > memory.use_hierarchy
> + if [ "$root_memory_use_hierarchy" != "1" ]; then
> + echo 1 > memory.use_hierarchy
> + fi
> mkdir subgroup
> EXPECT_FAIL echo 0 \> subgroup/memory.use_hierarchy
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] 答复: [PATCH] memcg_use_hierarchy_test.sh: skip setting use_hierarchy if not available
2020-09-17 5:21 ` Yang Xu
@ 2020-09-21 10:53 ` Chen, Hanxiao
2020-10-13 3:19 ` Yang Xu
0 siblings, 1 reply; 6+ messages in thread
From: Chen, Hanxiao @ 2020-09-21 10:53 UTC (permalink / raw)
To: ltp
Hi, Yang
> -----????-----
> ??: Re: [LTP] [PATCH] memcg_use_hierarchy_test.sh: skip setting
> use_hierarchy if not available
>
> Hi hanxiao
>
>
> > The precondition of this case is that we can disable use_hierarchy.
> > But some distributions such as CentOS 8 had enabled it in root cgroup
> > and hard to disabled.
[snip]
> /dev/memcg/memory.use_hierarchy" \
> > + "to 0 failed"
> > + fi
> > + fi
> I test this patch on centos7 and testcase2 skips. On centos7(without installing
> docker), /sys/fs/cgroup/memory/memory.use_hierarchy value is equal to 1 and I
> still can disable value for /dev/memcg/memory.use_hierarchy.
>
The behavior above looks conflicting with https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt.
> So why not directly use /dev/memcg/memory.use_hierarchy value to judge in
> testcase after setting 0.
In setup_test from memcg_lib.sh, we actually did:
mount -t cgroup -omemory memcg /dev/memcg
Then kernel will find a suitable cgroup root for us in cgroup1_mount.
In this case, /sys/fs/cgroup/memory/ would be the good choice.
So it's equivalent to read memory.use_hierarchy from either side.
Regards,
- Hanxiao
>
> Best Regards
> Yang Xu
> > fi
> >
> > ROD mkdir "/dev/memcg/$TEST_ID"
> > diff --git
> > a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_te
> > st.sh
> > b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_te
> > st.sh
> > index 4cf6b9fc2..1439b6352 100755
> > ---
> > a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_te
> > st.sh
> > +++ b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarch
> > +++ y_test.sh
> > @@ -34,7 +34,9 @@ TST_TOTAL=3
> > # test if one of the ancestors goes over its limit, the proces will be killed
> > testcase_1()
> > {
> > - echo 1 > memory.use_hierarchy
> > + if [ "$root_memory_use_hierarchy" != "1" ]; then
> > + echo 1 > memory.use_hierarchy
> > + fi
> > echo $PAGESIZE > memory.limit_in_bytes
> >
> > mkdir subgroup
> > @@ -48,6 +50,10 @@ testcase_1()
> > # test Enabling will fail if the cgroup already has other cgroups
> > testcase_2()
> > {
> > + if [ "$root_memory_use_hierarchy" = "1" ]; then
> > + tst_resm TCONF "root cgroup has use_hierarchy enabled,
> skip"
> > + return
> > + fi
> > mkdir subgroup
> > EXPECT_FAIL echo 1 \> memory.use_hierarchy
> >
> > @@ -57,7 +63,9 @@ testcase_2()
> > # test disabling will fail if the parent cgroup has enabled hierarchy.
> > testcase_3()
> > {
> > - echo 1 > memory.use_hierarchy
> > + if [ "$root_memory_use_hierarchy" != "1" ]; then
> > + echo 1 > memory.use_hierarchy
> > + fi
> > mkdir subgroup
> > EXPECT_FAIL echo 0 \> subgroup/memory.use_hierarchy
> >
> >
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] 答复: [PATCH] memcg_use_hierarchy_test.sh: skip setting use_hierarchy if not available
2020-09-21 10:53 ` [LTP] 答复: " Chen, Hanxiao
@ 2020-10-13 3:19 ` Yang Xu
2020-10-14 6:27 ` Li Wang
0 siblings, 1 reply; 6+ messages in thread
From: Yang Xu @ 2020-10-13 3:19 UTC (permalink / raw)
To: ltp
Hi Hanxiao
> Hi, Yang
>
>> -----????-----
>> ??: Re: [LTP] [PATCH] memcg_use_hierarchy_test.sh: skip setting
>> use_hierarchy if not available
>>
>> Hi hanxiao
>>
>>
>>> The precondition of this case is that we can disable use_hierarchy.
>>> But some distributions such as CentOS 8 had enabled it in root cgroup
>>> and hard to disabled.
> [snip]
>> /dev/memcg/memory.use_hierarchy" \
>>> + "to 0 failed"
>>> + fi
>>> + fi
>> I test this patch on centos7 and testcase2 skips. On centos7(without installing
>> docker), /sys/fs/cgroup/memory/memory.use_hierarchy value is equal to 1 and I
>> still can disable value for /dev/memcg/memory.use_hierarchy.
>>
> The behavior above looks conflicting with https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt.
Yes. Centos7 behavior is different from the documentation.
>> So why not directly use /dev/memcg/memory.use_hierarchy value to judge in
>> testcase after setting 0.
> In setup_test from memcg_lib.sh, we actually did:
> mount -t cgroup -omemory memcg /dev/memcg
> Then kernel will find a suitable cgroup root for us in cgroup1_mount.
>
> In this case, /sys/fs/cgroup/memory/ would be the good choice.
> So it's equivalent to read memory.use_hierarchy from either side.
I understand. Only a minor suggestion, please use tabs instead of spaces
at the beginning of the line.
This patch looks good to me,
Acked-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
@Li, I think this patch is ok, Do you have some comment about it?
Best Regards
Yang Xu
> Regards,
> - Hanxiao
>> Best Regards
>> Yang Xu
>>> fi
>>>
>>> ROD mkdir "/dev/memcg/$TEST_ID"
>>> diff --git
>>> a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_te
>>> st.sh
>>> b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_te
>>> st.sh
>>> index 4cf6b9fc2..1439b6352 100755
>>> ---
>>> a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_te
>>> st.sh
>>> +++ b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarch
>>> +++ y_test.sh
>>> @@ -34,7 +34,9 @@ TST_TOTAL=3
>>> # test if one of the ancestors goes over its limit, the proces will be killed
>>> testcase_1()
>>> {
>>> - echo 1 > memory.use_hierarchy
>>> + if [ "$root_memory_use_hierarchy" != "1" ]; then
>>> + echo 1 > memory.use_hierarchy
>>> + fi
>>> echo $PAGESIZE > memory.limit_in_bytes
>>>
>>> mkdir subgroup
>>> @@ -48,6 +50,10 @@ testcase_1()
>>> # test Enabling will fail if the cgroup already has other cgroups
>>> testcase_2()
>>> {
>>> + if [ "$root_memory_use_hierarchy" = "1" ]; then
>>> + tst_resm TCONF "root cgroup has use_hierarchy enabled,
>> skip"
>>> + return
>>> + fi
>>> mkdir subgroup
>>> EXPECT_FAIL echo 1 \> memory.use_hierarchy
>>>
>>> @@ -57,7 +63,9 @@ testcase_2()
>>> # test disabling will fail if the parent cgroup has enabled hierarchy.
>>> testcase_3()
>>> {
>>> - echo 1 > memory.use_hierarchy
>>> + if [ "$root_memory_use_hierarchy" != "1" ]; then
>>> + echo 1 > memory.use_hierarchy
>>> + fi
>>> mkdir subgroup
>>> EXPECT_FAIL echo 0 \> subgroup/memory.use_hierarchy
>>>
>>>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] 答复: [PATCH] memcg_use_hierarchy_test.sh: skip setting use_hierarchy if not available
2020-10-13 3:19 ` Yang Xu
@ 2020-10-14 6:27 ` Li Wang
0 siblings, 0 replies; 6+ messages in thread
From: Li Wang @ 2020-10-14 6:27 UTC (permalink / raw)
To: ltp
On Tue, Oct 13, 2020 at 11:19 AM Yang Xu <xuyang2018.jy@cn.fujitsu.com>
wrote:
> Hi Hanxiao
>
> > Hi, Yang
> >
> >> -----??????-----
> >> ???: Re: [LTP] [PATCH] memcg_use_hierarchy_test.sh: skip setting
> >> use_hierarchy if not available
> >>
> >> Hi hanxiao
> >>
> >>
> >>> The precondition of this case is that we can disable use_hierarchy.
> >>> But some distributions such as CentOS 8 had enabled it in root cgroup
> >>> and hard to disabled.
> > [snip]
> >> /dev/memcg/memory.use_hierarchy" \
> >>> + "to 0 failed"
> >>> + fi
> >>> + fi
> >> I test this patch on centos7 and testcase2 skips. On centos7(without
> installing
> >> docker), /sys/fs/cgroup/memory/memory.use_hierarchy value is equal to 1
> and I
> >> still can disable value for /dev/memcg/memory.use_hierarchy.
> >>
> > The behavior above looks conflicting with
> https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt.
> Yes. Centos7 behavior is different from the documentation.
> >> So why not directly use /dev/memcg/memory.use_hierarchy value to judge
> in
> >> testcase after setting 0.
> > In setup_test from memcg_lib.sh, we actually did:
> > mount -t cgroup -omemory memcg /dev/memcg
> > Then kernel will find a suitable cgroup root for us in cgroup1_mount.
> >
> > In this case, /sys/fs/cgroup/memory/ would be the good choice.
> > So it's equivalent to read memory.use_hierarchy from either side.
> I understand. Only a minor suggestion, please use tabs instead of spaces
> at the beginning of the line.
>
>
> This patch looks good to me,
> Acked-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
>
> @Li, I think this patch is ok, Do you have some comment about it?
>
I'm ok to go with memory.use_hierarchy checking in the preconditioning
phase.
But how can you assert the default memory cgroup is mount at path:
"/sys/fs/cgroup/memory", is there any possibility the default path mount at
other places(for different distribution)?
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20201014/932b3f8b/attachment.htm>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH] memcg_use_hierarchy_test.sh: skip setting use_hierarchy if not available
2020-10-14 7:31 Chen, Hanxiao
@ 2020-10-15 6:45 ` Li Wang
0 siblings, 0 replies; 6+ messages in thread
From: Li Wang @ 2020-10-15 6:45 UTC (permalink / raw)
To: ltp
Chen, Hanxiao <chenhx.fnst@cn.fujitsu.com> wrote:
*...*
>
> >@Li, I think this patch is ok, Do you have some comment about it?
>
> >
>
> >I'm ok to go with memory.use_hierarchy checking in the preconditioning
> phase.
>
> >
>
> >But how can you assert the default memory cgroup is mount at path:
> "/sys/fs/cgroup/memory", is there any possibility the default path mount at
> other places(for different distribution)?
>
>
>
>
> https://github.com/torvalds/linux/blob/b5fc7a89e58bcc059a3d5e4db79c481fb437de59/kernel/cgroup/cgroup.c#L5768
>
>
>
> WARN_ON(sysfs_create_mount_point(fs_kobj, "cgroup"));
>
>
>
> So the default mount place should be /sys/fs/cgroup if distributions
>
> did not modify these lines.
>
>
>
> As the discussion above,
>
> mount -t cgroup -omemory memcg /dev/memcg
>
> kernel will find a suitable cgroup root for us.
>
>
>
> How about reading /dev/memcg/memory.use_hierarchy as Yang recommended
> instead?
>
Sure.
But also, shouldn't we check if the '/dev/memcg' has sub-directory
before changing the memory.use_hiearchy in memcg_lib.sh?
As you noted in the description, enabling/disabling will fail if either
the cgroup already has other cgroups created below it.
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20201015/654192f6/attachment-0001.htm>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-10-15 6:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11 9:21 [LTP] [PATCH] memcg_use_hierarchy_test.sh: skip setting use_hierarchy if not available Chen Hanxiao
2020-09-17 5:21 ` Yang Xu
2020-09-21 10:53 ` [LTP] 答复: " Chen, Hanxiao
2020-10-13 3:19 ` Yang Xu
2020-10-14 6:27 ` Li Wang
2020-10-14 7:31 Chen, Hanxiao
2020-10-15 6:45 ` [LTP] " Li Wang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.