summaryrefslogtreecommitdiff
path: root/cesar/lib
diff options
context:
space:
mode:
authorlaranjeiro2010-01-29 12:46:34 +0000
committerlaranjeiro2010-01-29 12:46:34 +0000
commit4678d637e94f0eac7771dc93fcb47a880775b3f0 (patch)
tree2a9ddb8c165216079024c74aaa6eea4fea78fde7 /cesar/lib
parenta43b1e8aef794bc95f173da8658818ef19011e3d (diff)
cesar/lib: add a slack for memory block critical number
blk_slack return true if enough memory is available, if the slack is reached this function will return false. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6666 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/lib')
-rw-r--r--cesar/lib/Config1
-rw-r--r--cesar/lib/blk.h17
-rw-r--r--cesar/lib/src/blk.c5
-rw-r--r--cesar/lib/test/blk/Config1
-rw-r--r--cesar/lib/test/blk/src/test_blk.c27
5 files changed, 51 insertions, 0 deletions
diff --git a/cesar/lib/Config b/cesar/lib/Config
index d4b2ec6c71..3ff916a522 100644
--- a/cesar/lib/Config
+++ b/cesar/lib/Config
@@ -5,6 +5,7 @@ CONFIG_DEBUG_MORE = n
CONFIG_DEBUG_FATAL_CATCH = n
CONFIG_BLAME = n
CONFIG_BLK_NB = 1024
+CONFIG_BLK_SLACK = 0
CONFIG_HEAP_SKEW = y
CONFIG_HEAP_LEFTIST = n
CONFIG_RND_BUFFER_OPTIMISE = n
diff --git a/cesar/lib/blk.h b/cesar/lib/blk.h
index 8d2817a0f7..3e207d7417 100644
--- a/cesar/lib/blk.h
+++ b/cesar/lib/blk.h
@@ -218,6 +218,23 @@ blk_check_memory (void);
void
blk_print_memory (void);
+/**
+ * Querry blk when a huge number of blocks are needed.
+ * \return true if possible, false otherwise.
+ *
+ * Each time a numerous quantity of blocks are needed to handle a stuff, this
+ * function should be called. When the number of blocks reach a critical level
+ * (not enough) this function will return false, the client should delay the
+ * allocation request. Otherwise, the client can allocate the quantity of
+ * blocks needed.
+ *
+ * The slack level is configurable with a CONFIG_BLK_SLACK = X in the Config
+ * file. X is the minimum number of blocks under the one, the memory level
+ * is considered as critical.
+ */
+bool
+blk_slack (void);
+
END_DECLS
#endif /* lib_blk_h */
diff --git a/cesar/lib/src/blk.c b/cesar/lib/src/blk.c
index 9ea36da1bf..8dcd6bebda 100644
--- a/cesar/lib/src/blk.c
+++ b/cesar/lib/src/blk.c
@@ -387,3 +387,8 @@ blk_print_memory (void)
blk_global.total_nb, blk_global.free_nb);
}
+bool
+blk_slack (void)
+{
+ return blk_global.free_nb > CONFIG_BLK_SLACK;
+}
diff --git a/cesar/lib/test/blk/Config b/cesar/lib/test/blk/Config
new file mode 100644
index 0000000000..38581ed7f0
--- /dev/null
+++ b/cesar/lib/test/blk/Config
@@ -0,0 +1 @@
+CONFIG_BLK_SLACK=400
diff --git a/cesar/lib/test/blk/src/test_blk.c b/cesar/lib/test/blk/src/test_blk.c
index 94b8df1d3a..a96e86d0b1 100644
--- a/cesar/lib/test/blk/src/test_blk.c
+++ b/cesar/lib/test/blk/src/test_blk.c
@@ -270,12 +270,39 @@ blk_stress_test_case (test_t t)
} test_end;
}
+
+void
+blk_slack_test_case (test_t t)
+{
+ test_case_begin (t, "Slack test");
+
+ test_begin (t, "slack ok")
+ {
+ blk_t *b[CONFIG_BLK_NB - CONFIG_BLK_SLACK];
+ uint i;
+ for (i = 0; i < CONFIG_BLK_NB - CONFIG_BLK_SLACK; i++)
+ {
+ test_fail_unless (blk_slack () == true);
+ b[i] = blk_alloc ();
+ }
+
+ test_fail_unless (blk_slack () == false);
+ blk_release (b[CONFIG_BLK_NB - CONFIG_BLK_SLACK - 1]);
+ test_fail_unless (blk_slack () == true);
+
+ for (i = 0; i < CONFIG_BLK_NB - CONFIG_BLK_SLACK - 1; i++)
+ blk_release (b[i]);
+ }
+ test_end;
+}
+
void
blk_test_suite (test_t t)
{
test_suite_begin (t, "blk");
blk_basic_test_case (t);
blk_stress_test_case (t);
+ blk_slack_test_case (t);
blk_print_memory ();
}