From patchwork Mon Dec 12 23:19:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 2890 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2522675wrr; Mon, 12 Dec 2022 15:23:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf6F/KVp130TtHUrr2hqdFCUcV4PyJQIQ/le1wkOqhmCH+wMp3AUtEuDe18Px4QbIrsVNoGW X-Received: by 2002:a17:902:6bcc:b0:186:6ae1:5ee with SMTP id m12-20020a1709026bcc00b001866ae105eemr16978080plt.26.1670887415967; Mon, 12 Dec 2022 15:23:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670887415; cv=none; d=google.com; s=arc-20160816; b=oZ9/b69Dtmm8UAOPJqxvpgq61zZx+Ur8OS6McaF05vfO5skcUGRMi5zLG+Bj6zvp1v PTlnS9QwZmQya6hdhXOjcNHlv3n2kcZYdlLPupkDeyHS1nWauQqwVXVl5O5Jw9hBcM4B 9ZlOcp4DNEMjGE52IVlByTW9IQ+AK5uJtrGxCBuNn6HcOZfVviAlg4TqZS7gtBZmC0J6 kd9H7g+DD/Uo7j8JCam08RM2SXceBfvi1BtmsoqfklCYLDt9rRlDPhABJ5bwJPZxY7wY gKf8yg+d8pH/P40bmq2fV5SggdAxG7K3i1EMIf0xyjXf28Ve3gxXrfrZXqpMRm+WXjF1 0cWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d2D3szGCb9Vg2ywxzAo8nNWdIMuiqqy33S8+OxWxWj8=; b=TT0IoZhujU9lRKmhA7JbhrVNpjrao6Wm1fV/QBQzuKeEseyjx4tF9RlbmeL2qyTaVt o2q1D5b8uwzkr9OLvDlOoVPRPwxGPfAt7Q6hSVDDV3NK5gNYk3k537Zkjan/O76beqss r5uGMTknccQMPqLriBLO5oo6cSghRNV1oM0latNzZ7y07m+5YFYxcw6COgA1k/rQE7eR v4AqfR9zqTJCjHw3O2z9xtu6ys1Bk3eAl1QS1wG45jXCcEnzxwhde6IEoehhdYx6jAm1 iW76/dOJzWtqP/lIqnx4psQiBJDM1L1urWyG01rGCqMfR/FYR9xwJI15Wi39rXXcHNlk DFwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LCqSz2Y5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a170903110600b0017f7faef235si11650602plh.148.2022.12.12.15.23.22; Mon, 12 Dec 2022 15:23:35 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=LCqSz2Y5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233827AbiLLXTU (ORCPT + 99 others); Mon, 12 Dec 2022 18:19:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbiLLXTQ (ORCPT ); Mon, 12 Dec 2022 18:19:16 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EC471C136 for ; Mon, 12 Dec 2022 15:19:14 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id y16so13934589wrm.2 for ; Mon, 12 Dec 2022 15:19:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d2D3szGCb9Vg2ywxzAo8nNWdIMuiqqy33S8+OxWxWj8=; b=LCqSz2Y5qcjBfH7iD0GZiRb9FoHwH7kdToub9Er9PErtfhHz6XBINd7RRN1Iye6Yzb gYrqyS9JQwmC4uivOMIquAnjKxFP26ILfZP7sJSnTHkSpEcAhfnjQvBAL6p3l7eN6z/y PAPzYMGKDYsi+hb/RCRjYpk4anTFNvIjCwbxDIUQ3+K6RwjZaQa+S3uQYwnTnih7YbMj npd9wlmd4S7hXuLiGNTwtfZAARoKCTywEXTWYIGSudDWzDInhkhvr2NtyNuYGUTQprYl vbtqhPxPtBKjVeg+JTjgBBDur2iT2UtNf6FktLNQmWT/LjuON3ZVIG4/1UhZg/40GJSu n1PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d2D3szGCb9Vg2ywxzAo8nNWdIMuiqqy33S8+OxWxWj8=; b=hiX/7Kvub31PPT9YGOqNNVdrrn2encPJw0eq+16kVmA3hYlD2+37hrUt85njwShcUl F6Me6yrrLeqLWSwxqfMnY9ZXCpmv1YPHL4zmtCe/G3VnYoTcNZ50b9cGpph0E60jFM/7 ZCs+nZvjXC9FpsteStqEd6JO1WvHKuWAs6QUOb3F81nrrh55IpmiGZz2c+1312wqXNdk FzKpVvFGkhMkVhsA/LOPZEX/yqis+xnw4PrV9HGtzJWJIq1h0a8MDMV4qtsp0wvvLKpU pyEs/uIGZT6Pj4V3xjXyuNiATcK4nayhE0cSUIjLYKT7NGPqB/Fwq5M5pDjXPdbRG7LP iKXA== X-Gm-Message-State: ANoB5pmGYcYutN8kTusr/6njpZFdMYnaDVNtatXqPvkX8QEnfZrxWVPA /R5QhwXI65ujmKdR4llLY6M= X-Received: by 2002:a05:6000:50f:b0:236:c62f:eb70 with SMTP id a15-20020a056000050f00b00236c62feb70mr11424280wrf.13.1670887152833; Mon, 12 Dec 2022 15:19:12 -0800 (PST) Received: from localhost.localdomain (host-79-41-27-125.retail.telecomitalia.it. [79.41.27.125]) by smtp.gmail.com with ESMTPSA id v3-20020a5d6103000000b002423edd7e50sm9964304wrt.32.2022.12.12.15.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 15:19:11 -0800 (PST) From: "Fabio M. De Francesco" To: Evgeniy Dushistov , Al Viro , Ira Weiny , linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" Subject: [PATCH v2 0/3] fs/ufs: replace kmap() with kmap_local_page Date: Tue, 13 Dec 2022 00:19:03 +0100 Message-Id: <20221212231906.19424-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752052443036376997?= X-GMAIL-MSGID: =?utf-8?q?1752052443036376997?= kmap() is being deprecated in favor of kmap_local_page(). There are two main problems with kmap(): (1) It comes with an overhead as the 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). It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. Since its use in fs/ufs is safe everywhere, it should be preferred. Therefore, replace kmap() with kmap_local_page() in fs/ufs. kunmap_local() requires the mapping address, so return that address from ufs_get_page() to be used in ufs_put_page(). This series could have not been ever made because nothing prevented the previous patch from working properly but Al Viro made a long series of very appreciated comments about how many unnecessary and redundant lines of code I could have removed. He could see things I was entirely unable to notice. Furthermore, he also provided solutions and details about how I could decompose a single patch into a small series of three independent units.[1][2][3] I want to thank him so much for the patience, kindness and the time he decided to spend to provide those analysis and write three messages full of interesting insights.[1][2][3] Changes from v1 1/3: No changes. 2/3: Restore the return of "err" that was mistakenly deleted together with the removal of the "out" label in ufs_add_link(). Thanks to Al Viro.[4] Return the address of the kmap()'ed page instead of a pointer to a pointer to the mapped page; a page_address() had been overlooked in ufs_get_page(). Thanks to Al Viro.[5] 3/3: Return the kernel virtual address got from the call to kmap_local_page() after conversion from kmap(). Again thanks to Al Viro.[6] [1] https://lore.kernel.org/lkml/Y4E++JERgUMoqfjG@ZenIV/ [2] https://lore.kernel.org/lkml/Y4FG0O7VWTTng5yh@ZenIV/ [3] https://lore.kernel.org/lkml/Y4ONIFJatIGsVNpf@ZenIV/ [4] https://lore.kernel.org/lkml/Y5Zc0qZ3+zsI74OZ@ZenIV/ [5] https://lore.kernel.org/lkml/Y5ZZy23FFAnQDR3C@ZenIV/ [6] https://lore.kernel.org/lkml/Y5ZcMPzPG9h6C9eh@ZenIV/ The cover letter of the v1 is at https://lore.kernel.org/lkml/20221211213111.30085-1-fmdefrancesco@gmail.com/ Fabio M. De Francesco (3): fs/ufs: Use the offset_in_page() helper fs/ufs: Change the signature of ufs_get_page() fs/ufs: Replace kmap() with kmap_local_page() fs/ufs/dir.c | 138 +++++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 66 deletions(-)