fadvise invalidating range fix
Subsystems (3)
PATCH 1/1 fadvise invalidating range fix
Hi Andrew
I noticed fadvise(POSIX_FADV_DONTNEED) was invalidating more parts of the file than I expected. Here is the patch.
Notes for change in fadvise.c/sys_fadvise64_64():
- It should be noticed that the 'end' param of invalidate_mapping_pages() is inclusive;
- When 'offset' and/or 'offset+len' do no align to page boundary, we must decide whether to abandon the partial page at the beginning/end of the range. My patch assumes that the application is scanning forward,
which is the most common case.
So 'end_index' is set to the page just before the ending partial page.
- Manual pages for posix_fadvise() mentioned the case of 'len=0', which is not handled by the code. Perhaps the handling of 'len=0' is useless, so I leaved that alone.
Notes for change in truncate.c/invalidate_mapping_pages():
- Is there any reason that I din't know to free any page outside of [begin,end]? The origin code will abandon useful trailing pages when there's hole in the range, which may cause series of unecessary disk I/O in streaming applications.
best regards, Wu Fengguang
mm/fadvise.c +1 -2
@@ -66,8 +66,7 @@if (!bdi_write_congested (mapping->backing_dev_info))filemap_flush (mapping); start_index = offset >>PAGE_CACHE_SHIFT ; - end_index = (offset + len +PAGE_CACHE_SIZE -1 ) >> -PAGE_CACHE_SHIFT ; + end_index = ((offset + len) >>PAGE_CACHE_SHIFT ) -1 ;invalidate_mapping_pages (mapping, start_index, end_index);break ;default :
mm/truncate.c +2 -0
@@ -219,6 +219,8 @@ ret +=invalidate_complete_page (mapping, page); unlock:unlock_page (page); +if (next > end) +break ; }pagevec_release (&pvec);cond_resched ();