From patchwork Tue Oct 10 06:45:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13414851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A03C4CD68F4 for ; Tue, 10 Oct 2023 06:47:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DD606B01F5; Tue, 10 Oct 2023 02:47:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 684176B01F6; Tue, 10 Oct 2023 02:47:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54CBD6B01F8; Tue, 10 Oct 2023 02:47:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3B4B86B01F5 for ; Tue, 10 Oct 2023 02:47:14 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1300440174 for ; Tue, 10 Oct 2023 06:47:14 +0000 (UTC) X-FDA: 81328619988.12.4B29748 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf22.hostedemail.com (Postfix) with ESMTP id 83B27C0016 for ; Tue, 10 Oct 2023 06:47:11 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696920432; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7gdOMeLQZKF43HKLxI174ZWFuLbnPjI8+vrUMsgpZqc=; b=67AoyLqSCV+6g0Pzshox6Jk4qiuLhegfGlHk6ABjkFe3KpfiJdc2xVy25CM9Vgq0ONO1Iy NpNGJ/5WqIFKprVHxwZCMqprQ6YgfRZtg/hIt2Qxk5MngHVPevzhc3YLNAZMniRj62fHuS wsIhuy8BdZ5VidLJW/9T+iIdU4thBEk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696920432; a=rsa-sha256; cv=none; b=hcLC5Iys8azRRArE5OBZGeY6vgy1WxkSztZH4vwrisp3vzgUPy9hHFmi/DDMqRrkx8Fh5u 7ipy+ommXk9AlPjTu84N+67pJgy2yEKIdL91+NnzYLSklip7ARxjawgfbhTlg++oINoq6v YcwxyKSJ6VJt1nsjor5HbofG5Fi8R9I= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4S4RGD0GDHz1M92R; Tue, 10 Oct 2023 14:44:36 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 10 Oct 2023 14:47:07 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Kefeng Wang Subject: [PATCH -next 6/7] mm: make wp_page_reuse() and finish_mkwrite_fault() to take a folio Date: Tue, 10 Oct 2023 14:45:43 +0800 Message-ID: <20231010064544.4162286-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231010064544.4162286-1-wangkefeng.wang@huawei.com> References: <20231010064544.4162286-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 83B27C0016 X-Rspam-User: X-Stat-Signature: 4dn7jxcwdcq3kquttxurp8a7jehtocg5 X-Rspamd-Server: rspam03 X-HE-Tag: 1696920431-739640 X-HE-Meta: U2FsdGVkX1/XirNqX7rOxI9QFdnLn27LwWDHVH8xcL3ng2WTiAvINz/7NLf+j8c48Gr9QEjKAwhiHgnvXbFz9jIoHXZCaYu41NgkX2hyYjBzRSIUMX3wo49xEpQRl0IjRsYGXl+Ekm1FDuGToCYoLB3M4CgR65+xhi3Txej0f6BY+0kYSQdgn4FYiHcceX4eCZ2hidJEMHU+/aOq89CWfazqCNDJVCfKeTpRzEYGLB/yAiP1Ahn/bZdugCTiK2+hJFHdPCN57QGD/GIjlmMWvs8oIAbU53hX1edXB8CFlobYA2IPrqFVvF7yRTY+945wL2fsQdn0XXtC4uDeYg23fGRnUb/fShs/oJtxy6EtbUwn2L5cMSP1zp4SWT0/aBuCgeHQKZnliGEJixf5Gv38NHqSe4iqGRyTQMnyeTrOl+wLRSFnM06NppIsi3XdlywR4Cx1Y4oSYBPf3M4xqMlplfsu8EXGkQjK1FZW6e0ieM6RolBWCqAxbzMx4CTpIPfNMQyajmZ0ChUb4UsJFeBS25pdcrIZUeJqEJuxpVaS3AXz0AkkDM71wpaolrsclnlXRM7TW3j14lCAflTH3Gwo00yWkM8+ucfsxFYrq7+y3AGZKuOwi/bxJZ291Q0WxTE42uWNdhcR4fJPkxVQCe+8VGvlI52aRl5/wy2dK00w9k2oKcaBz3sZdhUWV3nnvtDhN20V/c338ryYdi77TgQy9wRsfvg00mBEzsAhUfEpxqu+pkaD4wmQ0UkAspgvDo9OEWliD4mK2vnqKaCLMNlR+nbnm22ev6mklJLXqyuM7zbTpJD6GQ1FdZqHndYL4kMD3mjpy1RzI7VbziHIKGK6Cekyqq1QSwK/yAkXWOUDXYQ3RsEdhK50a7PRb1na8qDo5sZ+0EJwsnJLG2dgHP076nURvhxrQtt3pncGr0aR/HE1a8Zr5TDt2Dg/t91MGBuNWpy8SOnlvdWhWb6JdHZ FBCw1521 HtWF3+bIEBUbqQu9bAxqAHNEUqyM0CuoIxz0n52PzRJrJ9Qi0SKW1aaKIm+9IT2SCiqDEYmObUUavtFH6UIwWCh36NyG1EJedtstnX/EyL0CEMTwNdTILzojp4C0CQyIqSljg6oBv4YaQoaA1fuVFUMbkjlO+qxq6Ns0sTfyS+5vt0Ob9TneDcQuB7sBFkCf/As43 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: Make finish_mkwrite_fault() to a static function, and convert wp_page_reuse() and finish_mkwrite_fault() to take a folio in preparation for page_cpupid_xchg_last() to folio conversion. Signed-off-by: Kefeng Wang --- include/linux/mm.h | 1 - mm/memory.c | 37 ++++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index e0bd8abae6c6..3d59455626fa 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1335,7 +1335,6 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio, struct page *page, unsigned int nr, unsigned long addr); vm_fault_t finish_fault(struct vm_fault *vmf); -vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf); #endif /* diff --git a/mm/memory.c b/mm/memory.c index 7566955d88e3..1a1a6a6ccd58 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3018,23 +3018,24 @@ static vm_fault_t fault_dirty_shared_page(struct vm_fault *vmf) * case, all we need to do here is to mark the page as writable and update * any related book-keeping. */ -static inline void wp_page_reuse(struct vm_fault *vmf) +static inline void wp_page_reuse(struct vm_fault *vmf, struct folio *folio) __releases(vmf->ptl) { struct vm_area_struct *vma = vmf->vma; - struct page *page = vmf->page; pte_t entry; VM_BUG_ON(!(vmf->flags & FAULT_FLAG_WRITE)); - VM_BUG_ON(page && PageAnon(page) && !PageAnonExclusive(page)); + if (folio) { + VM_BUG_ON(folio_test_anon(folio) && + !PageAnonExclusive(vmf->page)); - /* - * Clear the pages cpupid information as the existing - * information potentially belongs to a now completely - * unrelated process. - */ - if (page) - page_cpupid_xchg_last(page, (1 << LAST_CPUPID_SHIFT) - 1); + /* + * Clear the pages cpupid information as the existing + * information potentially belongs to a now completely + * unrelated process. + */ + page_cpupid_xchg_last(vmf->page, (1 << LAST_CPUPID_SHIFT) - 1); + } flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); entry = pte_mkyoung(vmf->orig_pte); @@ -3261,6 +3262,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * writeable once the page is prepared * * @vmf: structure describing the fault + * @folio: the folio of vmf->page * * This function handles all that is needed to finish a write page fault in a * shared mapping due to PTE being read-only once the mapped page is prepared. @@ -3272,7 +3274,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * Return: %0 on success, %VM_FAULT_NOPAGE when PTE got changed before * we acquired PTE lock. */ -vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf) +static vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf, + struct folio *folio) { WARN_ON_ONCE(!(vmf->vma->vm_flags & VM_SHARED)); vmf->pte = pte_offset_map_lock(vmf->vma->vm_mm, vmf->pmd, vmf->address, @@ -3288,7 +3291,7 @@ vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); return VM_FAULT_NOPAGE; } - wp_page_reuse(vmf); + wp_page_reuse(vmf, folio); return 0; } @@ -3312,9 +3315,9 @@ static vm_fault_t wp_pfn_shared(struct vm_fault *vmf) ret = vma->vm_ops->pfn_mkwrite(vmf); if (ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)) return ret; - return finish_mkwrite_fault(vmf); + return finish_mkwrite_fault(vmf, NULL); } - wp_page_reuse(vmf); + wp_page_reuse(vmf, NULL); return 0; } @@ -3342,14 +3345,14 @@ static vm_fault_t wp_page_shared(struct vm_fault *vmf, struct folio *folio) folio_put(folio); return tmp; } - tmp = finish_mkwrite_fault(vmf); + tmp = finish_mkwrite_fault(vmf, folio); if (unlikely(tmp & (VM_FAULT_ERROR | VM_FAULT_NOPAGE))) { folio_unlock(folio); folio_put(folio); return tmp; } } else { - wp_page_reuse(vmf); + wp_page_reuse(vmf, folio); folio_lock(folio); } ret |= fault_dirty_shared_page(vmf); @@ -3494,7 +3497,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); return 0; } - wp_page_reuse(vmf); + wp_page_reuse(vmf, folio); return 0; } /*