Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2159218lqb; Mon, 27 May 2024 09:36:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeSM97BckybeSRUaaSQl42GNdICVMMd2LQcUpTW1HXlKlrnzofVO0fLzAFnguqp1JIR8xXVWVwd9Fe5d3SLn4NRU3BnSGEeLGOuLl+7w== X-Google-Smtp-Source: AGHT+IHo6nbXvsEpXWAenMhAYsGxvWJh0tjS4RTTLl+ZHKEN1NLT9o8i/f7kLzahPa8Uwc6TAZZs X-Received: by 2002:a50:9b53:0:b0:579:c5df:af7a with SMTP id 4fb4d7f45d1cf-579c5dfb319mr3758591a12.2.1716827793367; Mon, 27 May 2024 09:36:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716827793; cv=pass; d=google.com; s=arc-20160816; b=IoPYaWd3et5hFmmj4PqEusqhbtrIJX3qAt7MhPaPGqK/sO2QaZZTZrid11FsG20WoA 2hr1EqFjlQF6ze18Sd7vhbzSToYmiQwRwbT4eydK9CMUFqLVxnvbPAnZjlaWYHjt5q+i tG7ZNQq46tMurCZRlET4y7vxMgF3jkfuxqqU1Ap+36absxtPXuCjypN1hjibceaWCye3 McYrln9xnM3RpBNyvw0AdxTivkU4RLI+6NWlE0kVhJSIzueZKY1ntpC+WPO1/kv0pSsB Ceyi3gdppGLNOfFNsM+oOYJbl6VjxzW2RWz0sK9+W4INq8d7Xwfroww1rhuCZ9XfQupC tOTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=27+lP32Q2mw19iey55M36pSytXlr5S4+SrngC3O6v+s=; fh=+am2lmm4Njqt07YFLXCtuL9a8jCC1hTpWkJ4JL4Bsxc=; b=qxorzxuiVCL3NYC7ZUN1cHtWKzosErvyUXy172JScd9i8wATKvsz9AM7H/RLjHq67w 88vEZQWT7RPex5cRPTC75sFYzLddSJ45Nh8mu/owSp+6HjjKSGFY6G9EIgTtIHF/m1Rp wW1bM5/5tw/nK7o92QL1+Sklsfvx6MipPN0nKvZGVbitHJGQW4zw64WeSJjXA7IlCZ9X 9o0fNXXTmRHJ4Sv1FMjpUn6PossWFu42t2jZRQQI3Q0zMurvUGVCn2NdkACbJF4nQRfD YKO1BuCGhEU0mG2+07IlGIjbtUj3yyLoPUao+Gq58VQgDgv+5hUzIV7IK1zWIGpLB8my o7gw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=DF+0PB+J; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-nfs+bounces-3420-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3420-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57869bc519fsi2900218a12.379.2024.05.27.09.36.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 09:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3420-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=DF+0PB+J; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-nfs+bounces-3420-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3420-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1D3D31F23045 for ; Mon, 27 May 2024 16:36:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6FF661FDB; Mon, 27 May 2024 16:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="DF+0PB+J" X-Original-To: linux-nfs@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 16C76155C96; Mon, 27 May 2024 16:36:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716827785; cv=none; b=V6Y68uJCsvRo6JZs4YRtClOSxQfraflnDsVARCEOaSkhPk2OC+9rueklfJdmpYSpH4Lu3MAIjulu2Xy3jB9P6eQbVlU6L/06C2uIapRKgsTtUUTZbZbB8tAfoBP+MC8NcOlgIOzqPTNLDbvqwHIAIWpplSOC5SfNsqF8EAqlsqQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716827785; c=relaxed/simple; bh=5PXQDAmsoR4Mi2gYo4EP22yZCBVVSAfwuHdb3qiEX/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oXPtghK3kUV6ndX/pVhUYp6J4j82/ozQFU1WngGbu7wf4THVoT16e8HI8MjGcoMyKRBUJVIoscKPwBM1Twtk75CeeYc4fJsPZSFHLFX/07Kl63wPxrFd1nEc7lyHrosdV0nUKTLAgzKUcmwTyEFlhVh01ksN+TgdJMJizvcyS1g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=DF+0PB+J; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=27+lP32Q2mw19iey55M36pSytXlr5S4+SrngC3O6v+s=; b=DF+0PB+J1G3GjShibBUkkXKzbg fXBJp4C12z3fLlSUjFb8iSZ12AevUEdRfRjZ65AWcrNk697Svt6DuF5gVqg4QjbjnUClInBMEI1fO TfEbmNaMYRqU/2QXTmXXyJL+AvEdUbrZ+JSijhLQH8oOgsoRdGmy8m7OGPwOckiF+0Z6qGrT1GbQv T/4dxOFKBIJdGP/bWENwVdcqF0qb34xY2V4MCNg0VQwK49HqlXvDjpSaCsAvfsFMLwrrOFg7l6wSd dCI/QdL+yV5U3WF7sB3kYhStTLsR9aFpkkG+H5/jCwMl6/YKu7F1t0WFZn5pMml3EY9duNuMKrv16 rsI69DyQ==; Received: from 2a02-8389-2341-5b80-3177-e4c1-2108-f294.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:3177:e4c1:2108:f294] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBdKh-0000000Ft6T-11pI; Mon, 27 May 2024 16:36:23 +0000 From: Christoph Hellwig To: Trond Myklebust , Anna Schumaker , Matthew Wilcox Cc: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios Date: Mon, 27 May 2024 18:36:08 +0200 Message-ID: <20240527163616.1135968-2-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527163616.1135968-1-hch@lst.de> References: <20240527163616.1135968-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html From: "Matthew Wilcox (Oracle)" Modelled after the loop in iomap_write_iter(), copy larger chunks from userspace if the filesystem has created large folios. 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(-) 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 = 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; 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 = NULL; - offset = (pos & (PAGE_SIZE - 1)); - bytes = min_t(unsigned long, PAGE_SIZE - offset, - iov_iter_count(i)); + bytes = iov_iter_count(i); +retry: + offset = pos & (chunk - 1); + bytes = min(chunk - offset, bytes); + balance_dirty_pages_ratelimited(mapping); -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; + folio = page_folio(page); + offset = offset_in_folio(folio, pos); + if (bytes > folio_size(folio) - offset) + bytes = folio_size(folio) - offset; + if (mapping_writably_mapped(mapping)) - flush_dcache_page(page); + flush_dcache_folio(folio); - copied = copy_page_from_iter_atomic(page, offset, bytes, i); - flush_dcache_page(page); + copied = copy_folio_from_iter_atomic(folio, offset, bytes, i); + flush_dcache_folio(folio); status = a_ops->write_end(file, mapping, pos, bytes, copied, page, fsdata); @@ -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 /= 2; + if (copied) { bytes = copied; - goto again; + goto retry; + } + } else { + pos += status; + written += status; } - pos += status; - written += status; - - balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); if (!written) -- 2.43.0