tmpfs not interleaving properly
Subsystems (3)
PATCH v2 1/1 tmpfs not interleaving properly
When tmpfs has the memory policy interleaved it always starts allocating at each file at node 0. When there are many small files the lower nodes fill up disproportionately.
This patch attempts to spread out node usage by starting files at nodes other then 0. I disturbed the addr parameter since alloc_pages_vma will only use it when the policy is MPOL_INTERLEAVE. Random was picked over using another variable which would require some sort of contention management.
--- include/linux/shmem_fs.h | 1 + mm/shmem.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletions(-)
include/linux/shmem_fs.h +1 -0
@@ -17,6 +17,7 @@ struct shmem_inode_info {char *symlink;/* unswappable short symlink */ };struct shared_policy policy;/* NUMA memory alloc policy */ +unsigned long node_offset;/* bias for interleaved nodes */ struct list_head swaplist;/* chain of maybes on swap */ struct list_head xattr_list;/* list of shmem_xattr */ struct inode vfs_inode;
mm/shmem.c +2 -1
@@ -929,7 +929,7 @@ static struct page *shmem_alloc_page(gfp_t gfp,/* * alloc_page_vma() will drop the shared policy reference */ - return alloc_page_vma(gfp, &pvma, 0); + return alloc_page_vma(gfp, &pvma, info->node_offset << PAGE_SHIFT ); }#else /* !CONFIG_NUMA */ #ifdef CONFIG_TMPFS
@@ -1357,6 +1357,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode inode->i_fop = &shmem_file_operations;mpol_shared_policy_init (&info->policy,shmem_get_sbmpol (sbinfo)); + info->node_offset =node_random (&node_online_map);break ;case S_IFDIR :inc_nlink (inode);
Signature · 1 line
1.6.0.2
Andrew Morton
maintainerQuoted 7 lines · On Thu, 31 May 2012 09:39:17 -0500 Nathan Zimmer <[email protected]> wrote:
When tmpfs has the memory policy interleaved it always starts allocating at each file at node 0. When there are many small files the lower nodes fill up disproportionately.
This patch attempts to spread out node usage by starting files at nodes other then 0. I disturbed the addr parameter sincealloc_pages_vmawill only use it when the policy isMPOL_INTERLEAVE. Random was picked over using another variable which would require some sort of contention management.
The patch title is a bit scummy ;) It describes a kernel problem, not the patch. I renamed it to "tmpfs: implement NUMA node interleaving".
It looks nice and simple
Quoted 1 line
We could probably sneak this past Greg, but should we? It's a feature and a performance enhancement. Such things are not normally added to -stable. If there were some nice performance improvements in workloads which our users care about then I guess we could backport it.
But you've provided us with no measurements at all, hence no reason to backport it.
Quoted 37 lines · Nathan Zimmer
When tmpfs has the memory policy interleaved it always starts allocating at each file at node 0. When there are many small files the lower nodes fill up disproportionately.
This patch attempts to spread out node usage by starting files at nodes other then 0. I disturbed the addr parameter sincealloc_pages_vmawill only use it when the policy isMPOL_INTERLEAVE. Random was picked over using another variable which would require some sort of contention management.Cc Christoph Lameter<[email protected]>Cc Nick Piggin<[email protected]>Cc Hugh Dickins<[email protected]>Cc Lee Schermerhorn<[email protected]>Acked-by Rik van Riel<[email protected]>Signed-off-by Nathan T Zimmer<[email protected]>--- include/linux/shmem_fs.h | 1 + mm/shmem.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletions(-)include/linux/shmem_fs.h +1
-0@@ -17,6 +17,7 @@ struct shmem_inode_info {char *symlink;/* unswappable short symlink */ };struct shared_policy policy;/* NUMA memory alloc policy */ +unsigned long node_offset;/* bias for interleaved nodes */ struct list_head swaplist;/* chain of maybes on swap */ struct list_head xattr_list;/* list of shmem_xattr */ struct inode vfs_inode;mm/shmem.c +0
-0
mm/shmem.c static struct page *shmem_alloc_page(gfp_t gfp, · line 932
Quoted 5 lines
mm/shmem.c +1
-1@@ -929,7 +929,7 @@ static struct page *shmem_alloc_page(gfp_t gfp,/* * alloc_page_vma() will drop the shared policy reference */ -return alloc_page_vma (gfp,&pvma,0 ); +return alloc_page_vma (gfp,&pvma, info->node_offset<<PAGE_SHIFT );
3rd argument of alloc_page_vma() is an address. This is type error.
Quoted 11 lines
mm/shmem.c +1
-0}#else /* !CONFIG_NUMA */ #ifdef CONFIG_TMPFS @@ -1357,6 +1357,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode inode->i_fop =&shmem_file_operations;mpol_shared_policy_init (&info->policy,shmem_get_sbmpol (sbinfo)); + info->node_offset =node_random (&node_online_map);break ;case S_IFDIR :inc_nlink (inode);
Andrew Morton
maintainerQuoted 10 lines · On Thu, 31 May 2012 16:09:15 -0400 KOSAKI Motohiro <[email protected]>…
mm/shmem.c static struct page *shmem_alloc_page(gfp_t gfp, · line 932
Quoted 8 lines
mm/shmem.c +1
-1@@ -929,7 +929,7 @@ static struct page *shmem_alloc_page(gfp_t gfp,/* * alloc_page_vma() will drop the shared policy reference */ -return alloc_page_vma (gfp,&pvma,0 ); +return alloc_page_vma (gfp,&pvma, info->node_offset<<PAGE_SHIFT );3rd argument of
alloc_page_vma()is an address. This is type error.
Well, it's an unsigned long...
But yes, it is conceptually wrong and *looks* weird. I think we can address that by overcoming our peculair aversion to documenting our code, sigh. This?
mm/shmem.c renamed from mm/shmem.c~tmpfs-implement-numa-node-interleaving-fix +5 -2
@@ -927,9 +927,12 @@ static struct page *shmem_alloc_page(gfp pvma.vm_policy =mpol_shared_policy_lookup (&info->policy, index);/* -* alloc_page_vma() will drop the shared policy reference +* alloc_page_vma() will drop the shared policy reference. +* +* To avoid allocating all tmpfs pages on node 0, we fake up a virtual +* address based on this file's predetermined preferred node. */ - return alloc_page_vma(gfp, &pvma, info->node_offset << PAGE_SHIFT ); + return alloc_page_vma(gfp, &pvma, info->node_offset << PAGE_SHIFT); }#else /* !CONFIG_NUMA */ #ifdef CONFIG_TMPFS
_
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Thu, 31 May 2012 16:09:15 -0400 KOSAKI Motohiro<[email protected]>…
mm/shmem.c static struct page *shmem_alloc_page(gfp_t gfp, · line 932
Quoted 8 lines
mm/shmem.c +1
-1@@ -929,7 +929,7 @@ static struct page *shmem_alloc_page(gfp_t gfp,/* * alloc_page_vma() will drop the shared policy reference */ -return alloc_page_vma (gfp,&pvma,0 ); +return alloc_page_vma (gfp,&pvma, info->node_offset<<PAGE_SHIFT );3rd argument of
alloc_page_vma()is an address. This is type error.
Quoted 5 lines
Well, it's an unsigned long...
But yes, it is conceptually wrong and *looks* weird. I think we can address that by overcoming our peculair aversion to documenting our code, sigh. This?
Sorry, no.
addr agrument of alloc_pages_vma() have two meanings.
1) interleave node seed
2) look-up key of shmem policy
I think this patch break (2). shmem_get_policy(pol, addr) assume caller honor to pass correct address.
Oh, yes. *NOW*, we are discussing shmem policy removing. but it haven't be removed. Please don't break.
Quoted 23 lines · KOSAKI Motohiro
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Thu, 31 May 2012 16:09:15 -0400 KOSAKI Motohiro<[email protected]>…
mm/shmem.c static struct page *shmem_alloc_page(gfp_t gfp, · line 932
Quoted 8 lines
mm/shmem.c +1
-1@@ -929,7 +929,7 @@ static struct page *shmem_alloc_page(gfp_t gfp,/* * alloc_page_vma() will drop the shared policy reference */ -return alloc_page_vma (gfp,&pvma,0 ); +return alloc_page_vma (gfp,&pvma, info->node_offset<<PAGE_SHIFT );3rd argument of
alloc_page_vma()is an address. This is type error.Quoted 5 lines
Well, it's an unsigned long...
But yes, it is conceptually wrong and *looks* weird. I think we can address that by overcoming our peculair aversion to documenting our code, sigh. This?
Sorry, no.
Quoted 7 lines
addr agrument of
alloc_pages_vma()have two meanings.1) interleave node seed
2) look-up key of shmem policyI think this patch break (2).
shmem_get_policy(pol, addr)assume caller honor to pass correct address.
But the pseudo vma we generated in shmem_alloc_page the vm_ops are set to NULL. So get_vma_policy will return the policy provided by the pseudo vma and not reach the shmem_get_policy.
Quoted 29 lines · Nathan Zimmer
Quoted 28 lines · KOSAKI Motohiro
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Thu, 31 May 2012 16:09:15 -0400 KOSAKI Motohiro<[email protected]>…
mm/shmem.c static struct page *shmem_alloc_page(gfp_t gfp, · line 932
Quoted 8 lines
mm/shmem.c +1
-1@@ -929,7 +929,7 @@ static struct page *shmem_alloc_page(gfp_t gfp,/* * alloc_page_vma() will drop the shared policy reference */ -return alloc_page_vma (gfp,&pvma,0 ); +return alloc_page_vma (gfp,&pvma, info->node_offset<<PAGE_SHIFT );3rd argument of
alloc_page_vma()is an address. This is type error.Quoted 5 lines
Well, it's an unsigned long...
But yes, it is conceptually wrong and *looks* weird. I think we can address that by overcoming our peculair aversion to documenting our code, sigh. This?
Sorry, no.
addr agrument of
alloc_pages_vma()have two meanings.1) interleave node seed
2) look-up key of shmem policy
Quoted 6 lines
Quoted 2 lines
I think this patch break (2).
shmem_get_policy(pol, addr)assume caller honor to pass correct address.But the pseudo vma we generated in
shmem_alloc_pagethevm_opsare set to NULL. Soget_vma_policywill return the policy provided by the pseudo vma and not reach theshmem_get_policy.
yes, and it is bug source. we may need to change soon. I guess the right way is to make vm_ops->interleave and interleave_nid uses it if povided.
btw, I don't think node_random() is good idea. it is random(pid + jiffies + cycle). current->cpuset_mem_spread_rotor is per-thread value. but you now need per-inode interleave offset. maybe, just inode addition is enough. Why do you need randomness?
Quoted 33 lines · KOSAKI Motohiro
Quoted 32 lines · Nathan Zimmer
Quoted 30 lines · KOSAKI Motohiro
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Thu, 31 May 2012 16:09:15 -0400 KOSAKI Motohiro<[email protected]>…
mm/shmem.c static struct page *shmem_alloc_page(gfp_t gfp, · line 932
Quoted 8 lines
mm/shmem.c +1
-1@@ -929,7 +929,7 @@ static struct page *shmem_alloc_page(gfp_t gfp,/* * alloc_page_vma() will drop the shared policy reference */ -return alloc_page_vma (gfp,&pvma,0 ); +return alloc_page_vma (gfp,&pvma, info->node_offset<<PAGE_SHIFT );3rd argument of
alloc_page_vma()is an address. This is type error.Quoted 5 lines
Well, it's an unsigned long...
But yes, it is conceptually wrong and *looks* weird. I think we can address that by overcoming our peculair aversion to documenting our code, sigh. This?
Sorry, no.
addr agrument of
alloc_pages_vma()have two meanings.1) interleave node seed
2) look-up key of shmem policyI think this patch break (2).
shmem_get_policy(pol, addr)assume caller honor to pass correct address.
Quoted 7 lines
Quoted 3 lines
But the pseudo vma we generated in
shmem_alloc_pagethevm_opsare set to NULL. Soget_vma_policywill return the policy provided by the pseudo vma and not reach theshmem_get_policy.yes, and it is bug source. we may need to change soon. I guess the right way is to make
vm_ops->interleaveandinterleave_niduses it if povided.
If we provide vm_ops then won't shmem_get_policy get called? That would be an issue since shmem_get_policy assumes vm_file is non NULL.
Quoted 4 lines
btw, I don't think
node_random()is good idea. it is random(pid + jiffies + cycle).current->cpuset_mem_spread_rotoris per-thread value. but you now need per-inode interleave offset. maybe, just inode addition is enough. Why do you need randomness?
I don't really need the randomness, the rotor should be good enough. The correct way to get that is cpuset_mem_spread_node(), yes?
Also apologies for such a delay in my response.
Quoted 44 lines · Nathan Zimmer
Quoted 33 lines · KOSAKI Motohiro
Quoted 32 lines · Nathan Zimmer
Quoted 30 lines · KOSAKI Motohiro
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Thu, 31 May 2012 16:09:15 -0400 KOSAKI Motohiro<[email protected]>…
mm/shmem.c static struct page *shmem_alloc_page(gfp_t gfp, · line 932
Quoted 8 lines
mm/shmem.c +1
-1@@ -929,7 +929,7 @@ static struct page *shmem_alloc_page(gfp_t gfp,/* * alloc_page_vma() will drop the shared policy reference */ -return alloc_page_vma (gfp,&pvma,0 ); +return alloc_page_vma (gfp,&pvma, info->node_offset<<PAGE_SHIFT );3rd argument of
alloc_page_vma()is an address. This is type error.Quoted 5 lines
Well, it's an unsigned long...
But yes, it is conceptually wrong and *looks* weird. I think we can address that by overcoming our peculair aversion to documenting our code, sigh. This?
Sorry, no.
addr agrument of
alloc_pages_vma()have two meanings.1) interleave node seed
2) look-up key of shmem policyI think this patch break (2).
shmem_get_policy(pol, addr)assume caller honor to pass correct address.Quoted 6 lines
Quoted 3 lines
But the pseudo vma we generated in
shmem_alloc_pagethevm_opsare set to NULL. Soget_vma_policywill return the policy provided by the pseudo vma and not reach theshmem_get_policy.yes, and it is bug source. we may need to change soon. I guess the right way is to make
vm_ops->interleaveandinterleave_niduses it if povided.If we provide
vm_opsthen won'tshmem_get_policyget called? That would be an issue sinceshmem_get_policyassumesvm_fileis non NULL.
Quoted 6 lines
Quoted 3 lines
btw, I don't think
node_random()is good idea. it is random(pid + jiffies + cycle).current->cpuset_mem_spread_rotoris per-thread value. but you now need per-inode interleave offset. maybe, just inode addition is enough. Why do you need randomness?I don't really need the randomness, the rotor should be good enough. The correct way to get that is
cpuset_mem_spread_node(), yes?
I think that's good idea too.