From patchwork Fri Dec 6 08:30:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13896645 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 30FDAE77173 for ; Fri, 6 Dec 2024 08:31:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9464D6B01AA; Fri, 6 Dec 2024 03:31:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F63D6B01B1; Fri, 6 Dec 2024 03:31:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BD8B6B01B3; Fri, 6 Dec 2024 03:31:44 -0500 (EST) 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 5DCEB6B01AA for ; Fri, 6 Dec 2024 03:31:44 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C53BE14193A for ; Fri, 6 Dec 2024 08:31:43 +0000 (UTC) X-FDA: 82863865560.29.A7B7424 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf15.hostedemail.com (Postfix) with ESMTP id EF521A000A for ; Fri, 6 Dec 2024 08:31:24 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dzAVGKSN; spf=pass (imf15.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=laoar.shao@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=1733473889; 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:references:dkim-signature; bh=gaIpQvkdoMLTjaf/6msdYPERNNt0XKX/eslq4dA70x8=; b=XgVDzpfdtJV2/WmumT+TeBbKF+fbXBaRtq0/SjVWt7JJCULxjPKtzmw8+jsN5i9FSyg2Cx vaq8yzbaNZabFbw6nsxkEqfj4lE+6MEZsIhvQ5QDbchuh5FqpcTggF2cDCqo4/Z/7aSGFu QOpz1bLPmD6u4NIETx9SKhss0fYr/hQ= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dzAVGKSN; spf=pass (imf15.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733473889; a=rsa-sha256; cv=none; b=QEBaUvg9VWmi8IW4DMJzUP/YWOOP5Y5kS3QoKfSa60b86AE9ncyjQbJR2cSjbtJQ5IxzpW NIofn+/yEgP2mtYd8FDXjKvsnn/6jxNYO01U/HK4HScIVF6Si8XcuVOWcbpAsdePViZTcR 03Ke/o0oBg9/Ckyi9dqdgQwFkjtX31g= Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7fd1dcbbc08so1052939a12.3 for ; Fri, 06 Dec 2024 00:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733473901; x=1734078701; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gaIpQvkdoMLTjaf/6msdYPERNNt0XKX/eslq4dA70x8=; b=dzAVGKSNYwZ91ghzLaTC5MnRVH8H8DEPIpudWDiTkKV1Fuf38wT7foWpk3H6Cacvyc BXrJ1G5bOYyKPu835mRFLR77iBDwLx6Wpk27oPPeVwX3JizjOA74wVzOWrdvOP7U1Sln hqVPo+fUKpcEa9vyqS70aKknTln//cFCiDnDtWOBwRyGbBdewAOJH9IhLsneziK+RsMe sobo7uBBZpCGccAHouP+AoiLgxmA0Gr8lguoLoqb9lgBwtnQn0R6+JNXh9H2zZiqnUlq YNwDcpjiWDpf4Vor+yqTHw2iPcEsyDhjJnYUMVwA3UErLYBf7GqA6uanUSR+Xfz6BjDp MBOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733473901; x=1734078701; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gaIpQvkdoMLTjaf/6msdYPERNNt0XKX/eslq4dA70x8=; b=IixXjlz9Mj29Ae58t+iRiprMP64Lfi3DddIEItw+/cInRpCPu9rbnfiIrB24Fm1Sne klbIK+6o3dfepogtFbUJUp3wcHklk/GjPYVVa9GYeSTSK0fYWoH5FVWyoTZ8OnVTxj77 xDNuRHFvelikyzpmo3mRs2puaZCM3WFDk4rztgbK41d/3zyL2fNm90woUsk6qyD6iukq QdBMYlrG/pJs0HIN7VoyoC01X0CBaP9rHUfMnVZ6cMhFt4jwmKQzg/dY8iWza3iic2/y V5B7+aAuSgerVD87daznENoE8hATSOrWS+N7gBsDWH7CdTeLt/XrciASMKCh0Fn6D3Ez ypyA== X-Forwarded-Encrypted: i=1; AJvYcCWwEUJ0nrud3u3f/JvU2aIZ/qgjk2rseg9YxjE3UYL3IR13dBos1tyLpAFjuIwqf6nXXVwuj4b8nw==@kvack.org X-Gm-Message-State: AOJu0Yy/HQYsnaMTlMO3cN/8oltXyh1x0Jzs8T1710ztWBWdrgBWuPoV V/kxXpZIfqvkGuFFUEv8fgzPNQCg5AwytDkC/7W4cjB0iXwGibJc X-Gm-Gg: ASbGncsPll7VzQC3H8+abA8ZWyt9lakcZz4hyDFAxSG7vu7pG4zZ4Ai2y+o+eMNBd+9 8dYxyziUr5h6+PtaS1pzowAUhD7jpC/8LslUULcVteQnV4+gE5vV7VS0aMWKvOM2SRBzHOJoIWw ZHgEKwWy9TBIefjtx7/pQOZ/YEYLhQouJIbTEKaHfeynVR0U+CXjfyt7lRlvJXXhjx/KzkAQHmH PLbABWjX8cjLj8kkigVQ8F0 X-Google-Smtp-Source: AGHT+IEvLMZ3ZxPJciJz3ObXqoij4WO4W4Oiw708kBft81mgnEsWCEQn/YsBCCJOK3kpW/swgyQmpg== X-Received: by 2002:a05:6a20:7fa6:b0:1d9:1a77:3875 with SMTP id adf61e73a8af0-1e18715fceemr2397434637.42.1733473900638; Fri, 06 Dec 2024 00:31:40 -0800 (PST) Received: from localhost.localdomain ([39.144.106.32]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd1568f29esm2550866a12.15.2024.12.06.00.31.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 06 Dec 2024 00:31:40 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org Cc: willy@infradead.org, david@redhat.com, oliver.sang@intel.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Yafang Shao , stable@vger.kernel.org Subject: [PATCH v3] mm/readahead: fix large folio support in async readahead Date: Fri, 6 Dec 2024 16:30:25 +0800 Message-Id: <20241206083025.3478-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 X-Rspamd-Queue-Id: EF521A000A X-Rspamd-Server: rspam12 X-Stat-Signature: cec7ne6xmw3upkmthmxojz4x1eub6hb6 X-Rspam-User: X-HE-Tag: 1733473884-328151 X-HE-Meta: U2FsdGVkX18SNZc1smWGOiro/ef3xfXmp1XzYRnJSwwB+NZCboFBxIGUYOuhaGRcnls8o/Pmf1CIEYDKA6G4SgqDtJ1ULi0yFQNYk4bX9pxkjybdvTJEPFGSh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ysKd3dhfZLP+HTfUfziy5wUOgd+GmepPvj7FLWtIJjr9BVkXXG3ZM8HNSD5KOFEsQj8vlqA+IElx1+i9Mo6hHnuZuFhtuG5qaKePy0fyI3cGQoULLbp1oo8uui/H+nRmlwYGhwyXDBWy/koEdmcCjjZIOFVwKn05+L7hRyAVtbWSj7WCywUJqb4yU7gBUBMgRPyx89I3U6Ac6bRu8JnfE78cAk58xSljiESc8SzTwZ0o+XINq/WHq9MbzdEPGv9X9fm8j6CScTEPLAsPb4UlWx326S1AWpqLbiGOcnQxAEmoco2tkCUNqKClGnUstsqgBJVG/mdS2qDlcTYAtGmwXd5xpvFs2GHBI0lwAA11Rgoxt/TuAL 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: When testing large folio support with XFS on our servers, we observed that only a few large folios are mapped when reading large files via mmap. After a thorough analysis, I identified it was caused by the `/sys/block/*/queue/read_ahead_kb` setting. On our test servers, this parameter is set to 128KB. After I tune it to 2MB, the large folio can work as expected. However, I believe the large folio behavior should not be dependent on the value of read_ahead_kb. It would be more robust if the kernel can automatically adopt to it. With /sys/block/*/queue/read_ahead_kb set to 128KB and performing a sequential read on a 1GB file using MADV_HUGEPAGE, the differences in /proc/meminfo are as follows: - before this patch FileHugePages: 18432 kB FilePmdMapped: 4096 kB - after this patch FileHugePages: 1067008 kB FilePmdMapped: 1048576 kB This shows that after applying the patch, the entire 1GB file is mapped to huge pages. The stable list is CCed, as without this patch, large folios don't function optimally in the readahead path. It's worth noting that if read_ahead_kb is set to a larger value that isn't aligned with huge page sizes (e.g., 4MB + 128KB), it may still fail to map to hugepages. Link: https://lkml.kernel.org/r/20241108141710.9721-1-laoar.shao@gmail.com Fixes: 4687fdbb805a ("mm/filemap: Support VM_HUGEPAGE for file mappings") Signed-off-by: Yafang Shao Tested-by: kernel test robot Cc: Matthew Wilcox Cc: David Hildenbrand Cc: --- mm/readahead.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) Changes: v2->v3: - Fix the softlockup reported by kernel test robot https://lore.kernel.org/linux-fsdevel/202411292300.61edbd37-lkp@intel.com/ v1->v2: https://lore.kernel.org/linux-mm/20241108141710.9721-1-laoar.shao@gmail.com/ - Drop the alignment (Matthew) - Improve commit log (Andrew) RFC->v1: https://lore.kernel.org/linux-mm/20241106092114.8408-1-laoar.shao@gmail.com/ - Simplify the code as suggested by Matthew RFC: https://lore.kernel.org/linux-mm/20241104143015.34684-1-laoar.shao@gmail.com/ diff --git a/mm/readahead.c b/mm/readahead.c index 3dc6c7a128dd..1dc3cffd4843 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -642,7 +642,11 @@ void page_cache_async_ra(struct readahead_control *ractl, 1UL << order); if (index == expected) { ra->start += ra->size; - ra->size = get_next_ra_size(ra, max_pages); + /* + * In the case of MADV_HUGEPAGE, the actual size might exceed + * the readahead window. + */ + ra->size = max(ra->size, get_next_ra_size(ra, max_pages)); ra->async_size = ra->size; goto readit; }