[CRIU] [PATCH v1 12/17] rst: Implement rst_mem_free_last_bytes()
Kirill Tkhai
ktkhai at virtuozzo.com
Thu Jan 12 09:54:04 PST 2017
Function for freeing a part of lastly allocated memory hunk.
It will be used in next patches.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/include/rst-malloc.h | 1 +
criu/rst-malloc.c | 16 ++++++++++++----
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/criu/include/rst-malloc.h b/criu/include/rst-malloc.h
index 67391ba77..d885ff101 100644
--- a/criu/include/rst-malloc.h
+++ b/criu/include/rst-malloc.h
@@ -63,6 +63,7 @@ extern void *rst_mem_remap_ptr(unsigned long pos, int type);
*/
extern void *rst_mem_alloc(unsigned long size, int type);
extern void rst_mem_free_last(int type);
+extern void rst_mem_free_last_bytes(int type, unsigned long bytes);
/* Word-align the current freelist pointer for the next allocation. If we don't
* align pointers, some futex and atomic operations can fail.
diff --git a/criu/rst-malloc.c b/criu/rst-malloc.c
index 4f7357ca2..d72f2a095 100644
--- a/criu/rst-malloc.c
+++ b/criu/rst-malloc.c
@@ -184,15 +184,23 @@ void *rst_mem_alloc(unsigned long size, int type)
return ret;
}
-void rst_mem_free_last(int type)
+void rst_mem_free_last_bytes(int type, unsigned long bytes)
{
struct rst_mem_type_s *t = &rst_mems[type];
BUG_ON(!t->enabled);
+ BUG_ON(bytes > t->last);
+
+ t->free_mem -= bytes;
+ t->free_bytes += bytes;
+ t->last -= bytes;
+}
+
+void rst_mem_free_last(int type)
+{
+ struct rst_mem_type_s *t = &rst_mems[type];
- t->free_mem -= t->last;
- t->free_bytes += t->last;
- t->last = 0; /* next free_last would be no-op */
+ return rst_mem_free_last_bytes(type, t->last);
}
unsigned long rst_mem_lock(void)
More information about the CRIU
mailing list