From patchwork Sun Dec 11 21:31:08 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: 2864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1927909wrr; Sun, 11 Dec 2022 13:50:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf6RUllPhmUHwDHWzqOmFSJJcJGyUHlpLORJ9djcH/bahuNfq7cMHDCj7Y4tfF/MxlbC2vQc X-Received: by 2002:a17:902:8494:b0:186:5f5a:5842 with SMTP id c20-20020a170902849400b001865f5a5842mr15884563plo.11.1670795447253; Sun, 11 Dec 2022 13:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670795447; cv=none; d=google.com; s=arc-20160816; b=l7MxZ3HO0pecrL0IWC0h1Knc+PrZ6Hs2eJVcvlCgo+2XJpGjSFvvo2IZjZr7+lm9QH GXQo9RR6fqjcnOFGt6OsByLqufgIaBRQX8EejmrdjrkEWxI8uCyP4/g2MG31AQVzEOvk sa1wyJvz1rDWevriivSwzb4uTmb9aIyk/OaI870KrlQVnRHwFCJXcbE4HPLMUKIwfMF2 7n0PEurhhqOYxj2OJCj0sPYDkpI9tEVagPFNI3Eqab0i4q14d1CL3UQRvqgfuN0hNJ33 czTqBskmbq9NN2SMzySVNMDiATX3/E3rFtVid88ijzjNdlXbHqSNfIYeqiJNNpBYcF7R WERw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=5FG9XFAhH1aAKNSCD7KXenAoQ7QCTJVpi7jZDxdnhI0=; b=z6LNAOrOoQKMDAdW/tRBEpuKApS5bfHdIcbmrkMy+FPi3cAEEq6hzxD7psxiWmI+CR ug0xpJZ2DxIEyaYoQUd/34ijZTc8bco2mlE7dDcMbtl3lFrB54VPMW8zP1ccYYxQyvoI Yyt6Pr+TCIMqIW1cuhzSS++8GsKCKZu17VlOC6HhfwrYLsoHC1EZ+X/VFk+OrfXy3Hqi nUqMfDBz7OC+OYkpDD6Harg0yOY74818w0YS+AzUzqLKkXI3QvsAors7tpkZkP7fEKJz 46LMgZekEaEbJTmox3Y0sVCfBSko5fCn0mBxMVY1AVShDEBO8trealU5dOcCl/+INRXn 2IfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OC9FRQ5b; 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 h6-20020a170902f54600b00189b421fff1si8305517plf.432.2022.12.11.13.50.17; Sun, 11 Dec 2022 13:50:47 -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=OC9FRQ5b; 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 S230328AbiLKVb2 (ORCPT + 99 others); Sun, 11 Dec 2022 16:31:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbiLKVbW (ORCPT ); Sun, 11 Dec 2022 16:31:22 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC178BC99; Sun, 11 Dec 2022 13:31:19 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so3671253wma.1; Sun, 11 Dec 2022 13:31:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5FG9XFAhH1aAKNSCD7KXenAoQ7QCTJVpi7jZDxdnhI0=; b=OC9FRQ5bdKmv3sGgoo1ZJg56K0vI4WY55htBKLsFGzk9o84vSEI5/l7nQi1LQ8Y9DI h9uxsFWD7cqUr7Mq/8K4p+o4GN6cu7f5w2Uztm1feVVXrXD7ikwr/+KyoFvWfWaq+IPm VVy4rkih1SoVMvYIwF/E/ID551LMhkPf2CutaMfzrefL+sGeuU24EB2sgCU2vLzAWCyQ 0rEHv+/E8UFMF1kbbRg976lsWYQ0fpLkADUr7jAbaZ5Nsg0Lbg4jgTnwomURdModQfpN oJphnSwkiX7U3EqmpQX89N65d0HJmWfU+BnjS7+yDopegOF3zkclfr+jxbYLVni8NGk3 CFBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5FG9XFAhH1aAKNSCD7KXenAoQ7QCTJVpi7jZDxdnhI0=; b=7oxMFvtpLa1hZ6PrQ0XnLzhwnBv0Cyg+z75XJH0+ZkXduSN1bzFzAiTePxr0ruP6m3 4MWSMZIYsQljpV90IfSi/sflzDTr8e96xJRJmuor74QMsO6EO4qEh8yqhCpbJWr8UHhq cWhdqiwvSoVTE9ALeBljd1VhOKLbazGBl0+sJesVw3N57ABJJn2jFY+13tgn1O4W0Z+/ 42CFKvX9TUak+rDjCbUU4QhrEKosCMgt9ZAquVH63nZJxOaKRqH1iWRATPkWuMuL7mOZ 5xCA/Ap/V1VG015bqMcYCqWGUHH8UJnI00pwAbXfuSEoRQzqC5DAJsmUw2dh1HZlzB9h k6xw== X-Gm-Message-State: ANoB5pl/1eoRF98Fvkl7jiqJO2ulE7QNpI6/EhT1OTATV1V7VnFyady3 /FKTi7fg+jmARyp6vOomgIaFd9GkNR0= X-Received: by 2002:a05:600c:991:b0:3cf:aa48:23d4 with SMTP id w17-20020a05600c099100b003cfaa4823d4mr10965839wmp.25.1670794278133; Sun, 11 Dec 2022 13:31:18 -0800 (PST) Received: from localhost.localdomain (host-95-247-100-134.retail.telecomitalia.it. [95.247.100.134]) by smtp.gmail.com with ESMTPSA id m127-20020a1c2685000000b003d1d5a83b2esm6866350wmm.35.2022.12.11.13.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Dec 2022 13:31:17 -0800 (PST) From: "Fabio M. De Francesco" To: Evgeniy Dushistov , Al Viro , Ira Weiny , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "Fabio M. De Francesco" , "Fabio M . De Francesco" Subject: [PATCH 0/3] fs/ufs: replace kmap() with kmap_local_page() Date: Sun, 11 Dec 2022 22:31:08 +0100 Message-Id: <20221211213111.30085-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.38.1 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?1751956006936250478?= X-GMAIL-MSGID: =?utf-8?q?1751956006936250478?= 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. I hope to have not misunderstood too many things, however I'm pretty sure that I made many mistakes due to my scarce knowledge of filesystem and, above all, lack of experience :-) I decided to get rid of the previous numbers and start from scratch (i.e., version 1) because this series has too little to share with the design of the previous patch.[4] [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/20221016163855.8173-1-fmdefrancesco@gmail.com/ Cc: Ira Weiny Suggested-by: Al Viro Signed-off-by: Fabio M. De Francesco 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 | 140 +++++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 67 deletions(-)