From patchwork Wed Sep 4 10:09:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13790322 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 A0F5FCD3431 for ; Wed, 4 Sep 2024 10:09:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FFA58D0239; Wed, 4 Sep 2024 06:09:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B2736B011F; Wed, 4 Sep 2024 06:09:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 001448D0239; Wed, 4 Sep 2024 06:09:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D254A6B010D for ; Wed, 4 Sep 2024 06:09:45 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8ED7FC0D93 for ; Wed, 4 Sep 2024 10:09:45 +0000 (UTC) X-FDA: 82526634330.24.8AF6D8A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf25.hostedemail.com (Postfix) with ESMTP id C72DDA0014 for ; Wed, 4 Sep 2024 10:09:43 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf25.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=1725444477; 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=lytgOqfDV4bDG82+WFMo7btweI4QjGE8z3T6eiE8ulI=; b=uhTjAPS0nHKCicnssRYMvgyKevhUtS9Gqy5/YUi7DigD2vu/n+sB/dlJ5cyNT+qVomgjNk Fcq96R/2CXVhwxYm3fWiOLHtKzjRtmcmWf0lduUjbiuKkbCT2NbHr9ca6VJfOHgfQwP9OL Wg1XCYtZXGNhmAdJWyx3NAG8qZyGe+A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725444477; a=rsa-sha256; cv=none; b=C7PY9OVe3fNGtZnDuO5yEyEGYqrKLaHDfTCmlwMhItJI21JDRJuIWpnV8hrZhA9s0b9d9j iMtjJyI/e2vvUmdpm/qmy0RTjUUaJNxs8cZMXlBelRAClfqkS1a1wdiSBuiEVgYD+8ZeCg +Lnoo0PZ2jX/GscOE9S65tx5z/tgVys= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf25.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 0AE1FFEC; Wed, 4 Sep 2024 03:10:09 -0700 (PDT) Received: from e116581.blr.arm.com (e116581.arm.com [10.162.43.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 298A33F66E; Wed, 4 Sep 2024 03:09:33 -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 v2 0/2] Do not shatter hugezeropage on wp-fault Date: Wed, 4 Sep 2024 15:39:21 +0530 Message-Id: <20240904100923.290042-1-dev.jain@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C72DDA0014 X-Stat-Signature: jyjxmkp1ztrtxtz63wpff6pbf79t8tpy X-Rspam-User: X-HE-Tag: 1725444583-528243 X-HE-Meta: U2FsdGVkX1+z9zC97TRUtqGN470TPxGvbghalYdtRRNouv3Oa6K1IN1CEnLod6qUUqEPt2yDqOMgIQYsR78HaOZSZBLemLrXx7HJvIrn0g5axbB6KFEeMHyI2SDIRlps3QVz6qGZ8TbUSCS2V4cWL1ZPKbSW8jFJELKJH97Q/YQz396gtEg8eroiE62Ybgr1rkgiLrzscTX8Yatkc/DYW94KNWLVCjjsVd7Wh9Lzs3GptD1spfLF1KPdvvl4pn/7OnuNA4ILC1RrkFK4gY41N6thrp4LCbGMODrjBzfXKhvvL2mX6Z8rsWm3JgRWTzDiPPDKlb8sSEM6FndxECeXoCfeY093zOnvYOCM6BbzdfD3EHq4ttaLHjK/Q8jFuAKA4qEeVxPnddPHRP51oEm0FNUGXYMuj1e2ss5fXw3dAsQVR5rp9mFrGp3BIznyC08QpNdCZLmHzOO40DGfmQsPq6o6iO/hGw/FcZC7G5dB4SmF+Mc51YBzkM4n6at3twmlVrNXiH8y0IBpHF9mmdug1kFIJKnKSTph6NrqUeBcoCYNRlU3espJo17hmHnX8MvVFKsd8yxbPtv/ZwnUZnNfbF+7WQbMKmYkwEqFJWjU9Q9hTYZZPifySTHkdurMebWN9Rwucx3yflyg2EhSrGfu1krfjY5GR2+TXpBjq88YBxUn+UW3qDn7AVKfKyur6SFimW4JnUk7zcHYmPW3sdKFhvcdKVIOEPyT/QrIIK00HGI1nYk8MpaqX0v6VZUPYJ57ZgPAMIDRgMigQMrL1eq46lpbt7nYXqcTtjM7SZI5o17XlrLM4bS4llb8MmCslgioAH3kYbvqx1Ov6tVKRoTmzgDuNR+UXKMYE9rdv0AuhRmBjb3yx7tHFkGqwLl/g9szeNdYrXdFm7S4YFMPWhb66J7SwpH3RuuMigwfqYK0rktuubOjyOBg1XjZmxoj+p2QqI+2+heDhMCFKiXEppo yW/h3nyn TVTju/YcSyRzEi1tXa1fpdOQXFG4jwsukHjmI6aPR5XNC2+7QKe8IaHz9NGy5IHZcB5DyYin5AHTQusY93fes9y+5pmd7VvwSuOcfi6vwIpmzZOTveiDqkeFzIBVprZ/sKwBVNktX8hbYTHyQGJEkhYoRbYMbOOKA7Kq6OVOIMls4d6AfhvOjDBV3RdQ511r/UBKa+OeRfUPh75YGsF1bZ3Ineg== 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: 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. v1->v2: - Wrap do_huge_zero_wp_pmd_locked() around lock and unlock - Call thp_fault_alloc() before do_huge_zero_wp_pmd_locked() to avoid - calling sleeping function from spinlock context [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 | 6 ++ mm/huge_memory.c | 171 +++++++++++++++++++++++++++++----------- mm/memory.c | 5 +- 3 files changed, 136 insertions(+), 46 deletions(-)