From: Nick Piggin <nickpiggin@yahoo.com.au>
To: jcabezas@ac.upc.edu
Cc: haveblue@us.ibm.com, linux-mm@kvack.org
Subject: Re: Selective swap out of processes
Date: Fri, 31 Aug 2007 10:34:11 +1000 [thread overview]
Message-ID: <46D76203.303@yahoo.com.au> (raw)
In-Reply-To: <49e98fc50708301650q611f9b0fi762f9c5d8d5fae01@mail.gmail.com>
Javier Cabezas Rodriguez wrote:
> Sorry. It was an old version:
>
> int try_to_put_page_in_swap(struct page *page)
> {
> get_page(page);
>
> if (page_count(page) == 1) /* page was freed from under us. So we are done. */
> return -EAGAIN;
>
> lock_page(page);
>
> if (PageWriteback(page))
> wait_on_page_writeback(page);
>
> try_to_unmap(page, 0);
>
> unlock_page(page);
> put_page(page);
> return 0;
> }
You'd surely have to add_to_swap here, and at some point
will want to also free the swapcache after writing it out.
Look at how the code in mm/vmscan.c does it.
> int free_process(struct vm_area_struct * vma, struct task_struct * p)
> {
> int write;
> int npages;
> struct page ** pages;
> int i;
>
> spin_lock(&p->mm->page_table_lock);
You rather need down_read(&mm->mmap_sem);
> write = (vma->vm_flags & VM_WRITE) != 0;
> npages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
> pages = kmalloc(npages * sizeof(struct page *), GFP_KERNEL);
>
> if (!pages)
> return -ENOMEM;
Careful of just returning while you're holding a spinlock or
other resources.
>
> npages = get_user_pages(p, p->mm, vma->vm_start, npages, write, 0,
> pages, NULL);
>
> spin_unlock(&p->mm->page_table_lock);
>
> for (i = 0; i < npages; i++)
> try_to_put_page_in_swap(pages[i]);
>
> kfree(pages);
> return npages;
You have to carefully keep track of what is happening with your
page refcounts and make sure you're doing the right thing here.
For example, get_user_pages increments the refcounts, and it looks
like you don't decrement them again -- this will leave the page
permanently pinned in memory.
> }
>
> void free_procs(void)
> {
> struct task_struct *g, *p;
> struct vm_area_struct * vma;
> int c, count;
>
> read_lock(&tasklist_lock);
> do_each_thread(g, p) {
> if (!p->pinned) { /* This process can be swapped out */
> down_read(&p->mm->mmap_sem);
Ah, you have down_read here. So you don't need ptl above. Unfortunately,
down_read sleeps, while tasklist_lock is a spinlock, so you'll need to
take some other approach here.
> for (vma = p->mm->mmap, count = 0; vma; vma = vma->vm_next, count += c) {
> if ((c = free_process(vma, p)) == -ENOMEM) {
> printk("VMC: Out of Memory\n");
> up_read(&p->mm->mmap_sem);
> goto out;
> }
> }
> up_read(&p->mm->mmap_sem);
> printk("VMC: Process %d. %d pages freed\n", p->pid, count);
> }
> } while_each_thread(g, p);
>
> out:
> read_unlock(&tasklist_lock);
I won't have time to help more as I'm heading overseas, good luck!
--
SUSE Labs, Novell Inc.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-08-31 0:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-28 16:54 Selective swap out of processes Javier Cabezas Rodríguez
2007-08-29 2:37 ` Nick Piggin
2007-08-29 10:37 ` Javier Cabezas Rodríguez
2007-08-29 18:06 ` Javier Cabezas Rodríguez
2007-08-29 22:01 ` Dave Hansen
2007-08-30 7:13 ` Nick Piggin
2007-08-30 23:41 ` Javier Cabezas Rodríguez
2007-08-30 23:47 ` Javier Cabezas Rodríguez
2007-08-30 23:50 ` Javier Cabezas Rodríguez
2007-08-31 0:34 ` Nick Piggin [this message]
2007-08-31 16:40 ` Dave Hansen
2007-09-08 1:45 ` Nick Piggin
2007-08-30 7:09 ` Nick Piggin
2007-08-29 5:18 ` Christoph Lameter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46D76203.303@yahoo.com.au \
--to=nickpiggin@yahoo.com.au \
--cc=haveblue@us.ibm.com \
--cc=jcabezas@ac.upc.edu \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.