util: remove dynamic sort vector growth 71/174871/2 accepted/tizen/unified/20180405.064256 submit/tizen/20180404.150538
authorMichal Bloch <m.bloch@samsung.com>
Wed, 4 Apr 2018 13:04:32 +0000 (15:04 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 4 Apr 2018 13:29:14 +0000 (15:29 +0200)
This reverts f9b568e5484d85d373033b2bf6857ef39cfc5c39.

Dynamic growth was originally implemented to help improve sorting quality.
However, it removes the bound on memory usage and was discovered to cause
starvation in case of a constant flow of logs. The need for very large
vectors has also recently been reduced with the implementation of sorting
in the daemon (cf. commit e937e788bfcf4d4e791dac47099f998c778dd4fc,
"logger: inserting logs in ordered way to the buffers").

Change-Id: I6d0c89531ea7aca28b9062a4054b9975e25f0d36
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logutil/logutil_doc.h
src/logutil/sort_vector.c

index a09039f..11ff7e0 100644 (file)
@@ -54,7 +54,7 @@ static void show_help(const char *cmd, bool requested_by_user)
                "  -b <buffer>       request alternate ring buffers (can use multiple)\n"
                "                    ('main', 'radio', 'system', 'apps', 'kmsg', 'syslog')\n"
                "                    the default set is main + system + apps\n"
-               "  -u <size>         Sets the initial size of sort buffer (0 to disable sorting)\n"
+               "  -u <size>         Sets the size of sort buffer (0 to disable sorting)\n"
                "                    Smaller is faster but lowers sorting quality\n"
                "  --pid <pid>       Filter messages by process id\n"
                "  --tid <tid>       Filter messages by thread id\n"
index 723a62e..0dfc891 100644 (file)
@@ -100,32 +100,6 @@ int sort_vector_used_size(struct sort_vector *logs)
                return logs->size - logs->begin + logs->end;
 }
 
-int sort_vector_enlarge(struct sort_vector *logs)
-{
-       assert(logs);
-       assert(IS_VECTOR_SIZE_SORTABLE(logs->size));
-
-       const int old_size = logs->size;
-       const int new_size = 2 * old_size;
-
-       typeof(logs->data) result = (typeof(logs->data))realloc(logs->data, new_size * sizeof *logs->data);
-       if (result == NULL)
-               return -ENOMEM;
-
-       memset(result + old_size, 0x00, (new_size - old_size) * sizeof *result);
-       if (logs->end < logs->begin) {
-               const size_t end_bytes = logs->end * sizeof *result;
-               memmove(result + old_size, result, end_bytes);
-               memset(result, 0x00, end_bytes);
-               logs->end += old_size;
-       }
-
-       logs->data = result;
-       logs->size = new_size;
-
-       return 0;
-}
-
 /**
  * @brief Push log
  * @details Push a log to the sorting container
@@ -148,7 +122,7 @@ int sort_vector_push(struct sort_vector *logs, struct logger_entry *p, struct lo
                return -EPERM;
        }
 
-       if (sort_vector_full(logs) && (sort_vector_enlarge(logs) < 0)) {
+       if (sort_vector_full(logs)) {
                logfile_write_with_rotation(sort_vector_back(logs), l_file);
                sort_vector_pop(logs);
        }