diff options
| -rw-r--r-- | debian/patches/libports-reduce-overhead.patch | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/debian/patches/libports-reduce-overhead.patch b/debian/patches/libports-reduce-overhead.patch index 624e2672..968673ba 100644 --- a/debian/patches/libports-reduce-overhead.patch +++ b/debian/patches/libports-reduce-overhead.patch @@ -1,4 +1,4 @@ -commit a7c6b5d7b1b669355439361a2a8eecf52dc78538 +commit 97737d1ee3ce95e45a1a4aa636cc2e11a106a9f5 Author: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sat Apr 26 12:20:20 2014 +0200 @@ -14,20 +14,23 @@ Date: Sat Apr 26 12:20:20 2014 +0200 _ports_bucket_class_iterate implements both ports_bucket_iterate and ports_class_iterate. For this change might make ports_class_iterate less efficient memory-wise if the number of ports belonging to the - class is low with respect to the number of ports in the bucket. - However, the array representation is more compact. Furthermore a - survey of the Hurd code revealed that ports_class_iterate is rarely - used, while ports_bucket_iterate is used more often, most prominently - in paging code. + class is low with respect to the number of ports in the bucket. If + this happens, we allocate too much. Alleviate this by releasing + unused memory. + + On the other hand, the array representation is more compact. + Furthermore a survey of the Hurd code revealed that + ports_class_iterate is rarely used, while ports_bucket_iterate is used + more often, most prominently in paging code. * libports/bucket-iterate.c (_ports_bucket_class_iterate): Use an array instead of a linked list. diff --git a/libports/bucket-iterate.c b/libports/bucket-iterate.c -index dc1c7b1..8e6bdc4 100644 +index dc1c7b1..498cf13 100644 --- a/libports/bucket-iterate.c +++ b/libports/bucket-iterate.c -@@ -31,40 +31,45 @@ _ports_bucket_class_iterate (struct port_bucket *bucket, +@@ -31,40 +31,54 @@ _ports_bucket_class_iterate (struct port_bucket *bucket, { /* This is obscenely ineffecient. ihash and ports need to cooperate more closely to do it efficiently. */ @@ -38,7 +41,7 @@ index dc1c7b1..8e6bdc4 100644 - } *list = 0; - struct item *i, *nxt; + void **p; -+ size_t i, n; ++ size_t i, n, nr_items; error_t err; pthread_mutex_lock (&_ports_lock); @@ -49,7 +52,8 @@ index dc1c7b1..8e6bdc4 100644 + return 0; + } + -+ p = malloc (bucket->htable.nr_items * sizeof *p); ++ nr_items = bucket->htable.nr_items; ++ p = malloc (nr_items * sizeof *p); + if (p == NULL) + return ENOMEM; + @@ -72,6 +76,14 @@ index dc1c7b1..8e6bdc4 100644 } pthread_mutex_unlock (&_ports_lock); ++ if (n != nr_items) ++ { ++ /* We allocated too much. Release unused memory. */ ++ void **new = realloc (p, n * sizeof *p); ++ if (new) ++ p = new; ++ } ++ err = 0; - for (i = list; i; i = nxt) + for (i = 0; i < n; i++) |
