Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1452879rdd; Wed, 10 Jan 2024 22:26:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9zX8Mvugsb4cFlu27V1rZ/u3CDz32VCSVje+Dax44h9FwARHxKUbxZRPYJvK0S7+GOTNA X-Received: by 2002:a17:902:d50e:b0:1d4:bbda:7c6c with SMTP id b14-20020a170902d50e00b001d4bbda7c6cmr688101plg.114.1704954395155; Wed, 10 Jan 2024 22:26:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704954395; cv=none; d=google.com; s=arc-20160816; b=wBmL3irqf8xE8ljsG8wo+5bRXZo8M1j6OhfYEjvUjD5X7mw5Q4HgIm3xg51Df6XEy5 Trj1Edkl+ETDUyDlF/xgRFe5bNjUlFpuvdcsYcjEvyqkPRr/0c9SPNGENJ2xmb2E+ioj Fy9mPNinGtExL3PM1kX+lxiPqc/r211ff+fIF485/HAFNofkkX/y8HsAWwpLTYUH71zX mRHtS2gVHdBqHklnqboaTLlbNu42//vkcn8LRUCCN8reO+7Urud9v+RBqWFmzKx2bgTj lW8C4p2839rcho91wH6xZwF73AsoUp+i42Cc7CsUqHKBs3koWwihnDH6Z6zuLWqJ0U6l lr6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=xyww7pMUuLyPBfG9ZuK6U6g9ZtqJWjn+tCNK2s25zA8=; fh=qkutryktk1+eA6li8Kr0a/P8xPDRQ0wHxGCKWFfNW0w=; b=NmMiiXn2G/ULEztfdhE+CrP2AXaBFrSEAh+Lfss/344xM4fZa8gh1RBiP296r8oTX5 C8FcbMIs3wfmdMhLklN0CfPrSI/ESZd0rTmBAPCfqBgwLHr7oeObSObOD/bIvfe26sZH Hlmjc9hpmjdZFFxIRnn1C1VxWITab/6dPn6jIBTEmxMmm0VRaorci07brJtNqPvTm2Ky FXUTxqghlrm/KE76S1s2LUZRrrYUUSmhNwQJfTucjx0Cria1KpHQvFyx2k3R2j0s4I/K fG8UThKulHJk68uR1DyjDugJMxCS77QDbrYRriqqmuSNJX9249udUK38C/IUs9vHPMxj 5aeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23089-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r2-20020a170902c60200b001d4910ff862si398765plr.309.2024.01.10.22.26.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 22:26:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23089-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23089-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 191FEB20B53 for ; Thu, 11 Jan 2024 06:24:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 536D7DDC3; Thu, 11 Jan 2024 06:23:35 +0000 (UTC) Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02C3D6D39 for ; Thu, 11 Jan 2024 06:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com X-AuditID: a67dfc5b-d6dff70000001748-f2-659f85c84066 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, xhao@linux.alibaba.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 Subject: [v5 5/7] mm: Add APIs to free a folio directly to the buddy bypassing pcp Date: Thu, 11 Jan 2024 15:07:55 +0900 Message-Id: <20240111060757.13563-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240111060757.13563-1-byungchul@sk.com> References: <20240111060757.13563-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRmVeSWpSXmKPExsXC9ZZnke6J1vmpBqvvClnMWb+GzeLzhn9s Fi82tDNafF3/i9ni6ac+FovLu+awWdxb85/V4vyutawWO5buY7K4dGABk8X1XQ8ZLY73HmCy 2LxpKrPF7x9AdXOmWFmcnDWZxUHA43trH4vHgk2lHptXaHks3vOSyWPTqk42j02fJrF7vDt3 jt3jxIzfLB47H1p6zDsZ6PF+31U2j62/7Dw+b5LzeDf/LVsAXxSXTUpqTmZZapG+XQJXRsd1 toI/UhWHj+9mbmD8IdrFyMkhIWAiMb3pOSOMvfHTX3YQm01AXeLGjZ/MILaIgJnEwdY/QHEu DmaBB0wSc9+uAGrg4BAWCJLo+VAGUsMioCrxrWkqG4jNK2Aq8WT6eyaImfISqzccAJvDCTTn wuFZYK1CQDWP2upARkoIvGeTmHVyEgtEvaTEwRU3WCYw8i5gZFjFKJSZV5abmJljopdRmZd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7Bh 386XlmErftw//++yc2zDdS8emZrLOjfeVl/LVelTebBgclSo0HLuloBNBnXJt5tsVX5J6f6p b/qnxFKckWioxVxUnAgAIn/9/1wCAAA= X-CFilter-Loop: Reflected Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.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) { /* -- 2.17.1