Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3965471iob; Mon, 2 May 2022 09:44:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnyfIhdkvctrG5ot8KLWL5DYSyqHUyw9mb3IPvHcCZ9+mQrzdTkkNavmzl0/j8FgQNzxPz X-Received: by 2002:a17:902:e051:b0:15c:e5dd:c1c0 with SMTP id x17-20020a170902e05100b0015ce5ddc1c0mr12507787plx.1.1651509869261; Mon, 02 May 2022 09:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651509869; cv=none; d=google.com; s=arc-20160816; b=EV/eOxymAAOzvbWFb62fbFkLt52BN4AvlmWpYH3RqBN1hoVMpBavFuYBwnuC8qhLhs CyEvleX7LKCWytNRPcJCNbhDzd6KXKXl8VW5nuL0duFDiJh+K6LWIUwvC/jMyLi0LgjD jvl5e7KQg6j9FtJ5rmpT2iMpG5+7WQmWRpy/iwXcKL4YpunSlH55XJMdz2xi9Hp4x2wR 25AmWL6McKgA15Mlv4Mye9jSVgGtsHOXYlfYrPO/GhfQZjnWJZcyGMhrWOy4hEScAzo1 5is8gjxQqUOU0BlPODpvTihb0M+snBso4h45jC6mLZTjbOgImr2uab7I6tDeGZ7zs5fW k1lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=koJtgn8z5L2IKkSD/2s/3JZQSkytsTKZddFVSeo5lv0=; b=pf75Xu9cfjblVsdrt8ogH7FE37AIuoxPBYf0iUY+VLkGtAx2yaZJkkjyqOsdpTqNyp zC2WpPCEXvPhGHqb7KPJ4pqbQaPnKcg91zZ+v8xF9cTgW/M2QDcB0yl7S3GxKMj2MauD uPiCF1epsPmMzyMcxz5LRFyGdTIkt5Spnf4Oma44Jbj/ziDd/dNyFUEYMj0Mdzs589xS 3HZuSCXtXu1J4DKThH675e47Zv4dUWe5KD+w6XguoqhRb8zyk5mDSDiseq6OXScU4VvS ZFZE8TkFMq66qqEOuLoSFjDKktd5L0PGQSh3IEU2Y41X3roANIVqnHTngYjGEhYiURZ3 apZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=quHyzEBZ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=B+6at1NS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id np4-20020a17090b4c4400b001d2865c095fsi17214784pjb.61.2022.05.02.09.44.12; Mon, 02 May 2022 09:44:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=quHyzEBZ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=B+6at1NS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382333AbiEBE1C (ORCPT + 99 others); Mon, 2 May 2022 00:27:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382115AbiEBE05 (ORCPT ); Mon, 2 May 2022 00:26:57 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C80317058; Sun, 1 May 2022 21:23:29 -0700 (PDT) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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