Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2133923rwa; Mon, 22 Aug 2022 02:45:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR5iEG5FyZ0kY7oJyd9Q1EWFtvxesRRVKfjv7lwoJ1OA1UhXUgX2O+ZcVBsGUDTiZeNDRUHk X-Received: by 2002:a17:90a:d818:b0:1fb:db8:87e3 with SMTP id a24-20020a17090ad81800b001fb0db887e3mr9735218pjv.125.1661161504277; Mon, 22 Aug 2022 02:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661161504; cv=none; d=google.com; s=arc-20160816; b=fTUtRhfOJ6DrCupRmiQw+gLo6jCHK+UFD9F1kDvO9iSDQ4LV5Lwm0y5Er2l83OO6w1 /tlr2t/4ADAbjJgxJTxJr+aUlqYiCO188C0NQ4Wql+cW3g+wzcqgXtjyyTCcy/XTsmPD G2BOLV3giy4uercx475zr99GNIIeLAY0pOBFEw37ljxhYerMHBPgZ9SuUhDjpm/f7VGg Yb8IJg4SNbA037EYPwIVjx6ewW6Oy5aYXlU6/RiiT/daPHdWMW5bobLAy6HxRpsQWd+x PPh1XcVXLLWqMVNmeJI9/SnYUZUsjARVEqjhYMQa66e05Nz3DpPYGvGDm2h7WGG4fEri jtew== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=Ziw2z60GLw6fCIwzNKouC00bFO+5NDXAJ4kW14DHQN8=; b=rqpxdRWNmhT1x1jc/euccGHwO2Xjmxm0w5ueFTmtkHbqINCdFbtoU+dtrfOYvPGAH5 U48PA1yLASPbV/zaiCVYo64+TLogldQf+HBPw4LQqPpYGyGPIx6G6qHN90B39GpGs3Ug CSER+MqxqnOoXDuarEtOS+gbtnZXgHwqdwvlA1w2aNCTNgMkAz51QqR7Ui4MvjX+YAaC dfGeTK5dmYOj12OSaSxSX/p61lGKZKsRdnBMToVgvDD2VssHstmjuI47P4Pbhd2X5GOh 45MoT9wy+UtBB4eEuhYkA0AcxEQmtmbpc6D/VSex9ChKmVHscaLZOqWL9CkoDweK5+Sg ce2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=b4+plMEV; dkim=neutral (no key) header.i=@suse.cz header.b=QjeKaFWE; 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 c25-20020aa78e19000000b0052dfe17ce46si11846007pfr.285.2022.08.22.02.44.53; Mon, 22 Aug 2022 02:45:04 -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=b4+plMEV; dkim=neutral (no key) header.i=@suse.cz header.b=QjeKaFWE; 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 S229586AbiHVJ0d (ORCPT + 99 others); Mon, 22 Aug 2022 05:26:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229565AbiHVJ02 (ORCPT ); Mon, 22 Aug 2022 05:26:28 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5596193F7 for ; Mon, 22 Aug 2022 02:26:27 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 61BA21FAC8; Mon, 22 Aug 2022 09:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1661160386; 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=Ziw2z60GLw6fCIwzNKouC00bFO+5NDXAJ4kW14DHQN8=; b=b4+plMEVnC3WjOXEMxc+oeYCjB1sXa/8367lT9eai2Y5hNqiDSrfOlWNvjvMITBWl7SXyf JleJPiAKSipWAnrjGofOB8Ws0o0vWMHXCmP2OriZwK4fIr6Zs3WXa5+t4j0G04SuE8WWSf 7zxyu5JTgCDdIputF09scTgrJ636u4k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1661160386; 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=Ziw2z60GLw6fCIwzNKouC00bFO+5NDXAJ4kW14DHQN8=; b=QjeKaFWEXNBMWAIURd6ajlldt3ZE6eC3e84BxlOwmD9RnLNIc5tVUZHpt83tJv88FQcz11 IQt27FZATxDYiwDw== Received: from quack3.suse.cz (unknown [10.100.200.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id DFFBB2C141; Mon, 22 Aug 2022 09:26:25 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id 8C3DCA066D; Mon, 22 Aug 2022 11:26:25 +0200 (CEST) Date: Mon, 22 Aug 2022 11:26:25 +0200 From: Jan Kara To: "Fabio M. De Francesco" Cc: "Matthew Wilcox (Oracle)" , Jan Kara , Muchun Song , Jens Axboe , Bart Van Assche , linux-kernel@vger.kernel.org, Andrew Morton , Ira Weiny , kernel test robot Subject: Re: [RESEND PATCH v2] fs/isofs: Replace kmap() with kmap_local_page() Message-ID: <20220822092625.ag2naoeuhhrq6pqz@quack3> References: <20220821175012.6866-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220821175012.6866-1-fmdefrancesco@gmail.com> 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 Sun 21-08-22 19:50:12, Fabio M. De Francesco wrote: > The use of kmap() is being deprecated in favor of kmap_local_page(). > > There are two main problems with kmap(): (1) It comes with an overhead as > mapping space is restricted and protected by a global lock for > synchronization and (2) it also requires global TLB invalidation when the > kmap’s pool wraps and it might block when the mapping space is fully > utilized until a slot becomes available. > > With kmap_local_page() the mappings are per thread, CPU local, can take > page faults, and can be called from any context (including interrupts). > Tasks can be preempted and, when scheduled to run again, the kernel > virtual addresses are restored and still valid. It is faster than kmap() > in kernels with HIGHMEM enabled. > > Since kmap_local_page() can be safely used in compress.c, it should be > called everywhere instead of kmap(). > > Therefore, replace kmap() with kmap_local_page() in compress.c. Where it > is needed, use memzero_page() instead of open coding kmap_local_page() > plus memset() to fill the pages with zeros. Delete the redundant > flush_dcache_page() in the two call sites of memzero_page(). > > Tested with mkisofs on a QEMU/KVM x86_32 VM, 6GB RAM, booting a kernel > with HIGHMEM64GB enabled. > > Cc: Andrew Morton > Cc: Jan Kara > Suggested-by: Ira Weiny > Signed-off-by: Fabio M. De Francesco Thanks for the patch! It looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > --- > > Some days ago Andrew requested a resend of this patch.[1] > > v1->v2: Cast zisofs_sink_page to pointer to unsigned char. > Reported-by: kernel test robot > > Many thanks to Jan Kara for the comments and suggestions provided with > replying to my previous RFC.[2] Furthermore, I want to thank Ira Weiny for > the advices he provided, especially about how to use mkisofs to test that > this patch is working properly. > > [1] https://lore.kernel.org/all/20220801122709.8164-1-fmdefrancesco@gmail.com/ > [2] https://lore.kernel.org/lkml/20220726145024.rryvw7ot7j2c6tqv@quack3/ > > fs/isofs/compress.c | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c > index 95a19f25d61c..107007c38d08 100644 > --- a/fs/isofs/compress.c > +++ b/fs/isofs/compress.c > @@ -67,8 +67,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start, > for ( i = 0 ; i < pcount ; i++ ) { > if (!pages[i]) > continue; > - memset(page_address(pages[i]), 0, PAGE_SIZE); > - flush_dcache_page(pages[i]); > + memzero_page(pages[i], 0, PAGE_SIZE); > SetPageUptodate(pages[i]); > } > return ((loff_t)pcount) << PAGE_SHIFT; > @@ -120,7 +119,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start, > zerr != Z_STREAM_END) { > if (!stream.avail_out) { > if (pages[curpage]) { > - stream.next_out = page_address(pages[curpage]) > + stream.next_out = kmap_local_page(pages[curpage]) > + poffset; > stream.avail_out = PAGE_SIZE - poffset; > poffset = 0; > @@ -176,6 +175,10 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start, > flush_dcache_page(pages[curpage]); > SetPageUptodate(pages[curpage]); > } > + if (stream.next_out != (unsigned char *)zisofs_sink_page) { > + kunmap_local(stream.next_out); > + stream.next_out = NULL; > + } > curpage++; > } > if (!stream.avail_in) > @@ -183,6 +186,8 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start, > } > inflate_out: > zlib_inflateEnd(&stream); > + if (stream.next_out && stream.next_out != (unsigned char *)zisofs_sink_page) > + kunmap_local(stream.next_out); > > z_eio: > mutex_unlock(&zisofs_zlib_lock); > @@ -283,9 +288,7 @@ static int zisofs_fill_pages(struct inode *inode, int full_page, int pcount, > } > > if (poffset && *pages) { > - memset(page_address(*pages) + poffset, 0, > - PAGE_SIZE - poffset); > - flush_dcache_page(*pages); > + memzero_page(*pages, poffset, PAGE_SIZE - poffset); > SetPageUptodate(*pages); > } > return 0; > @@ -343,10 +346,8 @@ static int zisofs_read_folio(struct file *file, struct folio *folio) > for (i = 0; i < pcount; i++, index++) { > if (i != full_page) > pages[i] = grab_cache_page_nowait(mapping, index); > - if (pages[i]) { > + if (pages[i]) > ClearPageError(pages[i]); > - kmap(pages[i]); > - } > } > > err = zisofs_fill_pages(inode, full_page, pcount, pages); > @@ -357,7 +358,6 @@ static int zisofs_read_folio(struct file *file, struct folio *folio) > flush_dcache_page(pages[i]); > if (i == full_page && err) > SetPageError(pages[i]); > - kunmap(pages[i]); > unlock_page(pages[i]); > if (i != full_page) > put_page(pages[i]); > -- > 2.37.1 > -- Jan Kara SUSE Labs, CR