From patchwork Mon Jan 15 08:19:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13519384 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 169CDC3DA79 for ; Mon, 15 Jan 2024 08:20:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D9C26B009B; Mon, 15 Jan 2024 03:20:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 78A7E6B009C; Mon, 15 Jan 2024 03:20:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DBC66B009D; Mon, 15 Jan 2024 03:20:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4CF636B009B for ; Mon, 15 Jan 2024 03:20:14 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1E18916045C for ; Mon, 15 Jan 2024 08:20:14 +0000 (UTC) X-FDA: 81680847948.09.4497AB6 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf02.hostedemail.com (Postfix) with ESMTP id 388CB80011 for ; Mon, 15 Jan 2024 08:20:11 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705306812; 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=dG8Uph3MxPgeztE8KaFCXDmudyRrjWTnBrF4eOMB9HSQLZP6z6jIdcYyt64Ip5H+3+jYda 0VKISR6z3tmN29TpMB/DNGouUfJ+YixL8h5fhnpKzPGwpsh3Oc1CXjDdwAusIfTLmOxEe1 T22w3fmP9rOy0mz7/Q00AKE/HPTY4SI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705306812; a=rsa-sha256; cv=none; b=X+A0Vf0Kg0TH3Nmu7rVKMFjGvqIc4ADLm2obosTaciEhiQzK63QP1UcXE3ydhkluBWat9Z oKmDEIZWd8iSrtjxDRk79apvfNis6ttOEGgMux0qP3TSSYVbJwpG2oFcucTPM0qyXgmrTY +9bDn4sPcgPHZWKkqYdBRnzjXs/Qgwo= X-AuditID: a67dfc5b-d85ff70000001748-89-65a4eab45724 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: [PATCH v6 5/7] mm: Add APIs to free a folio directly to the buddy bypassing pcp Date: Mon, 15 Jan 2024 17:19:51 +0900 Message-Id: <20240115081953.2521-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240115081953.2521-1-byungchul@sk.com> References: <20240115081953.2521-1-byungchul@sk.com> X-Brightmail-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u0PBbv ecnksWlVJ5vHpk+T2D3enTvH7nFixm8Wj3knAz3e77vK5rH4xQcmj62/7Dwap15j8/i8Sc7j 3fy3bAECUVw2Kak5mWWpRfp2CVwZHdfZCv5IVRw+vpu5gfGHaBcjJ4eEgInEhmM7mEBsNgF1 iRs3fjKD2CICZhIHW/+wdzFycTALfGSSWP29gwUkISwQIfHn8lmwIhYBVYnOf3vYuhg5OHiB Bi07WQ8xU15i9YYDYCWcAqYS7z4eZwexhYBKWu6uY53AyLWAkWEVo0hmXlluYmaOqV5xdkZl XmaFXnJ+7iZGYGgvq/0zcQfjl8vuhxgFOBiVeHh//F2cKsSaWFZcmXuIUYKDWUmEt/rOklQh 3pTEyqrUovz4otKc1OJDjNIcLErivF7hqQlCAumJJanZqakFqUUwWSYOTqkGRvX/9/84uPN9 eJAfK+R/+bb8Bbfsb9eaXhVMvvw3UlknWe7jkliWlntncvxVLkmfl1NY09grNDWU/WmJ7uUU J6WJPhpfz/S6HYsPaGeT2154+35Lt2PSgpyJa9dkeMn/9w1Otk7fMrtuM0/Ij3mRS3fMKnst YPzwS6dvt66K8+QTU5ZOXHi2TImlOCPRUIu5qDgRALgW8+dpAgAA X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 388CB80011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: w6mh9d47ozpe5zoqnzswe4zn6m4s71n7 X-HE-Tag: 1705306811-494182 X-HE-Meta: U2FsdGVkX18hJXmrrAovllGvOuD6ZfeJY3bj8Wrc5b0oZj/VCc3zKMGvb5Kiz676AVNbvb716QvHukqv4C5Dmd8njDtyzrU4vntpp7qitsIbkMJnZycJ2Vmf5W4gli4nAnvKC8ibteZjT5qRfB8MXxYkKNYdp6cO7dfJJyewBTP90oiapw+ITKMuW47IEPpBRKMfIZoHJsxj/BmTqFmG2xVTzraq7iqbZSDWpMY7iMxEkjF4Jdu2QTtzr2I8uY9PSwJj48Y4z7PVq6JsCSPrImj4FfPTNS325pl11JyxmvK/tXjs5N6vRqHSUMBlupv68eylCsJlx8X7U51tFec8ZruxKMGu3ZT1W6jM6xn1Iv97OkFzPZZ6M5E8CvoNxekOSMdG8mQWJk/FLPvkrh2seN42EVqwlpS/OZ6WipR1E+7tB13b7cJpcrW2Af/XGBEomW0sJqbolGLFLiHO3xUR866YOBVFqP6O1qXTi2wn2k/nagl/NtI+qCNiMU9sW3Crd2V3QyXhnkFVNj0XY3gWfRPeo1qM5nvTGtsHog0kRAKt3BEqe/r/iQxd0e920Foy/IPs28lxAyCLVtFuPPFprtdtgWf6VOmCWOJS85bY8iFi6cdOAfqXXDUg+61DNg17knPWAkNh3lAHnilesrw+pF0QYSQTeRZmRYY43TKxsShP90UTLHcE/uVhqgxeDWhAm0uRMgYUhFA8Z5TJOhC0rqp/z55fRf+0dYE4R4aJsWUHmEp2V/0T+y6owjD8KLGxilf/ZDwNUUmpXdNpI5B1uFvi9ugtqHcJRJoMSHveZerth/Fx9Wf4SXuz/PvASG62nVMTimaDtfoX2OoBspP6s4VJIiRw5ojC+g22qY3lclUHzP9sb5rY8kJYGLnLnI8Fi7mBphDpuwVKARRU5KPISn6BEQ6oMHCzTA76Iyn+Fh/04BhR7y7y19UKGamj5mfSGYb+SH3v0P0PehCV6MM kVTtWTA8 +oNWO2ESYB48i5vNS6iuhbTulAQ== 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) { /*