From patchwork Sun Feb 5 15:06:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Lee X-Patchwork-Id: 13129059 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 9B89EC636CC for ; Sun, 5 Feb 2023 15:06:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 078356B0072; Sun, 5 Feb 2023 10:06:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 001076B0073; Sun, 5 Feb 2023 10:06:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE3D66B0074; Sun, 5 Feb 2023 10:06:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C8CAB6B0072 for ; Sun, 5 Feb 2023 10:06:07 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8F49812026C for ; Sun, 5 Feb 2023 15:06:07 +0000 (UTC) X-FDA: 80433563574.04.9FFD1D8 Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) by imf12.hostedemail.com (Postfix) with ESMTP id D096040025 for ; Sun, 5 Feb 2023 15:06:05 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Q8paXj+i; spf=pass (imf12.hostedemail.com: domain of haolee.swjtu@gmail.com designates 209.85.166.176 as permitted sender) smtp.mailfrom=haolee.swjtu@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675609565; 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=Q29h+5pa7qc4gtg9UpocpWF+VOGMppgUk862ZKA99Fw=; b=J2cO8uE+CNfR47KG11/UEDIoz07rMV/WxzzWA90cM97HOUyupwIRIGwvHzXZJ9AsfWml/e lwwMP3o/kV4efLJBtxdeaWjcfkdfrOeomBPdKVpSrJ7JmHcdZhj/f/5fL8yIw87QakSzo9 cEjiZkfdJD1l4MVp/DSBZ3StbJyWykM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Q8paXj+i; spf=pass (imf12.hostedemail.com: domain of haolee.swjtu@gmail.com designates 209.85.166.176 as permitted sender) smtp.mailfrom=haolee.swjtu@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675609565; a=rsa-sha256; cv=none; b=YGCqe1kryqJdtb9tvfoSImDumPkMxmJvvLkrPUOvFKMnhr3EzQkNLtVfbWU2uVKZ7/o2PC EjALZM6mxOA+3y+qDZLkTBu3zWM/Dt7WMugTBgkO2fxkP5/EFON0/yGJuTJolFzwrlKjg/ d9HBHPp8oL30AKrMfVEb/XaSzG7fqPE= Received: by mail-il1-f176.google.com with SMTP id m15so3859178ilh.9 for ; Sun, 05 Feb 2023 07:06:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Q29h+5pa7qc4gtg9UpocpWF+VOGMppgUk862ZKA99Fw=; b=Q8paXj+i9kUYQZdNbgySo+rSKgTuuDvRZ8oyYlUNobDeshOPwsNcC5oAUQZENp0OpQ MBIbMLzR90RiEy4KLZKKy1+iwyAvlDxZcS+j8Q/NcBRGn2kgOSsb1ANJx2voSJhUYtR8 +tegpCiM7H0L3skPO6aXPD5vVeEsmVdm86GZLoVQKdORsEoS9gSqGqC2xwsfOjArlfXa G0WcXx6uKfoBRYdUao4ET39ZGdAZVYOkbcPJsbA7yKY6RxULXYSLBF+jKWl8vF0eKA1b emT9JJCyhU1KPehUT24mNPt4Hqxq9t9hr2Y9NqtcQFtBxjOEdjXAFQp1j68gHw1SEgeH 7g2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent: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=Q29h+5pa7qc4gtg9UpocpWF+VOGMppgUk862ZKA99Fw=; b=zQaz5k/TEivKfglHbW8tUPFUh1BXt2hmNU675vO2s//jASFQlDvt4/CHps9kAA3En9 Vlx39HhjoF472XpZIj32Ym8ZQ1sEfqI/Hz+Ko19rAuaZp+bdnblWWO1TSa42Co6Cd4PJ 9d/m+nNHk3+UdVOnNU3gP+NFKBLrP//3TYnMHB03cRd0XC0LDG58gSF4GnGaBWsKjQ57 MNYb9ujr2UqGGeb/M00OpiCwW8K5C2yEqoF1mIRvAu+yfn1Fj7PghgP73j0jpKU/a/aQ dKzp5QFhAr0FHHBualFWBc+ZLQ3/biCuUEgosJgeajhBCkPGQo6cxol/P6kpQAhNo0rW j33A== X-Gm-Message-State: AO0yUKVTkRMSXs7/OJffP1Q7hDqf/JOCVijb9wz7VLzuQAsazoHqOXD0 PFmhSXhbBEd3OqCZPjZ6vFc= X-Google-Smtp-Source: AK7set+uhZqKYqaiCDbU8803ot5KJZixWzHyUTIMAAk6k/pqJ9UEHUzBbVA8eXhD5fKlTpyscRUnMA== X-Received: by 2002:a92:7512:0:b0:313:bdde:613a with SMTP id q18-20020a927512000000b00313bdde613amr1009143ilc.28.1675609564999; Sun, 05 Feb 2023 07:06:04 -0800 (PST) Received: from haolee.io ([2600:3c04::f03c:91ff:fe02:b162]) by smtp.gmail.com with ESMTPSA id co12-20020a0566383e0c00b003b7d56593d6sm2666082jab.160.2023.02.05.07.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Feb 2023 07:06:04 -0800 (PST) Date: Sun, 5 Feb 2023 15:06:02 +0000 From: Hao Lee To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, haolee.swjtu@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH] mm: eliminate function call overhead during copy_page_range() Message-ID: <20230205150602.GA25866@haolee.io> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) X-Stat-Signature: 9rir7touqwzrjz56nn9a9qfg9n4t6z5h X-Rspam-User: X-Rspamd-Queue-Id: D096040025 X-Rspamd-Server: rspam06 X-HE-Tag: 1675609565-347216 X-HE-Meta: U2FsdGVkX1/tWhcA4DmiwPWhVWFaKIUs+WeQvqRvccufkSZLTYBO6hk3fVvX8Cl/jGcRZ0589CprWQFyiaNiDZ4KTr1tF4rnk3fcM6TCqeGgfYZuP0/liKpJlyteURsNsuDkI/0aEmebAB/RvxD/7OVSJKc8Mdq2NtpPi6KEjaF5YGyd1xTobqSyK+rR9sBjboGWFGdwX472PGH0LJovJ8V977d04txbefQ7BvjoLZPjn+EJ1eDe9/mR1fb1e0z9OOTvHADXe7/Ln/wXmqrf5+qbtISvYrcLZ13FaYvW8hWtRWK8qtRXIE91x/d9eJs+64a6EpYPN9vracEM4lU3QJkfr0Hg0EwOjLtwtWm7G5EmhPzHjszRUBnC47b39ymhs3GjT4nLd1434yB9y+bKjiAUBdIFEwbTbV+nsgTFr+4JLIktURNNugPJ6OGKeVizc+RfWssTjK0I6RuTxmVRi39Eua+AAD2KUpwmHfQ6XxkzXe1mJs9l5PtJMGPGelWjEgRHe1zQxqE/BttH+unUlW3Sht2TBev5M1DswsfC0nChzOQXQaO0Gm/00kl1H5xqGpx1z9MqIE/txGkKSG8JTLPoP02XtpzKUzZvzNar19Uw2cRo5FR4in7y02M6VwB2HRhIQItV3tSMQJq4h+srzpjS8Ug7Tg9e6C0X99l3hVBQJv9MWvXudRaBJ7L7pHwT3OHRT5QR7TmvK46bTytsMOUBHfcs3PmjLNOXItDAwj7pzRu6wF7Q+hXdFodLsVDVWnV9zelCLaEaqG8iqjmjya1x3j3SpTtdQUSp+43G7QbPGZQ5eHLmZUsBkXbYg4YPSn+STD8V7Hd2jpeFn8WZdWlryZ4juWqDFqPGLRTxmH+Q95EqOA0PzoVae6HI8oq/Z5CXJWXJkql0OrCqOP3oU8FjVQVUsq1yI9glPTzVRzzzvk2td4ckV13HOjSS+j1sKuO9+IUcZvEcyvqt8sJ bau3lkl4 PIvq7kx/vpAIkkQAn/V77ZyjBLS5vpUoSGi2Sv7mzY1dcEw/vkg3k9VGiTLW+hs9iehmDSRo6ZvImnAXqpMXX2nx8V97uNKCitx7m6VtoMjGsUv0bW067Pr1Ccsx61ScA7SEvFeM28tmbKsa6XmzOQUPAACqWF8MA+0lCbvF/ey/0PPsU51bzO1QScyYdlt23BDYqbmmQ1Z0U5aCUQ5PSK2HlCc3o+LKrctT/FThEZtdK2agqodgRzOZzroUaeNAYlrg3pULY13f9EVovTNUbK6Uq21Zc3X3Koyt9K4Ml8QzrBy5iEC67EkzRYOjP/alXSierdo79HTGTv3y3qgqGe6P27nK7DBHcPqItJyMnTbyWrQzHz8QQf0izDgfCNHdaX7vn3AIfa0/nV/DscqvuU+GLjn+9z8HyvTJrt4Jq7SsYGheaTvPmoXSJAGJazshKc7rC7wBPeCdPBQnY/C5sOVOiFNwSXHNBGtn52X3ylVFgsBO1tiiPkeJS2KDhbbZWi8kHvmtCVl4kLDDPUX9dSHz1mlt2gopxCdkq4XjjHxthtIMaUfxc/YzyIg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: vm_normal_page() is called so many times that its overhead is very high. After changing this call site to an inline function, copy_page_range() runs 3~5 times faster than before. Signed-off-by: Hao Lee --- mm/memory.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7a04a1130ec1..2084bb7aff85 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -562,7 +562,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr, * PFNMAP mappings in order to support COWable mappings. * */ -struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, +static inline struct page *__vm_normal_page(struct vm_area_struct *vma, unsigned long addr, pte_t pte) { unsigned long pfn = pte_pfn(pte); @@ -625,6 +625,12 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, return pfn_to_page(pfn); } +struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, + pte_t pte) +{ + return __vm_normal_page(vma, addr, pte); +} + struct folio *vm_normal_folio(struct vm_area_struct *vma, unsigned long addr, pte_t pte) { @@ -908,7 +914,7 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, struct page *page; struct folio *folio; - page = vm_normal_page(src_vma, addr, pte); + page = __vm_normal_page(src_vma, addr, pte); if (page) folio = page_folio(page); if (page && folio_test_anon(folio)) {