From patchwork Sat Aug 12 01:58:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13351626 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 F1A45EB64DD for ; Sat, 12 Aug 2023 01:58:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61ACC6B0074; Fri, 11 Aug 2023 21:58:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A3656B0078; Fri, 11 Aug 2023 21:58:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 444AC6B007B; Fri, 11 Aug 2023 21:58:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3090B6B0074 for ; Fri, 11 Aug 2023 21:58:49 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E818BC0471 for ; Sat, 12 Aug 2023 01:58:48 +0000 (UTC) X-FDA: 81113793936.01.1F67D93 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf18.hostedemail.com (Postfix) with ESMTP id A35B51C0012 for ; Sat, 12 Aug 2023 01:58:45 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=zhangpeng362@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=1691805527; 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=VaxVxeI+fJLCQkEZizc0KYChPXx/I7OYU+r4Dy5wUTM=; b=u2I3pH1gJlOwty9qF7wD4RRM5D+cPCVq/unW4vB35SkIul5boE+9pDQMSJrjkQnUN6WFy+ i7mYSI5l9TCjogvRmdlE4e/D7SvEZmBUcusRHMq6w4O+ML1XEJuYdo1NrdIhQkFwJ3o9OD BkhpumXszgVwSqKL69Lac0FGydT/2zM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691805527; a=rsa-sha256; cv=none; b=GoMFG64LSnoM92q0Ho62EMLbZ4OR1/QaCSrDME7HP/0wOpqwBprzN0A4wR2xXlrq0bnfiQ KPocxrh8WpIC0N3PISlFTsNbWh72HvNj9IFWCfSxuplq3nIoggzAlfKgozugAoYMGPlgF/ hqa5WfTRWCRSMPQEh5zgAR1eVRxkMR8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RN3dT2zXXzcdG7; Sat, 12 Aug 2023 09:55:09 +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 09:58:40 +0800 From: Peng Zhang To: CC: , , , , ZhangPeng Subject: [PATCH] mm/secretmem: use a folio in secretmem_fault() Date: Sat, 12 Aug 2023 09:58:35 +0800 Message-ID: <20230812015835.3041694-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: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Stat-Signature: 1k9t7wxumup51w47tj9bmcexxyfge7yz X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A35B51C0012 X-Rspam-User: X-HE-Tag: 1691805525-756795 X-HE-Meta: U2FsdGVkX1+0WoFl94Lt8LRs8n6nrXLKzOeb2zv51oZMR5hCga5TsulECbpfZwrCznIjSMjF95APAJjZR1aVxsy5CFtZxSK3osPUVie4N+zX9bsDhfK6djk3BDO5F0+i1YUggHDdf8p7TE/2jp81f0BAYfsUjCZaBd7ultl26bEFdAVeAnnmb+yjDSLyoDVP1CJG1upr//8bc3lPCEPr9j8zvbaUbYhce54PD16SjZSCUZylI/SnE6toVzqvhbWwA6TrR/yxYhdqiO60of73uxickHoLZ2tNzPfIbYzUqRZvSMOtUK0Qa5Xvd/sICkCb+gt7EY/HjxQH2LtAmTECaiQE8BNvuIzky4G9O8hSfQPjFAGm4MsRJ0pOelNTOPni/lkb3rCfzZElEmT9mN1lBcT80lch+eN6ocvkQi6cza9MKcYm2Rd3QEpSjWr75Lue7eAaT3DM62cLTNcqcnw+LQzKqLAxKSIbzKnbCBa+e/5oR8eYsU0satq6ANUioZ7fn7TcT5/Ukl+A0UjPBEzitsifW4NJqEp+6lpNV2FtPOxuYKcQITnR4Gppbi+gLbOK9xQC4rwl+GyGLFPUe7rSf+sYDnMuz3KRoCIdN5vsmMMUqnC9yjZWF8YhhbIwVP+x6m74EjOg0WXX06nhsuzS+ysMGJgphtsiIHcsg7w1sw7QtEtz8kPZ6oFcbVOfsra6fXiBh7qC+wmdINQqnX5PlZER+MZlOG18BcPbwQRXeDs9wrA5wc67ASE09meD22A26A4n36DEam7+6Cc5FWnVTeuTgdSAWksULP61Dw7aUvilLxxlsLbHLPmvfVD7vvtIewM0P9bxSfmmT6B4hTW2vIA0SOc1NGuCWXL5aaRzN55fIqap0BS5mV1DHRQ9B48fpSNdm9/Tgtd9g7MiZ6vflAYNCx5aV7nI9OIKrpBjD1clQTllXPfACdvrCcHCVS2JSjCDqjBzmkV4/UVUlnj MNeyKpgt 5yVDmd7SEpOwYCBXx7QDUG/V24WCM3io1NjgIH1yyXKEgjabqN2ms6kM16MgKNqjWABde/H/2ihexOuAP0qq06UPy+BnpTHJYWfGDwv2s8SAhmvimeXGdOZQJJSD6ltIdJ2Du9/XOOyzyvhyzERLRCF1hi9FpsqaPH9CHqu1vXqV2EBsIWRDPhs4UqPRiOqU5zVmw 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 three implicit call to compound_head(). Signed-off-by: ZhangPeng Reviewed-by: Matthew Wilcox (Oracle) --- 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