提交 3a291a20 编写于 作者: R Rafael J. Wysocki 提交者: Linus Torvalds

[PATCH] mm: add a new function (needed for swap suspend)

This adds the function get_swap_page_of_type() allowing us to specify an index
in swap_info[] and select a swap_info_struct structure to be used for
allocating a swap page.

This function (or another one of similar functionality) will be necessary for
implementing the image-writing part of swsusp in the user space.   It can also
be used for simplifying the current in-kernel implementation of the
image-writing part of swsusp.
Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
Acked-by: NPavel Machek <pavel@ucw.cz>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 ca0aec0f
...@@ -209,6 +209,7 @@ extern unsigned int nr_swapfiles; ...@@ -209,6 +209,7 @@ extern unsigned int nr_swapfiles;
extern struct swap_info_struct swap_info[]; extern struct swap_info_struct swap_info[];
extern void si_swapinfo(struct sysinfo *); extern void si_swapinfo(struct sysinfo *);
extern swp_entry_t get_swap_page(void); extern swp_entry_t get_swap_page(void);
extern swp_entry_t get_swap_page_of_type(int type);
extern int swap_duplicate(swp_entry_t); extern int swap_duplicate(swp_entry_t);
extern int valid_swaphandles(swp_entry_t, unsigned long *); extern int valid_swaphandles(swp_entry_t, unsigned long *);
extern void swap_free(swp_entry_t); extern void swap_free(swp_entry_t);
......
...@@ -211,6 +211,26 @@ swp_entry_t get_swap_page(void) ...@@ -211,6 +211,26 @@ swp_entry_t get_swap_page(void)
return (swp_entry_t) {0}; return (swp_entry_t) {0};
} }
swp_entry_t get_swap_page_of_type(int type)
{
struct swap_info_struct *si;
pgoff_t offset;
spin_lock(&swap_lock);
si = swap_info + type;
if (si->flags & SWP_WRITEOK) {
nr_swap_pages--;
offset = scan_swap_map(si);
if (offset) {
spin_unlock(&swap_lock);
return swp_entry(type, offset);
}
nr_swap_pages++;
}
spin_unlock(&swap_lock);
return (swp_entry_t) {0};
}
static struct swap_info_struct * swap_info_get(swp_entry_t entry) static struct swap_info_struct * swap_info_get(swp_entry_t entry)
{ {
struct swap_info_struct * p; struct swap_info_struct * p;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册