From: Ryan Roberts <ryan.roberts@arm.com>
To: Baolin Wang <baolin.wang@linux.alibaba.com>,
akpm@linux-foundation.org, hughd@google.com
Cc: willy@infradead.org, david@redhat.com, 21cnbao@gmail.com,
ziy@nvidia.com, ioworker0@gmail.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] mm: shmem: simplify the suitable huge orders validation for tmpfs
Date: Mon, 15 Jul 2024 14:30:36 +0100 [thread overview]
Message-ID: <cf919805-9fb1-4d7a-83bc-60225151cd63@arm.com> (raw)
In-Reply-To: <ee1b6ac287bb376a9da88a23e1ef16951eb94a4e.1720755678.git.baolin.wang@linux.alibaba.com>
On 13/07/2024 14:24, Baolin Wang wrote:
> Move the suitable huge orders validation into shmem_suitable_orders() for
> tmpfs, which can reuse some code to simplify the logic.
>
> In addition, we don't have special handling for the error code -E2BIG when
> checking for conflicts with PMD sized THP in the pagecache for tmpfs, instead,
> it will just fallback to order-0 allocations like this patch does, so this
> simplification will not add functional changes.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
> mm/shmem.c | 39 +++++++++++++++------------------------
> 1 file changed, 15 insertions(+), 24 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index f24dfbd387ba..db7e9808830f 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1685,19 +1685,29 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault
> struct address_space *mapping, pgoff_t index,
> unsigned long orders)
> {
> - struct vm_area_struct *vma = vmf->vma;
> + struct vm_area_struct *vma = vmf ? vmf->vma : NULL;
> unsigned long pages;
> int order;
>
> - orders = thp_vma_suitable_orders(vma, vmf->address, orders);
> - if (!orders)
> - return 0;
> + if (vma) {
> + orders = thp_vma_suitable_orders(vma, vmf->address, orders);
> + if (!orders)
> + return 0;
> + }
>
> /* Find the highest order that can add into the page cache */
> order = highest_order(orders);
> while (orders) {
> pages = 1UL << order;
> index = round_down(index, pages);
> + /*
> + * Check for conflict before waiting on a huge allocation.
> + * Conflict might be that a huge page has just been allocated
> + * and added to page cache by a racing thread, or that there
> + * is already at least one small page in the huge extent.
> + * Be careful to retry when appropriate, but not forever!
> + * Elsewhere -EEXIST would be the right code, but not here.
> + */
> if (!xa_find(&mapping->i_pages, &index,
> index + pages - 1, XA_PRESENT))
> break;
> @@ -1735,7 +1745,6 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf,
> {
> struct address_space *mapping = inode->i_mapping;
> struct shmem_inode_info *info = SHMEM_I(inode);
> - struct vm_area_struct *vma = vmf ? vmf->vma : NULL;
> unsigned long suitable_orders = 0;
> struct folio *folio = NULL;
> long pages;
> @@ -1745,26 +1754,8 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf,
> orders = 0;
>
> if (orders > 0) {
> - if (vma && vma_is_anon_shmem(vma)) {
> - suitable_orders = shmem_suitable_orders(inode, vmf,
> + suitable_orders = shmem_suitable_orders(inode, vmf,
> mapping, index, orders);
> - } else if (orders & BIT(HPAGE_PMD_ORDER)) {
> - pages = HPAGE_PMD_NR;
> - suitable_orders = BIT(HPAGE_PMD_ORDER);
> - index = round_down(index, HPAGE_PMD_NR);
> -
> - /*
> - * Check for conflict before waiting on a huge allocation.
> - * Conflict might be that a huge page has just been allocated
> - * and added to page cache by a racing thread, or that there
> - * is already at least one small page in the huge extent.
> - * Be careful to retry when appropriate, but not forever!
> - * Elsewhere -EEXIST would be the right code, but not here.
> - */
> - if (xa_find(&mapping->i_pages, &index,
> - index + HPAGE_PMD_NR - 1, XA_PRESENT))
> - return ERR_PTR(-E2BIG);
> - }
>
> order = highest_order(suitable_orders);
> while (suitable_orders) {
next prev parent reply other threads:[~2024-07-15 13:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-13 13:24 [PATCH v2 0/3] Some cleanups for shmem Baolin Wang
2024-07-13 13:24 ` [PATCH v2 1/3] mm: shmem: simplify the suitable huge orders validation for tmpfs Baolin Wang
2024-07-15 13:30 ` Ryan Roberts [this message]
2024-07-25 13:07 ` David Hildenbrand
2024-07-13 13:24 ` [PATCH v2 2/3] mm: shmem: rename shmem_is_huge() to shmem_huge_global_enabled() Baolin Wang
2024-07-15 13:32 ` Ryan Roberts
2024-07-25 13:08 ` David Hildenbrand
2024-07-13 13:24 ` [PATCH v2 3/3] mm: shmem: move shmem_huge_global_enabled() into shmem_allowable_huge_orders() Baolin Wang
2024-07-15 13:36 ` Ryan Roberts
2024-07-22 2:41 ` Baolin Wang
2024-07-25 13:09 ` David Hildenbrand
2024-07-26 1:09 ` Baolin Wang
2024-07-24 19:14 ` [PATCH v2 0/3] Some cleanups for shmem Andrew Morton
2024-07-24 19:15 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cf919805-9fb1-4d7a-83bc-60225151cd63@arm.com \
--to=ryan.roberts@arm.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=ioworker0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox