From: Yang Shi <yang@os.amperecomputing.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Liu Shixin <liushixin2@huawei.com>,
Andrew Morton <akpm@linux-foundation.org>,
Chengming Zhou <chengming.zhou@linux.dev>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Nanyong Sun <sunnanyong@huawei.com>,
Muchun Song <muchun.song@linux.dev>,
Qi Zheng <zhengqi.arch@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: khugepaged: fix call hpage_collapse_scan_file() for anonymous vma
Date: Fri, 10 Jan 2025 10:04:42 -0800 [thread overview]
Message-ID: <8e773a7c-e1dd-4e0e-8349-8aa52f39d85a@os.amperecomputing.com> (raw)
In-Reply-To: <Z4Ciu3E-XjcIga7e@casper.infradead.org>
On 1/9/25 8:31 PM, Matthew Wilcox wrote:
> On Thu, Jan 09, 2025 at 09:00:24AM -0800, Yang Shi wrote:
>> Thanks for catching this. It sounds a little bit weird to have vm_file for
>> an anonymous VMA. I'm not sure why we should keep such special case. It
>> seems shared mapping is treated as shmem file mapping. So can we set vm_file
>> to NULL when mmap'ing /dev/zero for private mapping? Something like:
>>
>> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
>> index 169eed162a7f..fc332efc5c11 100644
>> --- a/drivers/char/mem.c
>> +++ b/drivers/char/mem.c
>> @@ -527,6 +527,7 @@ static int mmap_zero(struct file *file, struct
>> vm_area_struct *vma)
>> if (vma->vm_flags & VM_SHARED)
>> return shmem_zero_setup(vma);
>> vma_set_anonymous(vma);
>> + vma->vm_file = NULL;
>> return 0;
>> }
> I'm wary this might cause other bugs somewhere. rc6 is a bit late to be
> introducing such a subtle change.
Thanks for the extra caution. Applying the proposed fix in khugepaged
code is fine to me either. We can try to kill the special case later.
Looking at the code further, I think we should do more to make private
/dev/zero mapping an anonymous mapping:
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 169eed162a7f..98cfac2bb01f 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -527,6 +527,10 @@ static int mmap_zero(struct file *file, struct
vm_area_struct *vma)
if (vma->vm_flags & VM_SHARED)
return shmem_zero_setup(vma);
vma_set_anonymous(vma);
+ fput(vma->vm_file);
+ vma->vm_file = NULL;
+ vma->vm_pgoff = vma->vm_start >> PAGE_SHIFT;
+
return 0;
}
AFAICT, the user visible effect is we will have different entry in
smaps/maps.
Before the change:
ffffb7190000-ffffb7590000 rw-p 00001000 00:06 8
/dev/zero
Size: 4096 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Rss: 4 kB
Pss: 4 kB
Pss_Dirty: 4 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 4 kB
Referenced: 4 kB
Anonymous: 4 kB
KSM: 0 kB
LazyFree: 0 kB
AnonHugePages: 0 kB
ShmemPmdMapped: 0 kB
FilePmdMapped: 0 kB
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
Locked: 0 kB
THPeligible: 0
VmFlags: rd wr mr mw me ac
After the change:
ffffb6130000-ffffb6530000 rw-p 00000000 00:00 0
Size: 4096 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Rss: 4 kB
Pss: 4 kB
Pss_Dirty: 4 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 4 kB
Referenced: 4 kB
Anonymous: 4 kB
KSM: 0 kB
LazyFree: 0 kB
AnonHugePages: 0 kB
ShmemPmdMapped: 0 kB
FilePmdMapped: 0 kB
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
Locked: 0 kB
THPeligible: 0
VmFlags: rd wr mr mw me ac
I'm not sure who really cares about the difference.
next prev parent reply other threads:[~2025-01-10 18:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 7:00 Liu Shixin
2025-01-09 13:40 ` Matthew Wilcox
2025-01-10 2:29 ` Liu Shixin
2025-01-09 17:00 ` Yang Shi
2025-01-10 2:08 ` Baolin Wang
2025-01-10 2:32 ` Liu Shixin
2025-01-10 4:31 ` Matthew Wilcox
2025-01-10 18:04 ` Yang Shi [this message]
2025-01-10 19:01 ` Matthew Wilcox
2025-01-10 19:40 ` Yang Shi
2025-01-11 3:54 ` Liu Shixin
2025-01-13 18:51 ` Yang Shi
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=8e773a7c-e1dd-4e0e-8349-8aa52f39d85a@os.amperecomputing.com \
--to=yang@os.amperecomputing.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liushixin2@huawei.com \
--cc=muchun.song@linux.dev \
--cc=sunnanyong@huawei.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=zhengqi.arch@bytedance.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