From patchwork Fri Sep 15 09:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 140326 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp933322vqi; Fri, 15 Sep 2023 03:10:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMGyXC3ew5Db6yXutUGUvgnMv20dNqu1VN0Y3+gOZZ3mtbjkVnHSnpL4vsr6SE93gJSnH4 X-Received: by 2002:a05:6a21:7189:b0:157:eb32:e739 with SMTP id wq9-20020a056a21718900b00157eb32e739mr1170332pzb.32.1694772647160; Fri, 15 Sep 2023 03:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694772647; cv=none; d=google.com; s=arc-20160816; b=B79ooSGXZj8itiHwV3SJsDIuCd3aS5wcGcPVPdArxm591mYriJ6mONfNd4C6Krn0Cu 3y0WHr9waXLvviAwkoqD7wUxuRNFB66Hh6BfRZn/8uaJSIOVQz255GUgiDQjU63FifyZ gzJ6hSAdi//iN+1hk4rF6g9megHEqUArKN1Yj3u+St3osGQV7bMgd5BMa6j6zIhbMpk5 TBIdlRb1FfoFbfuhy7Nmr/cPPSNigooOuozXYk8oWA4y4GKDfriUCkiSc4xgGYm8qRI1 fnixhCLFmsfXrGgy8ZgF/F5+5oWsrglaT9ihuVQ83lraoW8oXoMzw2gXWXVHXHRbu+jG m+Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:mime-version :content-transfer-encoding:content-language:accept-language :in-reply-to:message-id:date:thread-index:thread-topic:subject:cc:to :from:dkim-signature:dkim-filter; bh=KBxqvbiqwxbpjqMz9Z69KDs2z1l+Vy83NL/rF/oYkIA=; fh=uxBAUgUSkBYxjd1CTtcj7MO+vdwExfJsOb4I3IkdCcM=; b=Fs8tcMkUuwNWk/WID6TE773Z5nRTi8f/OQ0QzspW5xpaNtm3Fl0A3XmMEDllhGd+qL rB+MUSK1L2DznnygTnRLJDEoQGB/Myzu8asVvbKZK/A0kU96bLD4AhVW4LBMK76KEN6Z FCEFIcPhbWdm7ABghO57vkZUHqXQDcSYciMPDv0/7RD+BoTpU7TYp9trgK22ofRfvxaL l/jo6IUM0/vl5DIqp7q1AmBVmqFVjRlo2ChE1qTzmJQZJXzDx/eN4MaDecKi1SmIKYfN nmKZlZrs7jrdGSrp1n/4vMQRUyd6Nwy98bCSJnZWjmrSK0jrzuqTKs1ebA+TITkj8S8/ iDuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JOehX4by; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id k18-20020aa790d2000000b0068fc078b0casi2998107pfk.147.2023.09.15.03.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:10:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JOehX4by; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3D2DD8221541; Fri, 15 Sep 2023 02:55:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234144AbjIOJys (ORCPT + 32 others); Fri, 15 Sep 2023 05:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234035AbjIOJyd (ORCPT ); Fri, 15 Sep 2023 05:54:33 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2665430E6 for ; Fri, 15 Sep 2023 02:53:12 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230915095131euoutp017e940360aa0897eacbbb8f7680d63bfc~FCbFSwAr40839508395euoutp01V for ; Fri, 15 Sep 2023 09:51:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230915095131euoutp017e940360aa0897eacbbb8f7680d63bfc~FCbFSwAr40839508395euoutp01V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1694771492; bh=KBxqvbiqwxbpjqMz9Z69KDs2z1l+Vy83NL/rF/oYkIA=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=JOehX4by5wtuX/tE/lkY/wGdcZiXjGvV+uvowvsHd2pzTMwEPs6jAg6SaKbGyeYcE iR1US6vyNvUMUR3ILaF+Pv2qAnqLxDu6BYFROC3ouKN35j27QhPrumNlIemiLqUGlG wMaSFWpsfDW+px6/1X9wAnkxvPWX6ewHOlmRMtkE= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230915095131eucas1p25cc2b04fd359369a4fc473bf907da57c~FCbFAjAMZ1349613496eucas1p21; Fri, 15 Sep 2023 09:51:31 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 2B.9A.42423.32924056; Fri, 15 Sep 2023 10:51:31 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d~FCbEmMxFv0060700607eucas1p1L; Fri, 15 Sep 2023 09:51:31 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230915095131eusmtrp24a417d7970c44623708b2e39cfebe5a0~FCbElcNAu1712217122eusmtrp27; Fri, 15 Sep 2023 09:51:31 +0000 (GMT) X-AuditID: cbfec7f2-a51ff7000002a5b7-1a-65042923bb09 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 09.3B.10549.22924056; Fri, 15 Sep 2023 10:51:31 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230915095130eusmtip22dc6e7222c8a07a587bf7bef6f55c865~FCbES6n5V0935009350eusmtip2L; Fri, 15 Sep 2023 09:51:30 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 15 Sep 2023 10:51:30 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 15 Sep 2023 10:51:30 +0100 From: Daniel Gomez To: "minchan@kernel.org" , "senozhatsky@chromium.org" , "axboe@kernel.dk" , "djwong@kernel.org" , "willy@infradead.org" , "hughd@google.com" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" CC: "gost.dev@samsung.com" , Pankaj Raghav , Daniel Gomez Subject: [PATCH 5/6] shmem: add file length in shmem_get_folio path Thread-Topic: [PATCH 5/6] shmem: add file length in shmem_get_folio path Thread-Index: AQHZ57ozxEpCdFcMBk645e2R7dVRyg== Date: Fri, 15 Sep 2023 09:51:29 +0000 Message-ID: <20230915095042.1320180-6-da.gomez@samsung.com> In-Reply-To: <20230915095042.1320180-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SfVBMYRTG57179+7tjtW1Wr2EMduUsZul4Y+LUMNwfczEjDEYg2tdWX1g txX5KoNRI5K+7G6lsJS0WqXUrpJRtpSy+RhGwkY0JopY1abtLtN/v+c553nPOTMvzhNZ+ZNw ZVQ0q4piIiQYgd6pdTyZ6TsDZWdfbJ5G6Y2FGHXjzTmMstnHUh09Z1HK8kpGmS1WlLJV6DGq rXCIT1UMlAuol8kdgDL87BZQlcV5GNX/W48FC2ldXAtKXzJp6NvXpbStUUObChIw2tSTIqAf ZfajdK9p6hp8ExG0g41Q7mdVsxZtI3ZlJBXx9g7KDsTbT4A4cNw3EXjgkJwLu1vf8BIBgYvI 6wDe7/uMceIHgI76QT4negF8m6Xn/4v0vuhyR64BaG06I/jf1Vic484/HhYJ39wiH8BPueWI K4+RM+A9q2kk4kXq+PDB5dPAVeCRR2HhRy3q4vHkEphScnY4jQ830bAqc7nL9iLlsKzAKHDZ KOkHDT9GnhSSC2BNqmPE9iCDYPfvGJcNyCnwff4fAfe4N3xlz0G4C8bBPJ2Zx/EE6Kx4h3Ec ABtf2AHHs2Hp1XsoxxI4cDrXva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+AtcShKT/BwkJA9qzpXiAm p4CNxPsf5SAVjAKyEo9W/mKH2CMucevJfCaI+wUkluw5zwxhi0q8fPwP6i8dibPXn0D9ayCx dek+FghbSeJPx0Koe/UkbkydwgZha0ssW/iaGeIaQYmTM5+wTGCUnoVk3SwkLbOQtMxC0rKA kWUVo0hqaXFuem6xoV5xYm5xaV66XnJ+7iZGYGraduzn5h2M81591DvEyMTBeIhRgoNZSYSX zZYpVYg3JbGyKrUoP76oNCe1+BCjKTCAJjJLiSbnA5NjXkm8oZmBqaGJmaWBqaWZsZI4r2dB R6KQQHpiSWp2ampBahFMHxMHp1QD09psvsWhSvdN5prPPGOTsv76q4qHvxznfltUwXvXb7FG ve03ZmbPC5pPPAQPpe9umbpgbonXqegVcy7+51BJ5WSferX7nuSlPuaqfKZTzJ92VP7ddLyt uL779Azlw45v1pg+LitjuBTbz3Bx93TFld9ucff8f9h3oDM5MXjFScct3Kxlqicn6+1UujW7 XFo2+nG+o8cCN5/T7hHHk62qcpmyL0w4XPy5bGGKfezyV3EaG55IObOFO0ZIrvKbvjzw2MTX 8ydk/T5vtfjZYrXJWm8Tnl6JZD3GKXG5/FLRsrnzzk7Z+MRH0r3gV+i3mStjnO60TzyS21j4 v3mJxP+vnMmT02c8sTp+3flzua/+XRUlluKMREMt5qLiRABLoVzZ1gMAAA== X-CMS-MailID: 20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d X-Msg-Generator: CA X-RootMTR: 20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d References: <20230915095042.1320180-1-da.gomez@samsung.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 02:55:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777097923357683077 X-GMAIL-MSGID: 1777097923357683077 To be able to calculate folio order based on the file size when allocation occurs on the write path. Use of length 0 for non write paths. Signed-off-by: Daniel Gomez --- include/linux/shmem_fs.h | 2 +- mm/khugepaged.c | 2 +- mm/shmem.c | 28 ++++++++++++++++------------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 6b0c626620f5..b3509e7f1054 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -133,7 +133,7 @@ enum sgp_type { }; int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, - enum sgp_type sgp); + enum sgp_type sgp, size_t len); struct folio *shmem_read_folio_gfp(struct address_space *mapping, pgoff_t index, gfp_t gfp); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 88433cc25d8a..e5d3feff6de6 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1856,7 +1856,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, xas_unlock_irq(&xas); /* swap in or instantiate fallocated page */ if (shmem_get_folio(mapping->host, index, - &folio, SGP_NOALLOC)) { + &folio, SGP_NOALLOC, 0)) { result = SCAN_FAIL; goto xa_unlocked; } diff --git a/mm/shmem.c b/mm/shmem.c index ee297d8874d3..adff74751065 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -969,7 +969,7 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) * (although in some cases this is just a waste of time). */ folio = NULL; - shmem_get_folio(inode, index, &folio, SGP_READ); + shmem_get_folio(inode, index, &folio, SGP_READ, 0); return folio; } @@ -1950,7 +1950,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, struct folio **foliop, enum sgp_type sgp, gfp_t gfp, struct vm_area_struct *vma, struct vm_fault *vmf, - vm_fault_t *fault_type) + vm_fault_t *fault_type, size_t len) { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); @@ -2164,10 +2164,11 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, } int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop, - enum sgp_type sgp) + enum sgp_type sgp, size_t len) { return shmem_get_folio_gfp(inode, index, foliop, sgp, - mapping_gfp_mask(inode->i_mapping), NULL, NULL, NULL); + mapping_gfp_mask(inode->i_mapping), + NULL, NULL, NULL, len); } /* @@ -2251,7 +2252,7 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf) } err = shmem_get_folio_gfp(inode, vmf->pgoff, &folio, SGP_CACHE, - gfp, vma, vmf, &ret); + gfp, vma, vmf, &ret, i_size_read(inode)); if (err) return vmf_error(err); if (folio) @@ -2702,6 +2703,9 @@ shmem_write_begin(struct file *file, struct address_space *mapping, struct folio *folio; int ret = 0; + if (!mapping_large_folio_support(mapping)) + len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos)); + /* i_rwsem is held by caller */ if (unlikely(info->seals & (F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_FUTURE_WRITE))) { @@ -2711,7 +2715,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping, return -EPERM; } - ret = shmem_get_folio(inode, index, &folio, SGP_WRITE); + ret = shmem_get_folio(inode, index, &folio, SGP_WRITE, len); if (ret) return ret; @@ -2783,7 +2787,7 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) break; } - error = shmem_get_folio(inode, index, &folio, SGP_READ); + error = shmem_get_folio(inode, index, &folio, SGP_READ, 0); if (error) { if (error == -EINVAL) error = 0; @@ -2960,7 +2964,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, break; error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio, - SGP_READ); + SGP_READ, 0); if (error) { if (error == -EINVAL) error = 0; @@ -3147,7 +3151,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, error = -ENOMEM; else error = shmem_get_folio(inode, index, &folio, - SGP_FALLOC); + SGP_FALLOC, 0); if (error) { info->fallocend = undo_fallocend; /* Remove the !uptodate folios we added */ @@ -3502,7 +3506,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, inode->i_op = &shmem_short_symlink_operations; } else { inode_nohighmem(inode); - error = shmem_get_folio(inode, 0, &folio, SGP_WRITE); + error = shmem_get_folio(inode, 0, &folio, SGP_WRITE, 0); if (error) goto out_remove_offset; inode->i_mapping->a_ops = &shmem_aops; @@ -3550,7 +3554,7 @@ static const char *shmem_get_link(struct dentry *dentry, return ERR_PTR(-ECHILD); } } else { - error = shmem_get_folio(inode, 0, &folio, SGP_READ); + error = shmem_get_folio(inode, 0, &folio, SGP_READ, 0); if (error) return ERR_PTR(error); if (!folio) @@ -4923,7 +4927,7 @@ struct folio *shmem_read_folio_gfp(struct address_space *mapping, BUG_ON(!shmem_mapping(mapping)); error = shmem_get_folio_gfp(inode, index, &folio, SGP_CACHE, - gfp, NULL, NULL, NULL); + gfp, NULL, NULL, NULL, i_size_read(inode)); if (error) return ERR_PTR(error);