From nobody Wed Apr 15 05:45:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75A91C433EF for ; Mon, 25 Jul 2022 16:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234725AbiGYQXn (ORCPT ); Mon, 25 Jul 2022 12:23:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235468AbiGYQXl (ORCPT ); Mon, 25 Jul 2022 12:23:41 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1EDE1834F for ; Mon, 25 Jul 2022 09:23:39 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id ss3so21429842ejc.11 for ; Mon, 25 Jul 2022 09:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YwCFarmJh4PicurxfwsS6NacLOIP84PDUu/cBdBYT6E=; b=cF1O8ddzfyfKaJdJ4wtujqLScwlIHBFZGbaG/4vQ+/x911Q8sdQ3MO+OLOs2e9X0OV YzohYWePCOVpfaxfrKItmTf4IcsVt4RpHun/UxuoxLvG9NHxo0Ts9dsqlA+nCv/IiSGC r0iLjJ819dUEAB1HnLXUpQKmk98DfuEOCgATbyxyTa3XsqrIjzrVGpYiUK0aqwzeMex+ Yn7mrkngkOepHB1KTuVwtgNGGfImwaRGi0fsXjdoL+luNlHv9Y81FB7ZTVsBSua0ZHy1 vODcbnjXfGk2bNTZ+MM9bqk5p9bVyw616GrnZiQ5vBAql0/SauUbswPZGGnl2j/S+m0U RCZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YwCFarmJh4PicurxfwsS6NacLOIP84PDUu/cBdBYT6E=; b=1oX/rht00u0dBn8BrtjTwh/++ljktCH/oHAMaPpAsiDIBTf4vklKC6QIe0A5uoT5E/ 5bkmbr4FgICWq1S7eCYiIhOD1gZizz4hiKsYUmg+eLawh3yzaYS2hASJDODE5CDryR9x vcO3gOOHAVHPhMLcQInoWTMhazYqwWUwGyIcX730YDW8siWG2cGgk6ECkqPl50bFLmp2 JBpAEP+ukZCJLipepu819+8958GyargGrgebf4lVqk/Ex3VYEOkofGLX7ig7wLimh5BY ectFjRaOHSMuox//D7EDNCTyICI6qkSle/ltdJ22O/MclsfiOmYHyeBrm0oFtKAHvzOM RsVw== X-Gm-Message-State: AJIora9b2BJp4TCgG3SXMAX7iItqvxcl6Wzpp0d+qSm+ctJ8SJ7WKQeC w6KlJceJ8wfL2pDjrgxtC//eTMO4x8Q= X-Google-Smtp-Source: AGRyM1sUxh6g1PqZYFiNAssUhRB5i8BMUkNa89nNIM+alMp3cbdjD0LmJZ05+Wlz6K1kgctXFBS/pw== X-Received: by 2002:a17:907:a0c6:b0:72e:ee9a:cf89 with SMTP id hw6-20020a170907a0c600b0072eee9acf89mr10333441ejc.43.1658766218373; Mon, 25 Jul 2022 09:23:38 -0700 (PDT) Received: from localhost.localdomain (host-79-56-6-250.retail.telecomitalia.it. [79.56.6.250]) by smtp.gmail.com with ESMTPSA id kw23-20020a170907771700b007263713cfe9sm1576210ejc.169.2022.07.25.09.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 09:23:37 -0700 (PDT) From: "Fabio M. De Francesco" To: "Matthew Wilcox (Oracle)" , Jan Kara , Roman Gushchin , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Andrew Morton , Muchun Song , linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [RFC PATCH] fs/isofs: Replace kmap() with kmap_local_page() Date: Mon, 25 Jul 2022 18:23:31 +0200 Message-Id: <20220725162331.9825-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=E2=80=99s 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(). This is an RFC because these changes have not been tested (tests are welcome!), therefore I'm not entirely sure whether these conversions work properly. I'd like to hear comments from more experienced developers before sending a real patch. Suggestions about how to run tests would also be much appreciated. Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- fs/isofs/compress.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c index 95a19f25d61c..a1562124bb91 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 =3D 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,8 +119,7 @@ static loff_t zisofs_uncompress_block(struct inode *ino= de, loff_t block_start, zerr !=3D Z_STREAM_END) { if (!stream.avail_out) { if (pages[curpage]) { - stream.next_out =3D page_address(pages[curpage]) - + poffset; + stream.next_out =3D kmap_local_page(pages[curpage] + poffset); stream.avail_out =3D PAGE_SIZE - poffset; poffset =3D 0; } else { @@ -170,6 +168,12 @@ static loff_t zisofs_uncompress_block(struct inode *in= ode, loff_t block_start, } } =20 + if (stream.next_out) + if (stream.next_out !=3D (char *)zisofs_sink_page) { + kunmap_local(stream.next_out); + stream.next_out =3D NULL; + } + if (!stream.avail_out) { /* This page completed */ if (pages[curpage]) { @@ -183,6 +187,9 @@ static loff_t zisofs_uncompress_block(struct inode *ino= de, loff_t block_start, } inflate_out: zlib_inflateEnd(&stream); + if (stream.next_out) + if (stream.next_out !=3D (char *)zisofs_sink_page) + kunmap_local(stream.next_out); =20 z_eio: mutex_unlock(&zisofs_zlib_lock); @@ -283,9 +290,7 @@ static int zisofs_fill_pages(struct inode *inode, int f= ull_page, int pcount, } =20 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 +348,8 @@ static int zisofs_read_folio(struct file *file, struct= folio *folio) for (i =3D 0; i < pcount; i++, index++) { if (i !=3D full_page) pages[i] =3D grab_cache_page_nowait(mapping, index); - if (pages[i]) { + if (pages[i]) ClearPageError(pages[i]); - kmap(pages[i]); - } } =20 err =3D zisofs_fill_pages(inode, full_page, pcount, pages); @@ -357,7 +360,6 @@ static int zisofs_read_folio(struct file *file, struct = folio *folio) flush_dcache_page(pages[i]); if (i =3D=3D full_page && err) SetPageError(pages[i]); - kunmap(pages[i]); unlock_page(pages[i]); if (i !=3D full_page) put_page(pages[i]); --=20 2.37.1