Commit graph

338 commits

Author SHA1 Message Date
Yifan Hong
5ece395328 libcgrouprc: version script: linux only
mac builds doesn't support version script.
This fixes the build.

Test: pass

Change-Id: Ia3d06e4eff05b41982b3dfbb946efa41358b2c76
2019-04-03 14:44:46 -07:00
Yifan Hong
8df75fc304 CgroupSetupCgroups: don't leak fd.
- If file is unlinked, the mmapped region is still there.
- If file is truncated, a SIGBUS will be seen, and holding
  the fd doesn't help.

Test: boots (sanity)
Bug: 123664216
Change-Id: I6683804bc795fab6798891a4471e5fe58fbffe13
2019-04-03 12:13:26 -07:00
Yifan Hong
9d7b89abea CgroupSetupCgroups -> CgroupSetup
Test: builds
Bug: 123664216
Change-Id: I47c46ca9ba5c1fbf3f9f7a1b185dc48b058b1e32
Merged-In: I47c46ca9ba5c1fbf3f9f7a1b185dc48b058b1e32
2019-04-02 22:31:57 -07:00
Yifan Hong
53e0deb7b2 libprocessgroup: use libcgrouprc to read cgroup.rc
Use the LL-NDK library to read cgroup.rc.

As a side-effect, the CgroupController class is changed
to a wrapper of ACgroupController* from the library. The
class itself essentially becomes the pointer, and can be
trivially copied. Modify all client code for this change.

Test: builds and boots
Bug: 123664216

Change-Id: I635d9885db62e82f37421f6d20f59c84a6f4cbb2
Merged-In: I635d9885db62e82f37421f6d20f59c84a6f4cbb2
2019-04-02 22:31:57 -07:00
Yifan Hong
d8ce1fb1d1 libprocessgroup_setup: use libcgrouprc_format
Use CgroupController definition from libcgrouprc_format, not
libprocessgroup, because the wire format will be removed
from libprocessgroup later.

Bug: 123664216
Test: builds
Change-Id: If5e2301a1b65c3f6a51a1661cfeeed4e299f634e
Merged-In: If5e2301a1b65c3f6a51a1661cfeeed4e299f634e
2019-04-02 22:31:57 -07:00
Yifan Hong
6f9ce2e548 libprocessgroup: Move CgroupSetupCgroups() to libprocessgroup_setup
Only init uses SetupCgroups. This functionality is
moved from libprocessgroup to its own library, and only
init links to it.

Also, merge CgroupSetupCgroups() with CgroupMap::SetupCgroups()
because the former is just an alias of the latter, and
CgroupMap does not belong to libcgrouprc_setup.

Test: boots
Bug: 123664216
Change-Id: I941dc0c415e2b22ae663d43e30dc7a464687325e
Merged-In: I941dc0c415e2b22ae663d43e30dc7a464687325e
2019-04-02 22:31:57 -07:00
Yifan Hong
098323ba5b libprocessgroup: Add libcgrouprc
This module is an LL-NDK library that can be loaded by
modules that link to libprocessgroup (which is in VNDK).
This module defines APIs that reads cgroups.rc file
programatically. Internally, it uses libcgrouprc_format to
do so.

Test: builds
Bug: 123664216

Change-Id: I9c13c0528461758154e23cbab3a94ade7fb351ee
Merged-In: I9c13c0528461758154e23cbab3a94ade7fb351ee
2019-04-02 22:31:57 -07:00
Yifan Hong
c4b3ab4edc libprocessgroup: Add libcgrouprc_format
This module defines the wire format of the mmap()ed cgroup.rc
file.

Test: builds
Bug: 123664216

Change-Id: Iaf6199f759a6264590b13ca7ba6d7f576c3ed56a
Merged-In: Iaf6199f759a6264590b13ca7ba6d7f576c3ed56a
2019-04-02 22:31:57 -07:00
Suren Baghdasaryan
5b53573671 libprocessgroup: restrict SetupCgroups to one-time usage and only by init
SetupCgroups is called by init process during early-init stage and is not
supposed to be called again by anyone else. Ensure that the caller is the
init process, make sure cgroup.rc file is written only one time, keep the
file descriptor to cgroup.rc file open by the init process to ensure all
its further mappings stay valid even if the file is deleted.

Bug: 124774415
Test: build, run, verify no errors or warning in the logcat

Change-Id: Ib8822cf0112db7744e28d442182d54dcf06f46f2
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-03-28 01:25:22 +00:00
Elliott Hughes
be87d447b4 libprocessgroup: add -Wexit-time-destructors.
Exit time destructors already caused trouble (see
dba6d44376), and without this warning,
it's too easy to reintroduce issues.

Bug: 129023204
Test: builds
Change-Id: If5fb4d0c11c74ba4971bb218059c6d37edeaf4df
2019-03-26 18:50:22 -07:00
Suren Baghdasaryan
c8ac3b9152 Revert "libprocessgroup: make sure SetupCgroups is called once and only by init"
This reverts commit 798e805715.

Reason for revert: causes SELinux policy denials when vold calls KillProcessesWithOpenFiles.

Bug: 129298168
Change-Id: Ie00bfc2b743757209b40b55d2ee038d7d20c73ff
2019-03-26 02:49:13 +00:00
Suren Baghdasaryan
798e805715 libprocessgroup: make sure SetupCgroups is called once and only by init
SetupCgroups is called by init process during early-init stage and is not
supposed to be called again by anyone else. Ensure that the caller is the
init process, make sure cgroup.rc file is written only one time, keep the
file descriptor to cgroup.rc file open by the init process to ensure all
its further mappings stay valid even if the file is deleted.

Bug: 124774415
Test: build, run, verify no errors or warning in the logcat

Change-Id: I70ccec551fc07c380333566f618b969667dcf783
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-03-25 16:22:10 +00:00
Peter Collingbourne
dba6d44376 libprocessgroup: Deliberately leak TaskProfiles and CgroupMap instances.
This avoids a race between destruction on process exit and concurrent
access from another thread.

Bug: 129023204
Change-Id: Iecafa67a78e2cce53687156e7f91547b4a23ec13
2019-03-21 17:00:48 +00:00
Yifan Hong
830f837231 Merge changes from topic "libprocessgroup"
* changes:
  libprocessgroup: Add VTS tests for vendor JSON files
  libprocessgroup_proto_test split into multiple files
2019-03-18 16:53:47 +00:00
Yifan Hong
e8e2756f93 libprocessgroup: Add VTS tests for vendor JSON files
Test: vts_processgroup_validate_test
Bug: 123664216
Change-Id: I5518e34cde6fc30195fc99133f86cb23ae3be92f
2019-03-15 16:28:42 -07:00
Yifan Hong
28a44eb6f6 libprocessgroup_proto_test split into multiple files
... so that they can be reused later.

Also, removed test to strull and inline static constexpr variable.

Bug: 123664216
Test: libprocessgroup_proto_test
Change-Id: Ia6b93c6689d7531e6f597d1387434aed1b3efb0a
2019-03-15 12:34:42 -07:00
Elliott Hughes
08b4d32139 libprocessgroup: PLOG already includes strerror(errno).
Test: builds
Change-Id: Ic1fe6b46144f7dbeb7ffba5534d94b4dae192d5c
2019-03-14 20:06:36 -07:00
Wei Wang
d71d30179c Set cg_file_data_ to null when initialization failed
Cannot really do calls if initialization failed.
Also fix LOG usage.

But: 124774415
Test: Build
Change-Id: Ifd7db90cfee51ba5830e1d4db8f8d19b5bc9feba
2019-03-08 10:18:06 -08:00
Treehugger Robot
8dcd839158 Merge "Reduce log spam from libprocessgroup" 2019-03-01 22:11:15 +00:00
Suren Baghdasaryan
e681df44eb libprocessgroup: convert Json::Value to const refs
Convert Json::Value to const refs to prevent creation of a null member
if specified element does not exist. Fix variable naming in the parser
while we are at it.

Change-Id: I7dabfd1c73983b465984dd6c411c9fe48743a348
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-03-01 00:29:49 +00:00
Suren Baghdasaryan
05da67c390 Add vendor cgroups and task_profiles support
Vendors should be able to specify additional cgroups and task profiles
without changing system files. Add support for /vendor/etc/cgroups.json
and /vendor/etc/task_profiles.json files which will augment cgroups and
task profiles specified in /etc/cgroups.json and /etc/task_profiles.json
system files.

Bug: 124960615
Change-Id: I548c2e866b65c19856a3617d75b75dcd06f7d5b7
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-03-01 00:29:37 +00:00
Rick Yiu
e9d149fd7e Unify some text format in task_profiles.json
Bug: 111307099
Test: cgroup function is normal
Change-Id: Id992b875720ff67a5d1a2b052072ee7ea7b16a9a
2019-02-27 21:08:19 +08:00
Treehugger Robot
d5345f58fd Merge "Add blkio cgroup to libprocessgroup" 2019-02-27 13:04:00 +00:00
Wei Wang
1770566de6 Fix string reference usage
Bug: 124774415
Test: Build
Change-Id: Ic0e5ee4f3375c2fa21fbc2ce3796b7368e9e289c
2019-02-27 06:04:13 +00:00
Rick Yiu
2b3bf84373 Add blkio cgroup to libprocessgroup
To differentiate IO priority for different groups.

Bug: 111422845
Bug: 117857342
Test: tasks are assigned to the group as expected
Change-Id: Ibb108d1b8e0f720f7ac4cab248b3c33d35e5483d
2019-02-27 11:23:14 +08:00
Wei Wang
858f3e5343 Reduce log spam from libprocessgroup
EBUSY is expected when removing process group path if process is still
active. ESRCH is expected when kill if process died already. ENOENT is
also expected when opening cgroup path if process died already.
This CL also skip removing parent path if child failed when remove
process group.

Bug: 125340804
Test: Build and boot
Change-Id: Ief3b9cb913035a4050f6cf79c8b1e2f098e18244
2019-02-21 12:54:07 -08:00
Yifan Hong
4bb7b18fe1 Merge changes from topic "libprocessgroup_json"
* changes:
  Add schema for task profiles
  Move rootdir/*.json to libprocessgroup
2019-02-20 20:35:47 +00:00
Vic Yang
ab8d6ab62d libprocessgroup: Fix memcg path for apps
The expected memcg path for apps is
/dev/memcg/apps/uid_<uid>/pid_<pid>.  Right now we are missing the
"apps" component.  Fix it.

Bug: 124776663
Test: Boot on a Go device and does not see error from lmkd anymore.
Change-Id: I0e4c1d8520463fabb171ff4e61479034b6446548
2019-02-19 14:09:00 -08:00
Yifan Hong
72ff585bd0 Add schema for task profiles
- Add proto3 files as schema for JSON task profiles / cgroups
  files.

- Add tests to ensure the JSON files (on the device) conforms
  the schema. (libprocessgroup_proto_test)

Test: libprocessgroup_proto_test

Bug: 123664216
Change-Id: I1cab73bd0d3852ff8827fee0be22373da8a6fc5b
2019-02-19 13:26:46 -08:00
Yifan Hong
98a61dd583 Move rootdir/*.json to libprocessgroup
They are installed to /system/etc, not /. Hence, move
out of rootdir/ and move into the code that parse these
files (i.e. libprocessgroup).

Also, Android.mk->bp.

Test: builds

Change-Id: I1763c26f81ae51ee159552e39d252fd643c35b94
2019-02-14 16:06:49 -08:00
Suren Baghdasaryan
d032a92c04 Fix cgroup support for recovery mode
In recovery mode a separate set of cgroups should be mounted. Add a
cgroups.recovery.json file to describe cgroups mounted during recovery.
Change cgroups descriptor parset to allow cgroups and cgroups2 sections
to be omitted.

Bug: 124270406
Test: "adb reboot sideload; adb devices" shows 'sideload' as expected

Change-Id: Ic32bd2b4612ec8390064f87d4655d1bd1183d741
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-14 17:08:40 +00:00
Suren Baghdasaryan
2bc522878d Suppress error log when timerslack_ns write fails for already dead process
lmkd uses set_sched_priority to expedite killing of its victims and this
sometimes results in timerslack_ns writes for an process which is already
dead. These messages are detrimental during troubleshooting and do not
indicate a real problem, therefore need to be suppressed.

Bug: 124324891
Test: lmkd_unit_test

Change-Id: I5bc071b47d386c279dd9a56eee51dba7797f4520
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-14 03:51:17 +00:00
Suren Baghdasaryan
3a22225ac6 Merge "libprocessgroup: Fix file mode parsing that requires octal values" 2019-02-07 04:54:28 +00:00
Suren Baghdasaryan
e3ad888011 libprocessgroup: Fix cgroup directory ownership setup
When cgroup directory is created its user and ownership gets set, however
because previous code was storing getpwnam() return value the second
invocation would effectively override the previous ones result. Fix this
by copying necessary results. Also change getpwnam() to getgrnam() when
group name is converted into gid. getpwnam() works because of the way
Android uses these ids, however more generally this is incorrect and
getgrnam() should be used instead.

Bug: 111307099
Test: verified user/group membership of the cgroup directories
Change-Id: I78668bc1a36a74f53d8e9825e2d06e3e09501e7a
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-06 14:28:23 -08:00
Suren Baghdasaryan
c760231891 libprocessgroup: Fix file mode parsing that requires octal values
JSON supports only decimal values and therefore file mode which should
use octal values has to be represented as strings. Fix the implicit
octal-to-decimal conversion and convert from string to octal in the code.

Bug: 111307099
Test: confirmed by verifying correct file permissions

Change-Id: I3ef9de0aea259f93bf74efeffca72d37d4740e15
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-06 21:01:41 +00:00
Suren Baghdasaryan
bee9f5718b libprocessgroup: Disable file descriptor caching temporarily
File descriptor caching breaks boot on Android Go and Svelte targets.
Disable it temporarily to fix the builds and investigate the root cause
further.

Bug: 123868658
Test: Android Go device boots after this change

Change-Id: Idd0209029cde8454ea99b9de030f7a317c2988d7
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-06 02:15:37 +00:00
Greg Kaiser
5c5ed9c856 libprocessgroup: Fix return values
We want our default implementations to fail, but '-1' is implicitly
cast to 'true', since it's non-zero.  We explicitly use 'false' to
fix this.

Test: TreeHugger
Change-Id: I369897b519601ce1a887cf6acd5f2cb9a6113a9a
2019-02-04 06:33:26 -08:00
Suren Baghdasaryan
ff25a5f584 Disable SetupCgroup for non-Android targets
Non-android targets should not mount cgroups described in cgroup map
file. When used on non-Android targets SetupCgroup will fail. When
SetupCgroup is called via SetupCgroups a warning will be generated for
each cgroup that fails to mount.

Bug: 111307099
Change-Id: I213a5f9b02f312ba1dd7dc91c89b67334fb939b9
Merged-In: I213a5f9b02f312ba1dd7dc91c89b67334fb939b9
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-03 17:55:59 +00:00
Suren Baghdasaryan
eca87cb9ca Fix non-Android build targets
Non-Android build targets are missing sys/prctl.h header and functionality
should be disabled for them like it was done previously inside
sched_policy.cpp. Also make the set_sched_policy/get_sched_policy
functionality backward compatible by creating stubs for non-Android
targets.

Bug: 111307099
Test: built sdk_gphone_x86-sdk_addon_mac target using forrest

Change-Id: I1c195267e287a84a21c588bd61d7c452bff6cfbe
Merged-In: I1c195267e287a84a21c588bd61d7c452bff6cfbe
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-03 16:49:28 +00:00
Suren Baghdasaryan
82b72a5667 libprocessgroup: Add support for task profiles
Abstract usage of cgroups into task profiles that allows for changes
in cgroup hierarchy and version without affecting framework codebase.
Rework current processgroup and sched_policy API function implementations
to use task profiles instead of hardcoded paths and attributes.
Mount cgroups using information from cgroups.json rather than from init.rc

Exempt-From-Owner-Approval: already approved in internal master

Bug: 111307099
Test: builds, boots

Change-Id: If5532d6dc570add825cebd5b5148e00c7d688e32
Merged-In: If5532d6dc570add825cebd5b5148e00c7d688e32
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-02-03 16:48:35 +00:00
Suren Baghdasaryan
9491078300 DO NOT MERGE: Revert "Revert "Add dependencies on libprocessgroup for sched_policy users""
This reverts commit 1bef8c550c.

Reason for revert: AOSP is fixed with new vendor image

Change-Id: Ib341ac80e2f88c13a7815a490ea2d9422ebdf55f
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-25 16:49:18 +00:00
Suren Baghdasaryan
1bd127b72e DO NOT MERGE: Revert "Revert "libcutils: Move sched_policy functions into libprocessgroup""
This reverts commit b5394db682.

Reason for revert: AOSP is fixed with new vendor image

Change-Id: Ie1a2e0200600214a65f4fe2250c903c8e8ce0a29
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-25 16:49:09 +00:00
Suren Baghdasaryan
7bf4381a82 DO NOT MERGE: Revert "Revert "Add libprocessgroup into VNDK""
This reverts commit c4a02d25a9.

Reason for revert: AOSP is fixed with new vendor image

Change-Id: Ifc1c4d51aa1b168ef62cf58275b908d98b9a04bf
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-25 16:48:58 +00:00
Suren Baghdasaryan
c4a02d25a9 DO NOT MERGE: Revert "Add libprocessgroup into VNDK"
This reverts commit dad4749731.

Reason for revert: Broke AOSP

Change-Id: I019e1226a65b31495984cf47ad471771b4880c45
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-23 20:44:47 -08:00
Suren Baghdasaryan
b5394db682 DO NOT MERGE: Revert "libcutils: Move sched_policy functions into libprocessgroup"
This reverts commit facd40d0e1.

Reason for revert: Broke AOSP

Change-Id: Id333417d4970ced800ab801bddfed880cafa056d
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-23 20:44:09 -08:00
Suren Baghdasaryan
1bef8c550c DO NOT MERGE: Revert "Add dependencies on libprocessgroup for sched_policy users"
This reverts commit 02843339f9.

Reason for revert: Broke AOSP

Change-Id: I62f91c0adf440b5da0a145862b04dd27a7016faf
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-23 20:43:28 -08:00
Suren Baghdasaryan
02843339f9 Add dependencies on libprocessgroup for sched_policy users
After moving sched_policy functions into libprocessgroup its users require
additional dependency and inclusion of sched_policy_ctrl.h header.

Exempt-From-Owner-Approval: janitorial

Bug: 111307099
Test: builds, boots

Merged-In: Icc052080e1bce46ce06f7264446950cab0490a95
Change-Id: Icc052080e1bce46ce06f7264446950cab0490a95
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-22 18:19:45 +00:00
Suren Baghdasaryan
facd40d0e1 libcutils: Move sched_policy functions into libprocessgroup
Move functions operating on cgroups from sched_policy.h in libcutils
into sched_policy_ctrl.h under libprocessgroup. This consolidates
cgroup-related functionality inside libprocessgroup.

Bug: 111307099
Test: builds, boots

Merged-In: Iba75f33281162b889989214d0325a5973d53ed2d
Change-Id: Iba75f33281162b889989214d0325a5973d53ed2d
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-22 18:18:48 +00:00
Suren Baghdasaryan
dad4749731 Add libprocessgroup into VNDK
Include libprocessgroup into vndk in preparation for sched_policy
functions to be moved into it.

Bug: 111307099
Test: builds, boots
Merged-In: I09a528cac8821df3201c2428b151fd2eaece3ccb
Change-Id: I09a528cac8821df3201c2428b151fd2eaece3ccb
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-22 18:18:22 +00:00
Peter Collingbourne
d7157c22af Introduce additional service options for controlling memory cgroups.
The memcg.limit_percent option can be used to limit the cgroup's
max RSS to the given value as a percentage of the device's physical
memory. The memcg.limit_property option specifies the name of a
property that can be used to control the cgroup's max RSS. These
new options correspond to the arguments to the limitProcessMemory
function in frameworks/av/media/libmedia/MediaUtils.cpp; this will
allow us to add these options to the rc files for the programs that
call this function and then remove the callers in a later change.

There is also a change in semantics: the memcg.* options now have
an effect on all devices which support memory cgroups, not just
those with ro.config.low_ram or ro.config.per_app_memcg set to true.
This change also brings the semantics in line with the documentation,
so it looks like the previous semantics were unintentional.

Change-Id: I9495826de6e477b952e23866743b5fa600adcacb
Bug: 118642754
2018-10-31 17:09:59 -07:00
Treehugger Robot
8485d59790 Merge "Add OWNERS for libprocessgroup" 2018-09-14 21:08:32 +00:00
Tom Cherry
b1cb37b077 Add OWNERS for libprocessgroup
Test: n/a
Change-Id: I7c069e439cf1d9d26fd5274647567fb1c5575a72
2018-09-14 11:13:22 -07:00
fengshaobo
950f6f367e Fixed the can not kill some process using libprocessgroup
In DoKillProcessGroupOnce function, if process has a child process, pids set
will be clear probability and initialPid will not be killed, when the pid
is equal to initialPid.

Test: manual - start duomi app and remove it use recent apps key
Change-Id: Ifb9f4acacd725d2c367e547d2b5512807bb44fec
2018-09-13 15:13:13 +08:00
Tom Cherry
1151d15be5 Add recovery_available: true to init dependencies
Init needs this in order to be built in Android.bp

Test: build
Change-Id: I695438d69cc71b739b7648c4008ff3760da58ef0
2018-07-24 13:45:50 -07:00
Elliott Hughes
dc80312628 libbase: add host properties support.
Move init and libprocessgroup away from their existing hacks.

Bug: N/A
Test: ran tests
Change-Id: Ifabdd38e0cc4ab2582f1ea59d32159d386f48eb6
2018-05-24 18:04:31 -07:00
Suren Baghdasaryan
bc131c3244 Make per-application memcg hierarchy configurable via a property
Introduce ro.config.per_app_memcg Android property to enable/disable
per-application memcg hierarchy.
On low-ram devices (ro.config.low_ram=true) ro.config.per_app_memcg
defaults to true, otherwise it defaults to false.

Bug: 80201565
Test: set ro.config.per_app_memcg=true and verify /proc/<app_pid>/cgroup
membership (memory:/apps/uid_xxx/pid_xxx)
Test: set ro.config.per_app_memcg=false and verify /proc/<app_pid>/cgroup
membership (memory:/)
Change-Id: Iabd3ef6c9c16c774b9da959a7f43b5f66df120a3
Merged-In: Iabd3ef6c9c16c774b9da959a7f43b5f66df120a3
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-05-24 15:13:00 -07:00
Tom Cherry
574a081623 libprocessgroup: remove legacy C string handling and build for host
Bug: 36970783
Test: kill zygote and see that its children die correctly
Change-Id: I1b0e9a9cdb834a000fec82323d690e3bd288692d
2018-02-27 14:12:19 -08:00
Robert Benea
d485226951 Add memcg related configs to init.
Allow configuring memory.swappiness, memory.soft_limit_in_bytes
and memory.limit_in_bytes by init; by doing so there is better
control of memory consumption per native app.

Test: tested on gobo branch.
bug: 63765067
Change-Id: I8906f3ff5ef77f75a0f4cdfbf9d424a579ed52bb
2017-07-18 15:58:40 -07:00
Robert Benea
3280e48847 Use mem cgroups in libprocessgroup if they're available
Use mem cgroups if the kernel is built with CONFIG_MEMCG=y,
additionally add system group.

test: verified on both kernel with/without memcg enabled
Change-Id: Ia2ae89efa3905e9da68fa77adac1225c667864d1
2017-07-11 12:48:10 -07:00
Tim Murray
fc10e3d5e5 Revert "Use mem cgroups in libprocessgroup if they're available"
This reverts commit 32375c2328.

bug 63164307

Change-Id: I3336bbf7c2f3297b231c5b0a1ef538faff9513fd
2017-07-08 00:04:42 +00:00
Robert Benea
32375c2328 Use mem cgroups in libprocessgroup if they're available
Use mem cgroups if the kernel is built with CONFIG_MEMCG=y,
additionally add system group.

test: verified on both kernel with/without memcg enabled
Change-Id: Ib9d1c8e3c797e75f160e0e92edf3f11c9d8e9f17
2017-06-29 23:49:00 +00:00
Tom Cherry
70a5ed49ef init: move killing of process groups to libprocessgroup
libprocessgroup kills the cgroup associated with a given pid and uid,
but not the POSIX process group associated with it.  This means that
to kill both, two of the same signals must be sent, which may cause
some issues.

This change kills all POSIX process groups whose group leaders are
found within a cgroup.  It only then kills processes in the cgroup
that are not part of the POSIX process groups that have been killed.

Bug: 37853905
Bug: 62418791
Test: Boot, kill zygote, reboot
Change-Id: Id1d96935745899b4c454c36c351ec16a0b1d3827
2017-06-07 13:20:21 -07:00
Tom Cherry
efa81080fd Enable libprocessgroup on host bionic
Bug: 31559095

Test: Build
Change-Id: I1ee9fb492137c6c16f0d02586393837616127972
2017-05-11 17:55:04 -07:00
Tom Cherry
20514c4411 Better logging in libprocessgroup and make resources clean up themselves
Bug: 36661364
Bug: 36701253
Bug: 37540956

Test: Reboot bullhead
Test: Start and stop services
Change-Id: I97b6e17a7350850db733bee9fc83bdd296d88c61
2017-05-04 12:18:57 -07:00
Steven Moreland
419ce36c7d libprocessgroup: Android.mk -> Android.bp
Test: links
Test: (sanity) boot marlin in recovery + to system UI
Bug: 37512442
Change-Id: Ie19c02bda9df7c0cfdeeaf34c48f251b2b93961d
2017-04-19 14:29:08 -07:00
Keun-young Park
fac4b63eff add killProcessGroupOnce
- killProcessGroup retries if it fails while
  killProcessGroupOnce only tries once.
- useful for sending signal like SIGTERM once.

bug: 36696408
Test: will add usage to init
Change-Id: Ia1e3d4ec848e785a3238f262b02914695cded4c7
2017-03-29 16:33:15 -07:00
Elliott Hughes
290a228fdc Switch fastboot/init/libprocessgroup to std::this_thread::sleep_for.
Bug: http://b/32878766
Test: boots
Change-Id: Ie0ddfb7e60f2da5f6eefbb10c83a92e88c137ae3
2016-11-14 17:08:47 -08:00
Elliott Hughes
9f206938ed Use readdir instead of readdir_r.
http://elliotth.blogspot.com/2012/10/how-not-to-use-readdirr3.html

Test: boots.
Change-Id: If75532e24fe4d17743bf8e8c9590156dee378a63
2016-09-28 14:04:12 -07:00
Elliott Hughes
b6e1d15056 resolve merge conflicts of ed3596a to stage-aosp-master
Change-Id: I3c41782e2bf3563d3e3d6232d39eff3da94843fc
2016-08-03 13:29:04 -07:00
Elliott Hughes
171df0a092 Switch libprocessgroup to libbase logging.
This lets us see what's going on in init.

Bug: http://b/29751426
Merged-In: I73432dc7608ca0dc8e421a2f3a750b37c6743f62
Change-Id: I73432dc7608ca0dc8e421a2f3a750b37c6743f62
2016-08-03 09:11:04 -07:00
Elliott Hughes
8d532e4737 resolve merge conflicts of cea1d04 to nyc-dev-plus-aosp
Change-Id: I41cdca717664a16f00fd1b28076dd752fa96653d
2016-06-06 21:19:55 -07:00
Collin Mulliner
f7e79b99c1 use process groups for processes started by init
Put every service into a process group, kill the process group
and all child processes created within the group when killing the
service. Removed libutil dependency in libprocessgroup.

Bug: 25355957
Change-Id: Ieed60ec41579f638ab9b1e66a7e6330ed578ab05
Signed-off-by: Collin Mulliner <collinrm@squareup.com>
2016-06-06 16:31:01 -07:00
Elliott Hughes
c4248ae9a1 Remove useless #include.
Bug: http://b/28432688
Change-Id: I8982f42b2bf2305168a4ba167e422173f35c69c2
2016-04-30 09:10:07 -07:00
Martijn Coenen
d89cd41bc7 Merge "Don\'t use mem cgroups for pid accounting." into nyc-dev
am: e9ea8db

* commit 'e9ea8db617f52ddaa51e3b6fb9663e2f9b069425':
  Don't use mem cgroups for pid accounting.
2016-03-18 15:54:12 +00:00
Martijn Coenen
5bb91ab553 Don't use mem cgroups for pid accounting.
Commit b82bab66 introduced the use of memory cgroups for keeping track
of forked PIDs; it basically creates a separate memory cgroup for every
process forked from zygote.

Each such memory cgroup which also have its own LRU with (in)active file
and anonymous pages. The current theory is this could potentially introduce
two problems:
1) kswapd runs longer because it has to iterate over the LRUs of all mem
cgroups, instead of over the LRUs of a single root mem cgroup;
2) the way kswapd reclaims things will be different also - I think it will
tend to bias reclaim to smaller mem cgroups, and process private pages
will end up on ZRAM swap much sooner.

Until we figure this out, fall back to the CPU accounting cgroup for keeping
track of forked PIDs. This leaves us with a single root mem cgroup again. We
can also keep userspace lmkd enabled because it only requires the root mem
cgroup.

Bug: 27381069
Change-Id: Ife397a6ac232761f2adfe6f5056582be0d1b4ff1
2016-03-18 15:35:48 +01:00
James Hawkins
22b6f7a559 resolve merge conflicts of 0f5d443d0c to nyc-dev-plus-aosp
Change-Id: I850bda0808ae17ade5bc0e667211a599d284d6e3
2016-02-19 11:10:30 -08:00
James Hawkins
588a2cad7f system/core: Cleanup direct calls to opendir by containing in a
std::unique_ptr.

Bug: 26643633
Change-Id: Ia3491fdbff086558da694ae949cf08e4c89d0307
2016-02-18 14:52:46 -08:00
Martijn Coenen
623b56af5d Fix libprocessgroup SELinux denials.
libprocessgroup checks whether it can use memory
cgroups for keeping track of forked processes by
seeing whether /dev/memcg/apps is writable. However,
on systems with memory cgroups disabled, SELinux
(correctly) no longer classifies this directory as a cgroup,
and starts denying zygote access. To fix this,
first check whether /dev/memcg/apps/tasks exists to
see if the cgroup is mounted; only then check whether
we can write to the directory.

Bug: 27046965
Change-Id: I6e44cd62d8c396e20ceb162c50606b3e86f2cb3e
2016-02-08 11:45:27 +01:00
Martijn Coenen
b82bab66f3 Reuse mem cgroups for tracking forked PIDs.
It turns out we were using the CPU accounting
cgroups for keeping track of processes that were
forked by an app without the framework's knowledge,
so we could kill all of them reliably (see b/15313911
for context).

Since we want to use memory cgroups for other purposes,
we might as well use memory cgroups for tracking forked
PIDs if they're enabled. This also gets us automatic cleanup
of empty mem cgroups.

Also, removed old mem cgroup mount point that is no
longer used, as well as cgroup release agent code that
we're not using.

Change-Id: I69d5cc31c162ffa49ef6945755f41381e306cc8b
2016-02-01 21:04:24 +01:00
Yusuke Sato
d50393057a processgroup: change the polling interval for killProcessGroup()
to make the function faster on average. Since killing a process
takes about 40-60ms on a recent device, the previous logic tends
to sleep too long. This CL does not significantly change the total
timeout (old code: 204ms, new code: 200ms).

Bug: 21813611
Change-Id: Ica44b2437ccccaebadcf585d7a09d993ce71a499
2015-06-16 13:59:32 -07:00
Dan Albert
d0a793dca3 Remove uses of libcxx.mk.
This is a no-op.

Change-Id: Iecbcd5f6d818abbf98767a2e996c10f454b652e4
2015-03-27 11:24:04 -07:00
Elliott Hughes
0badbd6565 Fix missing #includes in system/core.
Change-Id: I4736e8c4f7bb8bb03640d26d58243efaa67dc75c
2014-12-29 12:24:25 -08:00
Chih-Hung Hsieh
fcc8115dcf Fix format string
Make a format string match the type of the parameter it represents

Change-Id: I0af88636448084b56450996ea9dafdba3c1fd2a3
Signed-off-by: Bernhard Rosenkränzer <Bernhard.Rosenkranzer@linaro.org
2014-11-20 19:38:26 -08:00
Bernhard Rosenkränzer
758aeb7dad Make mkdirAndChown do what it claims to do
Currently, mkdirAndChown takes parameters for mode, uid and gid, but
ignores them and hardcodes 0750, AID_SYSTEM, AID_SYSTEM instead.
This doesn't matter much because so far its only invocation passes
exactly those values as parameters -- but clang complains about unused
parameters.

Might as well make the function do what it claims to do.

Change-Id: I5a8056be3278a0c5d0a576dbc061288aa0956a35
Signed-off-by: Bernhard Rosenkränzer <Bernhard.Rosenkranzer@linaro.org>
2014-11-17 20:46:00 +01:00
Dianne Hackborn
67f46cb0e1 Fix issue #18000467: processgroup truncates buffer
Change-Id: I3d98a4da9c47d83d25a11ff0ef94cfcab1feabea
2014-10-15 11:36:28 -07:00
Dianne Hackborn
2c5e7e102b Maybe fix issue #17969789: Shamu FR: Runtime restart while scrolling Instagram
It looks like there were a couple problems in the code:

- It would not 0-terminate the string it read, to make sure we didn't
  see garbage at the end.
- It didn't reduce buf_len as it processes data in the buffer, so if
  we need to read more we will increase the buffer length to be longer
  than the actual available data.

Also put in some logs about every thing we kill, so we can see what
is going on when debugging.  And add a special check for us trying
to kill pid 0 for any reason, since doing so seem to be terminal to
the caller.

Change-Id: I2fe29bfef08938b8a2eb182475c0705c14d8d84f
2014-10-13 17:52:32 -07:00
Colin Cross
c15dd04470 processgroup: close directories opened by removeAllProcessGroups()
removeAllProcessGroups and removeUidProcessGroups were calling
opendir, but never called closedir.  This would leave a leaked
file descriptor for every /acct/uid_* directory that existed
at boot.

Change-Id: Ia08eccd42d6ad7a6c1c78402519ac2e53b4fc83a
2014-08-20 14:11:13 -07:00
Colin Cross
cf8d1c22f7 Add libprocessgroup
libprocessgroup will allow Zygote to place processes
in a cgroup, and then kill the process and all forked processes
later.  lmkd will also kill all forked processes.

Bug: 15313911
Change-Id: I20404d0dbe448f1c475d2f4c61cccca462f9e544
2014-07-09 17:24:39 -07:00