From patchwork Sat Sep 14 14:06:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13804404 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 B5D03C02197 for ; Sat, 14 Sep 2024 14:07:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBB5C6B007B; Sat, 14 Sep 2024 10:07:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6BA66B0082; Sat, 14 Sep 2024 10:07:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D33556B0083; Sat, 14 Sep 2024 10:07:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B3A896B007B for ; Sat, 14 Sep 2024 10:07:03 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D8E891C6EBC for ; Sat, 14 Sep 2024 14:07:02 +0000 (UTC) X-FDA: 82563520284.05.9498449 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf30.hostedemail.com (Postfix) with ESMTP id D209C80013 for ; Sat, 14 Sep 2024 14:06:58 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.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=1726322702; 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=7FFRVF1PZZ7lX7v8K53kJIXZOsStwew6WSQAEyQvM+w=; b=rTM4jFLyyNBKOu8kPcU6X4+28+jcN/YJPbE7CF6wjSOykwWXC83wAGJ7CBW6PaJ/mprkjc vLVNLvZHOnhHmNXdFxfA/yk/KvHM8X4f2sKC08MnDKdiOwidPhLr552zjO2zlcnYk93xCQ Df29Uvd78rVR3wlWdiWOI9yVVxXn9eQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726322702; a=rsa-sha256; cv=none; b=vifgR59OShFozPlRZDmPJXhK/kxdyOKNoCbIhUe4OVj+i75RS9wMKaN6+xd6RH0QNLvyui reEQ3gxBFWLRlUyCHqsU13jMOBTwbutT0chSz983uQuPQMZjrJhut5MvFY3elgOD4L69dK aClZRPfh/1pluevkQKiyO3O8Y3amiio= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4X5XyH2qYqzyQs3; Sat, 14 Sep 2024 22:05:43 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 68AC2140137; Sat, 14 Sep 2024 22:06:54 +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; Sat, 14 Sep 2024 22:06:53 +0800 From: Kefeng Wang To: Andrew Morton , Hugh Dickins , Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox CC: Anna Schumaker , , , Kefeng Wang Subject: [PATCH -next] tmpfs: fault in smaller chunks if large folio allocation not allowed Date: Sat, 14 Sep 2024 22:06:13 +0800 Message-ID: <20240914140613.2334139-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D209C80013 X-Stat-Signature: qnzhazkh8o1fbdm5qao6ng596eugy47j X-Rspam-User: X-HE-Tag: 1726322818-857713 X-HE-Meta: U2FsdGVkX1+ftjaV2vRsMIk/gdyoHqtnH0pC8gcDWtcT8NO8dMObCHBcub6moNKDvM7ChW1ZRXL+4fEuE87YA1MuVFdk85atzJH6HD2UEfRglt16HysQxQWEaVSt6+agI1z5uXoJE/4ZOFvPeVVd9hmLD/eaI5ew/92skeUuYDXXqCgNraba6lLxAcEsEQuViQ/xQvOPlCp2yIi7RNim7KGpnrrjLmGZ4E2eoEZYNC/vA0EoXkuiGk3+1io7kSWO410sdn1R+7bKJiXk463nmMxTKlWOYzEkBH5sSDIIrGN/SYEOYLG4FtoCoxKu1UOL/AY7iYdAMnKJaO1vblrA7ICDuJ7bBfEeGGDAV3/kxXsV43qz1qEaE7UR+k1lx5M5Yc0lSJSHQXcQk12DmWsnwjaFdv7N9glXcp3jia+sEigWj1njnb3N9IK6bXC9lc8VbUkVD7HQ+kC6c4P5CVoLHXm2g+qxZLpVKUh7KRKkBaW97LycBq1JMn8o9w0My+k6mI0lGcyD4eEoDwnx9ZUwWWtZ3uL4AMGA4SxDDtGduErxgQx/I3xOM+nyb9vDtNHXC6kRR+Khf5GPnTzI8rV5nGRy9zJ6jy9d/5r2j39iCj3WycpFq5bn7mmw1J+GIIafuhv4s1Sl0XKtRt1348yLozddBd/wePc3ui44dF2qRfnmrQFBhBloFlBQMoKzxnX8TkFFXTvZaLcIvDD5+O937rkj40rkjicUpo3vOIbETL/kWobMwfJQOIOl+dpqLYE2RCBvisa8vnxwTqoaXl2c5aSjxcMTWUrY5a9iYEL/gIvoxhaKMlp63fwkIm4istGHqeAc/HYMWY7NMYIrXybzYr5B/bzTgKfFM5q/pJZl7DKakRLB8YQy8Z60foS+2sKAmhgcDuchvpvwfJnczgUnqEvedPj5yydao8dKRbjINLEZjYm6kOCphZqOUEP0nSwWVy1s4jtuL0vB1y/Flfs BsfInSIm MiWXaDV3fBMQKzxIbM33+MXA1Z94Q3jBdSfCLxcYzY5PhSuX7UVxmDEkP5mluqbZ+7TNHtQvTe7sy/fh14MjCXdRJv4A5oxQgYcqYzbCRnHz2p/v5VXCv0GaRBnanrHCFuz5JBeHEj8YY7qMSt1rpfVxS7A== 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 --- include/linux/fs.h | 2 ++ mm/filemap.c | 7 ++++++- mm/shmem.c | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 1e25267e2e48..d642e323354b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -346,6 +346,8 @@ struct readahead_control; #define IOCB_DIO_CALLER_COMP (1 << 22) /* kiocb is a read or write operation submitted by fs/aio.c. */ #define IOCB_AIO_RW (1 << 23) +/* fault int small chunks(PAGE_SIZE) from userspace */ +#define IOCB_NO_LARGE_CHUNK (1 << 24) /* for use in trace events */ #define TRACE_IOCB_STRINGS \ diff --git a/mm/filemap.c b/mm/filemap.c index 3e46ca45e13d..27e73f2680ef 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4132,9 +4132,14 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) 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); long status = 0; ssize_t written = 0; + size_t chunk; + + if (iocb->ki_flags & IOCB_NO_LARGE_CHUNK) + chunk = PAGE_SIZE; + else + chunk = mapping_max_folio_size(mapping); do { struct folio *folio; diff --git a/mm/shmem.c b/mm/shmem.c index 530fe8cfcc21..2909bead774b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3228,6 +3228,7 @@ static ssize_t shmem_file_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; + pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; ssize_t ret; inode_lock(inode); @@ -3240,6 +3241,10 @@ static ssize_t shmem_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ret = file_update_time(file); if (ret) goto unlock; + + if (!shmem_allowable_huge_orders(inode, NULL, index, 0, false)) + iocb->ki_flags |= IOCB_NO_LARGE_CHUNK; + ret = generic_perform_write(iocb, from); unlock: inode_unlock(inode);