From mboxrd@z Thu Jan 1 00:00:00 1970 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 14BEFC433F5 for ; Mon, 2 May 2022 04:23:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2419B6B0072; Mon, 2 May 2022 00:23:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F08B6B0073; Mon, 2 May 2022 00:23:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 092D26B0074; Mon, 2 May 2022 00:23:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id EEDE26B0072 for ; Mon, 2 May 2022 00:23:29 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B1D2B1BA0 for ; Mon, 2 May 2022 04:23:29 +0000 (UTC) X-FDA: 79419508938.24.85456EF Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf24.hostedemail.com (Postfix) with ESMTP id 159FD180087 for ; Mon, 2 May 2022 04:23:23 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B002321878; Mon, 2 May 2022 04:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1651465407; h=from:from:reply-to: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=koJtgn8z5L2IKkSD/2s/3JZQSkytsTKZddFVSeo5lv0=; b=quHyzEBZI/hFJxAODyZ6SYf7jBWrXNzfFYxaegPRUvURKNtylYs+nubEyujozSqFVvlrV9 dDJUaO5FlohK4AnSsOUgegd5Uvk3ozxJlqYZ/NeqnKdmPgleKu/KkepA7i3o6X6FBSTx/5 65czRDVc2g0/LsteAky2c2PcGMFxz+Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1651465407; h=from:from:reply-to: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=koJtgn8z5L2IKkSD/2s/3JZQSkytsTKZddFVSeo5lv0=; b=B+6at1NSyfDjOVtOGy4LUUMtE45pQAIkTmJfepplYFk6VKuyyL/VJglcpgN8v2ExQY7aOP ptwxm4CkGGuEnTDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8E69D13491; Mon, 2 May 2022 04:23:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ClUsDrxcb2LnOgAAMHmgww (envelope-from ); Mon, 02 May 2022 04:23:24 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: "Yang Shi" Cc: "Andrew Morton" , "Geert Uytterhoeven" , "Christoph Hellwig" , "Miaohe Lin" , linux-nfs@vger.kernel.org, "Linux MM" , "Linux Kernel Mailing List" Subject: Re: [PATCH 1/2] MM: handle THP in swap_*page_fs() In-reply-to: References: <165119280115.15698.2629172320052218921.stgit@noble.brown>, <165119301488.15698.9457662928942765453.stgit@noble.brown>, Date: Mon, 02 May 2022 14:23:16 +1000 Message-id: <165146539609.24404.4051313590023463843@noble.neil.brown.name> X-Rspamd-Queue-Id: 159FD180087 X-Stat-Signature: inw89j1q64fqopffcycisg5tr95wunim X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=quHyzEBZ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=B+6at1NS; spf=pass (imf24.hostedemail.com: domain of neilb@suse.de designates 195.135.220.28 as permitted sender) smtp.mailfrom=neilb@suse.de; dmarc=pass (policy=none) header.from=suse.de X-Rspamd-Server: rspam09 X-HE-Tag: 1651465403-91496 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: On Sat, 30 Apr 2022, Yang Shi wrote: > On Thu, Apr 28, 2022 at 5:44 PM NeilBrown wrote: > > > > Pages passed to swap_readpage()/swap_writepage() are not necessarily all > > the same size - there may be transparent-huge-pages involves. > > > > The BIO paths of swap_*page() handle this correctly, but the SWP_FS_OPS > > path does not. > > > > So we need to use thp_size() to find the size, not just assume > > PAGE_SIZE, and we need to track the total length of the request, not > > just assume it is "page * PAGE_SIZE". >=20 > Swap-over-nfs doesn't support THP swap IIUC. So SWP_FS_OPS should not > see THP at all. But I agree to remove the assumption about page size > in this path. Can you help me understand this please. How would the swap code know that swap-over-NFS doesn't support THP swap? There is no reason that NFS wouldn't be able to handle 2MB writes. Even 1GB should work though NFS would have to split into several smaller WRITE requests. Thanks, NeilBrown >=20 > > > > Reported-by: Miaohe Lin > > Signed-off-by: NeilBrown > > --- > > mm/page_io.c | 23 +++++++++++++---------- > > 1 file changed, 13 insertions(+), 10 deletions(-) > > > > diff --git a/mm/page_io.c b/mm/page_io.c > > index c132511f521c..d636a3531cad 100644 > > --- a/mm/page_io.c > > +++ b/mm/page_io.c > > @@ -239,6 +239,7 @@ struct swap_iocb { > > struct kiocb iocb; > > struct bio_vec bvec[SWAP_CLUSTER_MAX]; > > int pages; > > + int len; > > }; > > static mempool_t *sio_pool; > > > > @@ -261,7 +262,7 @@ static void sio_write_complete(struct kiocb *iocb, lo= ng ret) > > struct page *page =3D sio->bvec[0].bv_page; > > int p; > > > > - if (ret !=3D PAGE_SIZE * sio->pages) { > > + if (ret !=3D sio->len) { > > /* > > * In the case of swap-over-nfs, this can be a > > * temporary failure if the system has limited > > @@ -301,7 +302,7 @@ static int swap_writepage_fs(struct page *page, struc= t writeback_control *wbc) > > sio =3D *wbc->swap_plug; > > if (sio) { > > if (sio->iocb.ki_filp !=3D swap_file || > > - sio->iocb.ki_pos + sio->pages * PAGE_SIZE !=3D pos) { > > + sio->iocb.ki_pos + sio->len !=3D pos) { > > swap_write_unplug(sio); > > sio =3D NULL; > > } > > @@ -312,10 +313,12 @@ static int swap_writepage_fs(struct page *page, str= uct writeback_control *wbc) > > sio->iocb.ki_complete =3D sio_write_complete; > > sio->iocb.ki_pos =3D pos; > > sio->pages =3D 0; > > + sio->len =3D 0; > > } > > sio->bvec[sio->pages].bv_page =3D page; > > - sio->bvec[sio->pages].bv_len =3D PAGE_SIZE; > > + sio->bvec[sio->pages].bv_len =3D thp_size(page); > > sio->bvec[sio->pages].bv_offset =3D 0; > > + sio->len +=3D thp_size(page); > > sio->pages +=3D 1; > > if (sio->pages =3D=3D ARRAY_SIZE(sio->bvec) || !wbc->swap_plug) { > > swap_write_unplug(sio); > > @@ -371,8 +374,7 @@ void swap_write_unplug(struct swap_iocb *sio) > > struct address_space *mapping =3D sio->iocb.ki_filp->f_mapping; > > int ret; > > > > - iov_iter_bvec(&from, WRITE, sio->bvec, sio->pages, > > - PAGE_SIZE * sio->pages); > > + iov_iter_bvec(&from, WRITE, sio->bvec, sio->pages, sio->len); > > ret =3D mapping->a_ops->swap_rw(&sio->iocb, &from); > > if (ret !=3D -EIOCBQUEUED) > > sio_write_complete(&sio->iocb, ret); > > @@ -383,7 +385,7 @@ static void sio_read_complete(struct kiocb *iocb, lon= g ret) > > struct swap_iocb *sio =3D container_of(iocb, struct swap_iocb, io= cb); > > int p; > > > > - if (ret =3D=3D PAGE_SIZE * sio->pages) { > > + if (ret =3D=3D sio->len) { > > for (p =3D 0; p < sio->pages; p++) { > > struct page *page =3D sio->bvec[p].bv_page; > > > > @@ -415,7 +417,7 @@ static void swap_readpage_fs(struct page *page, > > sio =3D *plug; > > if (sio) { > > if (sio->iocb.ki_filp !=3D sis->swap_file || > > - sio->iocb.ki_pos + sio->pages * PAGE_SIZE !=3D pos) { > > + sio->iocb.ki_pos + sio->len !=3D pos) { > > swap_read_unplug(sio); > > sio =3D NULL; > > } > > @@ -426,10 +428,12 @@ static void swap_readpage_fs(struct page *page, > > sio->iocb.ki_pos =3D pos; > > sio->iocb.ki_complete =3D sio_read_complete; > > sio->pages =3D 0; > > + sio->len =3D 0; > > } > > sio->bvec[sio->pages].bv_page =3D page; > > - sio->bvec[sio->pages].bv_len =3D PAGE_SIZE; > > + sio->bvec[sio->pages].bv_len =3D thp_size(page); > > sio->bvec[sio->pages].bv_offset =3D 0; > > + sio->len +=3D thp_size(page); > > sio->pages +=3D 1; > > if (sio->pages =3D=3D ARRAY_SIZE(sio->bvec) || !plug) { > > swap_read_unplug(sio); > > @@ -521,8 +525,7 @@ void __swap_read_unplug(struct swap_iocb *sio) > > struct address_space *mapping =3D sio->iocb.ki_filp->f_mapping; > > int ret; > > > > - iov_iter_bvec(&from, READ, sio->bvec, sio->pages, > > - PAGE_SIZE * sio->pages); > > + iov_iter_bvec(&from, READ, sio->bvec, sio->pages, sio->len); > > ret =3D mapping->a_ops->swap_rw(&sio->iocb, &from); > > if (ret !=3D -EIOCBQUEUED) > > sio_read_complete(&sio->iocb, ret); > > > > > > >=20