Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 217491
b: refs/heads/master
c: 66d7dd5
h: refs/heads/master
i:
  217489: fd8de30
  217487: 4a6b862
v: v3
  • Loading branch information
Kay Sievers authored and Linus Torvalds committed Oct 26, 2010
1 parent e945317 commit a3ad6a8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e1ca7788dec6773b1a2bce51b7141948f2b8bccf
refs/heads/master: 66d7dd518ae413a383ab2c6c263cc30617329842
49 changes: 48 additions & 1 deletion trunk/mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <linux/capability.h>
#include <linux/syscalls.h>
#include <linux/memcontrol.h>
#include <linux/poll.h>

#include <asm/pgtable.h>
#include <asm/tlbflush.h>
Expand Down Expand Up @@ -58,6 +59,10 @@ static struct swap_info_struct *swap_info[MAX_SWAPFILES];

static DEFINE_MUTEX(swapon_mutex);

static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
/* Activity counter to indicate that a swapon or swapoff has occurred */
static atomic_t proc_poll_event = ATOMIC_INIT(0);

static inline unsigned char swap_count(unsigned char ent)
{
return ent & ~SWAP_HAS_CACHE; /* may include SWAP_HAS_CONT flag */
Expand Down Expand Up @@ -1680,6 +1685,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
}
filp_close(swap_file, NULL);
err = 0;
atomic_inc(&proc_poll_event);
wake_up_interruptible(&proc_poll_wait);

out_dput:
filp_close(victim, NULL);
Expand All @@ -1688,6 +1695,25 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
}

#ifdef CONFIG_PROC_FS
struct proc_swaps {
struct seq_file seq;
int event;
};

static unsigned swaps_poll(struct file *file, poll_table *wait)
{
struct proc_swaps *s = file->private_data;

poll_wait(file, &proc_poll_wait, wait);

if (s->event != atomic_read(&proc_poll_event)) {
s->event = atomic_read(&proc_poll_event);
return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
}

return POLLIN | POLLRDNORM;
}

/* iterator */
static void *swap_start(struct seq_file *swap, loff_t *pos)
{
Expand Down Expand Up @@ -1771,14 +1797,32 @@ static const struct seq_operations swaps_op = {

static int swaps_open(struct inode *inode, struct file *file)
{
return seq_open(file, &swaps_op);
struct proc_swaps *s;
int ret;

s = kmalloc(sizeof(struct proc_swaps), GFP_KERNEL);
if (!s)
return -ENOMEM;

file->private_data = s;

ret = seq_open(file, &swaps_op);
if (ret) {
kfree(s);
return ret;
}

s->seq.private = s;
s->event = atomic_read(&proc_poll_event);
return ret;
}

static const struct file_operations proc_swaps_operations = {
.open = swaps_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
.poll = swaps_poll,
};

static int __init procswaps_init(void)
Expand Down Expand Up @@ -2084,6 +2128,9 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
swap_info[prev]->next = type;
spin_unlock(&swap_lock);
mutex_unlock(&swapon_mutex);
atomic_inc(&proc_poll_event);
wake_up_interruptible(&proc_poll_wait);

error = 0;
goto out;
bad_swap:
Expand Down

0 comments on commit a3ad6a8

Please sign in to comment.