Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OpenLDAP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
James Lowden
OpenLDAP
Commits
91628f0c
Commit
91628f0c
authored
15 years ago
by
Hallvard Furuseth
Committed by
Quanah Gibson-Mount
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add comments
parent
5360e660
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
servers/slapd/sl_malloc.c
+44
-9
44 additions, 9 deletions
servers/slapd/sl_malloc.c
with
44 additions
and
9 deletions
servers/slapd/sl_malloc.c
+
44
−
9
View file @
91628f0c
...
@@ -21,6 +21,41 @@
...
@@ -21,6 +21,41 @@
#include
"slap.h"
#include
"slap.h"
/*
* This allocator returns temporary memory from a slab in a given memory
* context, aligned on a 2-int boundary. It cannot be used for data
* which will outlive the task allocating it.
*
* A new memory context attaches to the creator's thread context, if any.
* Threads cannot use other threads' memory contexts; there are no locks.
*
* The caller of slap_sl_malloc, usually a thread pool task, must
* slap_sl_free the memory before finishing: New tasks reuse the context
* and normally reset it, reclaiming memory left over from last task.
*
* The allocator helps memory fragmentation, speed and memory leaks.
* It is not (yet) reliable as a garbage collector:
*
* It falls back to context NULL - plain ber_memalloc() - when the
* context's slab is full. A reset does not reclaim such memory.
* Conversely, free/realloc of data not from the given context assumes
* context NULL. The data must not belong to another memory context.
*
* Code which has lost track of the current memory context can try
* slap_sl_context() or ch_malloc.c:ch_free/ch_realloc().
*
* Allocations cannot yet return failure. Like ch_malloc, they succeed
* or abort slapd. This will change, do fix code which assumes success.
*/
/*
* The stack-based allocator stores (ber_len_t)sizeof(head+block) at
* the head and tail of each allocated block. The tail length of a freed
* block is ORed with 1 to mark it free. Freed blocks are only reclaimed
* from the last block forward. This is fast, but when a block is never
* freed, older blocks will not be reclaimed until the slab is reset...
*/
enum
{
enum
{
Align
=
2
*
sizeof
(
int
),
Align
=
2
*
sizeof
(
int
),
Align_log2
=
1
+
(
Align
>
2
)
+
(
Align
>
4
)
+
(
Align
>
8
)
+
(
Align
>
16
),
Align_log2
=
1
+
(
Align
>
2
)
+
(
Align
>
4
)
+
(
Align
>
8
)
+
(
Align
>
16
),
...
@@ -108,14 +143,7 @@ slap_sl_mem_init()
...
@@ -108,14 +143,7 @@ slap_sl_mem_init()
ber_set_option
(
NULL
,
LBER_OPT_MEMORY_FNS
,
&
slap_sl_mfuncs
);
ber_set_option
(
NULL
,
LBER_OPT_MEMORY_FNS
,
&
slap_sl_mfuncs
);
}
}
/* This allocator always returns memory aligned on a 2-int boundary.
/* Create, reset or just return the memory context of the current thread. */
*
* The stack-based allocator stores the size as a ber_len_t at both
* the head and tail of the allocated block. When freeing a block, the
* tail length is ORed with 1 to mark it as free. Freed space can only
* be reclaimed from the tail forward. If the tail block is never freed,
* nothing else will be reclaimed until the slab is reset...
*/
void
*
void
*
slap_sl_mem_create
(
slap_sl_mem_create
(
ber_len_t
size
,
ber_len_t
size
,
...
@@ -202,13 +230,16 @@ slap_sl_mem_create(
...
@@ -202,13 +230,16 @@ slap_sl_mem_create(
return
sh
;
return
sh
;
}
}
/*
* Separate memory context from thread context. Future users must
* know the context, since ch_free/slap_sl_context() cannot find it.
*/
void
void
slap_sl_mem_detach
(
slap_sl_mem_detach
(
void
*
thrctx
,
void
*
thrctx
,
void
*
memctx
void
*
memctx
)
)
{
{
/* separate from context */
SET_MEMCTX
(
thrctx
,
NULL
,
0
);
SET_MEMCTX
(
thrctx
,
NULL
,
0
);
}
}
...
@@ -578,6 +609,10 @@ slap_sl_free(void *ptr, void *ctx)
...
@@ -578,6 +609,10 @@ slap_sl_free(void *ptr, void *ctx)
}
}
}
}
/*
* Return the memory context of the current thread if the given block of
* memory belongs to it, otherwise return NULL.
*/
void
*
void
*
slap_sl_context
(
void
*
ptr
)
slap_sl_context
(
void
*
ptr
)
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment