Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp771480rwd; Thu, 8 Jun 2023 07:33:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4imwSz4bO9MTcqDq5IYmWWCqXz//paKOeWFiw3WA7boTJj5MeqtZYGN7DEBx+J/FwIeg9Q X-Received: by 2002:a17:903:451:b0:1b3:33c2:f773 with SMTP id iw17-20020a170903045100b001b333c2f773mr1234722plb.49.1686234798894; Thu, 08 Jun 2023 07:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234798; cv=none; d=google.com; s=arc-20160816; b=mkiHr6KqTUlldxwtP5PVqXkHyKtyKo5iV6ddRP7tsyANOo+5F+nqIZOHoEhRD8yDSL 4Z+cO8IG2StV5za72oP9qhYKUpBZBi+r0WD8Ly/wHyf71FElAi2nBip/rKsihd4Q0nlN 4ebeTgmDu8EenFuJzpFR4ciQlGM5j2vPoydrQ1JQYY5wrYMjGoaHfRCpqFjIixY6R6WV uYeR7KcgE5S2CVtQQo4T7AEygJApq8+13oIwxxMs580l/swSqj3znFnFSsCEYvqybztR 9NSDbzcjXXJJZPwwJaD5csRf+LvLSxUY0i2+PSui2cMDwYJ8DM3NtRPzs4PCgM6ZEiAf WGZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=OnoedkoiLsL0tLJYDXF1NYn5Qb4R2gxxmXGm3HjM2kw=; b=UaAx7efdRFSYpl7qhUncCXM6JE0BvIdkYRYrJbJfCvzZcNgyBj3HBxo3ENuap8zdWl E9imI6LiPPwKidwh3dqgMi9a0Re5uq1ZAqdhnPVUy1c/gyFSFaUibvsNPr5y+GcgPJHj lYDiRiD6Q6/uKPPWdyd+Q+BMn0ThTHxN1CKOFfqfn8008v7isaUnDlxS4Ck8xlDp6P5A qjKAAPpxEnAjbQOjJuGOJ5W3tgrUU1mlk3dxNIPcljJzT5Fij96VmGyJkUegxlqaCSzf y3YyFbIupuj69YysJCrhC/AgR9ip/T558IZG2iakePUWok0ko/fJ2MxCDvFJVbp0AQfW O/pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=H7UvU4+C; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 24-20020a631258000000b0051f869d7089si1052489pgs.74.2023.06.08.07.33.02; Thu, 08 Jun 2023 07:33:18 -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=@gmail.com header.s=20221208 header.b=H7UvU4+C; 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 S236568AbjFHO0m (ORCPT + 99 others); Thu, 8 Jun 2023 10:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236781AbjFHO0i (ORCPT ); Thu, 8 Jun 2023 10:26:38 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEBED2D68 for ; Thu, 8 Jun 2023 07:26:15 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-65292f79456so394507b3a.2 for ; Thu, 08 Jun 2023 07:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686234361; x=1688826361; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=OnoedkoiLsL0tLJYDXF1NYn5Qb4R2gxxmXGm3HjM2kw=; b=H7UvU4+Cu5Ls9GovjGu5sw+DLDlo+SEQ7Pj9pFQUXI+arPhcc/rG6cgn/N04MyMs4g rNQDDrHeQEAEQhh46HR8VhzW5Rhnff1RzC+72uF/cLXyudXFzJb9cftciLyMcKrEdh0E 8SAUuyNHD7Jy/w/ZaSbSTczyJaut2ZvBHXUYyfNC75FKC5QUUBNZN14Gd3XVPiZJRq2A Jwi4iH766Mw4gDvXULcD2y+YEX28oVJ6pr9BmgruKyukSHrrYnC8Hm6EXnqX/Fz/D+iW WnNEEb+LCoRqSwTryWnImZe7fp8L7hUSqa0zOH2FBTCM7VItFk4oGlf78WRkHG150ztx pxVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686234361; x=1688826361; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OnoedkoiLsL0tLJYDXF1NYn5Qb4R2gxxmXGm3HjM2kw=; b=ZWnIO8JJ2/cDbNdUNFlF+Jau9hCUEKy+pJglVYT4si33XH6ZAx5xH1jI7Fy+3uDEXw AfLZEwcWk9U5KsIjiL67uqc9YoCOuhHLjgSQ9bCpllagHsI4YXDwHv7nH99AqDwJRAkE zN+FDN8dhpRbLmWYyCQMldkvu9Kt9FTLJUlJR0bWt5b1SHEfVUAg1yuv14iPxwsbbq8o DSQOUqG7tUB7Jj/zlC17ASzx1RMuUwRQoNeK5jHlvFw45YDyxre0AX2sfM8RFECqaLY6 8zqU0xbQKcQERAA/lDNwjm07Dm8OW2C4eIwzP3a0+v3jyxEHhg7m+FTM2ZNFF20T3fch EFng== X-Gm-Message-State: AC+VfDyIGOHpI1s/s/P3rOhD5LxWljp07NwFRzlj11KQGMbRhsvoH81n wmfz2vzq2ZtglHZgHsFS/VU= X-Received: by 2002:a17:902:da8c:b0:1b0:5ca0:41a8 with SMTP id j12-20020a170902da8c00b001b05ca041a8mr5134985plx.39.1686234360542; Thu, 08 Jun 2023 07:26:00 -0700 (PDT) Received: from sumitra.com ([117.255.153.95]) by smtp.gmail.com with ESMTPSA id x21-20020a17090300d500b001a221d14179sm1483052plc.302.2023.06.08.07.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:26:00 -0700 (PDT) Date: Thu, 8 Jun 2023 07:25:53 -0700 From: Sumitra Sharma To: =?iso-8859-1?B?Suly9G1l?= Glisse , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Deepak R Varma , "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH] staging: lib: Use memcpy_to/from_page() Message-ID: <20230608142553.GA341787@sumitra.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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,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 Deprecate kmap() in favor of kmap_local_page() due to high cost, restricted mapping space, the overhead of a global lock for synchronization, and making the process sleep in the absence of free slots. kmap_local_page() offers thread-local and CPU-local mappings, take pagefaults in a local kmap region and preserves preemption by saving the mappings of outgoing task and restoring those of the incoming one during a context switch. It is faster than kmap(), and in functions "dmirror_do_read" and "dmirror_do_write" the mappings are kept local to the thread. Therefore, replace kmap/mem*()/kunmap pattern with memcpy_to/from_page() and remove the unused variable "tmp". Signed-off-by: Sumitra Sharma --- Suggested-by: Fabio M. De Francesco lib/test_hmm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 67e6f83fe0f8..cc96dfa54122 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -368,16 +368,13 @@ static int dmirror_do_read(struct dmirror *dmirror, unsigned long start, for (pfn = start >> PAGE_SHIFT; pfn < (end >> PAGE_SHIFT); pfn++) { void *entry; struct page *page; - void *tmp; entry = xa_load(&dmirror->pt, pfn); page = xa_untag_pointer(entry); if (!page) return -ENOENT; - tmp = kmap(page); - memcpy(ptr, tmp, PAGE_SIZE); - kunmap(page); + memcpy_from_page((char *)ptr, page, 0, PAGE_SIZE); ptr += PAGE_SIZE; bounce->cpages++; @@ -437,16 +434,13 @@ static int dmirror_do_write(struct dmirror *dmirror, unsigned long start, for (pfn = start >> PAGE_SHIFT; pfn < (end >> PAGE_SHIFT); pfn++) { void *entry; struct page *page; - void *tmp; entry = xa_load(&dmirror->pt, pfn); page = xa_untag_pointer(entry); if (!page || xa_pointer_tag(entry) != DPT_XA_TAG_WRITE) return -ENOENT; - tmp = kmap(page); - memcpy(tmp, ptr, PAGE_SIZE); - kunmap(page); + memcpy_to_page(page, 0, (char *)ptr, PAGE_SIZE); ptr += PAGE_SIZE; bounce->cpages++; -- 2.25.1