From patchwork Fri Aug 30 08:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13784559 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 12DF7CA0EF4 for ; Fri, 30 Aug 2024 08:42:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F6DD6B00D3; Fri, 30 Aug 2024 04:42:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A79B6B00D5; Fri, 30 Aug 2024 04:42:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BD286B00D6; Fri, 30 Aug 2024 04:42:09 -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 2D4506B00D3 for ; Fri, 30 Aug 2024 04:42:09 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A9C31C1395 for ; Fri, 30 Aug 2024 08:42:08 +0000 (UTC) X-FDA: 82508269536.23.6CBE80F Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id B79B81C0019 for ; Fri, 30 Aug 2024 08:42:06 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725007238; 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; bh=Flq1npThCzIGa2hYBYIiKdG6s8zwarSI7B8d3gSDeJs=; b=reiUtt0oHlDqadkV8AN8WpU4nz1ZtWxfDrDG52taj8xxFoaq4Q6DFkow6daRp7l4jCeiEd dEvIagJkKf1IIEScvH6eBvY1FKPXs4quifDQVy5wif5gdDVOG2YakfaKTFjsAgJus/KEnZ r8DIi0Cajh6Q8SrRuwXulOAAbPHld3c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725007238; a=rsa-sha256; cv=none; b=RswFoyFAi6pPoscOGdkxT22v+oIaQ+Mhlzjm5SM4Ssm0SMzpRNP8DNeOtS2gMjkVJSBzns X/qSbTkJcyaSDCYmwbXHJaqemmY84kc6kzZ6/jwozN2YuBr+Mzu09y9SzVtaE2AkxD/7Kb tgbJ2zDBBbZkIaPWDC5r/DkrNfXeFvs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BD1F71063; Fri, 30 Aug 2024 01:42:31 -0700 (PDT) Received: from e116581.blr.arm.com (e116581.arm.com [10.162.40.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2286A3F762; Fri, 30 Aug 2024 01:41:56 -0700 (PDT) From: Dev Jain To: akpm@linux-foundation.org, david@redhat.com, willy@infradead.org, kirill.shutemov@linux.intel.com Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, mark.rutland@arm.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, jglisse@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Dev Jain Subject: [PATCH 0/2] Do not shatter hugezeropage on wp-fault Date: Fri, 30 Aug 2024 14:11:15 +0530 Message-Id: <20240830084117.4079805-1-dev.jain@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: B79B81C0019 X-Stat-Signature: 5kqxm55fkict3wzbwmju361e4f75cioe X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725007326-874839 X-HE-Meta: U2FsdGVkX18/PhhKTyG++7OV8CAYqi6GyaJ9PAIHMYpysN7ArxESuIJASBzPfw6l/oD4m6x8f8pRZv74VkZiol3/iJwoPWYNonGetFIzf0h9oiNEWAnJCnw2y4rNNko+/0LNQST2fvI9OqB8OIb32poGfcqkpJNt6DYJ1PA1HaVM2TPxPnzPaPIeDkZKSOyySjdKijMdxsvfAmAqaFZ1hlWB+NWrsC2stXD+SW8rkvG7AJ6QawuD5N/S/tbzZzkjDxZJI8fBTK6/GO4L15ELbOchyG9qynDxXFRmA3MFOAil7QHxY7SqTUxdChZ4QJAQ/l3v7+T0Sz28Zk4FLncrYr68EiMPsPa3j+h+7rPci051WH2qGJcqItiJt/MZgPLP78ypuaTtBccQ5O1stORvSCQlHSYjwEooCsmsfGa+p4qIYD6osu9O28Nfw22E4LPgSOMwC73uyIpYvnUaIuWeVDieuT+h+LUxbRyUvqMEYBp6WWGaZ4pot0/RhT8kH6vefjnqnLVBxLIhBPqV0nuc32anP/OZFVODmzxduUvbWNj8wMqZMKyU0mcagpntz0MaEANCGA0cGA2D+zmYcizftYhybtyLqF+UY6vxM5HJyYLsPm5MoSIENWCk1BKxkFgSz1+4d4N9jwdqNljrWyZzIoOx8r4lNmLKcH4wsgKtpFdgJ6u0paVdHw0XTAm6YVTSz31TQy1isEVFFvDYDLzBjHR9twykuNpTYG+Dv5GF7z5oF7Oqhym4igatNtHoJvWmBu7TKoiUJt5oC+fQSLwGMu0QhBCuOoI4N791MnHB2H6CA/twrdfxRfZN1th7hiCb1Yi1wc1JbS28zlCd0OcO1+LljoWgxsWNi+ifbspiLex2mtEbCFPwki5kjULECKmcCvIntcRqqyMAALvJR9CNB7FVspbYuB4uG7AeSUsqnWCpyV6aCrcwpYgqFnWbXG4PnNCD4yNn6Wd+RuKcvCf Q+cMJcgt NonUxBAzv5W/BvxnrfZYUCTaZeNWsm6UumAy05KOcg7hhwnEXCpaj0A1+/FGawio+P6EtRxpX4fgbPmV40Lt4adx9wHMsVoiy8p85TODyZT+CKhOJqiTLVNbqG61f/J424h5U+EovPqAt3bHBJn91lPxUulzQQbMljovTukHXxkggUMs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: It was observed at [1] and [2] that the current kernel behaviour of shattering a hugezeropage is inconsistent and suboptimal. For a VMA with a THP allowable order, when we write-fault on it, the kernel installs a PMD-mapped THP. On the other hand, if we first get a read fault, we get a PMD pointing to the hugezeropage; subsequent write will trigger a write-protection fault, shattering the hugezeropage into one writable page, and all the other PTEs write-protected. The conclusion being, as compared to the case of a single write-fault, applications have to suffer 512 extra page faults if they were to use the VMA as such, plus we get the overhead of khugepaged trying to replace that area with a THP anyway. Instead, replace the hugezeropage with a THP on wp-fault. [1]: https://lore.kernel.org/all/3743d7e1-0b79-4eaf-82d5-d1ca29fe347d@arm.com/ [2]: https://lore.kernel.org/all/1cfae0c0-96a2-4308-9c62-f7a640520242@arm.com/ Dev Jain (2): mm: Abstract THP allocation mm: Allocate THP on hugezeropage wp-fault include/linux/huge_mm.h | 7 ++ mm/huge_memory.c | 171 +++++++++++++++++++++++++++++----------- mm/memory.c | 5 +- 3 files changed, 136 insertions(+), 47 deletions(-)