From patchwork Thu Feb 8 06:26:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13549359 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 CC37AC4829C for ; Thu, 8 Feb 2024 06:26:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 098E26B00A2; Thu, 8 Feb 2024 01:26:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F3DAB6B009F; Thu, 8 Feb 2024 01:26:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D54716B00A3; Thu, 8 Feb 2024 01:26:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9F7706B009F for ; Thu, 8 Feb 2024 01:26:30 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 79E08C01F3 for ; Thu, 8 Feb 2024 06:26:30 +0000 (UTC) X-FDA: 81767652540.04.2B2FBA5 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf14.hostedemail.com (Postfix) with ESMTP id 9606B10000C for ; Thu, 8 Feb 2024 06:26:28 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707373589; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=xyww7pMUuLyPBfG9ZuK6U6g9ZtqJWjn+tCNK2s25zA8=; b=K43rOcWm2yEB0yXv7RWxLQdOkcr+vcjA6Ok+0vpbWNHftftkd0TlD0bC+tDWeNsTgNaPIk ZbNLqPW6Dha2Y7xzIjlSUKNBDDtV8pY4IEtYTh3vwsu3rvQMqXX6GxodC5LsJYNOajYY7U UHNciX+41vYv0hPvzX/wLK5bLvUyS7s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707373589; a=rsa-sha256; cv=none; b=lNt98Xi5JypLMcQOtvpH2n/r1gND6PMVwtpEjm356q5QLIumQ9uYFVlhiyDwJxayqMfRyI 6oSbZjbPH0Wl+jPJZYiyznT0d8Rx6Lirknmo2vK1hQh8rrRNhZ6gdIiNQY1LwnkQ5cMkuS rh78aJbJ6L+2fvD29X9OMc1wH0SuI2A= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d85ff70000001748-8a-65c4740b3aca From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [RESEND PATCH v7 6/8] mm: Add APIs to free a folio directly to the buddy bypassing pcp Date: Thu, 8 Feb 2024 15:26:06 +0900 Message-Id: <20240208062608.44351-7-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208062608.44351-1-byungchul@sk.com> References: <20240208062608.44351-1-byungchul@sk.com> X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L7rFgU6nH5hVaHov3 vGTy2LSqk81j06dJ7B7vzp1j9zgx4zeLx7yTgR7v911l81j84gOTx9Zfdh6NU6+xeXzeJOfx bv5btgCBKC6blNSczLLUIn27BK6MjutsBX+kKg4f383cwPhDtIuRk0NCwETi0s1zLCA2m4C6 xI0bP5lBbBEBM4mDrX/Yuxi5OJgFPjJJrP7eAVYkLBAvMePAajCbRUBV4saxd2ANvAKmElP2 fWaCGCovsXrDAbA4J9CgndtOsYLYQkA1L2ZPZpvAyLWAkWEVo0hmXlluYmaOqV5xdkZlXmaF XnJ+7iZGYHAvq/0zcQfjl8vuhxgFOBiVeHhPlB9OFWJNLCuuzD3EKMHBrCTCa7bjQKoQb0pi ZVVqUX58UWlOavEhRmkOFiVxXq/w1AQhgfTEktTs1NSC1CKYLBMHp1QD492z8W6P5Z95z+n/ MOfwUXGW1feapvXGXpUz+b8t6qzOxv8flk+PEX59PfL1TdWn/meNV9v7xrblizvNa42PP/o0 actxlspLuRwMtosnvm3b/+f8S4mnvNuONGfqZ/hYOj0wa/k+veKI3rPpa6I3L3Jibdl2UO2t lOepdz4z2C63dvZPOWf6lUmJpTgj0VCLuag4EQAsrNOuagIAAA== X-CFilter-Loop: Reflected X-Stat-Signature: pozsak5ju7pa7p9o1jm579kmpqxghhyc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9606B10000C X-Rspam-User: X-HE-Tag: 1707373588-256095 X-HE-Meta: U2FsdGVkX18P/ykaKgxx8zGIpNKQMfvWyv7tObsUR+iKzBQeEiXGQPPUbcvYBov+qYFDg1jy2/TjDQcS6GxxMScBDVQKOkObSK0beLF9Fmm8fGQ7bMQdNZCYsMZzOpg3FSJrlirW45UxGTeTzZzTZw9RVps7wDoJZGP2LwWQAOzFkZca6+ZCG9UecLWM/Tf/DfIXMXvW1jodiLnwWEjVWWdfIZPQ0OLvG5C8aXixj7oDgr3tG9MINrTq4JWYhdVeWz1cPCRfLzx2W/WwnrxBfyUZzyq3iNMulwCU42oR1Zcbsz12MhyU3UAyF94wkF0iocCRBf1splBkN5Fq33HR5SbaHM7Z4o4jf1NvGaGghEN5DuL4BNK1bhD75+HZ/eUY9dus18rf7bn8YFKZLwUK0ccs2OcyZ5EV/h8famOlHe7voMXhK8s+WZUmVtllsmd58dOyd4/5IFM32HExtnknCc3HNTsrffkOPsWDPgVOkieIBLYTzqGM69OitMipRlEI5tEF9FvIYMPuQMdrgK/aJHsYQp9vyOAbTaswtvP3h4UzTOBpWpK4erC5bPJoHnzEd1tsdEjj5NQLWtWFo0GdnqMAE8WDi3i5GBWYAji7N6B3SNpMd2VH28Gsv6uhcFeB/K5vcuhoZsI2JkmNNXTYecMG7FNB/Q9utS431yZUm6WzuNkE27NSJHslq5sMH3cGZqQsCnYYNC+yoodYLg06GkE64Ul0tNKzWrzTRWuAL6+J2wTb2dsK2BZJSFEZNxhvOx3Ht4T79HuPySGXiBvl/FiLiGnXdieD7FrZsbDHDgjfUC/CJSIuOdrmdn9kDlo0S7d0955GRRNPoEnivO3A1E3zgE27FmIyCK8lFB7KzP0pKvs+gdCaK1rAmYPH48qV/crY6lVb2pOpJ7cI78o1WckXi2xeKm1LuPz+oJaUD6mab3zDVK4b3vr2iBt1Nr/AjEUgxvlP8Hjw9ULV/Qs ye6xb7KV NOnJ8DVzEGtURErckKcZCmhbj9Yxo/oViEBhDUBELLULdrRI= 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: This is a preparation for migrc mechanism that frees folios at a better time later, rather than the moment migrating folios. The folios freed by migrc are too old to keep in pcp. Signed-off-by: Byungchul Park --- include/linux/mm.h | 23 +++++++++++++++++++++++ mm/internal.h | 1 + mm/page_alloc.c | 10 ++++++++++ mm/swap.c | 7 +++++++ 4 files changed, 41 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index da5219b48d52..fc0581cce3a7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1284,6 +1284,7 @@ static inline struct folio *virt_to_folio(const void *x) } void __folio_put(struct folio *folio); +void __folio_put_small_nopcp(struct folio *folio); void put_pages_list(struct list_head *pages); @@ -1483,6 +1484,28 @@ static inline void folio_put(struct folio *folio) __folio_put(folio); } +/** + * folio_put_small_nopcp - Decrement the reference count on a folio. + * @folio: The folio. + * + * This is only for a single page folio to release directly to the buddy + * allocator bypassing pcp. + * + * If the folio's reference count reaches zero, the memory will be + * released back to the page allocator and may be used by another + * allocation immediately. Do not access the memory or the struct folio + * after calling folio_put_small_nopcp() unless you can be sure that it + * wasn't the last reference. + * + * Context: May be called in process or interrupt context, but not in NMI + * context. May be called while holding a spinlock. + */ +static inline void folio_put_small_nopcp(struct folio *folio) +{ + if (folio_put_testzero(folio)) + __folio_put_small_nopcp(folio); +} + /** * folio_put_refs - Reduce the reference count on a folio. * @folio: The folio. diff --git a/mm/internal.h b/mm/internal.h index b880f1e78700..3be8fd5604e8 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -451,6 +451,7 @@ extern int user_min_free_kbytes; extern void free_unref_page(struct page *page, unsigned int order); extern void free_unref_page_list(struct list_head *list); +extern void free_pages_nopcp(struct page *page, unsigned int order); extern void zone_pcp_reset(struct zone *zone); extern void zone_pcp_disable(struct zone *zone); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 733732e7e0ba..21b8c8cd1673 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -565,6 +565,16 @@ static inline void free_the_page(struct page *page, unsigned int order) __free_pages_ok(page, order, FPI_NONE); } +void free_pages_nopcp(struct page *page, unsigned int order) +{ + /* + * This function will be used in case that the pages are too + * cold to keep in pcp e.g. migrc mechanism. So it'd better + * release the pages to the tail. + */ + __free_pages_ok(page, order, FPI_TO_TAIL); +} + /* * Higher-order pages are called "compound pages". They are structured thusly: * diff --git a/mm/swap.c b/mm/swap.c index cd8f0150ba3a..3f37496a1184 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -106,6 +106,13 @@ static void __folio_put_small(struct folio *folio) free_unref_page(&folio->page, 0); } +void __folio_put_small_nopcp(struct folio *folio) +{ + __page_cache_release(folio); + mem_cgroup_uncharge(folio); + free_pages_nopcp(&folio->page, 0); +} + static void __folio_put_large(struct folio *folio) { /*