[Asterisk-code-review] astobj2: Reduce memory overhead. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Mon Oct 1 09:07:08 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/10310 )

Change subject: astobj2: Reduce memory overhead.
......................................................................

astobj2: Reduce memory overhead.

Reduce options to 2-bit field, magic to 30 bit field.  Move ref_counter
next to options the fields will pack.

This reduces memory overhead for every ao2 object by 8 bytes on x86_64.

Change-Id: Idc1baabb35ec3b3d8de463c4fa3011eaf7fcafb5
---
M main/astobj2.c
1 file changed, 6 insertions(+), 5 deletions(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/main/astobj2.c b/main/astobj2.c
index 147df7a..741bb64 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -50,20 +50,21 @@
  * The magic number is used for consistency check.
  */
 struct __priv_data {
-	int ref_counter;
 	ao2_destructor_fn destructor_fn;
 #if defined(AO2_DEBUG)
 	/*! User data size for stats */
 	size_t data_size;
 #endif
+	/*! Number of references held for this object */
+	int ref_counter;
 	/*! The ao2 object option flags */
-	uint32_t options;
+	uint32_t options:2;
 	/*! magic number.  This is used to verify that a pointer passed in is a
 	 *  valid astobj2 */
-	uint32_t magic;
+	uint32_t magic:30;
 };
 
-#define	AO2_MAGIC	0xa570b123
+#define	AO2_MAGIC	0x3a70b123
 
 /*!
  * What an astobj2 object looks like: fixed-size private data
@@ -583,8 +584,8 @@
 	}
 
 	/* Initialize common ao2 values. */
-	obj->priv_data.ref_counter = 1;
 	obj->priv_data.destructor_fn = destructor_fn;	/* can be NULL */
+	obj->priv_data.ref_counter = 1;
 	obj->priv_data.options = options;
 	obj->priv_data.magic = AO2_MAGIC;
 

-- 
To view, visit https://gerrit.asterisk.org/10310
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Idc1baabb35ec3b3d8de463c4fa3011eaf7fcafb5
Gerrit-Change-Number: 10310
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181001/96e6837f/attachment.html>


More information about the asterisk-code-review mailing list