]> xenbits.xensource.com Git - xen.git/commitdiff
oxenstored: add facilities to raise the max open fds uplimit
authorZheng Li <dev@zheng.li>
Thu, 25 Sep 2014 17:34:55 +0000 (18:34 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 8 Oct 2014 13:18:46 +0000 (14:18 +0100)
To go beyond 1024 fds, we also need to raise the process limitation on max
open fds (usually defaults to 1024).

We need to know the system level max open fds so that we won't go above that.
Simply setting the limit to RLIM_INFINITY doesn't work on Linux 3.x (EPERM), a
patch on this went into the 2.x branch but not 3.x for some reason.

Signed-off-by: Zheng Li <dev@zheng.li>
Reviewed-by: David Scott <dave.scott@citrix.com>
tools/ocaml/xenstored/select.ml
tools/ocaml/xenstored/select_stubs.c

index 3f4b67129ddd47d93eb10010bbbfe1a505a0eae3..ab8c847684e2290b8789407f07df0c51380a7ffc 100644 (file)
@@ -23,6 +23,16 @@ type event = {
 }
 
 external select_on_poll: (Unix.file_descr * event) array -> int -> int = "stub_select_on_poll"
+external set_fd_limit: int -> unit = "stub_set_fd_limit"
+
+(* The rlim_max given to setrlimit must not go above the system level nr_open,
+   which we can read from /proc/sys. *)
+let get_sys_fs_nr_open () =
+       try
+               let ch = open_in "/proc/sys/fs/nr_open" in
+               let v = int_of_string (input_line ch) in
+               close_in_noerr ch; v
+       with _ -> 1024 * 1024
 
 let init_event () = {read = false; write = false; except = false}
 
index 33beeb9d5310092c085799aafe24dcdac0e755bb..4a8edb55480d1cac5e4f3051435f90791aecdd3b 100644 (file)
@@ -66,3 +66,15 @@ CAMLprim value stub_select_on_poll(value fd_events, value timeo) {
 
        CAMLreturn(Val_int(rc));
 }
+
+
+CAMLprim value stub_set_fd_limit(value limit) {
+
+       CAMLparam1(limit);
+       struct rlimit rl;
+
+       rl.rlim_cur = rl.rlim_max = Int_val(limit);
+       if (setrlimit(RLIMIT_NOFILE, &rl) != 0) uerror("setrlimit", Nothing);
+       CAMLreturn(Val_unit);
+
+}