* [PATCH] mm/secretmem: use a folio in secretmem_fault()
@ 2023-08-12 1:58 Peng Zhang
2023-08-12 3:53 ` Matthew Wilcox
0 siblings, 1 reply; 3+ messages in thread
From: Peng Zhang @ 2023-08-12 1:58 UTC (permalink / raw)
To: linux-mm; +Cc: willy, akpm, wangkefeng.wang, sunnanyong, ZhangPeng
From: ZhangPeng <zhangpeng362@huawei.com>
Saves three implicit call to compound_head().
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
mm/secretmem.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/mm/secretmem.c b/mm/secretmem.c
index 86442a15d12f..3afb5ad701e1 100644
--- a/mm/secretmem.c
+++ b/mm/secretmem.c
@@ -55,6 +55,7 @@ static vm_fault_t secretmem_fault(struct vm_fault *vmf)
gfp_t gfp = vmf->gfp_mask;
unsigned long addr;
struct page *page;
+ struct folio *folio;
vm_fault_t ret;
int err;
@@ -66,23 +67,24 @@ static vm_fault_t secretmem_fault(struct vm_fault *vmf)
retry:
page = find_lock_page(mapping, offset);
if (!page) {
- page = alloc_page(gfp | __GFP_ZERO);
- if (!page) {
+ folio = folio_alloc(gfp | __GFP_ZERO, 0);
+ if (!folio) {
ret = VM_FAULT_OOM;
goto out;
}
+ page = &folio->page;
err = set_direct_map_invalid_noflush(page);
if (err) {
- put_page(page);
+ folio_put(folio);
ret = vmf_error(err);
goto out;
}
- __SetPageUptodate(page);
- err = add_to_page_cache_lru(page, mapping, offset, gfp);
+ __folio_mark_uptodate(folio);
+ err = filemap_add_folio(mapping, folio, offset, gfp);
if (unlikely(err)) {
- put_page(page);
+ folio_put(folio);
/*
* If a split of large page was required, it
* already happened when we marked the page invalid
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/secretmem: use a folio in secretmem_fault()
2023-08-12 1:58 [PATCH] mm/secretmem: use a folio in secretmem_fault() Peng Zhang
@ 2023-08-12 3:53 ` Matthew Wilcox
2023-08-12 6:24 ` zhangpeng (AS)
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2023-08-12 3:53 UTC (permalink / raw)
To: Peng Zhang; +Cc: linux-mm, akpm, wangkefeng.wang, sunnanyong
On Sat, Aug 12, 2023 at 09:58:35AM +0800, Peng Zhang wrote:
> From: ZhangPeng <zhangpeng362@huawei.com>
>
> Saves three implicit call to compound_head().
I count four!
> if (err) {
> - put_page(page);
> + folio_put(folio);
> ret = vmf_error(err);
One.
>
> - __SetPageUptodate(page);
> - err = add_to_page_cache_lru(page, mapping, offset, gfp);
> + __folio_mark_uptodate(folio);
> + err = filemap_add_folio(mapping, folio, offset, gfp);
Two, three.
> if (unlikely(err)) {
> - put_page(page);
> + folio_put(folio);
Four!
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/secretmem: use a folio in secretmem_fault()
2023-08-12 3:53 ` Matthew Wilcox
@ 2023-08-12 6:24 ` zhangpeng (AS)
0 siblings, 0 replies; 3+ messages in thread
From: zhangpeng (AS) @ 2023-08-12 6:24 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-mm, akpm, wangkefeng.wang, sunnanyong
On 2023/8/12 11:53, Matthew Wilcox wrote:
> On Sat, Aug 12, 2023 at 09:58:35AM +0800, Peng Zhang wrote:
>> From: ZhangPeng <zhangpeng362@huawei.com>
>>
>> Saves three implicit call to compound_head().
> I count four!
>
>> if (err) {
>> - put_page(page);
>> + folio_put(folio);
>> ret = vmf_error(err);
> One.
>
>>
>> - __SetPageUptodate(page);
>> - err = add_to_page_cache_lru(page, mapping, offset, gfp);
>> + __folio_mark_uptodate(folio);
>> + err = filemap_add_folio(mapping, folio, offset, gfp);
> Two, three.
>
>> if (unlikely(err)) {
>> - put_page(page);
>> + folio_put(folio);
> Four!
>
> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Indeed. Thanks!
--
Best Regards,
Peng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-12 6:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-12 1:58 [PATCH] mm/secretmem: use a folio in secretmem_fault() Peng Zhang
2023-08-12 3:53 ` Matthew Wilcox
2023-08-12 6:24 ` zhangpeng (AS)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox