From: jooseong.lee Date: Mon, 23 Mar 2015 15:09:14 +0000 (+0900) Subject: security: smack: add kmem_cache for smack_rule allocations X-Git-Tag: TizenStudio_2.0_p2.3.1~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5de52d91ed2d2015d8d6fa8c40689f4db8f5152;p=sdk%2Femulator%2Femulator-kernel.git security: smack: add kmem_cache for smack_rule allocations On ARM, sizeof(struct smack_rule)==20. Allocation by kmalloc() uses a32-byte-long chunk to allocate 20 bytes. Just ask ksize(). It means that 40%of memory is simply wasted for padding bytes. The problem is fixed in this patch by using kmem_cache. The cache allocatesstruct smack_rule using 24-byte-long chunks according to ksize(). This reducesamount of used memory by 25%. Change-Id: I0fc3d58b6ff96eab74bf24041d4872bf9e70ca4b Signed-off-by: jooseong.lee --- diff --git a/security/smack/smack.h b/security/smack/smack.h index 020307ef0972..45aa224b91ae 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h @@ -266,6 +266,9 @@ extern struct mutex smack_known_lock; extern struct list_head smack_known_list; extern struct list_head smk_netlbladdr_list; +/* Cache for fast and thrifty allocations */ +extern struct kmem_cache *smack_rule_cache; + extern struct security_operations smack_ops; #define SMACK_HASH_SLOTS 16 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 4b5515ec8620..523e106a274c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4016,6 +4016,9 @@ static __init void init_smack_known_list(void) smk_insert_entry(&smack_known_web); } +/* KMEM caches for fast and thrifty allocations */ +struct kmem_cache *smack_rule_cache; + /** * smack_init - initialize the smack system * @@ -4029,10 +4032,16 @@ static __init int smack_init(void) if (!security_module_enable(&smack_ops)) return 0; + smack_rule_cache = KMEM_CACHE(smack_rule, 0); + if (!smack_rule_cache) + return -ENOMEM; + tsp = new_task_smack(&smack_known_floor, &smack_known_floor, GFP_KERNEL); - if (tsp == NULL) + if (tsp == NULL) { + kmem_cache_destroy(smack_rule_cache); return -ENOMEM; + } printk(KERN_INFO "Smack: Initializing.\n"); diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index 32b248820840..e602a34bf7e1 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -235,7 +235,7 @@ static int smk_set_access(struct smack_parsed_rule *srp, } if (found == 0) { - sp = kzalloc(sizeof(*sp), GFP_KERNEL); + sp = kmem_cache_zalloc(smack_rule_cache, GFP_KERNEL); if (sp == NULL) { rc = -ENOMEM; goto out;