On ARM, sizeof(struct smack_master_list) == 12. Allocation by kmalloc() uses a32-byte-long chunk to allocate 12 bytes. Just ask ksize(). It means that 63%of memory is simply wasted for padding bytes.
The problem is fixed in this patch by using kmem_cache. The cache allocatesstruct smack_master_list using 16-byte-long chunks according to ksize(). Thisreduces amount of used memory by 50%.
Change-Id: I61562995c68f63e5e728656c4af7732ece403bf4
Signed-off-by: jooseong.lee <jooseong.lee@samsung.com>
struct smack_audit_data sad;
#endif
};
+
+struct smack_master_list {
+ struct list_head list;
+ struct smack_rule *smk_rule;
+};
+
/*
* These functions are in smack_lsm.c
*/
/* Cache for fast and thrifty allocations */
extern struct kmem_cache *smack_rule_cache;
+extern struct kmem_cache *smack_master_list_cache;
extern struct security_operations smack_ops;
/* KMEM caches for fast and thrifty allocations */
struct kmem_cache *smack_rule_cache;
+struct kmem_cache *smack_master_list_cache;
/**
* smack_init - initialize the smack system
if (!smack_rule_cache)
return -ENOMEM;
+ smack_master_list_cache = KMEM_CACHE(smack_master_list, 0);
+ if (!smack_master_list_cache) {
+ kmem_cache_destroy(smack_rule_cache);
+ return -ENOMEM;
+ }
+
tsp = new_task_smack(&smack_known_floor, &smack_known_floor,
GFP_KERNEL);
if (tsp == NULL) {
+ kmem_cache_destroy(smack_master_list_cache);
kmem_cache_destroy(smack_rule_cache);
return -ENOMEM;
}
* Rule lists are maintained for each label.
* This master list is just for reading /smack/load and /smack/load2.
*/
-struct smack_master_list {
- struct list_head list;
- struct smack_rule *smk_rule;
-};
-
LIST_HEAD(smack_rule_list);
struct smack_parsed_rule {
* it needs to get added for reporting.
*/
if (global) {
- smlp = kzalloc(sizeof(*smlp), GFP_KERNEL);
+ smlp = kmem_cache_zalloc(smack_master_list_cache,
+ GFP_KERNEL);
if (smlp != NULL) {
smlp->smk_rule = sp;
list_add_rcu(&smlp->list, &smack_rule_list);