From patchwork Wed Jul 24 07:04:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13740625 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 9F175C3DA70 for ; Wed, 24 Jul 2024 07:04:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D7476B0083; Wed, 24 Jul 2024 03:04:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 485EA6B0085; Wed, 24 Jul 2024 03:04:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D9E26B0088; Wed, 24 Jul 2024 03:04:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 064396B0083 for ; Wed, 24 Jul 2024 03:04:27 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A534D1C0B25 for ; Wed, 24 Jul 2024 07:04:27 +0000 (UTC) X-FDA: 82373757774.03.419002D Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by imf07.hostedemail.com (Postfix) with ESMTP id AC5594000F for ; Wed, 24 Jul 2024 07:04:25 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=tY+ggRWe; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721804642; 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=tdqWP64rTR+e1Asc5O6zn2fOj7NNlZAEMcoj2njyV9U=; b=2vU4cdS76QjYiTZnXunee+qLozOqCVIPXyILZxhFPp9SrtMbFi/WZ9nlXn3vjPowLVNg9U 5emiHeOA0m5+IxSyxiy6otSmcUCZkZUh3/X1VoBxHA7q1xljEW3m3ExV80LgqfKeXB5sFm lz8XYC5Evp5c/P/zLbd7O4/6bjFJ0x4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=tY+ggRWe; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721804642; a=rsa-sha256; cv=none; b=dTfO8zFnWzcTHcCMbpy6Cbh4oj/s3qq1LwdH7QuUzLQ0Sds/1X0WYewfb7lIPUGp2f6yuS H39akCBGuIpkz2LSNP1M2lr0OhPKSCHuCX+6WJ5UgLkb5uaxibOApp/WgeRQ6DyZ5NtGi+ g+wp8qyfrJIsvbJgEnnEJUBYk2KWfLE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1721804663; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=tdqWP64rTR+e1Asc5O6zn2fOj7NNlZAEMcoj2njyV9U=; b=tY+ggRWeZ7iwXAAcHSVxs1nslPchK6vv5cwzoJ0+vkrp6BtYWmlSvbfOjNAJRF7KjVLshyFhluJTpafbbUFYtSOW3vGGJauo0quUGz3EHZ27prrpo/Cewxr1mP7R6oDmUapkZ7L/Y1B74X6WXzmr5KJmZvCm2eDHTMehGcHV9F8= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0WBDDM3B_1721804661; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WBDDM3B_1721804661) by smtp.aliyun-inc.com; Wed, 24 Jul 2024 15:04:21 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/3] mm: shmem: use mTHP interface to control huge orders for tmpfs Date: Wed, 24 Jul 2024 15:04:00 +0800 Message-Id: <03c77c20a8a6ccdd90678dcc6bf7d4aeaa9d29ad.1721720891.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: AC5594000F X-Stat-Signature: fa9rgzife7qgdfcy7njp1a3fnho4gndz X-HE-Tag: 1721804665-771421 X-HE-Meta: U2FsdGVkX19WWDoNAOIHFl53jwESSwIZ6wRLSC4WyNAe+YfXaI1yBQ6ATvL1B5I1RMLBm9sWGFCdicWrZc/K4ShZKk8CXrH0tZQHzeBDjP+6kCoTYVia3MbvZvzp4U6x+Bl1sQZACR6vZO6lpYkvkC4t0pZPxGdvuCJ/YpP/+uabR1Z/PhMg/IPokVKkkLncfg2jvsq2FgBtrRjhF4iw1ffzxuERXlPyF6iR/ZfQTAXbFZVuBd3znK/xj1xXgr7mFHJRFLbh6Zq06AGeKeODuGBvGXpzGayvMXstq+jabUnbwejRhsKEhD5xeARQX0YiiuvMcxzpCqYj4Udmiq9RGqufH61mTy7hKscFBs2vwQsaSYaxrWr+ixrhfcfyd+n9fWMhieXyxHgUiqnG4AYvshLQit+T4I9XFRCX8oJisw7h78SxFwkm6JJzGce9HDvAVQWZkkm7aaK/81N0vZuJgk2FGiaou+10mv+F46fxc48TavwQL5B8V9wKHxIQhDOYBmV4HAvVIEBrbeRO3I2cg7uTdYBW82WmOPjqqEz/sOvAEKw9K22Q2WOu8eDcXEx5QTacDcwxvh5t+oNPYj97mGGQAtr/MmicnqPyV/cl/xhOhwqK556zKRR/qAcAKZ02O6cEbnE1auzngCvJAtikhd9wrgarrSB8hh6jsLuvbFCsqcLa+QjIRCLL5hg79tgo3as1hBzyHNf7hSmM71zzb3OWHwBrUm/fldpesQKNrOJdlVuODdmT66UX883R3f+OLYkd3VaM90FWFuf9EqGW5ZevXa4u6OwUnMFPibNXRa8q7Islhu0bBRoEPW9e89LNh9EP8FlXxzcHn/dY6mH4N0j/j4Z9Ix4wCsGza3toLeSYHRM5gSwV4s5esSJfDJJUvB/i41vJbD6NRl7N8hygUSDd+pFr5gOCQCPk8p5qX+5ukBedUsdYvPG7qNs1hZOeVxpfEZNtsFvjOtDtTe+ op8nKj5w etu9w7sKCEQ9mh+nmOs8BJOlwd2izqMk+qlJ6+uoboGr8Nu07aVdfEeZrl+crNUvH5DQGntBN1w2B0waZn7VlY/RvRSmQUWgWULbTIPegtmLOGmOEDA9LX4vwnOlJZwBZSQAnZCiCO6tBOl4ffJzn05UkbTR/63YIpYT9k9ppvtpxpLuf9xkPqA8FP17oVb3v/jAr4nWSvybvvpM= 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: For the huge orders allowed by writable mmap() faults on tmpfs, the mTHP interface is used to control the allowable huge orders, while 'huge_shmem_orders_inherit' maintains backward compatibility with top-level interface. For the huge orders allowed by write() and fallocate() paths on tmpfs, getting a highest order hint based on the size of write and fallocate paths, then will try each allowable huge orders filtered by the mTHP interfaces if set. Signed-off-by: Baolin Wang --- mm/memory.c | 4 ++-- mm/shmem.c | 42 ++++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 802d0d8a40f9..3a7f43c66db7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4877,10 +4877,10 @@ vm_fault_t finish_fault(struct vm_fault *vmf) /* * Using per-page fault to maintain the uffd semantics, and same - * approach also applies to non-anonymous-shmem faults to avoid + * approach also applies to non shmem/tmpfs faults to avoid * inflating the RSS of the process. */ - if (!vma_is_anon_shmem(vma) || unlikely(userfaultfd_armed(vma))) { + if (!vma_is_shmem(vma) || unlikely(userfaultfd_armed(vma))) { nr_pages = 1; } else if (nr_pages > 1) { pgoff_t idx = folio_page_idx(folio, page); diff --git a/mm/shmem.c b/mm/shmem.c index cc0c1b790267..8e60cc566196 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1692,26 +1692,6 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) return 0; - global_huge = shmem_huge_global_enabled(inode, index, shmem_huge_force, - vma, vm_flags); - if (!vma || !vma_is_anon_shmem(vma)) { - /* - * For tmpfs, if top level huge page is enabled, we just allow - * PMD size THP to keep interface backward compatibility. - */ - if (global_huge) - return BIT(HPAGE_PMD_ORDER); - - /* - * Otherwise, get a highest order hint based on the size of - * write and fallocate paths, then will try each allowable - * huge orders. - */ - order = shmem_mapping_size_order(inode->i_mapping, index, - len, SHMEM_SB(inode->i_sb)); - return BIT(order + 1) - 1; - } - /* * Following the 'deny' semantics of the top level, force the huge * option off from all mounts. @@ -1742,9 +1722,31 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, if (vm_flags & VM_HUGEPAGE) mask |= READ_ONCE(huge_shmem_orders_madvise); + global_huge = shmem_huge_global_enabled(inode, index, shmem_huge_force, + vma, vm_flags); if (global_huge) mask |= READ_ONCE(huge_shmem_orders_inherit); + /* + * For the huge orders allowed by writable mmap() faults on tmpfs, + * the mTHP interface is used to control the allowable huge orders, + * while 'huge_shmem_orders_inherit' maintains backward compatibility + * with top-level interface. + * + * For the huge orders allowed by write() and fallocate() paths on tmpfs, + * get a highest order hint based on the size of write and fallocate + * paths, then will try each allowable huge orders filtered by the mTHP + * interfaces if set. + */ + if (!vma && !global_huge) { + int highest_order = shmem_mapping_size_order(inode->i_mapping, index, len, + SHMEM_SB(inode->i_sb)); + + if (!mask) + return highest_order > 0 ? BIT(highest_order + 1) - 1 : 0; + + mask &= BIT(highest_order + 1) - 1; + } return orders & mask; }