[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 1/6] mm: shmem: Refactor out shmem_shared_policy() function
From: |
Ackerley Tng |
Subject: |
[RFC PATCH 1/6] mm: shmem: Refactor out shmem_shared_policy() function |
Date: |
Fri, 14 Apr 2023 00:11:50 +0000 |
Refactor out shmem_shared_policy() to allow reading of a file's shared
mempolicy
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
include/linux/shmem_fs.h | 7 +++++++
mm/shmem.c | 10 ++++++----
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
index d9e57485a686..bc1eeb4b4bd9 100644
--- a/include/linux/shmem_fs.h
+++ b/include/linux/shmem_fs.h
@@ -134,6 +134,13 @@ static inline bool shmem_file(struct file *file)
return shmem_mapping(file->f_mapping);
}
+static inline struct shared_policy *shmem_shared_policy(struct file *file)
+{
+ struct inode *inode = file_inode(file);
+
+ return &SHMEM_I(inode)->policy;
+}
+
/*
* If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages
* beyond i_size's notion of EOF, which fallocate has committed to reserving:
diff --git a/mm/shmem.c b/mm/shmem.c
index b053cd1f12da..4f801f398454 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2248,20 +2248,22 @@ unsigned long shmem_get_unmapped_area(struct file *file,
}
#ifdef CONFIG_NUMA
+
static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol)
{
- struct inode *inode = file_inode(vma->vm_file);
- return mpol_set_shared_policy(&SHMEM_I(inode)->policy, vma, mpol);
+ struct shared_policy *info;
+
+ info = shmem_shared_policy(vma->vm_file);
+ return mpol_set_shared_policy(info, vma, mpol);
}
static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
unsigned long addr)
{
- struct inode *inode = file_inode(vma->vm_file);
pgoff_t index;
index = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
- return mpol_shared_policy_lookup(&SHMEM_I(inode)->policy, index);
+ return mpol_shared_policy_lookup(shmem_shared_policy(vma->vm_file),
index);
}
#endif
--
2.40.0.634.g4ca3ef3211-goog
- [RFC PATCH 0/6] Setting memory policy for restrictedmem file, Ackerley Tng, 2023/04/13
- [RFC PATCH 1/6] mm: shmem: Refactor out shmem_shared_policy() function,
Ackerley Tng <=
- [RFC PATCH 3/6] mm: mempolicy: Refactor out __mpol_set_shared_policy(), Ackerley Tng, 2023/04/13
- [RFC PATCH 2/6] mm: mempolicy: Refactor out mpol_init_from_nodemask, Ackerley Tng, 2023/04/13
- [RFC PATCH 4/6] mm: mempolicy: Add and expose mpol_create, Ackerley Tng, 2023/04/13
- [RFC PATCH 6/6] selftests: mm: Add selftest for memfd_restricted_bind(), Ackerley Tng, 2023/04/13
- [RFC PATCH 5/6] mm: restrictedmem: Add memfd_restricted_bind() syscall, Ackerley Tng, 2023/04/13
- Re: [RFC PATCH 0/6] Setting memory policy for restrictedmem file, Michal Hocko, 2023/04/14