[haiku-commits] haiku: hrev53241 - src/system/kernel/cache

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 11 Jul 2019 22:00:31 -0400 (EDT)

hrev53241 adds 2 changesets to branch 'master'
old head: c91c69752b218144046d9164d85a8699baa95b80
new head: 0e6ece91c81de4bb1056c4743c09d40d6106c4a1
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=0e6ece91c81d+%5Ec91c69752b21

----------------------------------------------------------------------------

7a2f74485957: block_cache: Free up blocks more aggressively on low memory 
conditions.
  
  Only keep a single block when there is a "critical" low resource state.
  Also don't bother doing anything if there are no unused blocks.
  
  Change-Id: Ibfcbd8cb0beb1446083ca83030ea8e81c59a9628
  Reviewed-on: https://review.haiku-os.org/c/1576
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

0e6ece91c81d: block_cache: Use an object_cache for the cache_notifications.
  
  cache_listeners are (following packagefs changes) the second-most
  allocated object during the boot process, with 20799 on a
  *minimum* image. Since they are used so extensively in BFS I/O,
  making them object_cached for both performance and memory reasons
  seems to make a lot of sense.
  
  Change-Id: I6ef6c3e811c0c4189fea45ee7920131796c9e7c8
  Reviewed-on: https://review.haiku-os.org/c/1577
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
  Reviewed-by: Stephan Aßmus <superstippi@xxxxxx>

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

1 file changed, 47 insertions(+), 16 deletions(-)
src/system/kernel/cache/block_cache.cpp | 63 +++++++++++++++++++++--------

############################################################################

Commit:      7a2f7448595773c88896637de698592a535b399d
URL:         https://git.haiku-os.org/haiku/commit/?id=7a2f74485957
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Wed Jul 10 22:43:40 2019 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Fri Jul 12 02:00:27 2019 UTC

block_cache: Free up blocks more aggressively on low memory conditions.

Only keep a single block when there is a "critical" low resource state.
Also don't bother doing anything if there are no unused blocks.

Change-Id: Ibfcbd8cb0beb1446083ca83030ea8e81c59a9628
Reviewed-on: https://review.haiku-os.org/c/1576
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/system/kernel/cache/block_cache.cpp 
b/src/system/kernel/cache/block_cache.cpp
index 5d76a79d10..a81b9c2476 100644
--- a/src/system/kernel/cache/block_cache.cpp
+++ b/src/system/kernel/cache/block_cache.cpp
@@ -1598,21 +1598,24 @@ block_cache::_LowMemoryHandler(void* data, uint32 
resources, int32 level)
        // (if there is enough memory left, we don't free any)
 
        block_cache* cache = (block_cache*)data;
+       if (cache->unused_block_count <= 1)
+               return;
+
        int32 free = 0;
        int32 secondsOld = 0;
        switch (level) {
                case B_NO_LOW_RESOURCE:
                        return;
                case B_LOW_RESOURCE_NOTE:
-                       free = cache->unused_block_count / 8;
+                       free = cache->unused_block_count / 4;
                        secondsOld = 120;
                        break;
                case B_LOW_RESOURCE_WARNING:
-                       free = cache->unused_block_count / 4;
+                       free = cache->unused_block_count / 2;
                        secondsOld = 10;
                        break;
                case B_LOW_RESOURCE_CRITICAL:
-                       free = cache->unused_block_count / 2;
+                       free = cache->unused_block_count - 1;
                        secondsOld = 0;
                        break;
        }

############################################################################

Revision:    hrev53241
Commit:      0e6ece91c81de4bb1056c4743c09d40d6106c4a1
URL:         https://git.haiku-os.org/haiku/commit/?id=0e6ece91c81d
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Wed Jul 10 23:21:14 2019 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Fri Jul 12 02:00:27 2019 UTC

block_cache: Use an object_cache for the cache_notifications.

cache_listeners are (following packagefs changes) the second-most
allocated object during the boot process, with 20799 on a
*minimum* image. Since they are used so extensively in BFS I/O,
making them object_cached for both performance and memory reasons
seems to make a lot of sense.

Change-Id: I6ef6c3e811c0c4189fea45ee7920131796c9e7c8
Reviewed-on: https://review.haiku-os.org/c/1577
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
Reviewed-by: Stephan Aßmus <superstippi@xxxxxx>

----------------------------------------------------------------------------

diff --git a/src/system/kernel/cache/block_cache.cpp 
b/src/system/kernel/cache/block_cache.cpp
index a81b9c2476..37147582ca 100644
--- a/src/system/kernel/cache/block_cache.cpp
+++ b/src/system/kernel/cache/block_cache.cpp
@@ -114,6 +114,9 @@ typedef DoublyLinkedList<cached_block,
                &cached_block::link> > block_list;
 
 struct cache_notification : DoublyLinkedListLinkImpl<cache_notification> {
+       static inline void* operator new(size_t size);
+       static inline void operator delete(void* block);
+
        int32                   transaction_id;
        int32                   events_pending;
        int32                   events;
@@ -124,6 +127,38 @@ struct cache_notification : 
DoublyLinkedListLinkImpl<cache_notification> {
 
 typedef DoublyLinkedList<cache_notification> NotificationList;
 
+static object_cache* sCacheNotificationCache;
+
+struct cache_listener;
+typedef DoublyLinkedListLink<cache_listener> listener_link;
+
+struct cache_listener : cache_notification {
+       listener_link   link;
+};
+
+typedef DoublyLinkedList<cache_listener,
+       DoublyLinkedListMemberGetLink<cache_listener,
+               &cache_listener::link> > ListenerList;
+
+void*
+cache_notification::operator new(size_t size)
+{
+       // We can't really know whether something is a cache_notification or a
+       // cache_listener at runtime, so we just use one object_cache for both
+       // with the size set to that of the (slightly larger) cache_listener.
+       // In practice, the vast majority of cache_notifications are really
+       // cache_listeners, so this is a more than acceptable trade-off.
+       ASSERT(size <= sizeof(cache_listener));
+       return object_cache_alloc(sCacheNotificationCache, 0);
+}
+
+void
+cache_notification::operator delete(void* block)
+{
+       object_cache_free(sCacheNotificationCache, block, 0);
+}
+
+
 struct BlockHash {
        typedef off_t                   KeyType;
        typedef cached_block    ValueType;
@@ -219,18 +254,6 @@ private:
        cached_block*   _GetUnusedBlock();
 };
 
-struct cache_listener;
-typedef DoublyLinkedListLink<cache_listener> listener_link;
-
-struct cache_listener : cache_notification {
-       listener_link   link;
-};
-
-typedef DoublyLinkedList<cache_listener,
-       DoublyLinkedListMemberGetLink<cache_listener,
-               &cache_listener::link> > ListenerList;
-
-
 struct cache_transaction {
        cache_transaction();
 
@@ -963,7 +986,7 @@ add_transaction_listener(block_cache* cache, 
cache_transaction* transaction,
                }
        }
 
-       cache_listener* listener = new(std::nothrow) cache_listener;
+       cache_listener* listener = new cache_listener;
        if (listener == NULL)
                return B_NO_MEMORY;
 
@@ -2662,6 +2685,11 @@ block_cache_init(void)
        if (sBlockCache == NULL)
                return B_NO_MEMORY;
 
+       sCacheNotificationCache = create_object_cache("cache notifications",
+               sizeof(cache_listener), 8, NULL, NULL, NULL);
+       if (sCacheNotificationCache == NULL)
+               return B_NO_MEMORY;
+
        new (&sCaches) DoublyLinkedList<block_cache>;
                // manually call constructor
 


Other related posts:

  • » [haiku-commits] haiku: hrev53241 - src/system/kernel/cache - waddlesplash