]> xenbits.xensource.com Git - xen.git/commitdiff
oxenstored: trim history in the frequent_ops function stable-4.4 staging-4.4
authorThomas Sanders <thomas.sanders@citrix.com>
Tue, 28 Mar 2017 17:57:52 +0000 (18:57 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Wed, 5 Apr 2017 14:26:38 +0000 (15:26 +0100)
We were trimming the history of commits only at the end of each
transaction (regardless of how it ended).

Therefore if non-transactional writes were being made but no
transactions were being ended, the history would grow
indefinitely. Now we trim the history at regular intervals.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
tools/ocaml/xenstored/history.ml
tools/ocaml/xenstored/transaction.ml
tools/ocaml/xenstored/xenstored.ml

index 4079588896a04efa0c2ae282e8268e47d306260d..f39565bff5a81e2738511356cbe67431d6bd6f42 100644 (file)
@@ -39,7 +39,8 @@ let mark_symbols () =
 (* Keep only enough commit-history to protect the running transactions that we are still tracking *)
 (* There is scope for optimisation here, replacing List.filter with something more efficient,
  * probably on a different list-like structure. *)
-let trim () =
+let trim ?txn () =
+       Transaction.trim_short_running_transactions txn;
        history := match Transaction.oldest_short_running_transaction () with
        | None -> [] (* We have no open transaction, so no history is needed *)
        | Some (_, txn) -> (
@@ -49,8 +50,7 @@ let trim () =
 
 let end_transaction txn con tid commit =
        let success = Connection.end_transaction con tid commit in
-       Transaction.end_transaction txn;
-       trim ();
+       trim ~txn ();
        success
 
 let push (x: history_record) =
index da4a3e367f47295d4d1c34d662e1c14c017b9345..23e7ccff1b40aa18f20263b6c0a42a2679a4916c 100644 (file)
@@ -106,10 +106,14 @@ let oldest_short_running_transaction () =
                | x :: xs -> last xs
        in last !short_running_txns
 
-let end_transaction txn =
+let trim_short_running_transactions txn =
        let cutoff = Unix.gettimeofday () -. !Define.conflict_max_history_seconds in
+       let keep = match txn with
+               | None -> (function (start_time, _) -> start_time >= cutoff)
+               | Some t -> (function (start_time, tx) -> start_time >= cutoff && tx != t)
+       in
        short_running_txns := List.filter
-               (function (start_time, tx) -> start_time >= cutoff && tx != txn)
+               keep
                !short_running_txns
 
 let make ?(internal=false) id store =
index 979b7697127df3b68446de3d4676554c7a444903..180edd6a79c0a7cfd09a6c18460ec2c9bb4a1087 100644 (file)
@@ -278,6 +278,7 @@ let _ =
         * than the periodic_ops function *)
        let frequent_ops () =
                if Unix.gettimeofday () > !next_frequent_ops then (
+                       History.trim ();
                        Domains.incr_conflict_credit domains;
                        advance_next_frequent_ops ()
                ) in