From patchwork Thu Jun 8 14:25:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumitra Sharma X-Patchwork-Id: 13272433 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE061C7EE23 for ; Thu, 8 Jun 2023 14:26:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C0A56B0071; Thu, 8 Jun 2023 10:26:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46EA26B0074; Thu, 8 Jun 2023 10:26:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 338608E0001; Thu, 8 Jun 2023 10:26:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 20B5F6B0071 for ; Thu, 8 Jun 2023 10:26:05 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C6CF5120290 for ; Thu, 8 Jun 2023 14:26:04 +0000 (UTC) X-FDA: 80879805048.07.C396924 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf21.hostedemail.com (Postfix) with ESMTP id 026451C001A for ; Thu, 8 Jun 2023 14:26:01 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=H7UvU4+C; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of sumitraartsy@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=sumitraartsy@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686234362; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=OnoedkoiLsL0tLJYDXF1NYn5Qb4R2gxxmXGm3HjM2kw=; b=f7edh8Sqr1GL9bKGP91BXRE4g8zfitDhxCI5ZjtubymaXhmRZ6Hv/VThdAkiozsV9EsU9Z BM9HisNalA2GaQ9KLKvCLx6I8u+TRabCu8L3/lNRvicxRHFx/7YRH4/A/pyjqG3g8FviDH uGneun/CA9X/idhuNU73CFjzydL9uWw= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=H7UvU4+C; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of sumitraartsy@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=sumitraartsy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686234362; a=rsa-sha256; cv=none; b=KtlQ4gBVtcij4M/RWFp2XyVUSsyDWtmEMHxSYSb+ZUms28HUf2NHRzaH4Qdi/Trc9ANqOK ju585Znc4ca0PvA7YRjt3aOC4cNZx6c4njndmOQ9LeGB4rF+RSp0Rz9Fnr5jNcyfTBmC45 Mu+fBNUOWtwGbMbsOftghzqT1x7cQW8= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1b011cffe7fso3276095ad.1 for ; Thu, 08 Jun 2023 07:26:01 -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=XNNECjGXxGw4r1urO5bFq1exrncxQE7SGqRRaFvwxAskzAMGp3pPaZXc8Yr8fV03c5 3aPfMdAK504z/fmgKDqsY8p15Qu9kEtHkuizZpiX3ER4QEieXV9hOBGbU3WXtI+xzefE ntNYi1wzkBJpperC8iYdrY77Vj1vz96JPkSVajBBvssosPhELwEo9WoLgiM7i8FbmxmF vQDEb/6QYGaOmmf20YDT4/x36w8YYCrGcaQv3enJWt1gJU5mZVtsRsjgyI5UPi352Buf FzYbFiZWIqeZncIUcKDzDa/s5JuyvJE1z6rhJI0J8DPjoXkFOHgr1ZysH9caJU9CMxGe uGsQ== X-Gm-Message-State: AC+VfDzRIRoF30WlEwDWDSINDZ/21hOYeeIRncCuLuJDpBCEpwZYL1yh REngAmny63AABJajTz/rics= X-Google-Smtp-Source: ACHHUZ6MOG1Hd2uceavhD8Eb8zbsWGFQuQO+S1FpmJYxHNmRX/oBQu53oSWEWJIECUiRyik1J3RvCQ== 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?q?J=E9r=F4me?= 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-Disposition: inline X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 026451C001A X-Stat-Signature: g1gh57wjibz78bkrteooamppbz9dz6ig X-Rspam-User: X-HE-Tag: 1686234361-883034 X-HE-Meta: U2FsdGVkX1/J391ash1xMU9ba3Ob4j3LciVB7IdlEj37dmsh4QOgu7ot7ptjug1PmXVq1wBg+njEMaBb4l4yL7i7CvY94CluqYTB8/6fSKILTuDGymJZ8zL6d0pU/wZnTQoJ6ghl1nrzlt68zywsVR7JM2Oyyg2My9plVrPErV8UvTsVeSiMq0IljENhNxuc2p40hP1n1KCha7Lcvgmn8pQ3kRZSZQfzyIb63u8J3f9xepifSCa/4ra1zX3yZdJ3lABmrwS2pjvIKTatw3aM+OOvm5Y4/rB7sYhBJBR6M0i6mbmMFOH6VWYCsu05imv7udIpCNeA+id2BZLWw4BwT7SxY7gL97fpAmOpHJqKxlHwE8CAFu4Tj8vCgSz7jAJnojrNiclEJ8HV87o/gIvFD6M5OiYhBzRgVlZd7/8dQ8Xjbu2JJDW8Yovzl9GL79nxrft88gveJixSX6X6ghD1lwR0WicrGI5vUNKsMRI2ual2CDIHjvk1dFdR9RfayyqCWm1gfmmyW/U/q4uPizJBz4rWDtnorwf8rlhOJ+qyrN2l7mF85W/GoFLSRN8OxgA0LHYxv9kGbOIxkvu6fROQmdarEaaAna+yCxlVlvXRitghX9lOEPVQMqvRZfwasYi10k+Nw7WaE9AY8mHrz9i1chTCpVu4gvg7bA76ZgZk+w09ZWed3/KoGyE4g1P5YgNmEQURF1727crOB7AOyRc4C/eRhz6EALN0yK0G8jCIowbSmrnkdU+IlHFtKbegRrlJWkeyi0XXgsR4YOxAK7atOqSaSxC2tFC8CChO2n7qslcTWzPnayBGEeoptn7gjbREc4/yPH70rSGm722+80frsoO0RZPsdc5gFmJob7/6tIm9OmwhRAao2eJHAwrRj7D/iLxnVZWLtvi2KXamImP9nS86ghi/k2l0egvmFsriGUMYxrdygds348K1chcR3973RM/N+tQS0kElX3pUykh cUyILWkB 64Fpi2vW9nJYfr4dFNRrucK7p8k809pnGS45PRatqEgTboSr7u5strR2XYuCvih1Y349IntMFykQgrgYUY2hC42236vk1nIwzKclmIaFdiu9nSrVm7cqU0l1De5fJ573PJp+N82RSVwehpXQEfMBazf5ynm8LOi/L8n0qNe7ViHQYJ1v/vFOysT46eJVoKS9lAuzVT4wC7RCfEGDH5mzQsFxGlxwy6cwJ0babFgvKHBHpU0TCHskfzxT50l+STi+1s3E8UVZZb9ZuLxgTSjm32b0QEqtn/SghqYvwqYVFgM8RrxP26qDGxhILjDo8/iyALs00rniB7DOiSWgqHcCwkhsnZSxNTuT5NUTarmDSc66YUe3m18nJvAt3h6tb2lMqfs94QhZlUBby/+jlAC82Tu33Tjnz6eLdEo8w0Pm0aZwM0ixcnChQoM+303EqaYF07aLjkV/vCvPjUhbStLi3Ul+dZg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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++;