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 X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73B32C4646B for ; Tue, 25 Jun 2019 01:19:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4244A20663 for ; Tue, 25 Jun 2019 01:19:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729269AbfFYBTk (ORCPT ); Mon, 24 Jun 2019 21:19:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34476 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725784AbfFYBTk (ORCPT ); Mon, 24 Jun 2019 21:19:40 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB5FD13A82; Tue, 25 Jun 2019 01:19:21 +0000 (UTC) Received: from ming.t460p (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4094E5D9C5; Tue, 25 Jun 2019 01:19:06 +0000 (UTC) Date: Tue, 25 Jun 2019 09:19:03 +0800 From: Ming Lei To: Steffen Maier Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , James Bottomley , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Jim Gill , Cathy Avery , "Ewan D . Milne" , Brian King , James Smart , "Juergen E . Fischer" , Michael Schmitz , Finn Thain , Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-usb@vger.kernel.org, Dan Carpenter , Benjamin Block , Martin Schwidefsky , Heiko Carstens , linux-s390@vger.kernel.org Subject: Re: [PATCH V5 10/16] s390: zfcp_fc: use sg helper to operate scatterlist Message-ID: <20190625011902.GA23777@ming.t460p> References: <20190618013757.22401-1-ming.lei@redhat.com> <20190618013757.22401-11-ming.lei@redhat.com> <95bfa1fb-d0eb-fc61-ecc0-001ae52a326f@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <95bfa1fb-d0eb-fc61-ecc0-001ae52a326f@linux.ibm.com> User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 25 Jun 2019 01:19:39 +0000 (UTC) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Mon, Jun 24, 2019 at 05:13:24PM +0200, Steffen Maier wrote: > Hi Ming, > > On 6/18/19 3:37 AM, Ming Lei wrote: > > Use the scatterlist iterators and remove direct indexing of the > > scatterlist array. > > > > This way allows us to pre-allocate one small scatterlist, which can be > > chained with one runtime allocated scatterlist if the pre-allocated one > > isn't enough for the whole request. > > > > Cc: Steffen Maier > > Cc: Benjamin Block > > Cc: Martin Schwidefsky > > Cc: Heiko Carstens > > Cc: linux-s390@vger.kernel.org > > Acked-by: Benjamin Block > > Reviewed-by: Christoph Hellwig > > Reviewed-by: Bart Van Assche > > Signed-off-by: Ming Lei > > --- > > drivers/s390/scsi/zfcp_fc.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c > > index 33eddb02ee30..b018b61bd168 100644 > > --- a/drivers/s390/scsi/zfcp_fc.c > > +++ b/drivers/s390/scsi/zfcp_fc.c > > @@ -620,7 +620,7 @@ static void zfcp_fc_sg_free_table(struct scatterlist *sg, int count) > > { > > int i; > > - for (i = 0; i < count; i++, sg++) > > + for (i = 0; i < count; i++, sg = sg_next(sg)) > > if (sg) > > free_page((unsigned long) sg_virt(sg)); > > else > > @@ -641,7 +641,7 @@ static int zfcp_fc_sg_setup_table(struct scatterlist *sg, int count) > > int i; > > sg_init_table(sg, count); > > - for (i = 0; i < count; i++, sg++) { > > + for (i = 0; i < count; i++, sg = sg_next(sg)) { > > addr = (void *) get_zeroed_page(GFP_KERNEL); > > if (!addr) { > > zfcp_fc_sg_free_table(sg, i); > > > > I'm still catching up with emails that came during my vacation, so I'm not > fully up-to-date on the current state of this and how to bring in potential > fixups on top. > > I think, we also have two more (not so obvious) places in the corresponding > response/completion code path, where we might need to introduce the proper > iterator helper: > > zfcp_fsf.c: > > static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_req *fc_req, > struct zfcp_adapter *adapter, int max_entries) > { > struct scatterlist *sg = &fc_req->sg_rsp; > ... > /* first entry is the header */ > for (x = 1; x < max_entries && !last; x++) { > ... > if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) > ... > else > acc = sg_virt(++sg); > ^^^^ > > zfcp_dbf.c: > > static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag, > struct zfcp_fsf_req *fsf, > u16 len) > { > struct scatterlist *resp_entry = ct_els->resp; > ... > /* the basic CT_IU preamble is the same size as one entry in the GPN_FT > * response, allowing us to skip special handling for it - just skip it > */ > for (x = 1; x < max_entries && !last; x++) { > if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) > ... > else > acc = sg_virt(++resp_entry); > ^^^^^^^^^^^^ > > > What do you think? Yeah, looks this one is missed, so we need the following patch: >From c9c368308fefbf034d670984fe9746a4181fe514 Mon Sep 17 00:00:00 2001 From: Ming Lei Date: Tue, 25 Jun 2019 09:15:34 +0800 Subject: [PATCH] s390: scsi: use sg helper to iterate over scatterlist Unlike the legacy I/O path, scsi-mq preallocates a large array to hold the scatterlist for each request. This static allocation can consume substantial amounts of memory on modern controllers which support a large number of concurrently outstanding requests. To facilitate a switch to a smaller static allocation combined with a dynamic allocation for requests that need it, we need to make sure all SCSI drivers handle chained scatterlists correctly. Convert remaining drivers that directly dereference the scatterlist array to using the iterator functions. Cc: Steffen Maier Cc: Benjamin Block Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: linux-s390@vger.kernel.org Cc: Benjamin Block Signed-off-by: Ming Lei --- drivers/s390/scsi/zfcp_dbf.c | 2 +- drivers/s390/scsi/zfcp_fc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c index dccdb41bed8c..c7129f5234f0 100644 --- a/drivers/s390/scsi/zfcp_dbf.c +++ b/drivers/s390/scsi/zfcp_dbf.c @@ -552,7 +552,7 @@ static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag, if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) acc++; else - acc = sg_virt(++resp_entry); + acc = sg_virt(resp_entry = sg_next(resp_entry)); last = acc->fp_flags & FC_NS_FID_LAST; } diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c index b018b61bd168..5048812ce660 100644 --- a/drivers/s390/scsi/zfcp_fc.c +++ b/drivers/s390/scsi/zfcp_fc.c @@ -742,7 +742,7 @@ static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_req *fc_req, if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) acc++; else - acc = sg_virt(++sg); + acc = sg_virt(sg = sg_next(sg)); last = acc->fp_flags & FC_NS_FID_LAST; d_id = ntoh24(acc->fp_fid); -- 2.20.1 Thanks, Ming