From patchwork Fri Sep 20 14:36:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13808551 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 C7404C78853 for ; Fri, 20 Sep 2024 14:37:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 162326B0082; Fri, 20 Sep 2024 10:37:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 112ED6B0083; Fri, 20 Sep 2024 10:37:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 001DF6B0085; Fri, 20 Sep 2024 10:37:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D6EC86B0082 for ; Fri, 20 Sep 2024 10:37:24 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5575A16044B for ; Fri, 20 Sep 2024 14:37:24 +0000 (UTC) X-FDA: 82585369608.25.7C91D85 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf14.hostedemail.com (Postfix) with ESMTP id 5D094100008 for ; Fri, 20 Sep 2024 14:37:20 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726843030; a=rsa-sha256; cv=none; b=UdP+tNGH8uoUIUBZt/hBUxwUHqHUkbkTa8gK0aL6Au0uEbAR6VzeeRTrbMRQcGte7CddGt l97mty8GbrdZwlhZhd9+aH4p11svTE6/gpTpq76Ug2eKV+Lotb6ApOKXdRo2gv7oO0s1iC vrfYoe4WwcuVUs4YLFOR0hMy4eG7O2M= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726843030; 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=8QOKB2v7uzhGx6x0ohsSSfENggrGoLTKScd/ZgCgqcw=; b=uMB3RCMcIciOE95Rzp9uDtJg0l1TkawNATketD1YLuyDbxUtvOtmTlQw/fNImnqBkE1ak8 a0F8ft5E9VvUaAutcgQKsGFCQY8vP5ag8tn08Kgwzgz60CxS6kZzbBtthrLzAd2DxubKpd FTbnSYigJCIhPvHifsMuMXhPGd7+D6c= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4X9FLr4q0WzySBq; Fri, 20 Sep 2024 22:36:20 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 701C5140392; Fri, 20 Sep 2024 22:37:16 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 20 Sep 2024 22:37:15 +0800 From: Kefeng Wang To: Andrew Morton , Hugh Dickins , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox CC: Anna Schumaker , , , Baolin Wang , Kefeng Wang Subject: [PATCH v2] tmpfs: fault in smaller chunks if large folio allocation not allowed Date: Fri, 20 Sep 2024 22:36:54 +0800 Message-ID: <20240920143654.1008756-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240914140613.2334139-1-wangkefeng.wang@huawei.com> References: <20240914140613.2334139-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspam-User: X-Stat-Signature: hnkmt6c1graqjwwpaq5n75cfm4bqfy5j X-Rspamd-Queue-Id: 5D094100008 X-Rspamd-Server: rspam02 X-HE-Tag: 1726843040-462644 X-HE-Meta: U2FsdGVkX1/x33cUP3xMipYEkyBHLyfetp/Mc8mSQshXf6ZFdVDP4EkXPKzPc3jMH5JYw/fzGYwcgWRKecgSybIMb34ir314zxsn/+IrkrAKpCXh1st/ANSuFcY7a71fBNHEsYoBHv0Bf7SiJJ/6jIpMGBig8J9dm+cheAlc9Xq0j5we3TT+1bcRWHH4O7JPIapkhRTaJkdSNwEXV7tFIcTt+ThD53MVr9TqDPqHXJohMWlEHF0oEUvExHYTtWLT4XyxqG3hBeTmOJdgvofn7QnBAjAYT9VCkLyZqnTwtJemaLIC78HBowf4J81CGvDHRM3FGegDavYmbjbYf8gTszgxX69VWJKSMgEt86Gm8QdjP+voJwPRUyctJHal5BoQX0q3Ag/O4i5mlmt0Bfv7x/Bnvl8LN7+tdObxqqquSvpGFoCBGPA4kgDJTK6yUE/5WvMUiTQWgeh+4H7PHvmwAHdW5MiQ6EcQmVPHAxTyULRYiUi0OqudG6fz6AR3e44EE2hGgvZoEJSx4Z2cQ+VTe3vvoZDOMDzwV0y87Mt585mVfCbafpq77OyhZDRNRAUIA3x13pJprxnGvN/2UvmFECxNKNDiciZ8ywUmVHkc26eeJ39c/UonIV5ykBIWR9yg+gmS57k5Ps296EFawRMg/lmXPsJvhggWXwEuQic79vMTO835zrUDFrCocb1th5FhWIWTw5VMWWlnEyBlWCbTSCjou4XiD1S2opW0TYR0OHT/KkGmObW7KdT0GP0mmo2RP9OfkAh4LmdHxuh40+LUKmEAyOapH9LzOLOKhFqo7PbLEJwSnOrrGEyV0ajZodZjBZXqifUiAroHEagYl/6N5kWUrK1RcItN7HD8ye4dVK8GtHSXQ1U4fSWiyjnrCriyCqO5vcUq/8TCPn1BcrzEI1j5+y0VFDTnoGMemNCPxpS2HR3ER5NCBT1B8M5xSJ096IPHSgl9TAy/wEk2FZ/ 4OcH2rWh 2JSQIL+RJAAdkQdGw2fNPYWTKaVgvBPANtpAnVBfR68TSw4+GbfpEs6GTQYWrduacS3Wlq3ntA3tv2nkUAFSfvvwFHqUrWv9cSRwwk/ssTTmEnHSi9wxqZ6AFcCQpRCopl1+5WhepR23Uh+1Lq2C6Nl9Cyw== 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: List-Subscribe: List-Unsubscribe: The tmpfs supports large folio, but there is some configurable options to enable/disable large folio allocation, and for huge=within_size, large folio only allowabled if it fully within i_size, so there is performance issue when perform write without large folio, the issue is similar to commit 4e527d5841e2 ("iomap: fault in smaller chunks for non-large folio mappings"). Fix it by checking whether it allows large folio allocation or not before perform write. Fixes: 9aac777aaf94 ("filemap: Convert generic_perform_write() to support large folios") Signed-off-by: Kefeng Wang --- v2: - Don't use IOCB flags mm/filemap.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 3e46ca45e13d..b33f260fa32f 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4126,13 +4126,28 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) } EXPORT_SYMBOL(generic_file_direct_write); +static size_t generic_mapping_max_folio_size(struct address_space *mapping, + loff_t pos) +{ + struct inode *inode = mapping->host; + pgoff_t index = pos >> PAGE_SHIFT; + + if (!shmem_mapping(mapping)) + goto out; + + if (!shmem_allowable_huge_orders(inode, NULL, index, 0, false)) + return PAGE_SIZE; +out: + return mapping_max_folio_size(mapping); +} + ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) { struct file *file = iocb->ki_filp; loff_t pos = iocb->ki_pos; struct address_space *mapping = file->f_mapping; const struct address_space_operations *a_ops = mapping->a_ops; - size_t chunk = mapping_max_folio_size(mapping); + size_t chunk = generic_mapping_max_folio_size(mapping, pos); long status = 0; ssize_t written = 0;