Linux kernel warns on the cgroup controller name length greater than
32 bytes during the cgroup initialization in cgroup_init_early(). Adopt
the same size of 32 bytes (including the null byte) for controller name
in the struct cg_controller and struct cg_mount_table_s. This resize
from FILENAME_MAX (4096 bytes) to a mere 32 bytes, reduces the
libcgroup.so library:
Without the patch:
------------------
$ size -d src/.libs/libcgroup.so
text data bss dec hex filename
123841 3600
2476532 2603973 27bbc5 src/.libs/libcgroup.so
With the patch:
---------------
$ size -d src/.libs/libcgroup.so
text data bss dec hex filename
123569 3600
1257332 1384501 152035 src/.libs/libcgroup.so
also replace the index FILENAME_MAX with CONTROL_NAMELEN_MAX at the
struct cg_controller::name and struct cg_mount_table_s::name references.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
{
int i = *mnt_tbl_idx;
- strncpy(cg_mount_table[i].name, name, FILENAME_MAX);
- cg_mount_table[i].name[FILENAME_MAX-1] = '\0';
+ strncpy(cg_mount_table[i].name, name, CONTROL_NAMELEN_MAX);
+ cg_mount_table[i].name[CONTROL_NAMELEN_MAX-1] = '\0';
strncpy(cg_mount_table[i].mount.path, mount_path, FILENAME_MAX);
cg_mount_table[i].mount.path[FILENAME_MAX-1] = '\0';
if (!dst || !src)
return ECGFAIL;
- strncpy(dst->name, src->name, FILENAME_MAX);
+ strncpy(dst->name, src->name, CONTROL_NAMELEN_MAX);
for (i = 0; i < src->index; i++, dst->index++) {
struct control_value *src_val = src->values[i];
struct control_value *dst_val;
*/
#define CG_HIER_MAX CG_CONTROLLER_MAX
+/* Maximum length of a controller's name */
+#define CONTROL_NAMELEN_MAX 32
+
/* Definitions for the uid and gid members of a cgroup_rules */
#define CGRULE_INVALID ((uid_t) -1)
#define CGRULE_WILD ((uid_t) -2)
};
struct cgroup_controller {
- char name[FILENAME_MAX];
+ char name[CONTROL_NAMELEN_MAX];
struct control_value *values[CG_NV_MAX];
struct cgroup *cgroup;
int index;
struct cg_mount_table_s {
/** Controller name. */
- char name[FILENAME_MAX];
+ char name[CONTROL_NAMELEN_MAX];
/**
* List of mount points, at least one mount point is there for sure.
*/