Christian König
2022-May-31 09:59 UTC
[Nouveau] [PATCH 03/13] mm: shmem: provide oom badness for shmem files
This gives the OOM killer an additional hint which processes are referencing shmem files with potentially no other accounting for them. Signed-off-by: Christian K?nig <christian.koenig at amd.com> --- mm/shmem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 4b2fea33158e..a4ad92a16968 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2179,6 +2179,11 @@ unsigned long shmem_get_unmapped_area(struct file *file, return inflated_addr; } +static long shmem_oom_badness(struct file *file) +{ + return i_size_read(file_inode(file)) >> PAGE_SHIFT; +} + #ifdef CONFIG_NUMA static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol) { @@ -3780,6 +3785,7 @@ EXPORT_SYMBOL(shmem_aops); static const struct file_operations shmem_file_operations = { .mmap = shmem_mmap, .get_unmapped_area = shmem_get_unmapped_area, + .oom_badness = shmem_oom_badness, #ifdef CONFIG_TMPFS .llseek = shmem_file_llseek, .read_iter = shmem_file_read_iter, -- 2.25.1
Michal Hocko
2022-Jun-09 09:18 UTC
[Nouveau] [PATCH 03/13] mm: shmem: provide oom badness for shmem files
On Tue 31-05-22 11:59:57, Christian K?nig wrote:> This gives the OOM killer an additional hint which processes are > referencing shmem files with potentially no other accounting for them. > > Signed-off-by: Christian K?nig <christian.koenig at amd.com> > --- > mm/shmem.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/mm/shmem.c b/mm/shmem.c > index 4b2fea33158e..a4ad92a16968 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -2179,6 +2179,11 @@ unsigned long shmem_get_unmapped_area(struct file *file, > return inflated_addr; > } > > +static long shmem_oom_badness(struct file *file) > +{ > + return i_size_read(file_inode(file)) >> PAGE_SHIFT; > +}This doesn't really represent the in memory size of the file, does it? Also the memcg oom handling could be considerably skewed if the file was shared between more memcgs. -- Michal Hocko SUSE Labs
Christian König
2022-Jun-09 12:16 UTC
[Nouveau] [PATCH 03/13] mm: shmem: provide oom badness for shmem files
Am 09.06.22 um 11:18 schrieb Michal Hocko:> On Tue 31-05-22 11:59:57, Christian K?nig wrote: >> This gives the OOM killer an additional hint which processes are >> referencing shmem files with potentially no other accounting for them. >> >> Signed-off-by: Christian K?nig <christian.koenig at amd.com> >> --- >> mm/shmem.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/mm/shmem.c b/mm/shmem.c >> index 4b2fea33158e..a4ad92a16968 100644 >> --- a/mm/shmem.c >> +++ b/mm/shmem.c >> @@ -2179,6 +2179,11 @@ unsigned long shmem_get_unmapped_area(struct file *file, >> return inflated_addr; >> } >> >> +static long shmem_oom_badness(struct file *file) >> +{ >> + return i_size_read(file_inode(file)) >> PAGE_SHIFT; >> +} > This doesn't really represent the in memory size of the file, does it?Well the file could be partially or fully swapped out as anonymous memory or the address space only sparse populated, but even then just using the file size as OOM badness sounded like the most straightforward approach to me. What could happen is that the file is also mmaped and we double account.> Also the memcg oom handling could be considerably skewed if the file was > shared between more memcgs.Yes, and that's one of the reasons why I didn't touched the memcg by this and only affected the classic OOM killer. Thanks for the comments, Christian.