From: Peter Xu <peterx@redhat.com>
To: Zach O'Keefe <zokeefe@google.com>
Cc: Alex Shi <alex.shi@linux.alibaba.com>,
David Hildenbrand <david@redhat.com>,
David Rientjes <rientjes@google.com>,
Matthew Wilcox <willy@infradead.org>,
Michal Hocko <mhocko@suse.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
SeongJae Park <sj@kernel.org>, Song Liu <songliubraving@fb.com>,
Vlastimil Babka <vbabka@suse.cz>, Yang Shi <shy828301@gmail.com>,
Zi Yan <ziy@nvidia.com>,
linux-mm@kvack.org, Andrea Arcangeli <aarcange@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Arnd Bergmann <arnd@arndb.de>,
Axel Rasmussen <axelrasmussen@google.com>,
Chris Kennelly <ckennelly@google.com>,
Chris Zankel <chris@zankel.net>, Helge Deller <deller@gmx.de>,
Hugh Dickins <hughd@google.com>,
Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Jens Axboe <axboe@kernel.dk>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Matt Turner <mattst88@gmail.com>,
Max Filippov <jcmvbkbc@gmail.com>,
Miaohe Lin <linmiaohe@huawei.com>,
Minchan Kim <minchan@kernel.org>,
Patrick Xia <patrickx@google.com>,
Pavel Begunkov <asml.silence@gmail.com>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Subject: Re: [PATCH v3 04/12] mm/khugepaged: add struct collapse_result
Date: Wed, 27 Apr 2022 16:47:41 -0400 [thread overview]
Message-ID: <Ymmr7Z4Gx6sy02+1@xz-m1.local> (raw)
In-Reply-To: <20220426144412.742113-5-zokeefe@google.com>
[-- Attachment #1: Type: text/plain, Size: 1293 bytes --]
On Tue, Apr 26, 2022 at 07:44:04AM -0700, Zach O'Keefe wrote:
> +/* Gather information from one khugepaged_scan_[pmd|file]() request */
> +struct collapse_result {
> + enum scan_result result;
> +
> + /* Was mmap_lock dropped during request? */
> + bool dropped_mmap_lock;
> +};
IMHO this new dropped_mmap_lock makes things a bit more complicated..
To me, the old code actually is easy to read on when the lock is dropped:
- For file, we always drop it
- For anon, when khugepaged_scan_pmd() returns 1
That's fairly clear to me.
But I understand what you need, probably the "result" hidden in the old
world but you'd need that for MADV_COLLAPSE?
I also noticed major chunks of this patch is converting "result = XXX" into
"cr->result = XXX". IMHO that's really not necessary for touching up all
the places around.
I'm also wondering whether we could simply pass over the result into your
newly introduced collapse_control*.
In summary, this is what's in my mind..
- Add collapse_control.result
- Make sure both khugepaged_scan_file() and khugepaged_scan_pmd() to
simply remember to update cc->result before it returns
I've attached a pesudo code patch (note! it's pesudo not even compile but
to show what I meant..), so far I don't see a problem with it.
--
Peter Xu
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2507 bytes --]
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index d7c5bb9fd1fb..bd341115d359 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1040,7 +1040,7 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm,
return true;
}
-static void collapse_huge_page(struct mm_struct *mm,
+static int collapse_huge_page(struct mm_struct *mm,
unsigned long address,
struct page **hpage,
int node, int referenced, int unmapped)
@@ -1208,7 +1208,7 @@ static void collapse_huge_page(struct mm_struct *mm,
if (!IS_ERR_OR_NULL(*hpage))
mem_cgroup_uncharge(page_folio(*hpage));
trace_mm_collapse_huge_page(mm, isolated, result);
- return;
+ return result;
}
static int khugepaged_scan_pmd(struct mm_struct *mm,
@@ -1361,13 +1361,19 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
pte_unmap_unlock(pte, ptl);
if (ret) {
node = khugepaged_find_target_node();
- /* collapse_huge_page will return with the mmap_lock released */
- collapse_huge_page(mm, address, hpage, node,
- referenced, unmapped);
+ /*
+ * collapse_huge_page will return with the mmap_lock
+ * released. It'll also further update cc->result if
+ * anything wrong happens.
+ */
+ result = collapse_huge_page(mm, address, hpage, node,
+ referenced, unmapped, cc);
}
out:
trace_mm_khugepaged_scan_pmd(mm, page, writable, referenced,
none_or_zero, result, unmapped);
+ /* Deliver the result to the caller */
+ cc->result = result;
return ret;
}
@@ -1646,7 +1652,7 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff)
* + restore gaps in the page cache;
* + unlock and free huge page;
*/
-static void collapse_file(struct mm_struct *mm,
+static int collapse_file(struct mm_struct *mm,
struct file *file, pgoff_t start,
struct page **hpage, int node)
{
@@ -2009,6 +2015,7 @@ static void collapse_file(struct mm_struct *mm,
if (!IS_ERR_OR_NULL(*hpage))
mem_cgroup_uncharge(page_folio(*hpage));
/* TODO: tracepoints */
+ return result;
}
static void khugepaged_scan_file(struct mm_struct *mm,
@@ -2086,11 +2093,12 @@ static void khugepaged_scan_file(struct mm_struct *mm,
count_vm_event(THP_SCAN_EXCEED_NONE_PTE);
} else {
node = khugepaged_find_target_node();
- collapse_file(mm, file, start, hpage, node);
+ result = collapse_file(mm, file, start, hpage, node);
}
}
/* TODO: tracepoints */
+ cc->result = result;
}
#else
static void khugepaged_scan_file(struct mm_struct *mm,
next prev parent reply other threads:[~2022-04-27 20:47 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 14:44 [PATCH v3 00/12] mm: userspace hugepage collapse Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 01/12] mm/khugepaged: record SCAN_PMD_MAPPED when scan_pmd() finds THP Zach O'Keefe
2022-04-27 0:26 ` Peter Xu
2022-04-27 15:48 ` Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 02/12] mm/khugepaged: add struct collapse_control Zach O'Keefe
2022-04-27 19:49 ` Peter Xu
2022-04-28 0:19 ` Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 03/12] mm/khugepaged: make hugepage allocation context-specific Zach O'Keefe
2022-04-27 20:04 ` Peter Xu
2022-04-28 0:51 ` Zach O'Keefe
2022-04-28 14:51 ` Peter Xu
2022-04-28 15:37 ` Zach O'Keefe
2022-04-28 15:52 ` Peter Xu
2022-04-26 14:44 ` [PATCH v3 04/12] mm/khugepaged: add struct collapse_result Zach O'Keefe
2022-04-27 20:47 ` Peter Xu [this message]
2022-04-28 21:59 ` Zach O'Keefe
2022-04-28 23:21 ` Peter Xu
2022-04-29 16:01 ` Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 05/12] mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 06/12] mm/khugepaged: remove khugepaged prefix from shared collapse functions Zach O'Keefe
2022-04-27 21:10 ` Peter Xu
2022-04-28 22:51 ` Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 07/12] mm/khugepaged: add flag to ignore khugepaged_max_ptes_* Zach O'Keefe
2022-04-27 21:12 ` Peter Xu
2022-04-29 14:26 ` Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 08/12] mm/khugepaged: add flag to ignore page young/referenced requirement Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 09/12] mm/madvise: add MADV_COLLAPSE to process_madvise() Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 10/12] selftests/vm: modularize collapse selftests Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 11/12] selftests/vm: add MADV_COLLAPSE collapse context to selftests Zach O'Keefe
2022-04-26 14:44 ` [PATCH v3 12/12] selftests/vm: add test to verify recollapse of THPs Zach O'Keefe
2022-04-26 20:23 ` [PATCH v3 00/12] mm: userspace hugepage collapse Andrew Morton
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=Ymmr7Z4Gx6sy02+1@xz-m1.local \
--to=peterx@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alex.shi@linux.alibaba.com \
--cc=arnd@arndb.de \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=axelrasmussen@google.com \
--cc=chris@zankel.net \
--cc=ckennelly@google.com \
--cc=david@redhat.com \
--cc=deller@gmx.de \
--cc=hughd@google.com \
--cc=ink@jurassic.park.msu.ru \
--cc=jcmvbkbc@gmail.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linmiaohe@huawei.com \
--cc=linux-mm@kvack.org \
--cc=mattst88@gmail.com \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=pasha.tatashin@soleen.com \
--cc=patrickx@google.com \
--cc=rientjes@google.com \
--cc=shy828301@gmail.com \
--cc=sj@kernel.org \
--cc=songliubraving@fb.com \
--cc=tsbogend@alpha.franken.de \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
--cc=zokeefe@google.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;
as well as URLs for NNTP newsgroup(s).