Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp44168lqb; Tue, 28 May 2024 08:23:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWSqRy869uVKVw0+jdtFr0p3mfzT1Qrj+o/iIndiaEML2XtsVB5UH/PpFYIUk69JUJRNb1k1CmU80zsUW4z+I/mLo2+oDiIV8sVZTuNDA== X-Google-Smtp-Source: AGHT+IEKP9wFgDZaPOtl+7CbDArJ54s8DDcSybKE4nvtW3j2KY6QFb1iCA77f3mjy0WrO+ZxfStu X-Received: by 2002:a0d:d841:0:b0:611:191e:1de8 with SMTP id 00721157ae682-62b9987f762mr9915667b3.18.1716909836458; Tue, 28 May 2024 08:23:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716909836; cv=pass; d=google.com; s=arc-20160816; b=ROXzo7SBxI2IscymSjBORAYcCINSh2qYQWO2coj82lU5d0c5Y6DIwcS5nfvptfqtIn vTVVYjMW2DrbG4Tp4fqz/HvioSaq9GZdMcihlkQmaxwER+ZWa3IhFTdcoLbGn7cNzuPT FKlb9FlHWY8/GX3GUkrTHjjsZdW0b4UaO7DZojCr5R6e3KwSupqPw11TyrDWOuwhU+No fLAxPU/quQXclRrDxg1ktFRj0OAppicUSdvcXtLUubCMVgbcYisXnfruaKFktOGatTxE AfDIkxuJ1DHRzNXT8z3IuaJpiBgdxOfk1c41JLM+leNrdoxQCXMxWIMafQYhUU8+Fb9t aaIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:cms-type:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:content-transfer-encoding:content-id :content-language:accept-language:in-reply-to:message-id:date :thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-filter; bh=GOWqkzE625zVzrnr6gmTlsOXEK4aCs/rT+AEKWG310g=; fh=RKBSn1ooTbOBqvJFC5Y1zY62VHEjXOctoNvuL+PIwC8=; b=DzR22lyLVx4A8M3R8HcclgEt78gFru06gd+gVl3qw4SFuAE9c0RRjOUOCibzzunWRx 8IGHO25WgsXKwYBufvDAIfeiZMnrQe+ZiIC3wyXyL7IDZtiqJhUB2irrUWMbunbtV+Xw osJBPmOSHezzz1YhKVMRT2QfwCWnuCDZxzhokiCeAsi2beBgfLui17KVP5XnKG7NsSIi WDWjYelLv0FgJ3k0vbipDegJBVVLnMmootnej21di6q8PZWiVXW+QdwyyUxDr64AOPdt OlKlZoBa/pE2eQSBX45eiqlfOEPsKIZL9vmW9QXuhZEzK24tzkK29XUz1iOmPnb+bCYo Ldig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=BpU9rBQA; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-nfs+bounces-3445-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3445-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a1e0cc1a2514c-804e584dcdcsi1468583241.57.2024.05.28.08.23.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:23:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3445-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=BpU9rBQA; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-nfs+bounces-3445-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3445-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 247511C23059 for ; Tue, 28 May 2024 15:23:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A5111E507; Tue, 28 May 2024 15:23:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="BpU9rBQA" X-Original-To: linux-nfs@vger.kernel.org Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C67D91E867 for ; Tue, 28 May 2024 15:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716909831; cv=none; b=Jbs/jzrO0dvnNipoDluHC4dEjmovddudbq4b9nQo78X+i/o1cZ/SB0WyyraDnSaCihh/hhApP7xujyIFTQLUFRVrk4xubLZmIUANXGX2BoiV/JqhYcVhZ3l8T3px6+fuBft3HpdxYPR+6+iC1cX7A3EvXpLItFktEUsCyfkRrD4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716909831; c=relaxed/simple; bh=UFjeiiyRTSAPlP8Z30egdkFCfIOQ0fe61d9r1nNQaFg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=RNtlfES5tQK7NgdgwJ12fRcMQdRyFzxU3OZV8h8HoBsAc+WDedBSXjDOsQoGf41zXP6ZfyUkyx1eQUSGgIHkkMJxSMKUH5bUnxItpw3TG0FPDykVwoqch4qHTW9U4lqgatozL6o6AUkRCFAcMr8Zs3dikdg3TNAwbUVX9sJbGL8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=BpU9rBQA; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240528152341euoutp01728dbd7855f829ea1c87f993ef2fa72c~TsGLMMElW0968509685euoutp01u for ; Tue, 28 May 2024 15:23:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240528152341euoutp01728dbd7855f829ea1c87f993ef2fa72c~TsGLMMElW0968509685euoutp01u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716909821; bh=GOWqkzE625zVzrnr6gmTlsOXEK4aCs/rT+AEKWG310g=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=BpU9rBQAZSopP8JeqB5tAGzaeqwwouk28CrXUFcJ5qSsYOpjZsccOb04iQAFUwFkK qdXpom2sjsNySxeJHjKusJWogghHsIRtm/nbzZ81E36ajBgTEHSGH6/dbpT/S+5Zzf JLIyk1omEXUDijz55E/ppZO8xY2aV3uwJW+c2hFw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240528152341eucas1p1793aa45fad26502f9c59613851676eeb~TsGK_Kbzo0199301993eucas1p18; Tue, 28 May 2024 15:23:41 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id CA.7B.09620.CF6F5566; Tue, 28 May 2024 16:23:40 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240528152340eucas1p17ba2ad78d8ea869ef44cdeedb2601f80~TsGKoDAch2284122841eucas1p1O; Tue, 28 May 2024 15:23:40 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240528152340eusmtrp15b70716387565ba854fb3c6ae924b78d~TsGKnMI-e0935709357eusmtrp1j; Tue, 28 May 2024 15:23:40 +0000 (GMT) X-AuditID: cbfec7f5-d1bff70000002594-51-6655f6fc4e64 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 42.D3.09010.CF6F5566; Tue, 28 May 2024 16:23:40 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240528152340eusmtip276fdf57e16a6609cb6a99cfd1f444501~TsGKdhPNK2079320793eusmtip2b; Tue, 28 May 2024 15:23:40 +0000 (GMT) Received: from CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 28 May 2024 16:23:40 +0100 Received: from CAMSVWEXC01.scsc.local ([::1]) by CAMSVWEXC01.scsc.local ([fe80::7d73:5123:34e0:4f73%13]) with mapi id 15.00.1497.012; Tue, 28 May 2024 16:23:40 +0100 From: Daniel Gomez To: Christoph Hellwig CC: Trond Myklebust , Anna Schumaker , Matthew Wilcox , "linux-nfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" Subject: Re: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios Thread-Topic: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios Thread-Index: AQHasRMEv8C0Tteo9UiuY4wdfWDY+A== Date: Tue, 28 May 2024 15:23:39 +0000 Message-ID: In-Reply-To: <20240527163616.1135968-2-hch@lst.de> 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 Content-Type: text/plain; charset="us-ascii" Content-ID: <5CDE07DF0F56364FAE2F6E98A8927FE5@scsc.local> Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SaUwTURSFfTPTmQGtGcp23bUGF8QKiloT4oqmGoySuGOUkQ5LhEI64hoN xi0gMYgapKJlrVBF0yrKrlalElfihkQlYpXFDUFRlrQyjJr++947955z78ujcVmxZDgdo9nG aTVsrJx0Ja7VdD+e2te1OtJf1xikPFTmIJRFF+5iysqqWkL59qJDonxy875E6aifp+z9nUXO p1R9FhOlulLoqzIbk0mVuSOdUlW8SiJVnebRK8kNrkFqLjZmO6edNjfcNbrTZqMS6kbtPHZy XRI65p2CaBqYQNA1kCnIlZYxhQhaU6/jKcil//ADQcHZ2aLQiSD9h0MiCEJDSd17TBTOI3Cc KiX/V+X2PJeI7Q8QZH0EUShC8Ky5ChMEkpkM1bVmSmAPRg4f2h4igXHGiEGK1V1gdyYM+izv SLFmI9jzTYTICrjcYh2oJxgf0OtPkMIOUmY5vDImCNcuzHTILs8aaEXMKGgq6qFEe29osOkx cQM3yD1TiYvsBfZyMQoYP3j40oZE9oeSgmpC5PHQkv9aIvr4QXZFBynyHDB2VvwdfwoYcj4N eEr7/WszbYSwOzANLqA73U6JRsFgqLH+fUZ3aLNepdKQn85pPp1Ths4pQ+eUoXPKyEY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lli18DTaTV0BQ 4uTMJywTGGVmIVk9C0n7LCTts5C0z0LSvoCRdRWjSGppcW56brGRXnFibnFpXrpecn7uJkZg Ctp27OeWHYwrX33UO8TIxMF4iFGCg1lJhPfMpNA0Id6UxMqq1KL8+KLSnNTiQ4ymwKCbyCwl mpwPTIJ5JfGGZgamhiZmlgamlmbGSuK8ngUdiUIC6YklqdmpqQWpRTB9TBycUg1McvMlLHdu fDffftnxg/auR+evOP0i57/32taedGeh7/MdDx5I+RW4ZWHsluR/Qq9P+WxoqIybkvnU5L+q 2aqu62ZOYZ61oX53Gp5JRnYsE6rNW3Ax4eU6Ls5CZt6NDXPObCltk5axSX8SUXD/kczzp/Xr hb65lj+O+rWsTmxP+iN3Zn6BibatxjO3HZ3NoyoV/zbBPc3mzSn9U1Ebj0zcvGX3dxZ2DvsA 0zOLfPhnMymlc6585cviVToz76t+48ntx4WzuPQ8KlZ4xKicNBNfGbDioFsKg3tXaWPQbd3T bqvSPf8ENtk843h3XHWCi6CM1PO09T82rty5zWPmmY5L+3z3HzSqWHdt77bEQ4qTlViKMxIN tZiLihMB+xD6ocoDAAA= X-CMS-MailID: 20240528152340eucas1p17ba2ad78d8ea869ef44cdeedb2601f80 X-Msg-Generator: CA X-RootMTR: 20240528152340eucas1p17ba2ad78d8ea869ef44cdeedb2601f80 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240528152340eucas1p17ba2ad78d8ea869ef44cdeedb2601f80 References: <20240527163616.1135968-1-hch@lst.de> <20240527163616.1135968-2-hch@lst.de> Hi Christoph, Matthew, On Mon, May 27, 2024 at 06:36:08PM +0200, Christoph Hellwig wrote: > From: "Matthew Wilcox (Oracle)" >=20 > Modelled after the loop in iomap_write_iter(), copy larger chunks from > userspace if the filesystem has created large folios. >=20 > Signed-off-by: Matthew Wilcox (Oracle) > [hch: use mapping_max_folio_size to keep supporting file systems that do > not support large folios] > Signed-off-by: Christoph Hellwig > --- > mm/filemap.c | 40 +++++++++++++++++++++++++--------------- > 1 file changed, 25 insertions(+), 15 deletions(-) >=20 > diff --git a/mm/filemap.c b/mm/filemap.c > index 382c3d06bfb10c..860728e26ccf32 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -3981,21 +3981,24 @@ ssize_t generic_perform_write(struct kiocb *iocb,= struct iov_iter *i) > loff_t pos =3D iocb->ki_pos; > struct address_space *mapping =3D file->f_mapping; > const struct address_space_operations *a_ops =3D mapping->a_ops; > + size_t chunk =3D mapping_max_folio_size(mapping); > long status =3D 0; > ssize_t written =3D 0; > =20 > do { > struct page *page; > - unsigned long offset; /* Offset into pagecache page */ > - unsigned long bytes; /* Bytes to write to page */ > + struct folio *folio; > + size_t offset; /* Offset into folio */ > + size_t bytes; /* Bytes to write to folio */ > size_t copied; /* Bytes copied from user */ > void *fsdata =3D NULL; > =20 > - offset =3D (pos & (PAGE_SIZE - 1)); > - bytes =3D min_t(unsigned long, PAGE_SIZE - offset, > - iov_iter_count(i)); > + bytes =3D iov_iter_count(i); > +retry: > + offset =3D pos & (chunk - 1); > + bytes =3D min(chunk - offset, bytes); > + balance_dirty_pages_ratelimited(mapping); > =20 > -again: > /* > * Bring in the user page that we will copy from _first_. > * Otherwise there's a nasty deadlock on copying from the > @@ -4017,11 +4020,16 @@ ssize_t generic_perform_write(struct kiocb *iocb,= struct iov_iter *i) > if (unlikely(status < 0)) > break; > =20 > + folio =3D page_folio(page); > + offset =3D offset_in_folio(folio, pos); > + if (bytes > folio_size(folio) - offset) > + bytes =3D folio_size(folio) - offset; > + > if (mapping_writably_mapped(mapping)) > - flush_dcache_page(page); > + flush_dcache_folio(folio); > =20 > - copied =3D copy_page_from_iter_atomic(page, offset, bytes, i); > - flush_dcache_page(page); > + copied =3D copy_folio_from_iter_atomic(folio, offset, bytes, i); > + flush_dcache_folio(folio); > =20 > status =3D a_ops->write_end(file, mapping, pos, bytes, copied, > page, fsdata); I have the same patch for shmem and large folios tree. That was the last pi= ece needed for getting better performance results. However, it is also needed t= o support folios in the write_begin() and write_end() callbacks. In order to = avoid making them local to shmem, how should we do the transition to folios in th= ese 2 callbacks? I was looking into aops->read_folio approach but what do you t= hink? > @@ -4039,14 +4047,16 @@ ssize_t generic_perform_write(struct kiocb *iocb,= struct iov_iter *i) > * halfway through, might be a race with munmap, > * might be severe memory pressure. > */ > - if (copied) > + if (chunk > PAGE_SIZE) > + chunk /=3D 2; > + if (copied) { > bytes =3D copied; > - goto again; > + goto retry; > + } > + } else { > + pos +=3D status; > + written +=3D status; > } > - pos +=3D status; > - written +=3D status; > - > - balance_dirty_pages_ratelimited(mapping); > } while (iov_iter_count(i)); > =20 > if (!written) > --=20 > 2.43.0 >=20 Daniel=