From patchwork Sat Aug 12 06:26:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13351685 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 E4FA4C001E0 for ; Sat, 12 Aug 2023 06:26:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44BE28D0002; Sat, 12 Aug 2023 02:26:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FB436B007D; Sat, 12 Aug 2023 02:26:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E99F8D0002; Sat, 12 Aug 2023 02:26:32 -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 1E9B16B007B for ; Sat, 12 Aug 2023 02:26:32 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 29BA01C9723 for ; Sat, 12 Aug 2023 06:26:31 +0000 (UTC) X-FDA: 81114468582.14.A688FAC Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf12.hostedemail.com (Postfix) with ESMTP id B75FD4000B for ; Sat, 12 Aug 2023 06:26:28 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691821589; 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: references; bh=njX0ZLs4oITODIvXbCxzOfU3pqSgwZcz511YrkXiYKQ=; b=IBgFu2rNXJMlsTdRyjMZqX/HEdG1xy7AIl1V05CeNrwyMxBjC0WxyySO5+Z7HDLSJdEvy1 JtCa+B//zN2JB0M/RzcBmA4Iq9DbL1Qsv3Y+UTxrgTBWDoTPvCmHeIDiIIO9E90y+GeQTZ xnEXFK8jcLB28q0ihQYDQLrlLA5A2CE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691821589; a=rsa-sha256; cv=none; b=kLLxaymVKjhTzIrg0ssSN/m02IOQSC1okUIBdOmINW/hw2j1w6j9UuYID3F9DWb/LiUorf 6ydQ/kmtPSm0LQ4ilUEuI7igMP1JXKYH0QwDOsaxKAtyzKZOUS8W3tlO3dqc5nxHoJ/g3P kDSg3xUEDYbYg/rQmStfvC27eB6knV8= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RN9b210Nvz2Bd1P; Sat, 12 Aug 2023 14:23:26 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 12 Aug 2023 14:26:18 +0800 From: Peng Zhang To: , CC: , , , ZhangPeng Subject: [PATCH v2] mm/secretmem: use a folio in secretmem_fault() Date: Sat, 12 Aug 2023 14:26:12 +0800 Message-ID: <20230812062612.3184990-1-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: fwckjcauz7q9h5fnpkkwikys4trkhit1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B75FD4000B X-HE-Tag: 1691821588-423434 X-HE-Meta: U2FsdGVkX19GzAtGm7xFfkmJiVbff3YvAcuTISgU/cglxnCsnuSW8CeP+Iav28limLAcKkvWuQWRze5kkfJtP1OYy6lw61XOcASV/4cIOt2tAP/far7QcDict+bFq5KftPFNIMVaMuLOIrAnIP7y7y+/jA/biDrmSqBGhYYtAURwj9nOSNVOyIbXSZFZZymfSL0ve7iYdccYsYh28dHR2aEucpKwziHz81S9BZgop+cZZrcvzL2Kh9Ux+P9dvGh7aCyAb0S3/eAgOg5Ps4Ob8zooKcOAbEJnE2dNN2rKrrI7y/saPdOIxohrocNsATQUmepAWMMRaZBvrUywT3Mkh8pHgax13/ODkYTPewt9Qtks65iaAi/jfnKztqRTPihodI4CndmtzDlCIXNEqafih+NIEi63QnFoApIArvW+lin/2MYq+e7lmYLla/puLRHm0tA0sExdahhm0giS6JsNPG5X30YcbXGUYOtq9gBbWoauOU8zIe0qDejFdkbjbtxDKXV19d7C71MqPlCQ6uRP9wWdJsNz197uKN/6RZ8rKSgMfSTmfpTOu0p30vjDv4QfcRNvgcOr4q+aaqWrBoaoF9qcG7PSTFLBTGkpBR+4AcR13HxNJtUVVTwYaiKY8OkD6EEEov5VP/uQAOZrF7zDIOB6v0/C83rfAPl+odb94eZnN/SqBx9/V50EiTKBSBXW+Zsfmn0EBLFabjKAOBvw7J+XuMT6mTWc5Wsvkp+VAMGb2ir2529bmQQOIfXBELtsr4qNoMO3fT2+M32P58XNWP+8L90LKzW5GyoixScKN0jlaCBnPWchvza6tGacPLOh3sfhUVOrnL8dTTTtmJC1tBmLz4Op2tvaoryMXYC3Snh+W0Yo/bnY8USh0kofOX8a6vRn0pBO+yKQeFxA2ULSufpkBMwil43C6cs9CoYWlAUXEdQzPEzJAltyi9Qfytb94lQpQ1gDVqg24U8o30G 1dRK2TF5 LMdLv0/EtwlqqnN++p9H21EZgbtCMUCFRmx9Xqp1np3ZIg6rWPK1grUJbX3Z9j05AA/hXC3uFan5W59xpPwYLFB1Hdatqh5vhavf7ycz5LlllWGslKQ9TTQ4hgf10Wc0OfRgAa6wq8XARcfLiSwu+q4B796wfJmOTKCvqzER6KDbb1gSLz5LjYHJoTbvj31mXIONKsA8OEVhpOqBwpkOVXb+/2jjN380htKyjz2KroRz2cI99+oET1BGEKQ== 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: From: ZhangPeng Saves four implicit call to compound_head(). Signed-off-by: ZhangPeng Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: David Hildenbrand --- v2: update commit message per Matthew Wilcox --- mm/secretmem.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/secretmem.c b/mm/secretmem.c index 86442a15d12f..3afb5ad701e1 100644 --- a/mm/secretmem.c +++ b/mm/secretmem.c @@ -55,6 +55,7 @@ static vm_fault_t secretmem_fault(struct vm_fault *vmf) gfp_t gfp = vmf->gfp_mask; unsigned long addr; struct page *page; + struct folio *folio; vm_fault_t ret; int err; @@ -66,23 +67,24 @@ static vm_fault_t secretmem_fault(struct vm_fault *vmf) retry: page = find_lock_page(mapping, offset); if (!page) { - page = alloc_page(gfp | __GFP_ZERO); - if (!page) { + folio = folio_alloc(gfp | __GFP_ZERO, 0); + if (!folio) { ret = VM_FAULT_OOM; goto out; } + page = &folio->page; err = set_direct_map_invalid_noflush(page); if (err) { - put_page(page); + folio_put(folio); ret = vmf_error(err); goto out; } - __SetPageUptodate(page); - err = add_to_page_cache_lru(page, mapping, offset, gfp); + __folio_mark_uptodate(folio); + err = filemap_add_folio(mapping, folio, offset, gfp); if (unlikely(err)) { - put_page(page); + folio_put(folio); /* * If a split of large page was required, it * already happened when we marked the page invalid