[or-cvs] r10953: Weasel noticed that many buffers spend their time with empty (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Fri Jul 27 23:19:03 UTC 2007


Author: nickm
Date: 2007-07-27 19:19:02 -0400 (Fri, 27 Jul 2007)
New Revision: 10953

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/buffers.c
Log:
 r13952 at catbus:  nickm | 2007-07-27 19:18:46 -0400
 Weasel noticed that many buffers spend their time with empty 4k, 8k, and 16k memory chunks.  Thus, be more aggressive about putting empty chunks on the freelist, regardless of their high water marks.  (Also, run buffer_shrink_freelist on the 8k-chunk freelist.)



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r13952] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-07-27 23:18:58 UTC (rev 10952)
+++ tor/trunk/ChangeLog	2007-07-27 23:19:02 UTC (rev 10953)
@@ -40,6 +40,10 @@
     - Merge in some (as-yet-unused) IPv6 address manipulation code. (Patch
       from croup.)
 
+  o Performance improvements:
+    - Be more aggressive with freeing buffer RAM or putting it on the
+      free lists.
+
   o Performance improvements (win32):
     - Use Critical Sections rather than Mutexes for synchronizing threads
       on win32; Mutexes are heavier-weight, and designed for synchronizing

Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c	2007-07-27 23:18:58 UTC (rev 10952)
+++ tor/trunk/src/or/buffers.c	2007-07-27 23:19:02 UTC (rev 10953)
@@ -281,9 +281,9 @@
 void
 buf_shrink_freelists(int free_all)
 {
-  int j;
-  for (j = 0; j < 2; ++j) {
-    free_mem_list_t *list = j ? &free_mem_list_16k : &free_mem_list_4k;
+  int list_elt_size;
+  for (list_elt_size = 4096; list_elt_size <= 16384; list_elt_size *= 2) {
+    free_mem_list_t *list = get_free_mem_list(list_elt_size);
     if (list->lowwater > list->slack || free_all) {
       int i, n_to_skip, n_to_free;
       char **ptr;
@@ -452,8 +452,16 @@
   size_t new_len;
 
   new_len = buf->len;
-  if (buf->datalen == 0 && buf->highwater == 0 &&
+  /* Actually, we ignore highwater here if we're going to throw it on the
+   * freelist, since it's way cheaper to use the freelist than to use (some)
+   * platform mallocs.
+   *
+   * DOCDOC If it turns out to be a good idea, add it to the doxygen for this
+   * function.
+   */
+  if (buf->datalen == 0 && // buf->highwater == 0 &&
       IS_FREELIST_SIZE(buf->len)) {
+    buf->highwater = 0;
     if (add_buf_mem_to_freelist(buf))
       return;
   }



More information about the tor-commits mailing list