filemap.c (1ff8392c32a2645d2665ca779ecb91bb29361c13) filemap.c (d00806b183152af6d24f46f0c33f14162ca1262a)
1/*
2 * linux/mm/filemap.c
3 *
4 * Copyright (C) 1994-1999 Linus Torvalds
5 */
6
7/*
8 * This file handles the generic file mmap semantics used by

--- 1311 unchanged lines hidden (view full) ---

1320 struct file *file = area->vm_file;
1321 struct address_space *mapping = file->f_mapping;
1322 struct file_ra_state *ra = &file->f_ra;
1323 struct inode *inode = mapping->host;
1324 struct page *page;
1325 unsigned long size, pgoff;
1326 int did_readaround = 0, majmin = VM_FAULT_MINOR;
1327
1/*
2 * linux/mm/filemap.c
3 *
4 * Copyright (C) 1994-1999 Linus Torvalds
5 */
6
7/*
8 * This file handles the generic file mmap semantics used by

--- 1311 unchanged lines hidden (view full) ---

1320 struct file *file = area->vm_file;
1321 struct address_space *mapping = file->f_mapping;
1322 struct file_ra_state *ra = &file->f_ra;
1323 struct inode *inode = mapping->host;
1324 struct page *page;
1325 unsigned long size, pgoff;
1326 int did_readaround = 0, majmin = VM_FAULT_MINOR;
1327
1328 BUG_ON(!(area->vm_flags & VM_CAN_INVALIDATE));
1329
1328 pgoff = ((address-area->vm_start) >> PAGE_CACHE_SHIFT) + area->vm_pgoff;
1329
1330 pgoff = ((address-area->vm_start) >> PAGE_CACHE_SHIFT) + area->vm_pgoff;
1331
1330retry_all:
1331 size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1332 if (pgoff >= size)
1333 goto outside_data_content;
1334
1335 /* If we don't want any read-ahead, don't bother */
1336 if (VM_RandomReadHint(area))
1337 goto no_cached_page;
1338

--- 5 unchanged lines hidden (view full) ---

1344 */
1345 if (VM_SequentialReadHint(area))
1346 page_cache_readahead(mapping, ra, file, pgoff, 1);
1347
1348 /*
1349 * Do we have something in the page cache already?
1350 */
1351retry_find:
1332 size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1333 if (pgoff >= size)
1334 goto outside_data_content;
1335
1336 /* If we don't want any read-ahead, don't bother */
1337 if (VM_RandomReadHint(area))
1338 goto no_cached_page;
1339

--- 5 unchanged lines hidden (view full) ---

1345 */
1346 if (VM_SequentialReadHint(area))
1347 page_cache_readahead(mapping, ra, file, pgoff, 1);
1348
1349 /*
1350 * Do we have something in the page cache already?
1351 */
1352retry_find:
1352 page = find_get_page(mapping, pgoff);
1353 page = find_lock_page(mapping, pgoff);
1353 if (!page) {
1354 unsigned long ra_pages;
1355
1356 if (VM_SequentialReadHint(area)) {
1357 handle_ra_miss(mapping, ra, pgoff);
1358 goto no_cached_page;
1359 }
1360 ra->mmap_miss++;

--- 17 unchanged lines hidden (view full) ---

1378 ra_pages = max_sane_readahead(file->f_ra.ra_pages);
1379 if (ra_pages) {
1380 pgoff_t start = 0;
1381
1382 if (pgoff > ra_pages / 2)
1383 start = pgoff - ra_pages / 2;
1384 do_page_cache_readahead(mapping, file, start, ra_pages);
1385 }
1354 if (!page) {
1355 unsigned long ra_pages;
1356
1357 if (VM_SequentialReadHint(area)) {
1358 handle_ra_miss(mapping, ra, pgoff);
1359 goto no_cached_page;
1360 }
1361 ra->mmap_miss++;

--- 17 unchanged lines hidden (view full) ---

1379 ra_pages = max_sane_readahead(file->f_ra.ra_pages);
1380 if (ra_pages) {
1381 pgoff_t start = 0;
1382
1383 if (pgoff > ra_pages / 2)
1384 start = pgoff - ra_pages / 2;
1385 do_page_cache_readahead(mapping, file, start, ra_pages);
1386 }
1386 page = find_get_page(mapping, pgoff);
1387 page = find_lock_page(mapping, pgoff);
1387 if (!page)
1388 goto no_cached_page;
1389 }
1390
1391 if (!did_readaround)
1392 ra->mmap_hit++;
1393
1394 /*
1388 if (!page)
1389 goto no_cached_page;
1390 }
1391
1392 if (!did_readaround)
1393 ra->mmap_hit++;
1394
1395 /*
1395 * Ok, found a page in the page cache, now we need to check
1396 * that it's up-to-date.
1396 * We have a locked page in the page cache, now we need to check
1397 * that it's up-to-date. If not, it is going to be due to an error.
1397 */
1398 */
1398 if (!PageUptodate(page))
1399 if (unlikely(!PageUptodate(page)))
1399 goto page_not_uptodate;
1400
1400 goto page_not_uptodate;
1401
1401success:
1402 /* Must recheck i_size under page lock */
1403 size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1404 if (unlikely(pgoff >= size)) {
1405 unlock_page(page);
1406 goto outside_data_content;
1407 }
1408
1402 /*
1403 * Found the page and have a reference on it.
1404 */
1405 mark_page_accessed(page);
1406 if (type)
1407 *type = majmin;
1408 return page;
1409

--- 25 unchanged lines hidden (view full) ---

1435 * system is low on memory, or a problem occurs while trying
1436 * to schedule I/O.
1437 */
1438 if (error == -ENOMEM)
1439 return NOPAGE_OOM;
1440 return NOPAGE_SIGBUS;
1441
1442page_not_uptodate:
1409 /*
1410 * Found the page and have a reference on it.
1411 */
1412 mark_page_accessed(page);
1413 if (type)
1414 *type = majmin;
1415 return page;
1416

--- 25 unchanged lines hidden (view full) ---

1442 * system is low on memory, or a problem occurs while trying
1443 * to schedule I/O.
1444 */
1445 if (error == -ENOMEM)
1446 return NOPAGE_OOM;
1447 return NOPAGE_SIGBUS;
1448
1449page_not_uptodate:
1450 /* IO error path */
1443 if (!did_readaround) {
1444 majmin = VM_FAULT_MAJOR;
1445 count_vm_event(PGMAJFAULT);
1446 }
1447
1448 /*
1449 * Umm, take care of errors if the page isn't up-to-date.
1450 * Try to re-read it _once_. We do this synchronously,
1451 * because there really aren't any performance issues here
1452 * and we need to check for errors.
1453 */
1451 if (!did_readaround) {
1452 majmin = VM_FAULT_MAJOR;
1453 count_vm_event(PGMAJFAULT);
1454 }
1455
1456 /*
1457 * Umm, take care of errors if the page isn't up-to-date.
1458 * Try to re-read it _once_. We do this synchronously,
1459 * because there really aren't any performance issues here
1460 * and we need to check for errors.
1461 */
1454 lock_page(page);
1455
1456 /* Somebody truncated the page on us? */
1457 if (!page->mapping) {
1458 unlock_page(page);
1459 page_cache_release(page);
1460 goto retry_all;
1461 }
1462
1463 /* Somebody else successfully read it in? */
1464 if (PageUptodate(page)) {
1465 unlock_page(page);
1466 goto success;
1467 }
1468 ClearPageError(page);
1469 error = mapping->a_ops->readpage(file, page);
1462 ClearPageError(page);
1463 error = mapping->a_ops->readpage(file, page);
1470 if (!error) {
1471 wait_on_page_locked(page);
1472 if (PageUptodate(page))
1473 goto success;
1474 } else if (error == AOP_TRUNCATED_PAGE) {
1475 page_cache_release(page);
1464 page_cache_release(page);
1465
1466 if (!error || error == AOP_TRUNCATED_PAGE)
1476 goto retry_find;
1467 goto retry_find;
1477 }
1478
1468
1479 /*
1480 * Things didn't work out. Return zero to tell the
1481 * mm layer so, possibly freeing the page cache page first.
1482 */
1469 /* Things didn't work out. Return zero to tell the mm layer so. */
1483 shrink_readahead_size_eio(file, ra);
1470 shrink_readahead_size_eio(file, ra);
1484 page_cache_release(page);
1485 return NOPAGE_SIGBUS;
1486}
1487EXPORT_SYMBOL(filemap_nopage);
1488
1489static struct page * filemap_getpage(struct file *file, unsigned long pgoff,
1490 int nonblock)
1491{
1492 struct address_space *mapping = file->f_mapping;

--- 176 unchanged lines hidden (view full) ---

1669int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
1670{
1671 struct address_space *mapping = file->f_mapping;
1672
1673 if (!mapping->a_ops->readpage)
1674 return -ENOEXEC;
1675 file_accessed(file);
1676 vma->vm_ops = &generic_file_vm_ops;
1471 return NOPAGE_SIGBUS;
1472}
1473EXPORT_SYMBOL(filemap_nopage);
1474
1475static struct page * filemap_getpage(struct file *file, unsigned long pgoff,
1476 int nonblock)
1477{
1478 struct address_space *mapping = file->f_mapping;

--- 176 unchanged lines hidden (view full) ---

1655int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
1656{
1657 struct address_space *mapping = file->f_mapping;
1658
1659 if (!mapping->a_ops->readpage)
1660 return -ENOEXEC;
1661 file_accessed(file);
1662 vma->vm_ops = &generic_file_vm_ops;
1663 vma->vm_flags |= VM_CAN_INVALIDATE;
1677 return 0;
1678}
1679
1680/*
1681 * This is for filesystems which do not implement ->writepage.
1682 */
1683int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
1684{

--- 761 unchanged lines hidden ---
1664 return 0;
1665}
1666
1667/*
1668 * This is for filesystems which do not implement ->writepage.
1669 */
1670int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
1671{

--- 761 unchanged lines hidden ---