mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-10 16:58:47 +03:00
dmeventd oom_adj + reduce thread stack size
This commit is contained in:
parent
d838a1e314
commit
e125e1547f
@ -66,6 +66,8 @@ static pthread_mutex_t _global_mutex;
|
||||
#define DM_THREAD_SHUTDOWN 1
|
||||
#define DM_THREAD_DONE 2
|
||||
|
||||
#define THREAD_STACK_SIZE 300*1024
|
||||
|
||||
/* Data kept about a DSO. */
|
||||
struct dso_data {
|
||||
struct list list;
|
||||
@ -213,6 +215,15 @@ static struct dso_data *_alloc_dso_data(struct message_data *data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Create a device monitoring thread. */
|
||||
static int _pthread_create_smallstack(pthread_t *t, void *(*fun)(void *), void *arg)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE);
|
||||
return pthread_create(t, &attr, fun, arg);
|
||||
}
|
||||
|
||||
static void _free_dso_data(struct dso_data *data)
|
||||
{
|
||||
dm_free(data->dso_name);
|
||||
@ -458,8 +469,7 @@ static int _register_for_timeout(struct thread_status *thread)
|
||||
if (!_timeout_running) {
|
||||
pthread_t timeout_id;
|
||||
|
||||
if (!(ret = -pthread_create(&timeout_id, NULL,
|
||||
_timeout_thread, NULL)))
|
||||
if (!(ret = -_pthread_create_smallstack(&timeout_id, _timeout_thread, NULL)))
|
||||
_timeout_running = 1;
|
||||
}
|
||||
|
||||
@ -688,7 +698,7 @@ static void *_monitor_thread(void *arg)
|
||||
/* Create a device monitoring thread. */
|
||||
static int _create_thread(struct thread_status *thread)
|
||||
{
|
||||
return pthread_create(&thread->thread, NULL, _monitor_thread, thread);
|
||||
return _pthread_create_smallstack(&thread->thread, _monitor_thread, thread);
|
||||
}
|
||||
|
||||
static int _terminate_thread(struct thread_status *thread)
|
||||
@ -1407,6 +1417,21 @@ static int _lock_pidfile(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _set_oom_adj(int val)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("/proc/self/oom_adj", "w");
|
||||
|
||||
if (!fp)
|
||||
return 0;
|
||||
|
||||
fprintf(fp, "%i", val);
|
||||
fclose(fp);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _daemonize(void)
|
||||
{
|
||||
int status;
|
||||
@ -1495,6 +1520,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
_daemonize();
|
||||
|
||||
if (!_set_oom_adj(-16))
|
||||
syslog(LOG_ERR, "Failed to set oom_adj to protect against OOM killer");
|
||||
|
||||
_init_thread_signals();
|
||||
|
||||
//multilog_clear_logging();
|
||||
|
Loading…
x
Reference in New Issue
Block a user