Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6529767rdb; Fri, 15 Dec 2023 00:44:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEN4YqRMyWZQZGrVrNOJOSK3ls5GF+QzGlkaVpb78KQ8e54PTsufoAMvhdN1XMqxLuvHfCP X-Received: by 2002:a05:620a:268f:b0:77d:992d:4147 with SMTP id c15-20020a05620a268f00b0077d992d4147mr13391811qkp.57.1702629875682; Fri, 15 Dec 2023 00:44:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702629875; cv=none; d=google.com; s=arc-20160816; b=C31XdScLeRcFohl+LepZnPEFkQp3g1q+grpqD/S+/m+M80KlZzJu9VwmAufLsRvpl+ Y++dym3AHfLRl671bqiwm1euQW+nQYVO4+y4rW96TpxT4HJVG785qQ/vUcZzweCJ9T9W wEf0o+49KcMqx5lXDCs1f5RQfEqSgL5KRH7UX/nhR8VY2jUhCSj/KoocjxPfinriX+kH 2e0TtrxE83Zxx++KLlXl+61TQsxJsjR0ar+MjvLh9YdehoK2i4qu23WD/IZfRpaITTN8 KmPRuTrKU4tNwzIxexlA4GRDftuoEYjJJ7NjNswadyJWpfwUI2EyfI+TYmBgM+wulWH1 PIEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=JfgwSx9MLlfnDdw7inRAgD1RuEgYGXNHCOCtslBaJpc=; fh=XH3pxpKr7AUB4GM0Y3GdAQEzWmNMu4SdIEH1hms+9D0=; b=FdI+vqCyWQBYdmoLvmtlcxKOPeHhfl3iP9H7P0vSp+EFz0/aIh4586pTtk7Q9Gb2Nr +x0MHCq6S20RXjLLhO4sl5rFDfcyTmqnEYaOp/ghm3KJ23i3TOMXwXapGj3BjfpWWaCA nsNL4wTX/ZarluHm26gRVjqFKny8GoG2KE8g9pFGGFv60hOMplKqYOWsESUzppkKq/jh MEFe2sASAlY2QahhQPoN/sw24gSCjv5/fPLSpZcX8gNBkgvB7Zu3S6dcnNviFuTvEnoO xYJDVO31Ql51T+NCGzoybeKF4szUJ/Xm9PAdpKh3+rDexFY5yJORZs9nbx2mmW4j13ki TjZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g8pPYagq; spf=pass (google.com: domain of linux-kernel+bounces-633-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-633-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x11-20020a05620a0b4b00b0077f381ec530si15913933qkg.776.2023.12.15.00.44.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 00:44:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-633-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g8pPYagq; spf=pass (google.com: domain of linux-kernel+bounces-633-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-633-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6EB5C1C22714 for ; Fri, 15 Dec 2023 08:44:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 307121548D; Fri, 15 Dec 2023 08:44:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="g8pPYagq" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25D77D27A for ; Fri, 15 Dec 2023 08:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702629866; x=1734165866; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=pN6Za6QS6gH0Sone+vJpcFhDUA34F+4C+dHQJlQSAlc=; b=g8pPYagqW54B+3rP7kbG30x2G57uGPTWvP0RzFRbhfynpsszj1+h/iOP HokDceLy04mFAzVFdrJ8qzp3T3evr7YoK4lKzGusm9LSby/itMMn4+iDy 7OA5VIuFnIl4NFjb4p7TigvqCqZZlHLSwopGz84QKeuMcBKHwqHt1Ebmi eJc/MplvZrzjg/0L+jm7oTGeclutFfT3itcPElAqDoo5RJp29PEhEYzXx /+r95NgN6GCn9Eg1BF5xiMizvLRQpuzFBRCqZJEUZ9npXtxSP7uSPE6RV WOAmr76L88arzBzqQPUEDu6NPLe0TZqwiNY8yi9s5xy0ffD0ePUv37enb w==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="426381356" X-IronPort-AV: E=Sophos;i="6.04,278,1695711600"; d="scan'208";a="426381356" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 00:44:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="808895806" X-IronPort-AV: E=Sophos;i="6.04,278,1695711600"; d="scan'208";a="808895806" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.25.64]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 00:44:22 -0800 From: "Fabio M. De Francesco" To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH] mm/memory: Replace kmap() with kmap_local_page() Date: Fri, 15 Dec 2023 09:43:40 +0100 Message-ID: <20231215084417.2002370-1-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kmap() has been deprecated in favor of kmap_local_page(). Therefore, replace kmap() with kmap_local_page() in mm/memory.c. 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. The tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. Obviously, thread locality implies that the kernel virtual addresses returned by kmap_local_page() are only valid in the context of the callers (i.e., they cannot be handed to other threads). The use of kmap_local_page() in mm/memory.c does not break the above-mentioned assumption, so it is allowed and preferred. Cc: Ira Weiny Signed-off-by: Fabio M. De Francesco --- mm/memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7d9f6b685032..88377a107fbe 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5852,7 +5852,7 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr, if (bytes > PAGE_SIZE-offset) bytes = PAGE_SIZE-offset; - maddr = kmap(page); + maddr = kmap_local_page(page); if (write) { copy_to_user_page(vma, page, addr, maddr + offset, buf, bytes); @@ -5861,8 +5861,7 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr, copy_from_user_page(vma, page, addr, buf, maddr + offset, bytes); } - kunmap(page); - put_page(page); + unmap_and_put_page(page, maddr); } len -= bytes; buf += bytes; -- 2.43.0