From mboxrd@z Thu Jan 1 00:00:00 1970 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 D4A91C5B549 for ; Wed, 4 Jun 2025 03:44:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D20C6B03D4; Tue, 3 Jun 2025 23:44:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A9DE6B03D5; Tue, 3 Jun 2025 23:44:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C0B96B03D7; Tue, 3 Jun 2025 23:44:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 03EB96B03D4 for ; Tue, 3 Jun 2025 23:44:18 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2548A1A21BF for ; Wed, 4 Jun 2025 03:44:18 +0000 (UTC) X-FDA: 83516325396.13.30BF1D0 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf05.hostedemail.com (Postfix) with ESMTP id 77940100007 for ; Wed, 4 Jun 2025 03:44:16 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="cJi1R5/a"; spf=pass (imf05.hostedemail.com: domain of akpm@linux-foundation.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749008656; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xQhdM51MNTDazVWDaEPEFnLRU3eQkO+cPOQ/0n3Pq+w=; b=T0asww26hHJ7WCYsQtOSBRdGuf6ss6k9NNj5dMepKakFf73tBneZtMN/cW4LDWj0ts7F5R 99g3q/muK9JJbRjPQeuQ27rKGPXlwc41tajE0GnOwaSMYgrGKSvpml0r05hkA2INtl9AiV v/s5AFTkRfnO3RqZZGjQZ4XwqjL9To0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="cJi1R5/a"; spf=pass (imf05.hostedemail.com: domain of akpm@linux-foundation.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749008656; a=rsa-sha256; cv=none; b=KeOqFBDplE2KiQJE0ICwnoDJsk/9gF2AHbh7aqrayvNbCp8ZNe2/uAA+vH9Jh6wBmxPGt2 ZwzEB9HstDChEgkpTIYxqCgllJaIx5zpk1u/dgTEiPmnWFNz+O9sM7aDG5osSqG+SBjrL0 q99RV5nartMmqSnvOsKOdDGM5kKHfIY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 0BD354498F; Wed, 4 Jun 2025 03:44:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93F27C4CEE7; Wed, 4 Jun 2025 03:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1749008654; bh=BbZ9Q/nSUbSTJzvV4QKRTDB8TX7GZOe3HXqU9MTNjPk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cJi1R5/aIPln+w9qGzHl/DWn683Q6nxxiPcT/3R/fCYrk0kzHS7vHZnSaS2fAul42 rf4jBfuCevApSLpY+BJLYo1N6p6upSXY7zWSVPYYlBoMmxUywR+92+eVct5jlDPhxm 5QE2YUH/2Iw0a5E8vfFTTCMvkDVOulUDWx5KEex4= Date: Tue, 3 Jun 2025 20:44:14 -0700 From: Andrew Morton To: lizhe.67@bytedance.com Cc: david@redhat.com, jgg@ziepe.ca, jhubbard@nvidia.com, peterx@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dev.jain@arm.com, muchun.song@linux.dev Subject: Re: [PATCH v2] gup: optimize longterm pin_user_pages() for large folio Message-Id: <20250603204414.f2963e4a094e360cad7f966e@linux-foundation.org> In-Reply-To: <20250604031536.9053-1-lizhe.67@bytedance.com> References: <20250604031536.9053-1-lizhe.67@bytedance.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 77940100007 X-Rspamd-Server: rspam09 X-Stat-Signature: quafcafrr7s6mbf9m8hxaysmimno44gt X-HE-Tag: 1749008656-714036 X-HE-Meta: U2FsdGVkX1+L6SXJ0pM4zYuvOatqteOz4s2Uxm+tLSUSCx2SD7xfooy5tFK+AJfhW/Sw8Gve4G680j/5TTyfY0b9px83dLqdOvx732T2D8AzDQhpjeZKRMpHnomnMVbtC/h6GKxm8+umWgO1ZFNdcCJAA8JmVubIpVnx4Le3bmLsmdqvJQseF2PHD5JvaKyMxaKcXgXd2bNevoSxAWE0c4WcRd9OsmgV0rZ2FDls9+jyUMaII+xDPdYOZjym0wrt1z4rooWui5R5NkvYnROE79pDcqFrwUB/IBLksQkILNNwfvQI/vvO1JCRPOtTeoJaUMoGcBfwWJ/CDVQdlQV1hMOr6yLvu7zZ8Ao8PCyCowZ7B6coOGPXxQVkAQtnt0pqFNkXTiDs0HKaDm+VmEqmW0VMlfhs2jzJb0+MG5l/82RuARCSNsiMzsen3qpFnNtiusNY3Y3YcZ7If1EEhhYa5ZEohhsYZhrGYN9t1XRGPI2RL2bMqNpxtf2SHuQqH5Cut1b8vegMGHvLziEuO672jRvTwg2LhKlD8AvExeePtVQAJhlnU0keTx75cb0FTo5l6y1gD3YQ5VEmOI8hyn6/U8ma8Bms411d7G/HDceCwHHgdbOQTXufyy9UBJi/jZUi2hRmUyWELYz3SB7VcqOD9tvDtBEPHdc9QffxeZbG11VGsqmhglhUGv7f6iu6cpJuh5OdA0GEBDB4So3dSKiuK/PTYqBPhxxinzyj9GRRxQsbiw3Bo6Vj/Ihic2GR9ijdKIvxwgabjgVvgfVwf1WhB5g16PZ/oRwpYIWgzxmF2JBWLtC1P9xlOTWdcNsRFXh07WZihXyrB4KtMi9X51vNxcipoqSF9PBRVIdKmkx6b5XlozY+kbbTrmiacQxA0dB/wiDQZlwsoa7zSyGAcCr6BKmiQ68W8koYZd7CJqEXj3KiIrIbL52VCvZXWytbZsM1DCJHplvnZZ4vamvU3hr 0w1b/1oj CnVim 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: On Wed, 4 Jun 2025 11:15:36 +0800 lizhe.67@bytedance.com wrote: > From: Li Zhe > > In the current implementation of the longterm pin_user_pages() function, > we invoke the collect_longterm_unpinnable_folios() function. This function > iterates through the list to check whether each folio belongs to the > "longterm_unpinnabled" category. The folios in this list essentially > correspond to a contiguous region of user-space addresses, with each folio > representing a physical address in increments of PAGESIZE. If this > user-space address range is mapped with large folio, we can optimize the > performance of function pin_user_pages() by reducing the frequency of > memory accesses using READ_ONCE. This patch leverages this approach to > achieve performance improvements. > > The performance test results obtained through the gup_test tool from the > kernel source tree are as follows. We achieve an improvement of over 70% > for large folio with pagesize=2M. For normal page, we have only observed > a very slight degradation in performance. > > Without this patch: > > [root@localhost ~] ./gup_test -HL -m 8192 -n 512 > TAP version 13 > 1..1 > # PIN_LONGTERM_BENCHMARK: Time: get:13623 put:10799 us# > ok 1 ioctl status 0 > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 > [root@localhost ~]# ./gup_test -LT -m 8192 -n 512 > TAP version 13 > 1..1 > # PIN_LONGTERM_BENCHMARK: Time: get:129733 put:31753 us# > ok 1 ioctl status 0 > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 > > With this patch: > > [root@localhost ~] ./gup_test -HL -m 8192 -n 512 > TAP version 13 > 1..1 > # PIN_LONGTERM_BENCHMARK: Time: get:4075 put:10792 us# > ok 1 ioctl status 0 > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 > [root@localhost ~]# ./gup_test -LT -m 8192 -n 512 > TAP version 13 > 1..1 > # PIN_LONGTERM_BENCHMARK: Time: get:130727 put:31763 us# > ok 1 ioctl status 0 > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 I see no READ_ONCE()s in the patch and I had to go off and read the v1 review to discover that the READ_ONCE is invoked in page_folio()->_compound_head(). Please help us out by including such details in the changelogs. Is it credible that a humble READ_ONCE could yield a 3x improvement in one case? Why would this happen?