From: Chih-En Lin <shiyn.lin@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Qi Zheng <zhengqi.arch@bytedance.com>,
David Hildenbrand <david@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Luis Chamberlain <mcgrof@kernel.org>,
Kees Cook <keescook@chromium.org>,
Iurii Zaikin <yzaikin@google.com>,
Vlastimil Babka <vbabka@suse.cz>,
William Kucharski <william.kucharski@oracle.com>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
Peter Xu <peterx@redhat.com>,
Suren Baghdasaryan <surenb@google.com>,
Arnd Bergmann <arnd@arndb.de>,
Tong Tiangen <tongtiangen@huawei.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Li kunyu <kunyu@nfschina.com>, Nadav Amit <namit@vmware.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Minchan Kim <minchan@kernel.org>, Yang Shi <shy828301@gmail.com>,
Song Liu <song@kernel.org>, Miaohe Lin <linmiaohe@huawei.com>,
Thomas Gleixner <tglx@linutronix.de>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Andy Lutomirski <luto@kernel.org>,
Fenghua Yu <fenghua.yu@intel.com>,
Dinglan Peng <peng301@purdue.edu>,
Pedro Fonseca <pfonseca@purdue.edu>,
Jim Huang <jserv@ccns.ncku.edu.tw>,
Huichun Feng <foxhoundsk.tw@gmail.com>,
Chih-En Lin <shiyn.lin@gmail.com>
Subject: [RFC PATCH v2 8/9] mm: Handle COW PTE with reclaim algorithm
Date: Wed, 28 Sep 2022 00:29:56 +0800 [thread overview]
Message-ID: <20220927162957.270460-9-shiyn.lin@gmail.com> (raw)
In-Reply-To: <20220927162957.270460-1-shiyn.lin@gmail.com>
To avoid the PFRA reclaiming the page resided in the COWed PTE table,
break COW when it using rmap to unmap all the processes.
Signed-off-by: Chih-En Lin <shiyn.lin@gmail.com>
---
include/linux/rmap.h | 2 ++
mm/page_vma_mapped.c | 5 +++++
mm/rmap.c | 2 +-
mm/swapfile.c | 1 +
mm/vmscan.c | 1 +
5 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index b89b4b86951f8..5c7e3bedc068b 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -312,6 +312,8 @@ int make_device_exclusive_range(struct mm_struct *mm, unsigned long start,
#define PVMW_SYNC (1 << 0)
/* Look for migration entries rather than present PTEs */
#define PVMW_MIGRATION (1 << 1)
+/* Break COW PTE during the walking */
+#define PVMW_COW_PTE (1 << 2)
struct page_vma_mapped_walk {
unsigned long pfn;
diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
index 8e9e574d535aa..5008957bbe4a7 100644
--- a/mm/page_vma_mapped.c
+++ b/mm/page_vma_mapped.c
@@ -251,6 +251,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
step_forward(pvmw, PMD_SIZE);
continue;
}
+
+ /* TODO: Does breaking COW PTE here is correct? */
+ if (pvmw->flags & PVMW_COW_PTE)
+ handle_cow_pte(vma, pvmw->pmd, pvmw->address, false);
+
if (!map_pte(pvmw))
goto next_pte;
this_pte:
diff --git a/mm/rmap.c b/mm/rmap.c
index 93d5a6f793d20..8f737cb44e48a 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1477,7 +1477,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
unsigned long address, void *arg)
{
struct mm_struct *mm = vma->vm_mm;
- DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0);
+ DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, PVMW_COW_PTE);
pte_t pteval;
struct page *subpage;
bool anon_exclusive, ret = true;
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 1fdccd2f1422e..ef4d3d81a824b 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1916,6 +1916,7 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud,
do {
cond_resched();
next = pmd_addr_end(addr, end);
+ handle_cow_pte(vma, pmd, addr, false);
if (pmd_none_or_trans_huge_or_clear_bad(pmd))
continue;
ret = unuse_pte_range(vma, pmd, addr, next, type);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index b2b1431352dcd..030fad3d310d9 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1822,6 +1822,7 @@ static unsigned int shrink_page_list(struct list_head *page_list,
/*
* The folio is mapped into the page tables of one or more
* processes. Try to unmap it here.
+ * It will write to the page tables, break COW PTE here.
*/
if (folio_mapped(folio)) {
enum ttu_flags flags = TTU_BATCH_FLUSH;
--
2.37.3
next prev parent reply other threads:[~2022-09-27 16:28 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-27 16:29 [RFC PATCH v2 0/9] Introduce Copy-On-Write to Page Table Chih-En Lin
2022-09-27 16:29 ` [RFC PATCH v2 1/9] mm: Add new mm flags for Copy-On-Write PTE table Chih-En Lin
2022-09-27 17:23 ` Nadav Amit
2022-09-27 17:36 ` Chih-En Lin
2022-09-27 16:29 ` [RFC PATCH v2 2/9] mm: pgtable: Add sysctl to enable COW PTE Chih-En Lin
2022-09-27 17:27 ` Nadav Amit
2022-09-27 18:05 ` Chih-En Lin
2022-09-27 21:22 ` John Hubbard
2022-09-28 8:36 ` Chih-En Lin
2022-09-27 16:29 ` [RFC PATCH v2 3/9] mm, pgtable: Add ownership to PTE table Chih-En Lin
2022-09-27 17:30 ` Nadav Amit
2022-09-27 18:23 ` Chih-En Lin
2022-09-27 16:29 ` [RFC PATCH v2 4/9] mm: Add COW PTE fallback functions Chih-En Lin
2022-09-27 17:51 ` Nadav Amit
2022-09-27 19:00 ` Chih-En Lin
2022-09-27 16:29 ` [RFC PATCH v2 5/9] mm, pgtable: Add a refcount to PTE table Chih-En Lin
2022-09-27 17:59 ` Nadav Amit
2022-09-27 19:07 ` Chih-En Lin
2022-09-27 16:29 ` [RFC PATCH v2 6/9] mm, pgtable: Add COW_PTE_OWNER_EXCLUSIVE flag Chih-En Lin
2022-09-27 16:29 ` [RFC PATCH v2 7/9] mm: Add the break COW PTE handler Chih-En Lin
2022-09-27 18:15 ` Nadav Amit
2022-09-27 19:23 ` Chih-En Lin
2022-09-27 16:29 ` Chih-En Lin [this message]
2022-09-27 16:29 ` [RFC PATCH v2 9/9] mm: Introduce Copy-On-Write PTE table Chih-En Lin
2022-09-27 18:38 ` Nadav Amit
2022-09-27 19:53 ` Chih-En Lin
2022-09-27 21:26 ` John Hubbard
2022-09-28 8:52 ` Chih-En Lin
2022-09-28 14:03 ` David Hildenbrand
2022-09-29 13:38 ` Chih-En Lin
2022-09-29 13:49 ` Chih-En Lin
2022-09-29 17:24 ` David Hildenbrand
2022-09-29 18:29 ` Chih-En Lin
2022-09-29 18:38 ` David Hildenbrand
2022-09-29 18:57 ` Chih-En Lin
2022-09-29 19:00 ` David Hildenbrand
2022-09-29 18:40 ` Nadav Amit
2022-09-29 19:02 ` Chih-En Lin
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=20220927162957.270460-9-shiyn.lin@gmail.com \
--to=shiyn.lin@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=arnd@arndb.de \
--cc=bigeasy@linutronix.de \
--cc=christophe.leroy@csgroup.eu \
--cc=david@redhat.com \
--cc=fenghua.yu@intel.com \
--cc=foxhoundsk.tw@gmail.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=keescook@chromium.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=kunyu@nfschina.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mcgrof@kernel.org \
--cc=minchan@kernel.org \
--cc=namit@vmware.com \
--cc=pasha.tatashin@soleen.com \
--cc=peng301@purdue.edu \
--cc=peterx@redhat.com \
--cc=pfonseca@purdue.edu \
--cc=shy828301@gmail.com \
--cc=song@kernel.org \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=tongtiangen@huawei.com \
--cc=vbabka@suse.cz \
--cc=william.kucharski@oracle.com \
--cc=willy@infradead.org \
--cc=yzaikin@google.com \
--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