From mboxrd@z Thu Jan 1 00:00:00 1970 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 4EC58C48BF6 for ; Thu, 29 Feb 2024 18:34:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB03B6B00A1; Thu, 29 Feb 2024 13:34:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E36286B00A2; Thu, 29 Feb 2024 13:34:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD4DE6B00A3; Thu, 29 Feb 2024 13:34:52 -0500 (EST) 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 B6C7C6B00A1 for ; Thu, 29 Feb 2024 13:34:52 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 71D17A01F6 for ; Thu, 29 Feb 2024 18:34:52 +0000 (UTC) X-FDA: 81845692824.14.400CB4D Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf19.hostedemail.com (Postfix) with ESMTP id 9B2CA1A0014 for ; Thu, 29 Feb 2024 18:34:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=YfVDAr9k; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3Sc7gZQYKCJ4WSXF8MEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3Sc7gZQYKCJ4WSXF8MEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--yuzhao.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709231690; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=T4VtSg6n2CoEjcQGcRm6/S48W6BfaDcdHWqPoQHz4ho=; b=2PZfyZwDWpeXciEugFSmi0LxsCB8uqBvHSkhWaXMtz38gzIxU1hcZrMIYEwjcgBlAgDB1G i6TWbbZ2/wHadNnVTrzbgMCRA8rdhyJCSMzx7tRHlpNohIXdZcjHRBLZc1S2Neo6VQE2yI 0lek5gFFlF9JaCk1kuzJKloQEH/lix8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=YfVDAr9k; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3Sc7gZQYKCJ4WSXF8MEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3Sc7gZQYKCJ4WSXF8MEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709231690; a=rsa-sha256; cv=none; b=AIzJMiYIC4d9OLegHbSz5WCjMAxIjlSe2c7ONaMEZO50gbZNuDNmvBpzXjY3JmrDpLlCCD x3fKUdxGIe/La9NOOqgvrtSW8zUvR0i4yEgVmOlHyYAiJKnsGb6hvQjKBXgeD+MXpBynjt RYa1EuBHqUXFpI3khCnAMlW7ChwEgqs= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc743cc50a6so1633886276.2 for ; Thu, 29 Feb 2024 10:34:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709231690; x=1709836490; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=T4VtSg6n2CoEjcQGcRm6/S48W6BfaDcdHWqPoQHz4ho=; b=YfVDAr9km1DqBtMB1ZoOIOXwccwVv4v/nzrr+CYu5ygIXAhkUQAjDZap2jc3dvYvSy u/Xa+acy9yjN1/if8org0I3PU1PJysoHrgSXenWQDEagNLLa/I50Cge3e0OeDkobp9Dn wtOX4Dx/qULftgj1uiPUAvIIjanXpGLy4TYA/7Y1u5Wfke2mzRm+3qHhGSvWzDmTE24f AM1nnvxVFJTKLifynP7kYem5YEuVosditgRNXvuxq/stu/krVNRjmuz+tb+RzwiEavhP stUXGZMdT9G95GKQaw8JGR/d018ASPRiAbxmlxJU0nSSO1Px1bC2OXvMD40310GTICP2 5TVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709231690; x=1709836490; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T4VtSg6n2CoEjcQGcRm6/S48W6BfaDcdHWqPoQHz4ho=; b=bPr/0o1VQlbQDFcpIlqwUIQ0PDGGS2dHQ4uUZzAMEi4Oa+qsstS70jSfjA6yNlFamO Uwaw+bw3EEBaGPu2yed8JVPqDhEVGgDglqBde0F58Qu5P7oyMt7CC4igDb6+pCCcgI/v 5tBOg6D92YIISY7DoJA/kfIAVuU+NXix8X/+4d+3gufZgkU0HIGJYNGrn+Vag31B6Ly7 dF6wCOcIcCCBFACF2cmWcrAuQmLS9BEiGnXS24e+ycaBp3iAj0AFWQByLEZTYRfoj8L0 h5+U/MnTd85j1iDWugLaTlUpMAGutu5iMAiAHi0eVZ6Vv0o9bBAIPux4tofZgLWRpT94 j8zA== X-Gm-Message-State: AOJu0YwSv7S+R+X3heGSVphu0zvXMYz95tmCwpJzCR5Pm+X3lYz1tYZQ ux7CERyXopCcnvF+BtlhvF7qo7COB9rwxKdn5fQh6fe+OaufGj3hH3+Ek9CKkBELlTw4GlfQXo4 eWA== X-Google-Smtp-Source: AGHT+IGiF/gUwQtz5GJXh1CuOtPR0vyH0eeXKR4MmkFbG353zSGolmKZWXQ+EFk5EESp3DGe9qXcJOXjnZc= X-Received: from yuzhao2.bld.corp.google.com ([100.64.188.49]) (user=yuzhao job=sendgmr) by 2002:a05:6902:1004:b0:dc2:5273:53f9 with SMTP id w4-20020a056902100400b00dc2527353f9mr142349ybt.1.1709231689813; Thu, 29 Feb 2024 10:34:49 -0800 (PST) Date: Thu, 29 Feb 2024 11:34:36 -0700 In-Reply-To: <20240229183436.4110845-1-yuzhao@google.com> Mime-Version: 1.0 References: <20240229183436.4110845-1-yuzhao@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240229183436.4110845-5-yuzhao@google.com> Subject: [Epilogue] Profile-Guided Heap Optimization and THP fungibility From: Yu Zhao To: lsf-pc@lists.linux-foundation.org Cc: linux-mm@kvack.org, Jonathan Corbet , Yu Zhao Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 9B2CA1A0014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 17iywiwuxubuhbgbqrwscy5syq3xgg4u X-HE-Tag: 1709231690-756804 X-HE-Meta: U2FsdGVkX188uMgAbubb4XvM/aH/tB6944nVJF9td6v1YZk7AxEhtoPN1kdicqANdgQEzyp473lavQsAWrtN/LYtB+DfyymV7Y6kMTOJF7mRtyjMYcdfGdlL7pYJaEtBvCSDwJN6/Nb5ici02y1+z11wbAvJM+ff7+NhSSYFglrNekzpXduT20BdLym4i+YCyv7+ha0creIQ5AIuKncX+BUkMJ6Wj22iqxo8QVNvwi25HkLyXvqiQFhx1kOvJOs5/xXPd1hdSg1jOIubQKqQHRWlmLYpM4lz28xOXJiH8wrNZNjko8DKrIwXy1JWu27UM5cVJ3FEh/k5Mrse+PnxF1cM7dyXL0Ag2vDk2uB5YrFTjnTwNxxR2D+RyZTAFQJXW3WJbvkxwTjcvBzqhrWJy86VH6IkQZGDcyNICv7CXBngR/ReFkmxQTtiJSagVIq2wxgoPzi5TpsRYSnWuqxI/KVS54mQpCEbCALs+gEMgg/VLm08l2fvDJ8HTI8HyqBjbOGgCUU2RKYggn+fTRL5KsUnxq+dVHWCnzHkdtoRNxWLkUvNet3d6eFrANPEyZw47KY938e1gipuj6lFw1Gh6n4Fbi3r0XGF44rqfPYWCI3dN/BstVZ/zAgvndnC6hysos7nUzXMB+mCeTr5i4vqv+PXkwVLQwdEM7GSBBl46N/WkCKuQhg8+LAE4fLksZFb1P6pIgK9yPASuJHksO6QDrZd3QswEs6UdT+wqBP44Ed1bvao5fn8oA/gjqCWqYToMv/0CHUcDvrTA/8AlRL/DfV+kmAlTCH0GiAbU8hAdlqZvZ7G1zONW7PEu7vp1fhjJX3wjnuWZhEetYklg1YltwfL3/vt3Dl5GsDTpcRODgpxBZcCfJmPBqTFP4sGGOU7DQC7juxv4Eh4W61I/wNFlWdcJ8Xi7OdFSrLQ5kFjdIHkmpGAqQgBdvqGuUVsXX7OR4D4BHJKBEIt8w48Xc+ m/gaCTdm l2bCGHf1Rrl7X7nkJeA34K/1Gq6J2t00SSrneoCbITw8+Z0CUkOHLzDzDu+UdWl4d8uvq9g3Nha/4PBYXcEd0RG5rMwl8T9i6ZbGU+zOSffkWSazIa7c/hkBLnCnylJ9EbOZOlVC3OI9sQYCPLsNYbx+Za1R6+n6dHmT9Nohga+sdDaU4FWp4q8eCdenddwJTo9aShD6wg64CYFyowRI0iZ81FIOpcieN1drkwOWWaRU2jeONr2zgSG2QiHVCYCQlnsCP3bHeBNsCNhp6tWASinUe8yjQkK37EwMlMt3/u66Z2qiDOljMJLROW4Rdkqi0bJkkVEasOAk5NDh54d6db/eJktduPex9yc7r X-Bogosity: Ham, tests=bogofilter, spamicity=0.007996, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In a nutshell, Profile-Guided Heap Optimization (PGHO) [1] allows userspace memory allocators, e.g., TCMalloc [2], to 1. Group memory objects by hotness so that the accessed bit in the PMD entry mapping a THP can better reflect the overall hotness of that THP. A counterexample is a single hot page shielding the rest of the cold pages in that THP from being reclaimed. 2. Group objects by lifetime to reduce the chance of split. Frequency split increases the entropy of a system and can cause a higher consumption of physical contiguity and reduced overall performance (due to TLB misses [2]). None of PGOs (PGHO included) can account for every runtime behavior. For example, an object predicated hot or long-lived can turn out to be cold or short-lived. However, the kernel may not be able to reclaim the THP containing that object because of the aforementioned reasons. Instead, userspace memory allocators can choose to MADV_COLD or MADV_FREE that object to avoid reclaiming other hot folios or OOM kills. This is part of the whole process, called THP fungibility, and it ends up with the split of the THP containing that object. The full circle completes after userspace memory allocators recover the THP from the split above. This part, called MADV_RECOVER, is done by "collapsing" the pages of the original THP in place. Pages that have been reused since the split are either reclaimed or migrated so that they can become free again. Compared with MADV_COLLAPSE, MADV_RECOVER has the following advantages: 1. It is more likely to succeed, since it does not try to allocate a new THP. 2. It does not copy the pages that are already in place and therefore has a smaller window during which the hot objects in those pages are inaccessible. In essence, THP fungibility is a cooperation between the userspace memory allocator and TAO to better utilize physical contiguity in a system. It extends the heuristics for the bin packing problem from the allocation time (mobility and size as described in Chapter One) to the runtime (hotness and lifetime). Machine learning is likely to become the autotuner in the foreseeable future, just as it has with the software-defined far memory at Google [3]. [1] https://lists.llvm.org/pipermail/llvm-dev/2020-June/142744.html [2] https://www.usenix.org/conference/osdi21/presentation/hunter [3] https://research.google/pubs/software-defined-far-memory-in-warehouse-scale-computers/ -- 2.44.0.rc1.240.g4c46232300-goog