Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
e7831129
Commit
e7831129
authored
May 11, 2015
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #486 from dikei/master
Sort the cgroup memory settings before applying.
parents
54c23a6a
365d180a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
4 deletions
+69
-4
cgfs.c
src/lxc/cgfs.c
+12
-2
cgmanager.c
src/lxc/cgmanager.c
+12
-2
conf.c
src/lxc/conf.c
+44
-0
conf.h
src/lxc/conf.h
+1
-0
No files found.
src/lxc/cgfs.c
View file @
e7831129
...
...
@@ -1886,14 +1886,19 @@ static int do_cgroup_set(const char *cgroup_path, const char *sub_filename,
static
int
do_setup_cgroup_limits
(
struct
cgfs_data
*
d
,
struct
lxc_list
*
cgroup_settings
,
bool
do_devices
)
{
struct
lxc_list
*
iterator
;
struct
lxc_list
*
iterator
,
*
sorted_cgroup_settings
,
*
next
;
struct
lxc_cgroup
*
cg
;
int
ret
=
-
1
;
if
(
lxc_list_empty
(
cgroup_settings
))
return
0
;
lxc_list_for_each
(
iterator
,
cgroup_settings
)
{
sorted_cgroup_settings
=
sort_cgroup_settings
(
cgroup_settings
);
if
(
!
sorted_cgroup_settings
)
{
return
-
1
;
}
lxc_list_for_each
(
iterator
,
sorted_cgroup_settings
)
{
cg
=
iterator
->
elem
;
if
(
do_devices
==
!
strncmp
(
"devices"
,
cg
->
subsystem
,
7
))
{
...
...
@@ -1916,6 +1921,11 @@ static int do_setup_cgroup_limits(struct cgfs_data *d,
ret
=
0
;
INFO
(
"cgroup has been setup"
);
out:
lxc_list_for_each_safe
(
iterator
,
sorted_cgroup_settings
,
next
)
{
lxc_list_del
(
iterator
);
free
(
iterator
);
}
free
(
sorted_cgroup_settings
);
return
ret
;
}
...
...
src/lxc/cgmanager.c
View file @
e7831129
...
...
@@ -1218,7 +1218,7 @@ static bool cgm_unfreeze(void *hdata)
static
bool
cgm_setup_limits
(
void
*
hdata
,
struct
lxc_list
*
cgroup_settings
,
bool
do_devices
)
{
struct
cgm_data
*
d
=
hdata
;
struct
lxc_list
*
iterator
;
struct
lxc_list
*
iterator
,
*
sorted_cgroup_settings
,
*
next
;
struct
lxc_cgroup
*
cg
;
bool
ret
=
false
;
...
...
@@ -1233,7 +1233,12 @@ static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool
return
false
;
}
lxc_list_for_each
(
iterator
,
cgroup_settings
)
{
sorted_cgroup_settings
=
sort_cgroup_settings
(
cgroup_settings
);
if
(
!
sorted_cgroup_settings
)
{
return
false
;
}
lxc_list_for_each
(
iterator
,
sorted_cgroup_settings
)
{
char
controller
[
100
],
*
p
;
cg
=
iterator
->
elem
;
if
(
do_devices
!=
!
strncmp
(
"devices"
,
cg
->
subsystem
,
7
))
...
...
@@ -1261,6 +1266,11 @@ static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool
ret
=
true
;
INFO
(
"cgroup limits have been setup"
);
out:
lxc_list_for_each_safe
(
iterator
,
sorted_cgroup_settings
,
next
)
{
lxc_list_del
(
iterator
);
free
(
iterator
);
}
free
(
sorted_cgroup_settings
);
cgm_dbus_disconnect
();
return
ret
;
}
...
...
src/lxc/conf.c
View file @
e7831129
...
...
@@ -4563,3 +4563,46 @@ void suggest_default_idmap(void)
free
(
gname
);
free
(
uname
);
}
/*
* Return the list of cgroup_settings sorted according to the following rules
* 1. Put memory.limit_in_bytes before memory.memsw.limit_in_bytes
*/
struct
lxc_list
*
sort_cgroup_settings
(
struct
lxc_list
*
cgroup_settings
)
{
struct
lxc_list
*
result
;
struct
lxc_list
*
memsw_limit
=
NULL
;
struct
lxc_list
*
it
=
NULL
;
struct
lxc_cgroup
*
cg
=
NULL
;
struct
lxc_list
*
item
=
NULL
;
result
=
malloc
(
sizeof
(
*
result
));
if
(
!
result
)
{
ERROR
(
"failed to allocate memory to sort cgroup settings"
);
return
NULL
;
}
lxc_list_init
(
result
);
/*Iterate over the cgroup settings and copy them to the output list*/
lxc_list_for_each
(
it
,
cgroup_settings
)
{
item
=
malloc
(
sizeof
(
*
item
));
if
(
!
item
)
{
ERROR
(
"failed to allocate memory to sort cgroup settings"
);
return
NULL
;
}
item
->
elem
=
it
->
elem
;
cg
=
it
->
elem
;
if
(
strcmp
(
cg
->
subsystem
,
"memory.memsw.limit_in_bytes"
)
==
0
)
{
/* Store the memsw_limit location */
memsw_limit
=
item
;
}
else
if
(
strcmp
(
cg
->
subsystem
,
"memory.limit_in_bytes"
)
==
0
&&
memsw_limit
!=
NULL
)
{
/* lxc.cgroup.memory.memsw.limit_in_bytes is found before
* lxc.cgroup.memory.limit_in_bytes, swap these two items */
item
->
elem
=
memsw_limit
->
elem
;
memsw_limit
->
elem
=
it
->
elem
;
}
lxc_list_add_tail
(
result
,
item
);
}
return
result
;
}
\ No newline at end of file
src/lxc/conf.h
View file @
e7831129
...
...
@@ -431,4 +431,5 @@ extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
void
remount_all_slave
(
void
);
extern
void
suggest_default_idmap
(
void
);
FILE
*
write_mount_file
(
struct
lxc_list
*
mount
);
struct
lxc_list
*
sort_cgroup_settings
(
struct
lxc_list
*
cgroup_settings
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment