PERFORCE change 139907 for review

Aaron Meihm alm at FreeBSD.org
Sat Apr 12 16:33:04 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=139907

Change 139907 by alm at alm_praetorian on 2008/04/12 16:32:26

	In most cases we will have a 1:1 relationship between source and
	destination components.  We reference count usage of the audit
	record to avoid an extra copy.  This may be built upon to avoid
	copies altogether.

Affected files ...

.. //depot/projects/trustedbsd/netauditd/netauditd.h#14 edit
.. //depot/projects/trustedbsd/netauditd/reader.c#4 edit

Differences ...

==== //depot/projects/trustedbsd/netauditd/netauditd.h#14 (text+ko) ====

@@ -37,6 +37,7 @@
 
 struct audit_record {
 	void			*ar_buf;
+	int			ar_count;
 	u_int32_t		ar_record_len;
 };
 

==== //depot/projects/trustedbsd/netauditd/reader.c#4 (text+ko) ====

@@ -212,9 +212,6 @@
 
 	for (i = 0; i < ac->ac_ndsts; i++)
 		reader_q_record_cmpnt(ar, ac->ac_dsts[i]);
-	/* Once we have copied the record to all this components consumers
-	 * we can discard it. */
-	free(ar->ar_buf);
 	free(ar);
 }
 
@@ -226,9 +223,20 @@
 	new = malloc(sizeof(struct au_queue_ent));
 	assert(new != NULL);
 	bzero(new, sizeof(struct au_queue_ent));
-	new->aq_record.ar_buf = malloc(ar->ar_record_len);
-	assert(new->aq_record.ar_buf != NULL);
-	bcopy(ar->ar_buf, new->aq_record.ar_buf, ar->ar_record_len);
+	/*
+	 * In most cases we will have a 1:1 relationship between source
+	 * and destination components.  We avoid an extra copy by reference
+	 * counting usage of this audit record.  This may be built on to
+	 * avoid copying altogether.
+	 */
+	if (ar->ar_count == 0)
+		new->aq_record.ar_buf = ar->ar_buf;
+	else {
+		new->aq_record.ar_buf = malloc(ar->ar_record_len);
+		assert(new->aq_record.ar_buf != NULL);
+		bcopy(ar->ar_buf, new->aq_record.ar_buf, ar->ar_record_len);
+	}
+	ar->ar_count++;
 	new->aq_record.ar_record_len = ar->ar_record_len;
 	new->aq_remain = ar->ar_record_len;
 	(void) pthread_mutex_lock(&ac->ac_q.qp_lock);


More information about the p4-projects mailing list