linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ackerley Tng <ackerleytng@google.com>
To: kvm@vger.kernel.org, linux-api@vger.kernel.org,
	linux-arch@vger.kernel.org,  linux-doc@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, qemu-devel@nongnu.org
Cc: aarcange@redhat.com, ak@linux.intel.com,
	akpm@linux-foundation.org,  arnd@arndb.de, bfields@fieldses.org,
	bp@alien8.de,  chao.p.peng@linux.intel.com, corbet@lwn.net,
	dave.hansen@intel.com,  david@redhat.com, ddutile@redhat.com,
	dhildenb@redhat.com, hpa@zytor.com,  hughd@google.com,
	jlayton@kernel.org, jmattson@google.com, joro@8bytes.org,
	 jun.nakajima@intel.com, kirill.shutemov@linux.intel.com,
	linmiaohe@huawei.com,  luto@kernel.org,
	mail@maciej.szmigiero.name, mhocko@suse.com,
	 michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com,
	 pbonzini@redhat.com, qperret@google.com, rppt@kernel.org,
	seanjc@google.com,  shuah@kernel.org, steven.price@arm.com,
	tabba@google.com, tglx@linutronix.de,  vannapurve@google.com,
	vbabka@suse.cz, vkuznets@redhat.com,  wanpengli@tencent.com,
	wei.w.wang@intel.com, x86@kernel.org,
	 yu.c.zhang@linux.intel.com, muchun.song@linux.dev,
	feng.tang@intel.com,  brgerst@gmail.com, rdunlap@infradead.org,
	masahiroy@kernel.org,  mailhol.vincent@wanadoo.fr,
	Ackerley Tng <ackerleytng@google.com>
Subject: [RFC PATCH 1/6] mm: shmem: Refactor out shmem_shared_policy() function
Date: Fri, 14 Apr 2023 00:11:50 +0000	[thread overview]
Message-ID: <476aa5a107994d293dcdfc5a620cc52f625768c2.1681430907.git.ackerleytng@google.com> (raw)
In-Reply-To: <cover.1681430907.git.ackerleytng@google.com>

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



  reply	other threads:[~2023-04-14  0:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14  0:11 [RFC PATCH 0/6] Setting memory policy for restrictedmem file Ackerley Tng
2023-04-14  0:11 ` Ackerley Tng [this message]
2023-04-14  0:11 ` [RFC PATCH 2/6] mm: mempolicy: Refactor out mpol_init_from_nodemask Ackerley Tng
2023-04-14  0:11 ` [RFC PATCH 3/6] mm: mempolicy: Refactor out __mpol_set_shared_policy() Ackerley Tng
2023-04-14  0:11 ` [RFC PATCH 4/6] mm: mempolicy: Add and expose mpol_create Ackerley Tng
2023-04-14  0:11 ` [RFC PATCH 5/6] mm: restrictedmem: Add memfd_restricted_bind() syscall Ackerley Tng
2023-04-14  0:11 ` [RFC PATCH 6/6] selftests: mm: Add selftest for memfd_restricted_bind() Ackerley Tng
2023-04-14  6:33 ` [RFC PATCH 0/6] Setting memory policy for restrictedmem file Michal Hocko
2023-04-14 17:24   ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=476aa5a107994d293dcdfc5a620cc52f625768c2.1681430907.git.ackerleytng@google.com \
    --to=ackerleytng@google.com \
    --cc=aarcange@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bfields@fieldses.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@intel.com \
    --cc=david@redhat.com \
    --cc=ddutile@redhat.com \
    --cc=dhildenb@redhat.com \
    --cc=feng.tang@intel.com \
    --cc=hpa@zytor.com \
    --cc=hughd@google.com \
    --cc=jlayton@kernel.org \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=jun.nakajima@intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mail@maciej.szmigiero.name \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=masahiroy@kernel.org \
    --cc=mhocko@suse.com \
    --cc=michael.roth@amd.com \
    --cc=mingo@redhat.com \
    --cc=muchun.song@linux.dev \
    --cc=naoya.horiguchi@nec.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qperret@google.com \
    --cc=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=steven.price@arm.com \
    --cc=tabba@google.com \
    --cc=tglx@linutronix.de \
    --cc=vannapurve@google.com \
    --cc=vbabka@suse.cz \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=wei.w.wang@intel.com \
    --cc=x86@kernel.org \
    --cc=yu.c.zhang@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox