Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp516688iog; Fri, 17 Jun 2022 07:58:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vazJfVid7p/jw6q9Kr5ge8xSn3JcoQVd/jyXK1Txm+xgvBjtzTyZUdPPbQqOKoFM2mwrkg X-Received: by 2002:a17:907:1c07:b0:711:c966:f02e with SMTP id nc7-20020a1709071c0700b00711c966f02emr9797352ejc.221.1655477921109; Fri, 17 Jun 2022 07:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655477921; cv=none; d=google.com; s=arc-20160816; b=mXcppAPrBd5ABzwBvFXrsJk4uLgyXIxYEF0v0UNNHSA9rphH3xt5muYsO0mH58M9os DuGJo41F8UBcdGbBlz+G4ctcLiBdnBo/QhN2B80xHaAkidQBk1a4XuiGthYZoVu7Y229 6gqN8anAqL19UHjHGQAC1MMGgt2OWhMibALCCAB53WOwbJCMkg+DZh1fCT8TVtwskSn6 rLF52zb9R4RTaL1Y7X96JhY6C0srTFIa9gCCv7FHY4ejwGbh+G0ur4SyakjYxZL16CIG +hO3MJJAbJPa8wTSLL7SiYkEmFwL7h8VMLC93bF//3MercRjhXW36IggCbxz47/fKWdq kQbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:mail-followup-to:reply-to:message-id :subject:cc:to:from:date:dkim-signature:dkim-signature; bh=a9HpK8AQFCPpZGHqOflUkPRS+AfBo7nezyoDwo5EOxw=; b=w7+CnOME0PHjrk6dpMbvnU/CT9bCMAdP+wG3B8bGiMDOEEM5DxRcHUH7oc3+tVFPjc uxxCXHnCv3nNPGgVGnuY1/sHUvue70Zd2f6izugEBzeyEre5Ra8rGmzCJYO4W6Ws0XLP KUUKVHQoqfLVl7Yo/fBlr/zfa1z/ug4SUtQ541n/bl4DTY+UbwULJxG8NZ9f3Hy2zHV0 /KfNoUyc8MMuW32QgNBxRHBoGoh0Q2dx9IUyVpxLlLzqXYTZ3am3m2+7Hvr2Mb7crJGz aLsHArcpQraLJoC+UIm43ZebDGIH3LO2QPOPaj9ftzpgz+kX9fmEN30b3+os1N8EtXqB JIfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=wON5Z+a8; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020a05640205cc00b004351f578030si6486109edx.230.2022.06.17.07.58.14; Fri, 17 Jun 2022 07:58:41 -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.cz header.s=susede2_rsa header.b=wON5Z+a8; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234097AbiFQOZF (ORCPT + 99 others); Fri, 17 Jun 2022 10:25:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382476AbiFQOZC (ORCPT ); Fri, 17 Jun 2022 10:25:02 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC0B515AC; Fri, 17 Jun 2022 07:25:00 -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 6919B21E44; Fri, 17 Jun 2022 14:24:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1655475899; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=a9HpK8AQFCPpZGHqOflUkPRS+AfBo7nezyoDwo5EOxw=; b=wON5Z+a8PY3NERVTywme/dw6SGBNU5E2zNjD+c2ZeDbwICsTtnV4w3RAuhibm88j/JmuGV g8S70bLRewWvY75g9gCfu0RHBB3T3Sf3WShC3IdZZkTlLGIayCG9St8vhwG72ocTa25VmL 58dVm1pmwlVNQvWdEfcu/8XDtCq1DVU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1655475899; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=a9HpK8AQFCPpZGHqOflUkPRS+AfBo7nezyoDwo5EOxw=; b=Se/2b5X2lpR6pFkWpn6Hvd2pjIbTelvpE8uXqCZExx4u46Ub1zvNv6NMEnN8Wgx/B0w+D7 GeGj8iyXGisMmABA== 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 08E481348E; Fri, 17 Jun 2022 14:24:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +29EAbuOrGIdLgAAMHmgww (envelope-from ); Fri, 17 Jun 2022 14:24:59 +0000 Date: Fri, 17 Jun 2022 16:20:24 +0200 From: David Sterba To: Qu Wenruo Cc: "Fabio M. De Francesco" , Chris Mason , Josef Bacik , David Sterba , Nick Terrell , Chris Down , Filipe Manana , Qu Wenruo , Nikolay Borisov , Gabriel Niebler , Ira Weiny , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v2 3/3] btrfs: Use kmap_local_page() on "in_page" in zlib_compress_pages() Message-ID: <20220617142024.GL20633@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , "Fabio M. De Francesco" , Chris Mason , Josef Bacik , David Sterba , Nick Terrell , Chris Down , Filipe Manana , Qu Wenruo , Nikolay Borisov , Gabriel Niebler , Ira Weiny , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220617120538.18091-1-fmdefrancesco@gmail.com> <20220617120538.18091-4-fmdefrancesco@gmail.com> <8cbfc1ff-f86d-f2cc-d37e-ef874f4600bc@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8cbfc1ff-f86d-f2cc-d37e-ef874f4600bc@gmx.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) 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 Fri, Jun 17, 2022 at 09:09:47PM +0800, Qu Wenruo wrote: > On 2022/6/17 20:05, Fabio M. De Francesco wrote: > > @@ -126,6 +128,8 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > > ret = -ENOMEM; > > goto out; > > } > > + mstack[sind] = 'A'; > > + sind++; > > cpage_out = kmap_local_page(out_page); > > pages[0] = out_page; > > nr_pages = 1; > > @@ -148,26 +152,32 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, > > int i; > > > > for (i = 0; i < in_buf_pages; i++) { > > - if (in_page) { > > - kunmap(in_page); > > I don't think we really need to keep @in_page mapped for that long. > > We only need the input pages (pages from inode page cache) when we run > out of input. > > So what we really need is just to map the input, copy the data to > buffer, unmap the page. > > > + if (data_in) { > > + sind--; > > + kunmap_local(data_in); > > put_page(in_page); > > } > > in_page = find_get_page(mapping, > > start >> PAGE_SHIFT); > > - data_in = kmap(in_page); > > + mstack[sind] = 'B'; > > + sind++; > > + data_in = kmap_local_page(in_page); > > memcpy(workspace->buf + i * PAGE_SIZE, > > data_in, PAGE_SIZE); > > start += PAGE_SIZE; > > } > > workspace->strm.next_in = workspace->buf; > > } else { > > I think we can clean up the code. > > In fact the for loop can handle both case, I didn't see any special > reason to do different handling, we can always use workspace->buf, > instead of manually dancing using different paths. > > I believe with all these cleanup, it should be much simpler to convert > to kmap_local_page(). > > I'm pretty happy to provide help on this refactor if you don't feel > confident enough on this part of btrfs. My first thought was "why to clean up zlib loop if we want to just replace kmap" but after seeing the whole stack and fiddling with the indexes I agree that a simplification should be done first.