Replace use of the legacy vm_flags_t flags with vma_flags_t values in the
file fault and mmap readahead logic.

No functional change intended.

Signed-off-by: Lorenzo Stoakes (ARM) <[email protected]>
Reviewed-by: Barry Song <[email protected]>
---
 mm/filemap.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index acf5e562b732..ce720c4c55f0 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3359,13 +3359,14 @@ static struct file *do_sync_mmap_readahead(struct 
vm_fault *vmf)
        struct address_space *mapping = file->f_mapping;
        DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff);
        struct file *fpin = NULL;
-       vm_flags_t vm_flags = vmf->vma->vm_flags;
+       struct vm_area_struct *vma = vmf->vma;
        bool force_thp_readahead = false;
        unsigned int thp_order = 0;
        unsigned short mmap_miss;
 
        /* Use the readahead code, even if readahead is disabled */
-       if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && (vm_flags & 
VM_HUGEPAGE)) {
+       if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) &&
+           vma_test(vma, VMA_HUGEPAGE_BIT)) {
                /*
                 * Cap max THP order at 2MB: this is the common PMD-sized
                 * hugepage size, and it avoids memory pressure from very
@@ -3385,20 +3386,21 @@ static struct file *do_sync_mmap_readahead(struct 
vm_fault *vmf)
                 * If we don't want any read-ahead, don't bother.
                 * VM_EXEC case below is already intended for random access.
                 */
-               if ((vm_flags & (VM_RAND_READ | VM_EXEC)) == VM_RAND_READ)
+               if (vma_test(vma, VMA_RAND_READ_BIT) &&
+                   !vma_test(vma, VMA_EXEC_BIT))
                        return fpin;
 
                if (!ra->ra_pages)
                        return fpin;
 
-               if (vm_flags & VM_SEQ_READ) {
+               if (vma_test(vma, VMA_SEQ_READ_BIT)) {
                        fpin = maybe_unlock_mmap_for_io(vmf, fpin);
                        page_cache_sync_ra(&ractl, ra->ra_pages);
                        return fpin;
                }
        }
 
-       if (!(vm_flags & (VM_SEQ_READ | VM_EXEC))) {
+       if (!vma_test_any(vma, VMA_SEQ_READ_BIT, VMA_EXEC_BIT)) {
                /* Avoid banging the cache line if not needed */
                mmap_miss = READ_ONCE(ra->mmap_miss);
                if (mmap_miss < MMAP_LOTSAMISS * 10)
@@ -3414,6 +3416,7 @@ static struct file *do_sync_mmap_readahead(struct 
vm_fault *vmf)
 
        if (force_thp_readahead) {
                unsigned long folio_nr_pages = 1UL << thp_order;
+               const bool random_read = vma_test(vma, VMA_RAND_READ_BIT);
 
                fpin = maybe_unlock_mmap_for_io(vmf, fpin);
                ractl._index &= ~(folio_nr_pages - 1);
@@ -3422,7 +3425,7 @@ static struct file *do_sync_mmap_readahead(struct 
vm_fault *vmf)
                 * Fetch two folios so we get the chance to actually
                 * readahead, unless we've been told not to.
                 */
-               if (!(vm_flags & VM_RAND_READ))
+               if (!random_read)
                        ra->size *= 2;
                ra->async_size = folio_nr_pages;
                ra->order = thp_order;
@@ -3430,7 +3433,7 @@ static struct file *do_sync_mmap_readahead(struct 
vm_fault *vmf)
                return fpin;
        }
 
-       if (vm_flags & VM_EXEC) {
+       if (vma_test(vma, VMA_EXEC_BIT)) {
                /*
                 * Allow arch to request a preferred minimum folio order for
                 * executable memory. This can often be beneficial to
@@ -3442,7 +3445,6 @@ static struct file *do_sync_mmap_readahead(struct 
vm_fault *vmf)
                 * pad that might exist between sections, which would be a waste
                 * of memory.
                 */
-               struct vm_area_struct *vma = vmf->vma;
                const unsigned long start = vma_start_pgoff(vma);
                const unsigned long end = vma_end_pgoff(vma);
                unsigned long ra_end;
@@ -3485,7 +3487,7 @@ static struct file *do_async_mmap_readahead(struct 
vm_fault *vmf,
        unsigned short mmap_miss;
 
        /* If we don't want any read-ahead, don't bother */
-       if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages)
+       if (vma_test(vmf->vma, VMA_RAND_READ_BIT) || !ra->ra_pages)
                return fpin;
 
        /*
@@ -3499,7 +3501,7 @@ static struct file *do_async_mmap_readahead(struct 
vm_fault *vmf,
         * keep the counter symmetric.
         */
        if (likely(!folio_test_locked(folio)) &&
-           !(vmf->vma->vm_flags & (VM_SEQ_READ | VM_EXEC))) {
+           !vma_test_any(vmf->vma, VMA_SEQ_READ_BIT, VMA_EXEC_BIT)) {
                mmap_miss = READ_ONCE(ra->mmap_miss);
                if (mmap_miss)
                        WRITE_ONCE(ra->mmap_miss, --mmap_miss);
@@ -3532,7 +3534,7 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct 
vm_fault *vmf)
         * scenarios. Recheck the PTE without PT lock firstly, thereby reducing
         * the number of times we hold PT lock.
         */
-       if (!(vma->vm_flags & VM_LOCKED))
+       if (!vma_test(vma, VMA_LOCKED_BIT))
                return 0;
 
        if (!(vmf->flags & FAULT_FLAG_ORIG_PTE_VALID))
@@ -4018,7 +4020,7 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf,
                if ((map_ret & VM_FAULT_NOPAGE) &&
                    !(vmf->flags & FAULT_FLAG_TRIED) &&
                    !folio_test_workingset(folio) &&
-                   !(vma->vm_flags & (VM_SEQ_READ | VM_EXEC))) {
+                   !vma_test_any(vma, VMA_SEQ_READ_BIT, VMA_EXEC_BIT)) {
                        unsigned short mmap_miss;
 
                        mmap_miss = READ_ONCE(file->f_ra.mmap_miss);

-- 
2.56.1


Reply via email to