[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1588812129-8596-34-git-send-email-anthony.yznaga@oracle.com>
Date: Wed, 6 May 2020 17:41:59 -0700
From: Anthony Yznaga <anthony.yznaga@...cle.com>
To: linux-mm@...ck.org, linux-kernel@...r.kernel.org
Cc: willy@...radead.org, corbet@....net, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, x86@...nel.org, hpa@...or.com,
dave.hansen@...ux.intel.com, luto@...nel.org, peterz@...radead.org,
rppt@...ux.ibm.com, akpm@...ux-foundation.org, hughd@...gle.com,
ebiederm@...ssion.com, masahiroy@...nel.org, ardb@...nel.org,
ndesaulniers@...gle.com, dima@...ovin.in, daniel.kiper@...cle.com,
nivedita@...m.mit.edu, rafael.j.wysocki@...el.com,
dan.j.williams@...el.com, zhenzhong.duan@...cle.com,
jroedel@...e.de, bhe@...hat.com, guro@...com,
Thomas.Lendacky@....com, andriy.shevchenko@...ux.intel.com,
keescook@...omium.org, hannes@...xchg.org, minchan@...nel.org,
mhocko@...nel.org, ying.huang@...el.com,
yang.shi@...ux.alibaba.com, gustavo@...eddedor.com,
ziqian.lzq@...fin.com, vdavydov.dev@...il.com,
jason.zeng@...el.com, kevin.tian@...el.com, zhiyuan.lv@...el.com,
lei.l.li@...el.com, paul.c.lai@...el.com, ashok.raj@...el.com,
linux-fsdevel@...r.kernel.org, linux-doc@...r.kernel.org,
kexec@...ts.infradead.org
Subject: [RFC 33/43] PKRAM: atomically add and remove link pages
Add and remove pkram_link pages from a pkram_obj atomically to prepare
for multithreading.
Signed-off-by: Anthony Yznaga <anthony.yznaga@...cle.com>
---
mm/pkram.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/mm/pkram.c b/mm/pkram.c
index 5f4e4d12865f..042c14dedc25 100644
--- a/mm/pkram.c
+++ b/mm/pkram.c
@@ -551,22 +551,31 @@ static void pkram_truncate(void)
static void pkram_add_link(struct pkram_link *link, struct pkram_obj *obj)
{
- link->link_pfn = obj->link_pfn;
- obj->link_pfn = page_to_pfn(virt_to_page(link));
+ __u64 link_pfn = page_to_pfn(virt_to_page(link));
+ __u64 *head = &obj->link_pfn;
+
+ do {
+ link->link_pfn = *head;
+ } while (cmpxchg64(head, link->link_pfn, link_pfn) != link->link_pfn);
}
static struct pkram_link *pkram_remove_link(struct pkram_obj *obj)
{
struct pkram_link *current_link;
+ __u64 *head = &obj->link_pfn;
+ __u64 head_pfn = *head;
+
+ while (head_pfn) {
+ current_link = pfn_to_kaddr(head_pfn);
+ if (cmpxchg64(head, head_pfn, current_link->link_pfn) == head_pfn) {
+ current_link->link_pfn = 0;
+ return current_link;
+ }
- if (!obj->link_pfn)
- return NULL;
-
- current_link = pfn_to_kaddr(obj->link_pfn);
- obj->link_pfn = current_link->link_pfn;
- current_link->link_pfn = 0;
+ head_pfn = *head;
+ }
- return current_link;
+ return NULL;
}
static void pkram_stream_init(struct pkram_stream *ps,
--
2.13.3
Powered by blists - more mailing lists