hal: Branch 'master' - 2 commits
David Zeuthen
david at kemper.freedesktop.org
Thu Dec 14 18:54:02 PST 2006
configure.in | 1 +
hald/hald.c | 17 ++++++++++++++++-
hald/linux/blockdev.c | 12 +++++-------
hald/linux/coldplug.c | 3 +--
hald/linux/hotplug.c | 5 ++++-
hald/linux/osspec.c | 15 +++++++++++++--
6 files changed, 40 insertions(+), 13 deletions(-)
New commits:
diff-tree 0ad8decdb9923754bb1fd8e25f9be4b3b90f2840 (from 14e949f7903a3b58eee38541d0f59f05b7b74140)
Author: Sergey Lapin <slapinid at gmail.com>
Date: Thu Dec 14 21:53:58 2006 -0500
reduce memory fragmentation by using POSIX readlink rather than glib
Replaces all calls to g_file_read_link with POSIX readlink
and uses static buffers where possible.
Reduces memory fragmentation.
diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index b7b2b86..97097b7 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -36,6 +36,7 @@
#include <sys/stat.h>
#include <syslog.h>
#include <unistd.h>
+#include <errno.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
@@ -565,17 +566,15 @@ resolve_symlink (const char *file)
{
GError *error;
char *dir;
- char *link;
+ gchar link[HAL_PATH_MAX] ;
char *f;
char *f1;
f = g_strdup (file);
-
+ memset(link, 0, HAL_PATH_MAX);
while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) {
- link = g_file_read_link (f, &error);
- if (link == NULL) {
- g_warning ("Cannot resolve symlink %s: %s", f, error->message);
- g_error_free (error);
+ if(readlink(f, link, HAL_PATH_MAX-1)<0) {
+ g_warning ("Cannot resolve symlink %s: %s", f, strerror(errno));
g_free (f);
f = NULL;
goto out;
@@ -584,7 +583,6 @@ resolve_symlink (const char *file)
dir = g_path_get_dirname (f);
f1 = g_strdup_printf ("%s/%s", dir, link);
g_free (dir);
- g_free (link);
g_free (f);
f = f1;
}
diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c
index 177f05a..fd81e6a 100644
--- a/hald/linux/coldplug.c
+++ b/hald/linux/coldplug.c
@@ -310,13 +310,12 @@ static int device_list_insert(const char
if (S_ISLNK(statbuf.st_mode)) {
gchar *target;
- if ((target = g_file_read_link (path, NULL)) != NULL) {
+ if ((target = hal_util_readlink (path)) != NULL) {
gchar *normalized_target;
g_strlcpy(filename, path, sizeof(filename));
hal_util_path_ascend (filename);
normalized_target = hal_util_get_normalized_path (filename, target);
- g_free (target);
sysfs_dev->path = normalized_target;
goto found;
}
diff --git a/hald/linux/hotplug.c b/hald/linux/hotplug.c
index 1b9282a..7a089da 100644
--- a/hald/linux/hotplug.c
+++ b/hald/linux/hotplug.c
@@ -123,7 +123,10 @@ hotplug_event_begin_sysfs (HotplugEvent
*/
if (hotplug_event->type == HOTPLUG_EVENT_SYSFS) {
g_snprintf (subsystem, HAL_PATH_MAX, "%s/subsystem", hotplug_event->sysfs.sysfs_path);
- subsystem_target = g_file_read_link (subsystem, NULL);
+ /* g_file_read_link leaks memory. We alloc lots of trash here but return NULL, damn
+ Re-implemented this using POSIX readlink() */
+ /* subsystem_target = g_file_read_link (subsystem, NULL); */
+ subsystem_target = hal_util_readlink(subsystem);
if (subsystem_target != NULL) {
if (strstr(subsystem_target, "/block") != NULL) {
HAL_INFO (("%s is a block device (subsystem)", hotplug_event->sysfs.sysfs_path));
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 991dadf..9fcfd51 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -694,6 +694,18 @@ static gboolean get_parent_device(char *
return FALSE;
return TRUE;
}
+static gchar path_buffer [HAL_PATH_MAX];
+
+gchar *
+hal_util_readlink(gchar * link)
+{
+ memset(path_buffer, 0, HAL_PATH_MAX);
+ if(readlink(link, path_buffer, HAL_PATH_MAX-1)<0)
+ return NULL;
+
+ return path_buffer;
+}
+
/* return the first already known parent device */
gboolean
hal_util_find_known_parent (const gchar *sysfs_path, HalDevice **parent, gchar **parent_path)
@@ -720,9 +732,8 @@ hal_util_find_known_parent (const gchar
/* try if the parent chain is constructed by the device-link */
g_snprintf (parentdevpath, HAL_PATH_MAX, "%s/device", sysfs_path);
- if (((target = g_file_read_link (parentdevpath, NULL)) != NULL)) {
+ if ((target = hal_util_readlink (parentdevpath)) != NULL) {
parent_devpath = hal_util_get_normalized_path (sysfs_path, target);
- g_free (target);
while (TRUE) {
parent_dev = hal_device_store_match_key_value_string (hald_get_gdl (),
diff-tree 14e949f7903a3b58eee38541d0f59f05b7b74140 (from 9d607e21cac65dddaf0c8cb2443865d9ae509393)
Author: Sergey Lapin <slapinid at gmail.com>
Date: Thu Dec 14 21:49:25 2006 -0500
use mallopt since we mostly allocate small chunks
A patch attached is about optimization of malloc usage for small
chunks. Reduces memory fragmentation. Uses mallopt for that. Mostly
targeted for small-memory embedded devices.
diff --git a/configure.in b/configure.in
index af075ae..8a5e786 100644
--- a/configure.in
+++ b/configure.in
@@ -359,6 +359,7 @@ fi
AC_CHECK_FUNCS(getgrouplist)
AC_CHECK_FUNCS(asprintf)
+AC_CHECK_FUNCS(mallopt)
# DocBook Documentation
diff --git a/hald/hald.c b/hald/hald.c
index 4e3c8da..d946c4e 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -41,7 +41,9 @@
#include <signal.h>
#include <grp.h>
#include <syslog.h>
-
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <malloc.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
@@ -374,6 +376,19 @@ main (int argc, char *argv[])
openlog ("hald", LOG_PID, LOG_DAEMON);
+#ifdef HAVE_MALLOPT
+
+#define HAL_MMAP_THRESHOLD 100
+#define HAL_TRIM_THRESHOLD 100
+
+ /* We use memory in small chunks, thus optimize
+ it this way.
+ */
+ mallopt(M_MMAP_THRESHOLD, HAL_MMAP_THRESHOLD);
+ mallopt(M_TRIM_THRESHOLD, HAL_TRIM_THRESHOLD);
+
+#endif
+
#ifdef HALD_MEMLEAK_DBG
/*g_mem_set_vtable (glib_mem_profiler_table);*/
#endif
More information about the hal-commit
mailing list