aboutsummaryrefslogtreecommitdiffstats
path: root/fs/splice.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@suse.de>2006-04-02 17:11:04 -0400
committerJens Axboe <axboe@suse.de>2006-04-02 17:11:04 -0400
commit3e7ee3e7b36fa4e2d88d8fb0a2577be95fc4636d (patch)
tree46e972e78122f8a719dafc87572bffb25716e745 /fs/splice.c
parentad8d6f0a783ffa2ff9b0cf09910b889715772201 (diff)
[PATCH] splice: fix page stealing LRU handling.
Originally from Nick Piggin, just adapted to the newer branch. You can't check PageLRU without holding zone->lru_lock. The page release code can get away with it only because the page refcount is 0 at that point. Also, you can't reliably remove pages from the LRU unless the refcount is 0. Ever. Signed-off-by: Nick Piggin <nickpiggin@yahoo.com.au> Signed-off-by: Jens Axboe <axboe@suse.de>
Diffstat (limited to 'fs/splice.c')
-rw-r--r--fs/splice.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/fs/splice.c b/fs/splice.c
index b5fb2f3e3ac6..bfa42a277bb8 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -67,16 +67,7 @@ static int page_cache_pipe_buf_steal(struct pipe_inode_info *info,
67 if (!remove_mapping(mapping, page)) 67 if (!remove_mapping(mapping, page))
68 return 1; 68 return 1;
69 69
70 if (PageLRU(page)) { 70 buf->flags |= PIPE_BUF_FLAG_STOLEN | PIPE_BUF_FLAG_LRU;
71 struct zone *zone = page_zone(page);
72
73 spin_lock_irq(&zone->lru_lock);
74 BUG_ON(!PageLRU(page));
75 __ClearPageLRU(page);
76 del_page_from_lru(zone, page);
77 spin_unlock_irq(&zone->lru_lock);
78 }
79
80 return 0; 71 return 0;
81} 72}
82 73
@@ -85,6 +76,7 @@ static void page_cache_pipe_buf_release(struct pipe_inode_info *info,
85{ 76{
86 page_cache_release(buf->page); 77 page_cache_release(buf->page);
87 buf->page = NULL; 78 buf->page = NULL;
79 buf->flags &= ~(PIPE_BUF_FLAG_STOLEN | PIPE_BUF_FLAG_LRU);
88} 80}
89 81
90static void *page_cache_pipe_buf_map(struct file *file, 82static void *page_cache_pipe_buf_map(struct file *file,
@@ -414,11 +406,12 @@ static int pipe_to_file(struct pipe_inode_info *info, struct pipe_buffer *buf,
414{ 406{
415 struct file *file = sd->file; 407 struct file *file = sd->file;
416 struct address_space *mapping = file->f_mapping; 408 struct address_space *mapping = file->f_mapping;
409 gfp_t gfp_mask = mapping_gfp_mask(mapping);
417 unsigned int offset; 410 unsigned int offset;
418 struct page *page; 411 struct page *page;
419 pgoff_t index; 412 pgoff_t index;
420 char *src; 413 char *src;
421 int ret, stolen; 414 int ret;
422 415
423 /* 416 /*
424 * after this, page will be locked and unmapped 417 * after this, page will be locked and unmapped
@@ -429,7 +422,6 @@ static int pipe_to_file(struct pipe_inode_info *info, struct pipe_buffer *buf,
429 422
430 index = sd->pos >> PAGE_CACHE_SHIFT; 423 index = sd->pos >> PAGE_CACHE_SHIFT;
431 offset = sd->pos & ~PAGE_CACHE_MASK; 424 offset = sd->pos & ~PAGE_CACHE_MASK;
432 stolen = 0;
433 425
434 /* 426 /*
435 * reuse buf page, if SPLICE_F_MOVE is set 427 * reuse buf page, if SPLICE_F_MOVE is set
@@ -443,15 +435,15 @@ static int pipe_to_file(struct pipe_inode_info *info, struct pipe_buffer *buf,
443 goto find_page; 435 goto find_page;
444 436
445 page = buf->page; 437 page = buf->page;
446 stolen = 1; 438 if (add_to_page_cache(page, mapping, index, gfp_mask))
447 if (add_to_page_cache_lru(page, mapping, index,
448 mapping_gfp_mask(mapping)))
449 goto find_page; 439 goto find_page;
440
441 if (!(buf->flags & PIPE_BUF_FLAG_LRU))
442 lru_cache_add(page);
450 } else { 443 } else {
451find_page: 444find_page:
452 ret = -ENOMEM; 445 ret = -ENOMEM;
453 page = find_or_create_page(mapping, index, 446 page = find_or_create_page(mapping, index, gfp_mask);
454 mapping_gfp_mask(mapping));
455 if (!page) 447 if (!page)
456 goto out; 448 goto out;
457 449
@@ -494,7 +486,7 @@ find_page:
494 } else if (ret) 486 } else if (ret)
495 goto out; 487 goto out;
496 488
497 if (!stolen) { 489 if (!(buf->flags & PIPE_BUF_FLAG_STOLEN)) {
498 char *dst = kmap_atomic(page, KM_USER0); 490 char *dst = kmap_atomic(page, KM_USER0);
499 491
500 memcpy(dst + offset, src + buf->offset, sd->len); 492 memcpy(dst + offset, src + buf->offset, sd->len);
@@ -511,7 +503,7 @@ find_page:
511 503
512 balance_dirty_pages_ratelimited(mapping); 504 balance_dirty_pages_ratelimited(mapping);
513out: 505out:
514 if (!stolen) { 506 if (!(buf->flags & PIPE_BUF_FLAG_STOLEN)) {
515 page_cache_release(page); 507 page_cache_release(page);
516 unlock_page(page); 508 unlock_page(page);
517 } 509 }