Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp176564rwi; Wed, 19 Oct 2022 19:30:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5DDJqDWxKaI2tSv3DYixUnMqU+XkBxFstzFuNekvahHWcj/Th2eqlivMCSDoZLQeT4Zw0l X-Received: by 2002:a62:8249:0:b0:565:c121:dedd with SMTP id w70-20020a628249000000b00565c121deddmr11698057pfd.40.1666233012146; Wed, 19 Oct 2022 19:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666233012; cv=none; d=google.com; s=arc-20160816; b=Eb2f/TH8yrRqgI/RFef4dJ8XpQyVROkA8YXBXeIUP25LMaUASDVNvr+eTPQicHw4Hi aW0qmtYdKTIc8EwGS77j9QB0veYlIAS4WLkxAsT9o0e/0QA35d/yrDlxE4rUJIJwHCSa 8avOlWF5x9ZhghP4GpBi85xs76MxLyGUidmtNm5spWgtsnyW8J0FrJ2fPKKZ2nzeJy4r AN8mYWwhA+xjpOFijM2NU7Xo7VKN2RRv/cUMnJNv5brzblHzLcfJH36xI0Dcqo1CExUa aYcItcuZbZiCFAs7uyeU85eDyyFi3B5KxZNso8hs0/3tHU34RvTAR7zZX+ys/FX/92MY nFZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=rUHDxArNbRDYeiDSpVifc613eFD5E6kJRdExvUFyz84=; b=jSOSOu9udy/w/Ih516wLDtOCLSUtBLdBVKmJC3k5rNNZ7aTmJFmAHRyfXisqgJNX5Z OiZbZCjUvqruLr2cd6tB3Q00kWOqFcqSaVLG5T5YOtAGTWqds8QFq7EbMTgVS+d66mMx 0td8zLmBvUJxACbvH+cdS5nkYetjrf/Y/bFxP7fS95A8WHwIIktHRUVdcdBZmV+Vrjyw nsEuPmDxdb7f1P9GyMsIq3VcNfOlXQ6NcUWJyQVvywYLbjWvKkyD6UWvNdiGJTXoRi4P cPCVeaWrxEA+t5rsXuAVB/Vcx4rHhinJcxVRh1IqUTqiWWonV+jtGtObLtsvBQ/V+NnL 0beA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x7-20020a1709029a4700b0017f5bacd4d8si17627659plv.571.2022.10.19.19.30.00; Wed, 19 Oct 2022 19:30:12 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbiJTCSr (ORCPT + 99 others); Wed, 19 Oct 2022 22:18:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229840AbiJTCSq (ORCPT ); Wed, 19 Oct 2022 22:18:46 -0400 Received: from out199-10.us.a.mail.aliyun.com (out199-10.us.a.mail.aliyun.com [47.90.199.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CF55170DDC for ; Wed, 19 Oct 2022 19:18:43 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VScrTTV_1666232317; Received: from B-P7TQMD6M-0146.local(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VScrTTV_1666232317) by smtp.aliyun-inc.com; Thu, 20 Oct 2022 10:18:39 +0800 Date: Thu, 20 Oct 2022 10:18:36 +0800 From: Gao Xiang To: "Fabio M. De Francesco" Cc: linux-erofs@lists.ozlabs.org, Chao Yu , LKML , ira.weiny@intel.com Subject: Re: [PATCH v2] erofs: use kmap_local_page() only for erofs_bread() Message-ID: References: <20221018105313.4940-1-hsiangkao@linux.alibaba.com> <2019477.yKVeVyVuyW@mypc> <12077010.O9o76ZdvQC@mypc> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <12077010.O9o76ZdvQC@mypc> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 Wed, Oct 19, 2022 at 08:17:05PM +0200, Fabio M. De Francesco wrote: > On Wednesday, October 19, 2022 1:36:55 AM CEST Gao Xiang wrote: > > On Wed, Oct 19, 2022 at 01:21:27AM +0200, Fabio M. De Francesco wrote: > > > On Tuesday, October 18, 2022 11:29:21 PM CEST Gao Xiang wrote: > > > > ... > > > > > > > > > One of what I need to care is nested kmap() usage, > > > > some unmap/remap order cannot be simply converted to kmap_local() > > > > > > Correct about nesting. If we map A and then B, we must unmap B and then A. > > > > > > However, as you seem to convey, not always unmappings in right order > (stack > > > based) is possible, sometimes because very long functions have many loop's > > > breaks and many goto exit labels. > > > > > > > but I think > > > > it's not the case for erofs_bread(). Actually EROFS has one of such > nested > > > > kmap() usage, but I don't really care its performance on HIGHMEM > platforms, > > > > so I think kmap() is still somewhat useful compared to kmap_local() from > > > this > > > > point of view], > > > > > fs/erofs conversions are in our (Ira's and my) list. So I'm am happy to see > that we can delete some entries because of your changes. :-) > > > > In Btrfs I solved (thanks to David S.' advice) by mapping only one of two > > > pages, only the one coming from the page cache. > > > > > > The other page didn't need the use of kmap_local_page() because it was > > > allocated in the filesystem with "alloc_page(GFP_NOFS)". GFP_NOFS won't > ever > > > allocate from ZONE_HIGHMEM, therefore a direct page_address() could avoid > the > > > mapping and the nesting issues. > > > > > > Did you check if you may solve the same way? > > > > That is not simple. Currently we have compressed pages and decompressed > > pages (page cache or others), and they can be unmapped when either data > > is all consumed, so compressed pages can be unmapped first, or > > decompressed pages can be unmapped first. That quite depends on which > > pages goes first. > > > > I think such usage is a quite common pattern for decoder or encoder, > > you could take a look at z_erofs_lzma_decompress() in > > fs/erofs/decompressor_lzma.c. > > I haven't yet read that code, however I may attempt to propose a pattern for > solving this kinds of issue, I mean where you don't know which page got mapped > last... > > It's not elegant but it may work. You have compressed and decompressed pages > and you can't know in advance what page should be unmapped first because you > can't know in which order they where mapped, right? > Not really. > I'd use a variable to save two different values, each representing the last > page mapped. When the code gets to the unmapping block (perhaps in an "out" > label), just check what that variable contains. Depending on that value, say > 'c' or 'd', you will be able to know what must be unmapped for first. An "if / > else" can do the work. That is not the simple nested unmapped case as you said above, I could take a very brief example: 1. map a decompresed page 2. map a compressed page 3. working 4. decompressed page is all consumed, unmap the current decompressed page 5. map the next decompressed page 6. working 7. decompressed page is all consumed, unmap the current decompressed page 8. map the next decompressed page 9. working 10. compressed page is all consumed, unmap the current compressed page 11. map the next compressed page 12. working 13. ... (anyway, unmap and remap a compressed page or a decompressed page in any order.) until all process is finished. by using kmap(), it's much simple to implement this, but kmap_local(), it only complexes the code. Thanks, Gao Xiang > > What do you think of this? >