]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: chunk: inline alloc_trash_chunk()
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Aug 2022 08:45:22 +0000 (10:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 Aug 2022 08:45:22 +0000 (10:45 +0200)
This function is responsible for all calls to pool_alloc(trash), whose
total size can be huge. As such it's quite a pain that it doesn't provide
more hints about its users. However, since the function is tiny, it fully
makes sense to inline it, the code is less than 0.1% larger with this.
This way we can now detect where the callers are via "show profiling",
e.g.:

       0 1953671           0 32071463136| 0x59960f main+0x10676f p_free(-16416) [pool=trash]
       0       1           0       16416| 0x59960f main+0x10676f p_free(-16416) [pool=trash]
 1953672       0 32071479552           0| 0x599561 main+0x1066c1 p_alloc(16416) [pool=trash]
       0  976835           0 16035723360| 0x576ca7 http_reply_to_htx+0x447/0x920 p_free(-16416) [pool=trash]
       0       1           0       16416| 0x576ca7 http_reply_to_htx+0x447/0x920 p_free(-16416) [pool=trash]
  976835       0 16035723360           0| 0x576a5d http_reply_to_htx+0x1fd/0x920 p_alloc(16416) [pool=trash]
       1       0       16416           0| 0x576a5d http_reply_to_htx+0x1fd/0x920 p_alloc(16416) [pool=trash]

include/haproxy/chunk.h
src/chunk.c

index b5d515170e7a8735af6de187609f0888072f07d4..43c7270ad429b0c1cf9b497f665207e9426f9bdb 100644 (file)
@@ -46,18 +46,8 @@ int chunk_asciiencode(struct buffer *dst, struct buffer *src, char qc);
 int chunk_strcmp(const struct buffer *chk, const char *str);
 int chunk_strcasecmp(const struct buffer *chk, const char *str);
 struct buffer *get_trash_chunk(void);
-struct buffer *alloc_trash_chunk(void);
 int init_trash_buffers(int first);
 
-/*
- * free a trash chunk allocated by alloc_trash_chunk(). NOP on NULL.
- */
-static inline void free_trash_chunk(struct buffer *chunk)
-{
-       pool_free(pool_head_trash, chunk);
-}
-
-
 static inline void chunk_reset(struct buffer *chk)
 {
        chk->data  = 0;
@@ -96,6 +86,34 @@ static inline void chunk_initstr(struct buffer *chk, const char *str)
        chk->size = 0;                  /* mark it read-only */
 }
 
+/*
+ * Allocate a trash chunk from the reentrant pool. The buffer starts at the
+ * end of the chunk. This chunk must be freed using free_trash_chunk(). This
+ * call may fail and the caller is responsible for checking that the returned
+ * pointer is not NULL.
+ */
+static forceinline struct buffer *alloc_trash_chunk(void)
+{
+       struct buffer *chunk;
+
+       chunk = pool_alloc(pool_head_trash);
+       if (chunk) {
+               char *buf = (char *)chunk + sizeof(struct buffer);
+               *buf = 0;
+               chunk_init(chunk, buf,
+                          pool_head_trash->size - sizeof(struct buffer));
+       }
+       return chunk;
+}
+
+/*
+ * free a trash chunk allocated by alloc_trash_chunk(). NOP on NULL.
+ */
+static forceinline void free_trash_chunk(struct buffer *chunk)
+{
+       pool_free(pool_head_trash, chunk);
+}
+
 /* copies chunk <src> into <chk>. Returns 0 in case of failure. */
 static inline int chunk_cpy(struct buffer *chk, const struct buffer *src)
 {
index d67e9f1d27e200cdb08b7fe80bae4c38a578bfc4..2d24fa596d36a4018c118e6d72a1ff7c107fa7e5 100644 (file)
@@ -98,26 +98,6 @@ int init_trash_buffers(int first)
        return 1;
 }
 
-/*
- * Allocate a trash chunk from the reentrant pool. The buffer starts at the
- * end of the chunk. This chunk must be freed using free_trash_chunk(). This
- * call may fail and the caller is responsible for checking that the returned
- * pointer is not NULL.
- */
-struct buffer *alloc_trash_chunk(void)
-{
-       struct buffer *chunk;
-
-       chunk = pool_alloc(pool_head_trash);
-       if (chunk) {
-               char *buf = (char *)chunk + sizeof(struct buffer);
-               *buf = 0;
-               chunk_init(chunk, buf,
-                          pool_head_trash->size - sizeof(struct buffer));
-       }
-       return chunk;
-}
-
 /*
  * Does an snprintf() at the beginning of chunk <chk>, respecting the limit of
  * at most chk->size chars. If the chk->len is over, nothing is added. Returns