summaryrefslogtreecommitdiff
path: root/src/swap.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-10-18 23:09:09 +0200
committerLennart Poettering <lennart@poettering.net>2010-10-18 23:09:09 +0200
commit4e4343146ade25b1ccfc927e2807d854be863ec4 (patch)
treee33d93110852b91bdf43732a538283c651346894 /src/swap.c
parent5a33f657b52f30a77fac41feb8854b563d77382e (diff)
swap: listen for POLLPRI events on /proc/swaps if available
Diffstat (limited to 'src/swap.c')
-rw-r--r--src/swap.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/swap.c b/src/swap.c
index 487b18350a..cf9644fc69 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -1056,16 +1056,23 @@ static int swap_load_proc_swaps(Manager *m, bool set_flags) {
}
int swap_dispatch_reload(Manager *m) {
- Meta *meta;
- int r;
-
- assert(m);
+ /* This function should go as soon as the kernel properly notifies us */
if (_likely_(!m->request_reload))
return 0;
m->request_reload = false;
+ return swap_fd_event(m, EPOLLPRI);
+}
+
+int swap_fd_event(Manager *m, int events) {
+ Meta *meta;
+ int r;
+
+ assert(m);
+ assert(events & EPOLLPRI);
+
if ((r == swap_load_proc_swaps(m, true)) < 0) {
log_error("Failed to reread /proc/swaps: %s", strerror(-r));
@@ -1169,12 +1176,24 @@ static void swap_shutdown(Manager *m) {
static int swap_enumerate(Manager *m) {
int r;
+ struct epoll_event ev;
assert(m);
- if (!m->proc_swaps)
+ if (!m->proc_swaps) {
if (!(m->proc_swaps = fopen("/proc/swaps", "re")))
return -errno;
+ m->swap_watch.type = WATCH_SWAP;
+ m->swap_watch.fd = fileno(m->proc_swaps);
+
+ zero(ev);
+ ev.events = EPOLLPRI;
+ ev.data.ptr = &m->swap_watch;
+
+ if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->swap_watch.fd, &ev) < 0)
+ return -errno;
+ }
+
/* We rely on mount.c to load /etc/fstab for us */
if ((r = swap_load_proc_swaps(m, false)) < 0)