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 72F03C369DC for ; Wed, 30 Apr 2025 11:20:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDFD96B00A1; Wed, 30 Apr 2025 07:20:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D8B6E6B00B5; Wed, 30 Apr 2025 07:20:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C04ED6B00B9; Wed, 30 Apr 2025 07:20:12 -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 9F6EA6B00A1 for ; Wed, 30 Apr 2025 07:20:12 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AD09F1413CA for ; Wed, 30 Apr 2025 11:20:13 +0000 (UTC) X-FDA: 83390466306.08.BA8F72E Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by imf10.hostedemail.com (Postfix) with ESMTP id D3884C000E for ; Wed, 30 Apr 2025 11:20:10 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fabXhYrQ; spf=none (imf10.hostedemail.com: domain of ville.syrjala@linux.intel.com has no SPF policy when checking 192.198.163.9) smtp.mailfrom=ville.syrjala@linux.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=1746012011; 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=46bgJx6cf0O9gqF2BSM8xe1d0NUa0uTdeiKNTHFhhRc=; b=dnU6vWXhE11R4OQVh3da1qjdibXaFzURpkHuKVD50U5Wdh4Pk4geZmhNF0ja014OoLilBc mXk/4CAWBS0sMTYweW3jWtWirTMrC7gKcuutbyU5INwygJGq6bn/4jCrwPXcp9XfDm0Dmf E0FjlYk9ctq6rFOC8vJJF3zTCMTYC5I= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fabXhYrQ; spf=none (imf10.hostedemail.com: domain of ville.syrjala@linux.intel.com has no SPF policy when checking 192.198.163.9) smtp.mailfrom=ville.syrjala@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746012011; a=rsa-sha256; cv=none; b=fPNYapDvNpLDI4IubmmKPha1gmBgfQrh/3V2cH0SdUTGweG48zK5MMKSNvmRyhTdbjDY+U sg5UXWYyfyGCpRkeuNl5K0o4THukIGO35a7+HfJJsHx5Hywde8XXgTYFRx3haqoPx4D03k JbeFP3Ney2+zrrK52f/0yf4woLLmPX4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1746012011; x=1777548011; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=EF01kkqV58wp6RAxtOeYWzYzYSD4HksIbDbTbhiLyCg=; b=fabXhYrQvCh2+fb0tLiBddMXFQag9UzFz7M6TcDMIckStqhvfR3FR/BY 8Gka1yxzt9Ly8E+dm8DI7X+MXaGitPJ06dpiljEdF23fJZVfNkp9g1ldj FYY/z9gcgWPKqBdDTyntWSB5NPMmf+4tykNrLWhVJvK7FNe47YZ0DCm0m bIcE6PBSOWEq2rK35Te8tCtfQyvq/JVVxhOzFvkfORdtcUkxGV5Rod9g8 abfX/jS0uEmnAvolOxxsSRAqTHia7lSbje64ZDHLf9lGJYwFSLr5VLqR9 pnotC40zs3duYEPCOMcYQLu5vD1CAqjEc5GjH3HF8uKuGMJnm2WBqrHkz Q==; X-CSE-ConnectionGUID: rKyjpYuHRj+a4ywsbzcnjg== X-CSE-MsgGUID: nJysH4rETnmB6FEsrMNp0g== X-IronPort-AV: E=McAfee;i="6700,10204,11418"; a="58324924" X-IronPort-AV: E=Sophos;i="6.15,251,1739865600"; d="scan'208";a="58324924" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2025 04:20:09 -0700 X-CSE-ConnectionGUID: B4W/LccOQpyqnhDeH4uUWA== X-CSE-MsgGUID: +WRh437uRJyCd4LKnyOlpA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,251,1739865600"; d="scan'208";a="139275736" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by orviesa005.jf.intel.com with SMTP; 30 Apr 2025 04:20:04 -0700 Received: by stinkbox (sSMTP sendmail emulation); Wed, 30 Apr 2025 14:20:02 +0300 Date: Wed, 30 Apr 2025 14:20:02 +0300 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: Baolin Wang Cc: akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ioworker0@gmail.com, da.gomez@samsung.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, regressions@lists.linux.dev, intel-gfx@lists.freedesktop.org, Eero Tamminen Subject: Re: [REGRESSION] Re: [PATCH v3 3/6] mm: shmem: add large folio support for tmpfs Message-ID: References: <035bf55fbdebeff65f5cb2cdb9907b7d632c3228.1732779148.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding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kBJ2mleswmtJ/ba+VyFQr1lD/Jggj6dnmPuhXVQPbAnnXaLLZdEovopoZ VlXNwJmJ ExT1tpqPEw8gB6iOwyrm6beuoO0DMEVgKcHbVEbiBsitGNflnLNrcAC4MXjOPW0+Ao7BwOF7kxtI/0eygpcpu6pP5kJdF9o0y1Awm+frbTmn8Fx+BD6M9ojjpu9Q92MIatwYbwjecriBpc73AMU4mj9kiU4FVSmt6rxyvQ3cy3EhIZFRuzAWVEG7ghuftacRKEnqhraVY7ACy/t4903pbDVKnVgbJUdc8yrpGtc6Z10p7SUf1jK0ucNtlZ32QOi0ju731yERP6vXOtu7EoeSarezwsUOQaCe4LGOo9VNqH/qpB+KNhCwYbw8MFAp6ttO6aZzx7Q5PDU51JzE= 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, Apr 30, 2025 at 02:32:39PM +0800, Baolin Wang wrote: > Hi, > > On 2025/4/30 01:44, Ville Syrjälä wrote: > > On Thu, Nov 28, 2024 at 03:40:41PM +0800, Baolin Wang wrote: > >> Add large folio support for tmpfs write and fallocate paths matching the > >> same high order preference mechanism used in the iomap buffered IO path > >> as used in __filemap_get_folio(). > >> > >> Add shmem_mapping_size_orders() to get a hint for the orders of the folio > >> based on the file size which takes care of the mapping requirements. > >> > >> Traditionally, tmpfs only supported PMD-sized large folios. However nowadays > >> with other file systems supporting any sized large folios, and extending > >> anonymous to support mTHP, we should not restrict tmpfs to allocating only > >> PMD-sized large folios, making it more special. Instead, we should allow > >> tmpfs can allocate any sized large folios. > >> > >> Considering that tmpfs already has the 'huge=' option to control the PMD-sized > >> large folios allocation, we can extend the 'huge=' option to allow any sized > >> large folios. The semantics of the 'huge=' mount option are: > >> > >> huge=never: no any sized large folios > >> huge=always: any sized large folios > >> huge=within_size: like 'always' but respect the i_size > >> huge=advise: like 'always' if requested with madvise() > >> > >> Note: for tmpfs mmap() faults, due to the lack of a write size hint, still > >> allocate the PMD-sized huge folios if huge=always/within_size/advise is set. > >> > >> Moreover, the 'deny' and 'force' testing options controlled by > >> '/sys/kernel/mm/transparent_hugepage/shmem_enabled', still retain the same > >> semantics. The 'deny' can disable any sized large folios for tmpfs, while > >> the 'force' can enable PMD sized large folios for tmpfs. > >> > >> Co-developed-by: Daniel Gomez > >> Signed-off-by: Daniel Gomez > >> Signed-off-by: Baolin Wang > > > > Hi, > > > > This causes a huge regression in Intel iGPU texturing performance. > > Unfortunately, I don't have such platform to test it. > > > > > I haven't had time to look at this in detail, but presumably the > > problem is that we're no longer getting huge pages from our > > private tmpfs mount (done in i915_gemfs_init()). > > IIUC, the i915 driver still limits the maximum write size to PAGE_SIZE > in the shmem_pwrite(), pwrite is just one random way to write to objects, and probably not something that's even used by current Mesa. > which prevents tmpfs from allocating large > folios. As mentioned in the comments below, tmpfs like other file > systems that support large folios, will allow getting a highest order > hint based on the size of the write and fallocate paths, and then will > attempt each allowable huge order. > > Therefore, I think the shmem_pwrite() function should be changed to > remove the limitation that the write size cannot exceed PAGE_SIZE. > > Something like the following code (untested): > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c > b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c > index ae3343c81a64..97eefb73c5d2 100644 > --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c > +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c > @@ -420,6 +420,7 @@ shmem_pwrite(struct drm_i915_gem_object *obj, > struct address_space *mapping = obj->base.filp->f_mapping; > const struct address_space_operations *aops = mapping->a_ops; > char __user *user_data = u64_to_user_ptr(arg->data_ptr); > + size_t chunk = mapping_max_folio_size(mapping); > u64 remain; > loff_t pos; > unsigned int pg; > @@ -463,10 +464,10 @@ shmem_pwrite(struct drm_i915_gem_object *obj, > void *data, *vaddr; > int err; > char __maybe_unused c; > + size_t offset; > > - len = PAGE_SIZE - pg; > - if (len > remain) > - len = remain; > + offset = pos & (chunk - 1); > + len = min(chunk - offset, remain); > > /* Prefault the user page to reduce potential recursion */ > err = __get_user(c, user_data); -- Ville Syrjälä Intel