From patchwork Thu Oct 10 17:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pintu Kumar X-Patchwork-Id: 13830600 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 C7DFECFC5E9 for ; Thu, 10 Oct 2024 17:52:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 235BC6B0082; Thu, 10 Oct 2024 13:52:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E5EA6B0083; Thu, 10 Oct 2024 13:52:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 085B46B0085; Thu, 10 Oct 2024 13:52:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D00DA6B0082 for ; Thu, 10 Oct 2024 13:52:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 30281A8D26 for ; Thu, 10 Oct 2024 17:52:18 +0000 (UTC) X-FDA: 82658437050.29.B81CAA8 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf18.hostedemail.com (Postfix) with ESMTP id E94F21C0014 for ; Thu, 10 Oct 2024 17:52:22 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="jM Bof34"; spf=pass (imf18.hostedemail.com: domain of quic_pintu@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_pintu@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728582560; 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=oNl8qbJwfIXDG/UAwjT6ZFo0a8CuYyPXXz44Avl05qc=; b=i1LKDost4oEPvk5puKK42T6qkmUABUeBGIgs5FzB4M+nr4l4E3d+6UOv/BOljoF9jMRhXw 5FQhATEQFzalsFeMXCK2GjVrChG95cjJ9plWdvDaPdytZef/MdUOJ8SPj2V2/oMJiyygK5 CgOj+mFL2bUoVv0b+gI4fJkeRO2mLvM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="jM Bof34"; spf=pass (imf18.hostedemail.com: domain of quic_pintu@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_pintu@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728582560; a=rsa-sha256; cv=none; b=X4pOUqVoOgxsqsYOPd0S3Zhm9sbWoGaFkkJ/DgI86OCWmKkgbryP/4f30a1bMx1jPd5Ij8 ONlgY7BkXe6TJaNqI03n3MHWTECt3VcST1UbSnHBAaSuFt/ELOm+sA8UJkcb3if26cKyy9 XO0hn5oeYmCAENrIu/MXfPO+ozhZzs4= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49AD8kOC027035; Thu, 10 Oct 2024 17:52:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-type:date:from:message-id:mime-version:subject:to; s= qcppdkim1; bh=oNl8qbJwfIXDG/UAwjT6ZFo0a8CuYyPXXz44Avl05qc=; b=jM Bof341BFv4s5/sMJr0NfS9JQv/gHer+u90f8QNg4JVFo/cge/lvIvcgaWzTaNVxs uPrc2evx8QN8p2t1r05luUrt2Fu2ikLWqTW9oKKIIVYtv1WL4wLagsdzHyaiTpNM si5q1IxkDOxQE9SbfGh8hKaWsentIVfbsvRjf8xNsieK2WA6HiV1FCNXArQdaju1 qrlqeor9Iu7cu5Bpji1sb3NwUl58fuKPSI9hCTpK5vTVcrmS2gArFLO8ieec7WYy Xgub/n6MGl6RwvktekzxHVHxHi9QZNVDagGhkOXnOyyPRH2rOglwO+l9l1TKBGvh j0xSRwC3yCCKJN8xqrEg== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 426fj6rqyc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Oct 2024 17:52:12 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 49AHqBcx011580 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Oct 2024 17:52:11 GMT Received: from hu-pintu-blr.qualcomm.com (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Thu, 10 Oct 2024 10:52:07 -0700 From: Pintu Kumar To: , , , , , CC: , , , Pintu Kumar Subject: [PATCH] mm/zsmalloc: Use memcpy_from/to_page whereever possible Date: Thu, 10 Oct 2024 23:21:43 +0530 Message-ID: <20241010175143.27262-1-quic_pintu@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: fqU7cb6IRHNjToMAf-LH-u0MmQNgoe0x X-Proofpoint-ORIG-GUID: fqU7cb6IRHNjToMAf-LH-u0MmQNgoe0x X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=796 lowpriorityscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 clxscore=1011 mlxscore=0 impostorscore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410100118 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E94F21C0014 X-Stat-Signature: ptk6h1twjtufbomjzgtkmuogs41tczxt X-Rspam-User: X-HE-Tag: 1728582742-24762 X-HE-Meta: U2FsdGVkX18hKqgiCXuFDd+1yKOxzLbJyPPswvs9BXkYzzxoSKFBwtnjUy7XjOqkGNf0Qz8W+mV/5fcznj49Pr+PiHmoSla63ggA0wKcBZS6oCddairV6h72gHQBup00WhKknLCykSxsIJ/fuNvmpy3w/WDhqOKxcQYdPrzwcGI5KxSwlHOjDGFrxNWbuCV8mQ1PUXC/q9XrFFqlmeCxbBupAHP5kMZdMN0ZaUXw+1rV/I0dqeQNUMNS6pferqFvSYfAwvP2amuxe3xudGOV0CRBrxcD7JGQ8UheumB0SaPfPUQAca5m538FoNeU8LHsSt5JSwLy3dntIh6DXNIRook7xCxXsRVoLdSC034vsQa0eUARzii6noeinub6OiLPOwI2T1yahlDqP/bZXFxqeSZ/55fMHpb6ZDSARBPpPgYDwZLkVxU0+YSFdKlw41tSzzNqzY72qBM4anHbHLO3j+mbhRLKE0ZhKcQUdySKJYJLVQW5GCZ6z07DWscU9jFyH4eD6pxBSsPWLtK/o2cq7FQmP9SnOJVhMDS6+QmTynpljIBx+4qK/+7okEDx2XKW3a6TnVj9C9CLFyyaBoU9W1RI9xboTTi6GG7ptFVyEK3tiVQLkjfukoMcFqka1CWPP4CAe/La3SEmJY9xc463QYKCWOahMx0HsIL/MYECfOrQM19+CRD92otLmgvZcxc8iyCW3p0PoGqGDMjarhjSTh/J24oQJkpNvdFhPdqXMp7gJPMEIwGD3abxeaoBMA3ReWVoFEtsOr1XvISbt/NAB/39UtDBUKLtZMVo6mThzVRhIwoNV+Nc2Ty7qEGnbP8B+gD9A+oPE7LWJFkWHOHUDaZ+1+KdJgncyRm86bW/T3OVoHu/KanJiLQ8tPJzdSJt/MdJprzDxkwbzvDsXbPqF7LfVEmYqsh7bKsJ7ARdRdptzVvowmlO6XXTYRvJemD2o2ICaegUTEQ+KmNPM6z /Lk44yTv 0nrTbLowEqFV8oaTMK7SuWv5nnRhgstVuI88aGsDfB9A5QsqKolHbzeWC9oUhbGmIYeSBkd6tzSWuxwEmsntkdpZn0g5733WhpqvAxjPyBgxgdVG05fvhAd27SEoMXGJLxQ/5ipvN38wGS7/4inmq1XpNeI4de+YvbnRUtZxYkWkRu8aNewBmenzGGUPtBFn/VoIv369Vsp8FrJ1qNIXvLIU8rMwrASDoOQxGoIxlKXtrzfuWYQBSmV6qOAxpOSVA2q/bfZ00xW7FLupuaP48JyBqX+oHJDgJUleEb+JXRMVHMLdOXoHu+HseXeVyrDf5oWhmnE01vxHtyYL2CWrpMvPQXIHH9Xzb50JD1MpKKIHzR/yKmki3T8bDySEVk48UjynYDzTvvhVH1gI9AkbfF+vuPlhH1t7Lfdi189Dg29JxJvSxaRB0QT6uDv4p1UAoCm0moFGq2mRxXeKdqiwClChBMIJbZ9G3zwuMw8lkDX1WpY/xgdempW1O5A== 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: List-Subscribe: List-Unsubscribe: As part of [1] we have replaced kmap/kunmap_atomic() with kmap_local_page()/kunmap_local(). But later it was found that some of the code could be replaced with already available apis in highmem.h, such as memcpy_from_page()/memcpy_to_page(). Also, update the comments with correct api naming. [1] https://lkml.kernel.org/r/20241001175358.12970-1-quic_pintu@quicinc.com Signed-off-by: Pintu Kumar Suggested-by: Matthew Wilcox Suggested-by: Sergey Senozhatsky --- mm/zsmalloc.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index d3ff10160a5f..64b66a4d3e6e 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -263,7 +263,7 @@ struct zspage { struct mapping_area { local_lock_t lock; char *vm_buf; /* copy buffer for objects that span pages */ - char *vm_addr; /* address of kmap_atomic()'ed pages */ + char *vm_addr; /* address of kmap_local_page()'ed pages */ enum zs_mapmode vm_mm; /* mapping mode */ }; @@ -1046,11 +1046,10 @@ static inline void __zs_cpu_down(struct mapping_area *area) static void *__zs_map_object(struct mapping_area *area, struct page *pages[2], int off, int size) { - int sizes[2]; - void *addr; + size_t sizes[2]; char *buf = area->vm_buf; - /* disable page faults to match kmap_atomic() return conditions */ + /* disable page faults to match kmap_local_page() return conditions */ pagefault_disable(); /* no read fastpath */ @@ -1061,12 +1060,8 @@ static void *__zs_map_object(struct mapping_area *area, sizes[1] = size - sizes[0]; /* copy object to per-cpu buffer */ - addr = kmap_local_page(pages[0]); - memcpy(buf, addr + off, sizes[0]); - kunmap_local(addr); - addr = kmap_local_page(pages[1]); - memcpy(buf + sizes[0], addr, sizes[1]); - kunmap_local(addr); + memcpy_from_page(buf, pages[0], off, sizes[0]); + memcpy_from_page(buf + sizes[0], pages[1], 0, sizes[1]); out: return area->vm_buf; } @@ -1074,8 +1069,7 @@ static void *__zs_map_object(struct mapping_area *area, static void __zs_unmap_object(struct mapping_area *area, struct page *pages[2], int off, int size) { - int sizes[2]; - void *addr; + size_t sizes[2]; char *buf; /* no write fastpath */ @@ -1091,15 +1085,11 @@ static void __zs_unmap_object(struct mapping_area *area, sizes[1] = size - sizes[0]; /* copy per-cpu buffer to object */ - addr = kmap_local_page(pages[0]); - memcpy(addr + off, buf, sizes[0]); - kunmap_local(addr); - addr = kmap_local_page(pages[1]); - memcpy(addr, buf + sizes[0], sizes[1]); - kunmap_local(addr); + memcpy_to_page(pages[0], off, buf, sizes[0]); + memcpy_to_page(pages[1], 0, buf + sizes[0], sizes[1]); out: - /* enable page faults to match kunmap_atomic() return conditions */ + /* enable page faults to match kunmap_local() return conditions */ pagefault_enable(); } @@ -1511,10 +1501,10 @@ static void zs_object_copy(struct size_class *class, unsigned long dst, d_size -= size; /* - * Calling kunmap_atomic(d_addr) is necessary. kunmap_atomic() - * calls must occurs in reverse order of calls to kmap_atomic(). - * So, to call kunmap_atomic(s_addr) we should first call - * kunmap_atomic(d_addr). For more details see + * Calling kunmap_local(d_addr) is necessary. kunmap_local() + * calls must occurs in reverse order of calls to kmap_local_page(). + * So, to call kunmap_local(s_addr) we should first call + * kunmap_local(d_addr). For more details see * Documentation/mm/highmem.rst. */ if (s_off >= PAGE_SIZE) {