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);