From patchwork Sun Dec 20 05:03:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11983787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62ABFC4361B for ; Sun, 20 Dec 2020 05:03:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E3730233E2 for ; Sun, 20 Dec 2020 05:03:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3730233E2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 70E316B006E; Sun, 20 Dec 2020 00:03:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E2E46B0070; Sun, 20 Dec 2020 00:03:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F76D6B0071; Sun, 20 Dec 2020 00:03:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 480BC6B006E for ; Sun, 20 Dec 2020 00:03:51 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0D201824999B for ; Sun, 20 Dec 2020 05:03:51 +0000 (UTC) X-FDA: 77612468262.04.lunch69_4110ba92744c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id E9C25800EFDE for ; Sun, 20 Dec 2020 05:03:50 +0000 (UTC) X-HE-Tag: lunch69_4110ba92744c X-Filterd-Recvd-Size: 4969 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Sun, 20 Dec 2020 05:03:50 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id lj6so4297964pjb.0 for ; Sat, 19 Dec 2020 21:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mlVbCPwoNrfW6cjE2V8EB9QCL2g3Vy4Qw8GvHG/LcAU=; b=URb3Vg9SdwTZBOiLK8y88RsF5HESBOEz9rbiZcKi+TeiIG2Cmwmb3+6k/mJzrJyucR nxAuCR7m3ir4jinS5FWhpwE2mnWny8MviPbjFkUku6u/L4EnfmCh+AdBO8JmJbdjhZAh jR5zVOarmDTAwPSrBblKSuRPduAtsOGSpcxNWQ6z6rCLwpWbZscsjb/+1MtLMF4I9DFu 7adHzcgP1YQpkx5hw2njjC6fE0/Yp6kQ4Nwf3il5MPpBJf0rpEG9QuJi5fOS9ud8RlUw +dXZJLXBlfTb8Za1CMbMlurz9n61xExLBD6VRPLBPyhTImvNr58HG8G4pj3+B/+133jb QPQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mlVbCPwoNrfW6cjE2V8EB9QCL2g3Vy4Qw8GvHG/LcAU=; b=sXtFjmR1BxoelY8gtx+C5IV8KF60Nn9jA7LfoID8VVEXaPbUQIYNb84yZUXkk7alpM xyMsudn88rFqKt1TIKIY3p9rWN1EfKJyRVcOcn0NupFv9hZFty4N2txDl2W/a+L8d2UF a2VVQpCFBlX3IL/nqBM/InPdVKUVeAfkwnFBoOlHB5flIm9wB8hL2QL6NAYZfeD1MszX e8BhRZRBysQmZ9Rzmtoj1w4f8tNuCHeaqbOWafXjSYH+iG/UzYqDNUxOuz/L40elS90J m/H4ZMINMiCEvG3ijo+Ej3qSFftXfLsV65zLIqib8Y0KLS3dV4JIRSNHMbZ26MMbGeRB hC2A== X-Gm-Message-State: AOAM532SMxVyn1T3fIU6Hm0GePKxkT+JtbPu14w5tBrwcgEC4x8APeac /4GtrNHPgfbYChkrKgWvwbB4gSa2UFQ= X-Google-Smtp-Source: ABdhPJzJPAIKwJg3emFRVbBHkaSjJnN+CldO+4Ye80pA9M365q6ymCzFvoOLJlBuoUPAGIPPKIhvXw== X-Received: by 2002:a17:902:b282:b029:da:fd05:7766 with SMTP id u2-20020a170902b282b02900dafd057766mr11016197plr.52.1608440629500; Sat, 19 Dec 2020 21:03:49 -0800 (PST) Received: from bobo.ibm.com (193-116-97-30.tpgi.com.au. [193.116.97.30]) by smtp.gmail.com with ESMTPSA id a23sm11625185pjh.19.2020.12.19.21.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Dec 2020 21:03:49 -0800 (PST) From: Nicholas Piggin To: linux-mm@kvack.org Cc: Nicholas Piggin , Peter Zijlstra Subject: [PATCH 2/3] mm: add page_cpupid_reset_last atomic variant Date: Sun, 20 Dec 2020 15:03:39 +1000 Message-Id: <20201220050340.849754-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201220050340.849754-1-npiggin@gmail.com> References: <20201220050340.849754-1-npiggin@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This can be used when there is concurrency on the struct page. If cpupid is not in page flags, it can use a store. Use this to replace the open-coded reset in wp_page_reuse. Signed-off-by: Nicholas Piggin --- include/linux/mm.h | 15 +++++++++++++++ mm/memory.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 5b3fc2c8fd8b..6ece500464e0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1362,6 +1362,11 @@ static inline void __page_cpupid_reset_last(struct page *page) { page->_last_cpupid = -1 & LAST_CPUPID_MASK; } + +static inline void page_cpupid_reset_last(struct page *page) +{ + WRITE_ONCE(page->_last_cpupid, -1 & LAST_CPUPID_MASK); +} #else static inline int page_cpupid_last(struct page *page) { @@ -1374,6 +1379,12 @@ static inline void __page_cpupid_reset_last(struct page *page) { page->flags |= LAST_CPUPID_MASK << LAST_CPUPID_PGSHIFT; } + +static inline void page_cpupid_reset_last(struct page *page) +{ + page_cpupid_xchg_last(page, (1 << LAST_CPUPID_SHIFT) - 1); +} + #endif /* LAST_CPUPID_NOT_IN_PAGE_FLAGS */ #else /* !CONFIG_NUMA_BALANCING */ static inline int page_cpupid_xchg_last(struct page *page, int cpupid) @@ -1415,6 +1426,10 @@ static inline void __page_cpupid_reset_last(struct page *page) { } +static inline void page_cpupid_reset_last(struct page *page) +{ +} + static inline bool cpupid_match_pid(struct task_struct *task, int cpupid) { return false; diff --git a/mm/memory.c b/mm/memory.c index 7d608765932b..990e5d704c08 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2798,7 +2798,7 @@ static inline void wp_page_reuse(struct vm_fault *vmf) * unrelated process. */ if (page) - page_cpupid_xchg_last(page, (1 << LAST_CPUPID_SHIFT) - 1); + page_cpupid_reset_last(page); flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); entry = pte_mkyoung(vmf->orig_pte);