View Issue Details

IDProjectCategoryView StatusLast Update
0000601LDMud 3.3Efunspublic2009-05-04 11:49
Reporterzesstra Assigned Tozesstra  
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
Platformx86_64OSMacOS XOS Version10.5.x
Product Version3.3.718 
Target Version3.3.719Fixed in Version3.3.719 
Summary0000601: Add possibility to change limits for memory allocation (MAX_MALLOCED, SOFT_MALLOC_LIMIT) at runtime
DescriptionI am in the process of introducing a soft memory allocation limit (0000081). If exceeded the driver will call low_memory() in the mudlib master which can decide if there a need/possibilty to do something (e.g. perform garabge_collection() at a suitable time during the night).

The mudlib should be able to set the soft limit at runtime. And if it can set the soft limit, it should also be able to set the hard limit I believe.
TagsNo tags attached.
Attached Files
0001-Added-new-efun-configure_driver.patch (6,847 bytes)   
From 1741eeafae974bee3d62d14abd7a57fbc6bf31f1 Mon Sep 17 00:00:00 2001
From: zesstra <zesstra@zesstra.de>
Date: Fri, 17 Apr 2009 01:19:19 +0200
Subject: [PATCH 1/2] Added new efun: configure_driver().

configure_driver() will configure variuous aspects of the driver at run-time.
The first settings available is now the soft and hard memory limits.
configure_driver() always causes a call to privilege_violation() in the
mudlib master.
---
 doc/efun/configure_driver      |   22 ++++++++++++++++
 doc/master/privilege_violation |    1 +
 mudlib/sys/configuration.h     |    4 +++
 src/efuns.c                    |   54 ++++++++++++++++++++++++++++++++++++++++
 src/efuns.h                    |    1 +
 src/func_spec                  |    1 +
 src/string_spec                |    1 +
 7 files changed, 84 insertions(+), 0 deletions(-)
 create mode 100644 doc/efun/configure_driver

diff --git a/doc/efun/configure_driver b/doc/efun/configure_driver
new file mode 100644
index 0000000..9c1bf77
--- /dev/null
+++ b/doc/efun/configure_driver
@@ -0,0 +1,22 @@
+SYNOPSIS
+        #include <sys/configuration.h>
+
+        void configure_driver (int what, mixed data)
+
+DESCRIPTION
+        Sets the option <what> to the value <data>.
+
+        This function always causes the privilege_violation
+        ("configure_driver", this_object(), what, data).
+
+        <what> == DC_MEMORY_LIMIT
+           Set new soft and hard memory limits for the driver.
+           <data> is expected to be an array with two elements, which have to
+           be integers giving the amount of memory in bytes.
+           ({<soft memory limit>, <hard memory limit>})
+
+HISTORY
+        Introduced in LDMud 3.3.719.
+
+SEE ALSO
+        configure_interactive(E)
diff --git a/doc/master/privilege_violation b/doc/master/privilege_violation
index 675da0b..372a21d 100644
--- a/doc/master/privilege_violation
+++ b/doc/master/privilege_violation
@@ -20,6 +20,7 @@ DESCRIPTION
                           informations.
         configure_interactive Set option <arg2> with value <arg3> as
                           default (<arg>==0) or for object <arg>.
+        configure_driver  Set option <arg1> to value(s) <arg2>.
         enable_telnet     Enable/disable telnet (<arg2>) for object <arg>.
         execute_command   Execute command string <arg2> for the object
                           <arg>.
diff --git a/mudlib/sys/configuration.h b/mudlib/sys/configuration.h
index 3e46b91..e703914 100644
--- a/mudlib/sys/configuration.h
+++ b/mudlib/sys/configuration.h
@@ -8,4 +8,8 @@
  */
 #define IC_MAX_WRITE_BUFFER_SIZE 0
 
+/* Possible options for configure_driver().
+ */
+#define DC_MEMORY_LIMIT 0
+
 #endif /* LPC_CONFIGURATION_H_ */
diff --git a/src/efuns.c b/src/efuns.c
index a3f440e..a297ab7 100644
--- a/src/efuns.c
+++ b/src/efuns.c
@@ -139,6 +139,7 @@
 
 #include "../mudlib/sys/debug_info.h"
 #include "../mudlib/sys/driver_hook.h"
+#include "../mudlib/sys/configuration.h"
 #include "../mudlib/sys/objectinfo.h"
 #include "../mudlib/sys/regexp.h"
 #include "../mudlib/sys/strings.h"
@@ -7766,6 +7767,59 @@ f_sgn (svalue_t *sp)
 
 /*-------------------------------------------------------------------------*/
 svalue_t *
+f_configure_driver (svalue_t *sp)
+
+/* EFUN void configure_driver(int what, mixed data)
+ *
+ * This efun configures several aspects of the driver at run-time.
+ * 
+ * <what> is an identifier the setting:
+ *        - DC_MEMORY_LIMIT (0): configures the memory limits
+ * 
+ * <data> is dependent on <what>:
+ *   DC_MEMORY_LIMIT: ({soft-limit, hard-limit}) both <int>, given in Bytes.
+ *
+ */
+
+{
+
+    // Check for privilege_violation.
+    if (!privilege_violation2(STR_CONFIGURE_DRIVER, sp-1, sp, sp))
+    {
+        return pop_n_elems(2, sp);
+    }
+    
+    switch(sp[-1].u.number) {
+        default:
+            errorf("Illegal value %"PRIdPINT" for configure_driver().\n", sp[-1].u.number);
+            return sp; /* NOTREACHED */
+        case DC_MEMORY_LIMIT:
+            if (sp->type != T_POINTER)
+                efun_arg_error(1, T_POINTER, sp->type, sp);
+            if (VEC_SIZE(sp->u.vec) != 2)
+                errorf("Bad arg 1 to configure_driver(): Invalid array size %"PRIdPINT
+                       ", expected 2.\n"
+                       , VEC_SIZE(sp->u.vec));
+            if (sp->u.vec->item[0].type != T_NUMBER)
+                errorf("Bad arg 1 to configure_driver(): Element 0 is '%s', expected 'int'.\n"
+                       , typename(sp->u.vec->item[0].type));
+            if (sp->u.vec->item[1].type != T_NUMBER)
+                errorf("Bad arg 1 to configure_driver(): Element 1 is '%s', expected 'int'.\n"
+                       , typename(sp->u.vec->item[1].type));
+            if (!set_memory_limit(MALLOC_SOFT_LIMIT, sp->u.vec->item[0].u.number))
+                errorf("Could not set the soft memory limit (%"PRIdPINT") in configure_driver()\n",
+                       sp->u.vec->item[0].u.number);
+            if (!set_memory_limit(MALLOC_HARD_LIMIT, sp->u.vec->item[1].u.number))
+                errorf("Could not set the hard memory limit (%"PRIdPINT") in configure_driver()\n",
+                       sp->u.vec->item[1].u.number);
+            break;
+    }
+    
+    // free arguments
+    return pop_n_elems(2, sp);
+} /* f_configure_driver() */
+/*-------------------------------------------------------------------------*/
+svalue_t *
 v_debug_info (svalue_t *sp, int num_arg)
 
 /* EFUN debug_info()
diff --git a/src/efuns.h b/src/efuns.h
index 344d7ee..3f75a23 100644
--- a/src/efuns.h
+++ b/src/efuns.h
@@ -88,6 +88,7 @@ extern svalue_t *tell_room(svalue_t *sp);
 extern svalue_t *f_ctime(svalue_t *);
 extern svalue_t *v_strftime(svalue_t *, int num_arg);
 extern svalue_t *v_debug_info(svalue_t *sp, int num_arg);
+extern svalue_t *f_configure_driver(svalue_t *);
 extern svalue_t *f_rusage(svalue_t *sp);
 extern svalue_t *f_random(svalue_t *);
 extern svalue_t *f_shutdown(svalue_t *sp);
diff --git a/src/func_spec b/src/func_spec
index e48deca..7ec5c37 100644
--- a/src/func_spec
+++ b/src/func_spec
@@ -602,6 +602,7 @@ int     write_file(string, string, int default: F_CONST0);
 
         /* Driver and System functions */
 
+void    configure_driver(int, mixed);
 mixed   debug_info(int, ...);
 void    debug_message(string, int default: F_CONST0);
 string  expand_define(string, null|string default: F_CONST0);
diff --git a/src/string_spec b/src/string_spec
index 7a37976..9dcded6 100644
--- a/src/string_spec
+++ b/src/string_spec
@@ -72,6 +72,7 @@ ATTACH_ERQ_DEMON   "attach_erq_demon"
 BIND_LAMBDA        "bind_lambda"
 CALL_OUT_INFO      "call_out_info"
 CONFIGURE_INTERACTIVE  "configure_interactive"
+CONFIGURE_DRIVER  "configure_driver"
 SEND_ERQ           "erq"
 INPUT_TO           "input_to"
 SEND_UDP           "send_udp"
-- 
1.6.1

Relationships

related to 0000596 resolvedGnomi LDMud 3.5 new efuns for configuring objects and the driver 
related to 0000081 resolvedzesstra LDMud 3.3 Better feedback on low memory situations. 

Activities

zesstra

2009-01-17 12:06

administrator   ~0000919

The question is, if we should directly go for a configure_driver() (originally planned for 3.5.x, see 0000596) or create a set_malloc_limits() in the meantime. Querying the limits can be easily done in debug_info() now, but for setting them we need to create the general configure efun first.

Gnomi

2009-01-17 12:13

manager   ~0000920

I don't want to implement a function that will be deprecated soon. That's why I will implement a preliminary configure_interactive() in 3.3 for 0000297. (But we have to decide whether it should already handle all options or just the new one.)

zesstra

2009-01-17 12:20

administrator   ~0000921

I agree.
Then I suggest to create a preliminary configure_driver() as well, which will handle only new settings in 3.3 like these two limits. This seems to reasonable, because otherwise we would deprecate the existing functions already in 3.3 which I don't like.

zesstra

2009-04-19 16:14

administrator   ~0001060

The attached patch adds a basic configure_driver() efun which can configure the soft and hard memory limits.
The draft does not allow to set the limits separately, but expects them as array argument: ({soft limit, hard limit}). If that disturbs anyone, please say so. ;-)

zesstra

2009-05-04 11:49

administrator   ~0001075

Applied with minor codestyle changes as r2556.

Issue History

Date Modified Username Field Change
2009-01-17 12:06 zesstra New Issue
2009-01-17 12:06 zesstra Status new => assigned
2009-01-17 12:06 zesstra Assigned To => zesstra
2009-01-17 12:06 zesstra Note Added: 0000919
2009-01-17 12:07 zesstra Relationship added child of 0000081
2009-01-17 12:07 zesstra Relationship added related to 0000596
2009-01-17 12:13 Gnomi Note Added: 0000920
2009-01-17 12:20 zesstra Note Added: 0000921
2009-02-28 16:13 zesstra Relationship deleted child of 0000081
2009-02-28 16:14 zesstra Relationship added related to 0000081
2009-04-19 16:11 zesstra File Added: 0001-Added-new-efun-configure_driver.patch
2009-04-19 16:14 zesstra Note Added: 0001060
2009-05-04 11:49 zesstra Note Added: 0001075
2009-05-04 11:49 zesstra Status assigned => resolved
2009-05-04 11:49 zesstra Fixed in Version => 3.3.719
2009-05-04 11:49 zesstra Resolution open => fixed