Skip to content

Commit 2687a35

Browse files
Matthew WilcoxMatthew Wilcox
authored andcommitted
Add lock_page_killable
This routine is like lock_page, but can be interrupted by a fatal signal Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
1 parent f776d12 commit 2687a35

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎include/linux/pagemap.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ static inline pgoff_t linear_page_index(struct vm_area_struct *vma,
157157
}
158158

159159
extern void FASTCALL(__lock_page(struct page *page));
160+
extern int FASTCALL(__lock_page_killable(struct page *page));
160161
extern void FASTCALL(__lock_page_nosync(struct page *page));
161162
extern void FASTCALL(unlock_page(struct page *page));
162163

@@ -170,6 +171,19 @@ static inline void lock_page(struct page *page)
170171
__lock_page(page);
171172
}
172173

174+
/*
175+
* lock_page_killable is like lock_page but can be interrupted by fatal
176+
* signals. It returns 0 if it locked the page and -EINTR if it was
177+
* killed while waiting.
178+
*/
179+
static inline int lock_page_killable(struct page *page)
180+
{
181+
might_sleep();
182+
if (TestSetPageLocked(page))
183+
return __lock_page_killable(page);
184+
return 0;
185+
}
186+
173187
/*
174188
* lock_page_nosync should only be used if we can't pin the page's inode.
175189
* Doesn't play quite so well with block device plugging.

‎mm/filemap.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ static int sync_page(void *word)
173173
return 0;
174174
}
175175

176+
static int sync_page_killable(void *word)
177+
{
178+
sync_page(word);
179+
return fatal_signal_pending(current) ? -EINTR : 0;
180+
}
181+
176182
/**
177183
* __filemap_fdatawrite_range - start writeback on mapping dirty pages in range
178184
* @mapping: address space structure to write
@@ -577,6 +583,14 @@ void fastcall __lock_page(struct page *page)
577583
}
578584
EXPORT_SYMBOL(__lock_page);
579585

586+
int fastcall __lock_page_killable(struct page *page)
587+
{
588+
DEFINE_WAIT_BIT(wait, &page->flags, PG_locked);
589+
590+
return __wait_on_bit_lock(page_waitqueue(page), &wait,
591+
sync_page_killable, TASK_KILLABLE);
592+
}
593+
580594
/*
581595
* Variant of lock_page that does not require the caller to hold a reference
582596
* on the page's mapping.

0 commit comments

Comments
 (0)