Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2598,21 +2598,21 @@ static int __cache_ext_dio(struct file *file, struct address_space *mapping,
if (!folio) {
if (i == index)
return -ENOMEM;
// We added some folios that we want to copy and then
// free, so this could fix our OOM
return 1;
}

filemap_invalidate_lock_shared(mapping);
__folio_set_locked(folio);

folio_ref_add(folio, folio_nr_pages(folio));
folio->mapping = mapping;
folio->index = i;
error = filemap_read_folio_cache_ext(
file, mapping->a_ops->read_folio, folio);
filemap_invalidate_unlock_shared(mapping);
folio->mapping = NULL;
if (error) {
folio_put(folio);

if (i == index)
return error;
return 1;
Expand Down Expand Up @@ -2797,7 +2797,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
* mark it as accessed the first time.
*/
if (!pos_same_folio(iocb->ki_pos, last_pos - 1,
fbatch.folios[0]))
fbatch.folios[0]) && !cache_ext_flag)
folio_mark_accessed(fbatch.folios[0]);

for (i = 0; i < folio_batch_count(&fbatch); i++) {
Expand All @@ -2818,7 +2818,6 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
* before reading the folio on the kernel side.
*/

// TODO: investigate
if (writably_mapped)
flush_dcache_folio(folio);

Expand All @@ -2832,15 +2831,10 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
error = -EFAULT;
break;
}

// TODO: drop reference count before freeing?
if (cache_ext_flag)
filemap_free_folio(mapping, folio);
}
put_folios:
if (!cache_ext_flag)
for (i = 0; i < folio_batch_count(&fbatch); i++)
folio_put(fbatch.folios[i]);
for (i = 0; i < folio_batch_count(&fbatch); i++)
folio_put(fbatch.folios[i]);

cache_ext_flag = 0;
folio_batch_init(&fbatch);
Expand Down