Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2077018lqt; Mon, 22 Apr 2024 00:03:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXe+s9doT8P59vjeAeZMjaXMasM+wW/mGkMjcAyrXdLhevAX9u2OyGBzx5/n64+lCV3cV37ZmP6cRq+Ib5IcbIcQ3H5k3evEjV2nFMvQw== X-Google-Smtp-Source: AGHT+IGADDtGKppiWHETvqVB+ORTDOB9hUw76hS+dHIUC08ZS5hBxpjdY/z+Jo7Nk1EixX1P/D6w X-Received: by 2002:a05:622a:1486:b0:437:ade8:89c8 with SMTP id t6-20020a05622a148600b00437ade889c8mr10578945qtx.64.1713769399801; Mon, 22 Apr 2024 00:03:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713769399; cv=pass; d=google.com; s=arc-20160816; b=Fj0Rqt9oy/CEzrXLWgjwdzaI5KOLg1M4aPQ0LjQfF0EzXDRnl8Ac5PP7UJZ7eHF8h0 SU91pwISS7x3It1AE+OPbUC8xs9wcrde8nglfIkOkHqVx4fu9UpW5qO2j+fwsKWvAdtG G1K2C9xJ81/57hOX3q3O7PMB9QyfDfg9s50xsq1jbJokvlg3RcAX+dLrf4toUaieO85l 9U6zDZz9qoIpvDid7lAyvXU5e2uCVUR1OVogHjkAgJ6obURUe+CeyW3VIqLZYsRH1Cgq hIQRIpas/RHtE5tlLkTxzSemYsjKs1z6/irx27oX2ID4+ezrC0zER9xBvsw00L+NV/XJ pLsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=EzoH5/TP5PtYl4wtjV6rpqRZK0tNrBnQaBo2IsOMKmA=; fh=g586Og5O/SXhL23QYbFhGrsFvTrke7WPI63lNAC0sdg=; b=pYJ7854WF2apr5iEB7ZJTTAob0Gj3VstdZmTHcUTTFmDI/HuKdE3PKm/8eIHV5Qgfq pSGnPRz8fZpjve0BljzQrk4liBt5z15JXkuw2jaA9ocRJaD/4aKKbTHstyq7Ql0URCer zcnjZahxXH1GWiLIejmdBWMRkxTNmlTgKrORdTYEc8zx9S5h0k/Bw0M2asHfWa9P1Ja7 9snmBsp0eOpvo0zRl4bf6pzDzkP3r5KWsBp9nSr4Hb1ls6lEJ+RFSJO7kiqmwIWb8pSd Ip7rhzsyUfz+w+dHDFzMXoHUnC3vQIZg42LxeFoIKU0sk4uwoME6Yu4oE+8gx+buU+7y R1Ag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=pXaD6oHa; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-152818-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y8-20020ac85f48000000b00434e7ea018csi10064423qta.261.2024.04.22.00.03.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:03:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152818-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=pXaD6oHa; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-152818-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 869C61C20CE3 for ; Mon, 22 Apr 2024 07:03:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C30B4AEEA; Mon, 22 Apr 2024 07:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="pXaD6oHa" Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCDFE482FE for ; Mon, 22 Apr 2024 07:03:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713769385; cv=none; b=ldKHOSvSKQKrRV9htfTeC1jEhneVfHjIkXUiC40wRaltq7Aea/fR5wq7D6ynkOdavMJgn/n0v4PbCMIjCs75jAMWAqSW+foj8gTsr9wyF2r6RzgtgXFrJKowhmBRom04mOWCGXP7S+XEy0jPsUlir8J4DEia9udPD3unTTruZfI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713769385; c=relaxed/simple; bh=Igv+soIxm8VlLHoVz15y7f//HTc0E/HeAkBEGILFQM4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=MrqFeuzW2YVwDeavBicj9DV2jPk3km5vJQh7YvCtTb6CUa89o6AzXKPQQI5vvhBAUmFdOoQDLB2UJoyTEw7Vb0Onon0XKfiMI4reYWSUAnFDFg/J1ACn/viCKTqnkyfqwi4KQtSQYZ5o43pSG9RFqcboLvWNADoMEi2nMu6AqKE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=pXaD6oHa; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1713769377; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=EzoH5/TP5PtYl4wtjV6rpqRZK0tNrBnQaBo2IsOMKmA=; b=pXaD6oHafPyNRdOFmU6L6BUWJucQO4gyxKeSQlEFBQlQZYRpt70ysI9JdxKTrbIf1NrstIMNbQUmCm6FEq3FyX32kIzA5wmzgwXdQ+ribbo2YBTUKLOIC3z5etW+54gj7EAwIrd8h55X6QG8UBLFuEh4axh0z/BtMzVCxLzvf+Q= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R561e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0W5.T-Xb_1713769374; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W5.T-Xb_1713769374) by smtp.aliyun-inc.com; Mon, 22 Apr 2024 15:02:55 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 0/5] add mTHP support for anonymous share pages Date: Mon, 22 Apr 2024 15:02:38 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Anonymous pages have already been supported for multi-size (mTHP) allocation through commit 19eaf44954df, that can allow THP to be configured through the sysfs interface located at '/sys/kernel/mm/transparent_hugepage/hugepage-XXkb/enabled'. However, the anonymous shared pages will ignore the anonymous mTHP rule configured through the sysfs interface, and can only use the PMD-mapped THP, that is not reasonable. Many implement anonymous page sharing through mmap(MAP_SHARED | MAP_ANONYMOUS), especially in database usage scenarios, therefore, users expect to apply an unified mTHP strategy for anonymous pages, also including the anonymous shared pages, in order to enjoy the benefits of mTHP. For example, lower latency than PMD-mapped THP, smaller memory bloat than PMD-mapped THP, contiguous PTEs on ARM architecture to reduce TLB miss etc. The primary strategy is that, the use of huge pages for anonymous shared pages still follows the global control determined by the mount option "huge=" parameter or the sysfs interface at '/sys/kernel/mm/transparent_hugepage/shmem_enabled'. The utilization of mTHP is allowed only when the global 'huge' switch is enabled. Subsequently, the mTHP sysfs interface (/sys/kernel/mm/transparent_hugepage/hugepage-XXkb/enabled) is checked to determine the mTHP size that can be used for large folio allocation for these anonymous shared pages. TODO: - More testing and provide some performance data. - Need more discussion about the large folio allocation strategy for a 'regular file' operation created by memfd_create(), for example using ftruncate(fd) to specify the 'file' size, which need to follow the anonymous mTHP rule too? - Do not split the large folio when share memory swap out. - Can swap in a large folio for share memory. Baolin Wang (5): mm: memory: extend finish_fault() to support large folio mm: shmem: add an 'order' parameter for shmem_alloc_hugefolio() mm: shmem: add THP validation for PMD-mapped THP related statistics mm: shmem: add mTHP support for anonymous share pages mm: shmem: add anonymous share mTHP counters include/linux/huge_mm.h | 4 +- mm/huge_memory.c | 8 ++- mm/memory.c | 25 +++++++--- mm/shmem.c | 107 ++++++++++++++++++++++++++++++---------- 4 files changed, 108 insertions(+), 36 deletions(-) -- 2.39.3