Tim Zhang
ec4cda1dd9
Fix clippy for rust 1.53
...
There are new lints are added in clippy for rust 1.53
Signed-off-by: Tim Zhang <tim@hyper.sh >
2021-06-30 19:07:56 +08:00
Tim Zhang
0e2430fde1
clippy: turn on lint upper_case_acronyms
...
cargo-clippy has moved the upper_case_acronyms lint to
pedantic(removed from the default list), but we need
the lint to keep names consistent and follow the rust
naming conventions.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2021-05-21 00:48:50 +08:00
Tim Zhang
5aa7e6c90e
Fix clippy for rust 1.52
...
There are new lints are added in clippy for rust 1.52
Signed-off-by: Tim Zhang <tim@hyper.sh >
2021-05-21 00:45:27 +08:00
Tim Zhang
aa207edca8
Impl Clone for hierarchies:V1, hierarchies:V2
...
Clone is useful.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2021-03-23 21:50:18 +08:00
Tim Zhang
9ec1010a15
Fix clippy warnings
...
Fix clippy warnings.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2021-03-03 13:44:29 +08:00
Peng Tao
0a3e4a828f
memory: fix parse_oom_control panic on older kernels
...
Where the oom control fields might not be present.
Fixes : #36
Signed-off-by: Peng Tao <bergwolf@hyper.sh >
2021-02-26 01:40:19 +08:00
Peng Tao
8720aed656
memory: fix panic when no hierarchical numa stat is available
...
For older kernels, it is possible that there is no hierarchical numa
stats.
Fixes : #36
Signed-off-by: Peng Tao <bergwolf@hyper.sh >
2021-02-25 11:00:48 +08:00
quanweiZhou
81d286f31d
cgroup: get the mount info without procinfo
...
The procinfo library gets all the mount info,
but we don't need all the mount info.
Signed-off-by: quanweiZhou <quanweiZhou@linux.alibaba.com >
2021-02-01 11:26:54 +08:00
fupan.lfp
cd5645bb14
cgroup: fix the issue of remove cgroup
...
It should remove the child cgroups recursively
and then remove the parent cgroup, otherwise,
it would remove failed.
Signed-off-by: fupan.lfp <fupan.lfp@antfin.com >
2021-01-25 17:36:49 +08:00
Tim Zhang
15b65c5e5e
Apply customized attributes in MemController.apply
...
Fixes : #25
Signed-off-by: Tim Zhang <tim@hyper.sh >
2021-01-25 12:11:43 +08:00
Tim Zhang
f0a695cc00
Add trait bound Sync for Hierarchy
...
So that the struct Cgroup could across await
Signed-off-by: Tim Zhang <tim@hyper.sh >
2021-01-06 22:31:04 +08:00
LiYa'nan
033fa4b857
optimize and refactor: read_to_string and read_i[u]64_from
...
There's so many Duplicated read_string_from method in different
subsystem's implementation, so as read_u64_from/read_i64_from methods.
(1) Move the read_string_from method into `lib.rs`,
called by each subsystem implementation as needed.
(2) Refactor read_u[i]64_from method with the help Rust Generic f
unction `read_from` and wrapped by read_u64_from or read_i64_from.
fix : #20
Signed-off-by: LiYa'nan <oliverliyn@gmail.com >
2020-12-24 09:25:00 +08:00
Tim Zhang
eb6577e3e0
Change package name to cgroups-rs
...
We need a new package name to create a new crate
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-21 15:46:30 +08:00
Tim Zhang
e160df0751
Make read_i64_from private and merge read_str_from to its caller
...
Also remove duplicated read_i64_from.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
e1e05d3a1c
Make new_with_relative_paths=new and load_with_relative_paths=new in v2
...
Because the relative_paths is only valid for cgroup v1, the v2 use
unified hierarchy.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Qingyuan Hou
a89f4a062e
Support set notify_on_release & release_agent
...
Support set notify_on_release & release_agent
Signed-off-by: Qingyuan Hou <qingyuan.hou@linux.alibaba.com >
2020-12-17 17:56:46 +08:00
Tim Zhang
61a0957a65
Fix set_swappiness in cgroup v2
...
The file should be memory.swap.max in cgroup v2.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
059204589c
Ignore kmem in cgroup v2
...
Because there is no kmem in cgroup v2.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
438d774866
Fix test
...
Fix test
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
42ee1bafbd
Make Cgroup can be stored in struct
...
- Change type of hier to remove lifetimes
- impl Clone, Default, Debug for Cgroup
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
b6bb5ae947
docs: Hide Re-exports
...
Make `pub use crate::cgroup::Cgroup` display as struct in docs.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
d2882b1d85
Print cause when println!("{}")
...
> Print like following:
unable to write to a control group file caused by: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }) }
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
abcb5ed031
Add more logs for create_dir error in controller.create
...
We need know the path name which failed to create.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
1f188be405
Detect subsystems and get root from /proc/self/mountinfo
...
Delete check_support and stop detecting subsystems by finding in the
root folders because the detecting method is not accurate.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
fbd7164c29
Fix warnings in tests
...
Remove following warnings
- unused import
- unused Result
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
f34225411e
Remove Box wrap of Cgroup.hire
...
It's unnecessary.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
cd998f3f9b
Do not place cgroup under relative path read from cgroup by default
...
Add new_with_corresponding_relative_paths to do the original action.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
1ac76b69ba
Make function find_v1_mount pub
...
The function find_v1_mount is useful for customized impl for Hierarchy.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
121f78d8e8
Expose deletion error
...
So that users can retry or do some aftercare.
Fixes : #18
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
0f76570677
Avoid exception caused by cgroup writeback feature
...
The cgroup writeback feature requires cooperation
between memcgs and blkcgs.
To avoid exceptions, we should add_task for blkcg before
memcg(push BlkIo before Mem).
For more Information:
https://www.alibabacloud.com/help/doc-detail/155509.ht
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:46 +08:00
Tim Zhang
567cdb43b3
Use Option as resource fields, remove the update switch: update_values
...
Use idiomatic Option::None to represent optional fields.
This enables updates where not all fields need to be specified.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 17:56:41 +08:00
Tim Zhang
0c18b0855e
Support customized attributes for CpuController and MemController
...
Customized attributes are useful for customized kernels.
Usage:
let resource = &mut cgroups::Resources::default();
resource.cpu.attrs.insert("cpu.cfs_init_buffer_us", "10".to_string());
// apply here
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 16:45:41 +08:00
Yang, Wei
ca610bb57e
add add_task_by_tgid
...
Add task by writing thread group id to cgroup.procs.
Signed-off-by: Yang, Wei <wei.yang1@linux.alibaba.com >
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-12-17 15:57:22 +08:00
Tim Zhang
6f9e89572e
MemController: add method reset_max_usage
...
We need a method to reset the max memory usage recorded.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-10-29 19:35:39 +08:00
Tim Zhang
42eb32765b
Make methods to_controller and controller_name of Subsystem public
...
We need these functions to detect whether subsystem path exists.
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-10-29 19:32:55 +08:00
Tim Zhang
efb98108fc
Fix warnings
...
Got:
cargo build --target x86_64-unknown-linux-musl
Compiling cgroups v0.1.1-alpha.0 (/home/tim/project/cgroups-rs)
warning: unused import: `nix::sys::statfs`
--> src/hierarchies.rs:220:5
|
220 | use nix::sys::statfs;
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: 1 warning emitted
Signed-off-by: Tim Zhang <tim@hyper.sh >
2020-10-29 19:31:55 +08:00
bin liu
152af17f8f
fix build warnings
...
And in Travis CI, treat warnings as error
to keep from merging codes with warning.
Fixes : #13
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-23 16:19:51 +08:00
zhanghj
cd7e737149
lib: fix compiling error for type i8 in aarch64 environment
...
c_char is equal to i8 on x86, but it is equal to u8 on arm arch,
so we need to use type c_char instead of i8 to avoid compiling error.
Fixes : #9
Signed-off-by: zhanghj <zhanghj.lc@inspur.com >
2020-09-21 05:40:57 -04:00
Peng Tao
3852d7c180
Merge pull request #8 from liubin/fix/7-add-sync-marker-to-error-cause
...
errors: add sync marker to error cause
2020-09-14 16:15:12 +08:00
bin liu
42685bbfe9
errors: add sync marker to error cause
...
Errors cause should be shared to let anyhow to wrap it.
Fixes : #7
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-14 15:22:55 +08:00
bin liu
f8d653e987
cpu: change cfs_quota from u64 to i64
...
cfs_quota can be set to -1 to indicate no limit
Fixes : #5
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-14 13:00:43 +08:00
bin liu
250ada183a
cargo fmt
...
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-09 16:42:55 +08:00
bin liu
ff6a0ea82a
add SPDX-License-Identifier for modified files
...
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-09 13:35:46 +08:00
bin liu
bcbf438823
Merge remote-tracking branch 'upstream/master'
2020-09-09 13:27:12 +08:00
bin liu
c3912223d0
use let Some() instead of is_some() to make codes clear
...
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-09 13:26:18 +08:00
bin liu
5d51e50bec
get relative paths at new/load func default.
...
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-08 10:30:29 +08:00
bin liu
86b245076c
add SPDX-License-Identifier for all source
...
Add SPDX-License-Identifier for all existing codes.
Fixes : #2
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-07 20:29:40 +08:00
bin liu
cd2c748a74
add systemd controller; add more tests; update blkio stat for v2
...
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-07 14:18:41 +08:00
bin liu
c623dc3fba
add basic v2 cpu/memory functions
...
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-02 22:03:11 +08:00
bin liu
704db324ae
fix: create all dirs
...
Signed-off-by: bin liu <bin@hyper.sh >
2020-09-01 00:01:28 +08:00