From patchwork Tue May 30 08:07:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13259403 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 71238C77B7A for ; Tue, 30 May 2023 08:06:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16572900005; Tue, 30 May 2023 04:06:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 11533900002; Tue, 30 May 2023 04:06:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1F00900005; Tue, 30 May 2023 04:06:22 -0400 (EDT) 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 E2EF8900002 for ; Tue, 30 May 2023 04:06:22 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B5E8E80163 for ; Tue, 30 May 2023 08:06:22 +0000 (UTC) X-FDA: 80846189004.15.FFB290D Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf05.hostedemail.com (Postfix) with ESMTP id 84471100013 for ; Tue, 30 May 2023 08:06:20 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="bwb4dS4/"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf05.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685433980; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QcmAtoapKK7yru7JzizE776svgCIjig/xw1n/cwyuXY=; b=IKzcibZBaiMeCIUc2v66X4d5HwvMHpc5zltIDHmKcfJtw5/5SKCklQWjcNd2Xr4VQ6P3Hr xbFMqsV0JKgrH3A3DSNI61X0dOWyP3iaSktUS6oVA4NGk/CuANwsTZwCtpbVcTkS1iMPAF jBImpW5+tp/JM1peFk0VYT/TSUuEr7I= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="bwb4dS4/"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf05.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685433980; a=rsa-sha256; cv=none; b=UYILgrG01t69XlHfpkPEJ5Omxsj+QK4S9M95GowJUn8NNkKrxWSR96pBXmOK5uTMkA8jhw V38aIrBRtQ2DN+GFWtdSZh1cf6mtyWVByYQF0I6iPmxLbwo6pW30zX65SENm/4p10RqM1c lKB5nLxb6NbvvxcoM/FIx7unobEc4Kk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685433980; x=1716969980; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OGmxL+UqnOoB6DUSYUyFxvx/lt+FRL5wf9KNfFiPBCY=; b=bwb4dS4/uTKMTgr9eZGPhOIzcryDKq1gPTnBY6GIqimLY+9JmgzXLjbN AkMxH5Q1s+IWhtkJE+m74TNuwO+OOlK2UUEshsw4ItbtVZgPHnrDTiXJv HADPC5vilTclmRuP40zua3fMWM+Y3H6mHHu+GisniEMBDNE5lP+d3ceDl cVsDUOOFS3KngPNzC2M8NslPzIWlfwYakqbr3gdnULzy8bIIrOe6MEzsj wrMoOnRf3Faeb/WV9j0YzYq3drfOjm8/Y4jDbt5VpodYmJZMoujIn8HcI B5DbYUGvwqUx/WcSSa1Kz1QMo3yJEU9zN/z/hIKthjuCiCKrgi/V4ANB/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="418332096" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="418332096" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2023 01:06:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="739426336" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="739426336" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga001.jf.intel.com with ESMTP; 30 May 2023 01:06:16 -0700 From: Yin Fengwei To: willy@infradead.org, ryan.roberts@arm.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: fengwei.yin@intel.com Subject: [PATCH 1/4] filemap: avoid interfere with xas.xa_index Date: Tue, 30 May 2023 16:07:28 +0800 Message-Id: <20230530080731.1462122-2-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230530080731.1462122-1-fengwei.yin@intel.com> References: <20230530080731.1462122-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 84471100013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: yrxfi8xubasmhsg3swarnw54eghoijox X-HE-Tag: 1685433980-311221 X-HE-Meta: U2FsdGVkX1+PgVAItPukPc/VRdHGD3CPJhvh4rPpR7+IDYW/aKooB3GnWeAC9F7lXJ8Aa79vpsF7HHGP2t1+gUs3LOZ7NRcfS8K87xulXPV8aJ+LwxqYm6xN87TVG2nEeL46Pw5KhJEmrLWM7lK+XZaszHOIjoS0rNz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6NjIxthyobSIrclikG9ymcVGqeIMQOjg4GXyC6t6qo/kCC9nLamdDlkEhsQ/7ZwzXZN2nvz 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: Ryan noticed 1% performance regression for kernel build with the ranged file map with ext4 file system. It was later identified wrong xas.xa_index update in filemap_map_pages() when folio is not large folio. Matthew suggested to use XArray API instead of touch xas.xa_index directly at [1]. [1] https://lore.kernel.org/linux-mm/ZBho6Q6Xq%2FYqRmBT@casper.infradead.org/ Signed-off-by: Yin Fengwei Suggested-by: Matthew Wilcox --- mm/filemap.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 40be33b5ee46..fdb3e0a339b3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3416,10 +3416,10 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct folio *folio, return false; } -static struct folio *next_uptodate_page(struct folio *folio, - struct address_space *mapping, - struct xa_state *xas, pgoff_t end_pgoff) +static struct folio *next_uptodate_folio(struct xa_state *xas, + struct address_space *mapping, pgoff_t end_pgoff) { + struct folio *folio = xas_next_entry(xas, end_pgoff); unsigned long max_idx; do { @@ -3457,22 +3457,6 @@ static struct folio *next_uptodate_page(struct folio *folio, return NULL; } -static inline struct folio *first_map_page(struct address_space *mapping, - struct xa_state *xas, - pgoff_t end_pgoff) -{ - return next_uptodate_page(xas_find(xas, end_pgoff), - mapping, xas, end_pgoff); -} - -static inline struct folio *next_map_page(struct address_space *mapping, - struct xa_state *xas, - pgoff_t end_pgoff) -{ - return next_uptodate_page(xas_next_entry(xas, end_pgoff), - mapping, xas, end_pgoff); -} - /* * Map page range [start_page, start_page + nr_pages) of folio. * start_page is gotten from start by folio_page(folio, start) @@ -3543,12 +3527,11 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, unsigned long addr; XA_STATE(xas, &mapping->i_pages, start_pgoff); struct folio *folio; - unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss); vm_fault_t ret = 0; int nr_pages = 0; rcu_read_lock(); - folio = first_map_page(mapping, &xas, end_pgoff); + folio = next_uptodate_folio(&xas, mapping, end_pgoff); if (!folio) goto out; @@ -3570,15 +3553,14 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, ret |= filemap_map_folio_range(vmf, folio, xas.xa_index - folio->index, addr, nr_pages); - xas.xa_index += nr_pages; folio_unlock(folio); folio_put(folio); - } while ((folio = next_map_page(mapping, &xas, end_pgoff)) != NULL); + folio = next_uptodate_folio(&xas, mapping, end_pgoff); + } while (folio); pte_unmap_unlock(vmf->pte, vmf->ptl); out: rcu_read_unlock(); - WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss); return ret; } EXPORT_SYMBOL(filemap_map_pages); From patchwork Tue May 30 08:07:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13259404 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 4E493C7EE23 for ; Tue, 30 May 2023 08:06:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC08F900004; Tue, 30 May 2023 04:06:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D4A97900002; Tue, 30 May 2023 04:06:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEABA900004; Tue, 30 May 2023 04:06:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AF643900002 for ; Tue, 30 May 2023 04:06:36 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 737501A015E for ; Tue, 30 May 2023 08:06:36 +0000 (UTC) X-FDA: 80846189592.09.6138939 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf04.hostedemail.com (Postfix) with ESMTP id 6367840018 for ; Tue, 30 May 2023 08:06:34 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=nHUeILLw; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf04.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685433994; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jBPCVDHZuQ2wYY4bZMS/Jy+G2//+D+pxOEKs2w0BXQg=; b=A9b0exFHCC2w5CmJY4hO7mzfrWAp5rKpgNUSjkpm5KFUQqv2g08fX952B2BxltSUBFutMt Vff7h/IzC3ahZRJjybCYqxoN+9Xv/ycTpSo+mP41mSgmBHhXcVq+INSGM1oHvo4MtxrSMC i7R2xwkX0XzhJ0KgSCbIWXO0dk/8orw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=nHUeILLw; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf04.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685433994; a=rsa-sha256; cv=none; b=MhfvMjzTPlL5T1xxRTH24iBvNAY/DJWyvTomoOsZ+EQVdw7hok8L8x4aXkhcydau+guoM5 iDdGgDgkkW+rczHDR/iOkIBzxI54enYud8QdFDuaCJS4dHVWIsqiXJ4zb6EjiwXzi4YfWC 1hszwYe5e2GXxntVKywW7OmLGRod01c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685433994; x=1716969994; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JECnRzWsjoveNrvZKVFqMJv39FXO8gY9Cjv6t+BF/f4=; b=nHUeILLwC2NcLfUhljJHqZEAEeZrjRlNQZbzqXg0iu1mGGOlsc8Jpk8R vkABtEWN+u9ZN8YmQ6mxLWx7mJotSCBZySx53+TxPbRjyo9QGSM7EOd7u BorX2xFqvb6SRI+ld2IEAKWvQ1RGvNytwg6/oWw2EQUkvy/HvKYVc6jn+ LaO1t3tKbn2yzupLqVUgEouKh6mq/ehUDh7jq3XPTDBFe2kWUVnfW/nSi qi07TScDEOtrO6IIyfBEurajISzmGTgwb6nqjs/f7se5mcX3g8+H3puyJ CYh5Cb/I0mIh5E2GY9Z8JNcHV6//aErbbAwbCaWjKgUo8Rugd7WDxnrpQ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="418332165" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="418332165" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2023 01:06:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="739426363" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="739426363" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga001.jf.intel.com with ESMTP; 30 May 2023 01:06:30 -0700 From: Yin Fengwei To: willy@infradead.org, ryan.roberts@arm.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: fengwei.yin@intel.com Subject: [PATCH 2/4] rmap: fix typo in folio_add_file_rmap_range() Date: Tue, 30 May 2023 16:07:29 +0800 Message-Id: <20230530080731.1462122-3-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230530080731.1462122-1-fengwei.yin@intel.com> References: <20230530080731.1462122-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6367840018 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: d61o39j6f3r6jft4368x671db7qjzp11 X-HE-Tag: 1685433994-994954 X-HE-Meta: U2FsdGVkX1/AhZpvYwei4epZ3GJWnkxPfETO/lSH8wnSRwe+9/Zc798JKgt3B/S51oVWJmspvg9uEHdxphPDFewsHHjp4jGI1uElhMa8UK28DyBDb5JUk4pCwnrtSFxsb5obFrgkMygHscDwfff96Zi1bsO2tLcz5+vML5E/yZyJ6lqIlDFKJTr6usuglnDC7cffAUdDxJlfcKWkwVzx586iumW14ujFnciIJwAsyLNCIMhBWv9RVWXZuZ0EiszJD57Fwrx8VQkYpw3YiTwxClpA4SNtiLzpG8DlC8O7lhUFOKwtNiTw9os3nRILm9rq0SZ+6YIAFd7SZUAL1gCxrGcz5Z6WNBfi5e6RljlEIDfTlIhgjfNlpDiZbv6xh8eZcUX4nLaYvhjzkbQdDqJ4iMXWqkSjG51WPk0EmNzwdBq3YiomXNAfpMiri1Dwbbpwl06qXvXjH4IXQGNIxEpQ6QMp7SGzPtes6uU0oGj2sQWXpp2DhEGYLuNz9hO4+uWwYRPlNYP5LFWji/oIRtvo3DEiPNDoLeoVoYtex9sVJA9VpV8ouf5A8G6q32VP+iPQIzVdFnBp+rJpV2IUMCag7a3niwB52ahc5D/1oEbLLi/zXrnx1h5BCb480RFXUAm4vWpV3JsYwcNODfX1Ep4Wc+DX/dS9k4OVhP+KqsmNYn2z74KOoeymK1t91d5l+QNIUG4V8TQntF4B9baQi/+KVQ/4Cc0zYzUazwv3i6SMouvvSOfTizB1BIsU4lw43kaOEBjBsqW+lp5paeIq5ByjM+DtdunJSV4gehykRj8g3Y+Q92qf5tahibXcXSlnnaLHh129OQSQ8pdlN1ga0haK1ucdU/LyzwPxAYp68S5Sm3bii1a6YIzcceAII+7w//k0+ZV9FvpqaG5GLF5ymTK0yh9Crrk3CKhLdIjsQYLeSN0tRimZzDzRKbTvzYq8R/zGUkENSYvmQPu3NimnnZe DgkaT/gE +oNGX4ctz57I1Mbcz4OBhlQT7rZqkSiKtxZKu5OjK/IT5mkndxydQZRjrTMh/4d7MjwErLYyAl/hQ9b1hFvQngon8kc600O4NKHlzuVaAy8wK2jHCjtOyisJsrUBwyEwgKwJZrLPQLufXZpG+qx25STFjKLbVUV/G4bmlCQ7tGFLRgXmVycnmwdmo3veQxQqY2DF7CtNofXQTvng= 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: The "first" should be used to compare with COMPOUND_MAPPED instead of "nr". Signed-off-by: Yin Fengwei --- mm/rmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index ec52d7f264aa..b352c14da16c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1330,7 +1330,7 @@ void folio_add_file_rmap_range(struct folio *folio, struct page *page, first = atomic_inc_and_test(&page->_mapcount); if (first && folio_test_large(folio)) { first = atomic_inc_return_relaxed(mapped); - first = (nr < COMPOUND_MAPPED); + first = (first < COMPOUND_MAPPED); } if (first) From patchwork Tue May 30 08:07:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13259405 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 E45D9C7EE2E for ; Tue, 30 May 2023 08:06:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 583BB900006; Tue, 30 May 2023 04:06:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 50BCD900002; Tue, 30 May 2023 04:06:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3ACD5900006; Tue, 30 May 2023 04:06:49 -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 28974900002 for ; Tue, 30 May 2023 04:06:49 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EE56C80178 for ; Tue, 30 May 2023 08:06:48 +0000 (UTC) X-FDA: 80846190096.07.CF18A2D Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf29.hostedemail.com (Postfix) with ESMTP id BFCFB12001F for ; Tue, 30 May 2023 08:06:46 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ePA0Sj4e; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf29.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685434007; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PKZNCA+gImQ6X/nKXu5Qkif03K0WFVHkt6kXEgXM2N4=; b=sa7emqnireQjSam+FkzACUBbZmPlOlZzTiCP/nHkSAz6xtmeEMlJ/6OUQAo5/1uTvp+SlT jS3Fr6c+ysIk64NDPT+LT9/CgmSaxCWY5CaxQBpy5FVGMgGEIKA9ohHcLlgKNQmewN3eGM cz2QkwD/nr2tCBY+te4wacOorclOljo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ePA0Sj4e; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf29.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685434007; a=rsa-sha256; cv=none; b=uotYxEU2Nvp+mtziDDbNIRYvyQ8T3XJXN7KfELJg9vHN1YlTFhOPRxyHYowtfy/nNtKI0z +Cfm06BUobzF7W9IXDKnjaa8yrOMqtLAWg/VY+gi9MXH2h8bra1Dhoq0MzilsiIdJ3+lRA IQgnpt/UdkDLlb03LQQ5sJ1C0jexx0k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685434006; x=1716970006; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3NUJ2cV526DtOmRsdjgiB8BAWkISfmdbH9OrsnpKKCA=; b=ePA0Sj4et55eLFzeuvoOqqtw9lnmEFV7f/t413xNcDEHZiWCYdZlUnQD lvEqYmfdmbho0vUVORm+9jOtpY/B13XvgSmYXgRptxe/7+U3dO10YcOKK QfT701J0TQYILBE9/z63L364amL2YdjGrfbc8s2H2qFOKx/L/MmbyMLqW w5mansNW0WptJ6mRYmvb3GnffIcqf0Dwc7miErg493dZ3bkJpb5HitIOW B7OLD3R0Pi4h3CC0xxvxGz1WRab2S59R9Z4+5pb78PBpd557Vc6i+HrQG iFFxJqRos3LK75H3Dis8UTCGght0r/pVENy/J+DEfU0w7dxoWarhKeTyR A==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="335196941" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="335196941" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2023 01:06:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="706326971" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="706326971" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga002.jf.intel.com with ESMTP; 30 May 2023 01:06:43 -0700 From: Yin Fengwei To: willy@infradead.org, ryan.roberts@arm.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: fengwei.yin@intel.com Subject: [PATCH 3/4] mm: mark PTEs referencing the accessed folio young Date: Tue, 30 May 2023 16:07:30 +0800 Message-Id: <20230530080731.1462122-4-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230530080731.1462122-1-fengwei.yin@intel.com> References: <20230530080731.1462122-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BFCFB12001F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: wtrjg63iy8a3yx789ukfufd9od3e5spn X-HE-Tag: 1685434006-949785 X-HE-Meta: U2FsdGVkX18ksLrWMQ2oe9ifacFxnTG8vpTW+OQz5nx+iD4o6vqPlE0lobAO3669dGzMSWPaEm8odZZXy42LnGm5TRjt5uFsgkiLou4O+n5HVbIHQdn9lzzqIsxziZg/7iSFMPcadYST47krW0jrB/HKbHhj9WGBKyL78SNYuyTnpqJU9j1J1N7i3LJD7AXRHxhzUm7FCZSD5reisRbrXdr2EVaq8Gqt99cA3FurRHzPjgVKuHEynju9kwfcEO4LFmRvKFLJ7f3rB2tscdu3H/WQkE1emtSrDUKpvZr6935AR24d+QbBUuDJmJPsYoNR/H+7szF1pA0elFj2Be8o01tvrZ+8Wj8oVPdhs7bZghiUFPKsBKUi3R2a9JuKmx5U+dKdFuSvSqYa7xjw9cseH56uSSJ9AkO4kbht0C8DG1MRT1CquompfkDBhB2VEenUeF1jFHvqatJwkhlmhUsls2pnPDzAsr5995+6Uf76CivKmC592iOV5TEcac90dt/McyLmX5VeZt+E8eejLpw46mpv4xikRWcTokJtuVaH0wd29oIWs2fqVvCpI4AgHNB/yAewVmuh8C0tQeYV8hEmrpB+djTNK+foB+ycGjltiJFyLPqv29E/EXX1diLzgeVdKmmfD2B9Mt2c6vQBzB6EmmV5UDBtGO95wdJ37Z5cNQdIkjrlilGHVOgoi0+cbNOcqBII2RHt4dPCxgO89TM0zfpB5IIn6gvvGfwe/Bb5cO0+8F5L76/vNSczO1W1gKls2+1+78NLYIzYyXdyR47DUrAPoyr3sNX+bEn7H6aXY8hpKNQYdi85vcPWOJVtl8p31FH8Q07ZGJ3xZT96yAd9VbxgelM0eyLPGAo7hLkHFwXEb1fKs1uuG04noKAKWQArm1QFaQ/uFCpDebKNmiSKInmy3g/T67NZHNNdrJd3ntu9rXDxCVWVJ5d+RtrnGIjTdBq9Ev3jpg0jKdCxZZN Ij/Vnf0N JQ7EIKjh6hWLM5+swwG2+SHxRYXF4OWsJ+L3heIBRwm9mf2to7PrZA/xV4rFtXL8ngliR8wouJl4mnG+L9JHPbtXZ9MJUjqzHlABhx5APCXAWYiXeRx6ZN+zyhXpogRq+oEV4HllXMtGVfOkpe84U3K1FxLcOJ8CAbJ5bq+IPpOrSzYqspPaDAMCyCCBXezpZLYUlJBwOV1AjZV4GETpmHfLKS1Hbt9AEXrahER2pxjQuAgQ= 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: To allow using larger TLB entries, it's better to mark the PTEs of same folio accessed when setup the PTEs. Reported-by: Ryan Roberts Signed-off-by: Yin Fengwei --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index c359fb8643e5..2615ea552613 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4259,7 +4259,7 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio, struct vm_area_struct *vma = vmf->vma; bool uffd_wp = pte_marker_uffd_wp(vmf->orig_pte); bool write = vmf->flags & FAULT_FLAG_WRITE; - bool prefault = vmf->address != addr; + bool prefault = (addr > vmf->address) || ((addr + nr) < vmf->address); pte_t entry; flush_icache_pages(vma, page, nr); From patchwork Tue May 30 08:07:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13259406 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 53D18C7EE23 for ; Tue, 30 May 2023 08:07:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E36C3900003; Tue, 30 May 2023 04:07:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBEBB900002; Tue, 30 May 2023 04:07:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3885900007; Tue, 30 May 2023 04:07:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B3B49900002 for ; Tue, 30 May 2023 04:07:01 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 848EB4014A for ; Tue, 30 May 2023 08:07:01 +0000 (UTC) X-FDA: 80846190642.12.B933BA0 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf21.hostedemail.com (Postfix) with ESMTP id 658E51C0019 for ; Tue, 30 May 2023 08:06:59 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=c9JZIZga; spf=pass (imf21.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685434019; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YnZxXReVL1I6DCXtGtPRve4mJl7NAfBnjCqu1uEcaFE=; b=h/EAggMZmYWAs2V/SaXCOaaKVJkb434taXKglB7k1eftPkIhTkUrhTsUJ7/BBSwVZlrHcw QBWfg5Rd4snS4W3BqWBKM3H2ZqC7z8ghWD5qSiUI+u09/M7thT4flHNLQFVYyWreE7KB3U u5PCE89pIsX7B5F2D7SNP/QpQX1DM3I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685434019; a=rsa-sha256; cv=none; b=HzKPsT9BQ2gdJWskngzg4zTfSQoRqVfpaMTVp1uodwQHftEQ3hpn+2LWzqYb8qbLMBDTv+ DcgdTZjUKfKTZduE8G0LqoBJL5Vx6qkBLF8aYHTaYetM6wDuoc02FyEQ8jIh6m8eEhDBMo 9SClycHO4OpLmhTfLuHzIFVHPno20ZM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=c9JZIZga; spf=pass (imf21.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685434019; x=1716970019; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iLg8+BuQb6cfAwix3TzfWOi+K6oPegJSPNVGDscU724=; b=c9JZIZgaAQZOSOP05/iLfi76lMSenbsAGAfwPOSkOj3+dNtSw9qiJ3X2 Z4PGkGT42JE5ZepmRBaLzps9GHr5FLLsREktAu2tJXFiWu2WN5bjDgibw qCqNsBeswFzF+IwDHd200RMQGD28K3yZeFyWN2lUzvpWyyN5a+jdGW8mD hlx9Dmn63h35oXy7Z+rLOVt3YSLdokeZjWOrtTOOtIsA8VKdjJn161yN7 iuzIZRrXDCdJZIDfrIGw4ch9zZo/rACNRo9OxzM2kcPMPAVb4cOaSQIxy nxDujwTyGa+etGs4kI39p5IUIvFX1pisU3w0cAGM0qhmVPhc85Cd0+kuj w==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="344349316" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="344349316" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2023 01:06:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="880678883" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="880678883" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga005.jf.intel.com with ESMTP; 30 May 2023 01:06:54 -0700 From: Yin Fengwei To: willy@infradead.org, ryan.roberts@arm.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: fengwei.yin@intel.com Subject: [PATCH 4/4] filemap: Check address range in filemap_map_folio_range() Date: Tue, 30 May 2023 16:07:31 +0800 Message-Id: <20230530080731.1462122-5-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230530080731.1462122-1-fengwei.yin@intel.com> References: <20230530080731.1462122-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 658E51C0019 X-Rspam-User: X-Stat-Signature: 4sz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6TXTXqQ41ImQJaV/Hx12nn4FEje6SyCIwkN7ZlBVit34dJn8VO9AF//OBNGOz8KP49KOpQSlfsTq+8Jh/vfwFNVC7TagtL2hAaXWs64Rtj7+XkZemXc1TMhaRLHby/X2ZIp0WC8soDIE0r3Csi2253vcyZvX/kVwEDyil+TeimXyfi6T4wp9Jg= 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: With filemap_map_folio_range(), the addr is updated with range also. Address range checking is needed to make sure correct return value (VM_FAULT_NOPAGE) if vmf->address is handled. Signed-off-by: Yin Fengwei --- mm/filemap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index fdb3e0a339b3..0f4baba1cd31 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3488,15 +3488,15 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, if (!pte_none(vmf->pte[count])) goto skip; - if (vmf->address == addr) - ret = VM_FAULT_NOPAGE; - count++; continue; skip: if (count) { set_pte_range(vmf, folio, page, count, addr); folio_ref_add(folio, count); + if ((vmf->address < (addr + count * PAGE_SIZE)) && + (vmf->address >= addr)) + ret = VM_FAULT_NOPAGE; } count++; @@ -3509,6 +3509,9 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, if (count) { set_pte_range(vmf, folio, page, count, addr); folio_ref_add(folio, count); + if ((vmf->address < (addr + count * PAGE_SIZE)) && + (vmf->address >= addr)) + ret = VM_FAULT_NOPAGE; } vmf->pte = old_ptep;