From owner-p4-projects@FreeBSD.ORG Sat Apr 12 16:33:04 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1AA921065671; Sat, 12 Apr 2008 16:33:04 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D017D106566C for ; Sat, 12 Apr 2008 16:33:03 +0000 (UTC) (envelope-from alm@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id B65B48FC13 for ; Sat, 12 Apr 2008 16:33:03 +0000 (UTC) (envelope-from alm@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m3CGX3sI082291 for ; Sat, 12 Apr 2008 16:33:03 GMT (envelope-from alm@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m3CGX3LM082289 for perforce@freebsd.org; Sat, 12 Apr 2008 16:33:03 GMT (envelope-from alm@freebsd.org) Date: Sat, 12 Apr 2008 16:33:03 GMT Message-Id: <200804121633.m3CGX3LM082289@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to alm@freebsd.org using -f From: Aaron Meihm To: Perforce Change Reviews Cc: Subject: PERFORCE change 139907 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Apr 2008 16:33:04 -0000 http://perforce.freebsd.org/chv.cgi?CH=139907 Change 139907 by alm@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);