From patchwork Thu Jan 11 06:07:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13516784 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 B0D43C47077 for ; Thu, 11 Jan 2024 06:08:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F416D6B0093; Thu, 11 Jan 2024 01:08:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA1BA6B0095; Thu, 11 Jan 2024 01:08:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1B496B0096; Thu, 11 Jan 2024 01:08:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id AE5126B0093 for ; Thu, 11 Jan 2024 01:08:17 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 852F5140606 for ; Thu, 11 Jan 2024 06:08:17 +0000 (UTC) X-FDA: 81666000234.15.219DA8E Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf24.hostedemail.com (Postfix) with ESMTP id 9ECAC180019 for ; Thu, 11 Jan 2024 06:08:15 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.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=1704953296; 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=6ThMsOXQXb6s/prHLR2vPW/3wVbmvzphlfQrTOVXdQyYS9sMcyJQCOKs0FNHJtMnebUi8B 8mXBMoIFFr1AM5mRdXsKjoJKhJjlW+RssuGzzCsXcv+hyMeg6GGxEjpCu5Tx5KhVKty1DO +kYmf9sAIy7Fr5cmxT+wzzzEiZymZbA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.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=1704953296; a=rsa-sha256; cv=none; b=G9W83fKpt2J6h8Gbs5YQtwwcIlTs5X30TdrfrzQSK4CytyG7UniitEzJDP7a0cdGp4xo3G Tn6pSx3bg3bhCmbC7fCMvMVzgTt01sPdEYfOIKx6Y8cePHOOhY4xAo6XPZ3ZMMTol4fdBa 9Ah1XeuiBVQONsq2SRCVQGW2uo3Iv6o= 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: H4sIAAA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ePEjN8sHjsfWnrMOxno8X7fVTaPxS8+MHls/WXn8XmTnMe7+W/ZAvijuGxSUnMy y1KL9O0SuDI6rrMV/JGqOHx8N3MD4w/RLkZODgkBE4mNn/6yg9hsAuoSN278ZAaxRQTMJA62 /gGKc3EwCzxgkpj7dgVjFyMHh7BAkETPhzKQGhYBVYlvTVPZQGxeAVOJJ9PfM0HMlJdYveEA 2BxOoDkXDs8CaxUCqnnUVjeBkWsBI8MqRpHMvLLcxMwcU73i7IzKvMwKveT83E2MwABeVvtn 4g7GL5fdDzEKcDAq8fAavJyXKsSaWFZcmXuIUYKDWUmEV+HznFQh3pTEyqrUovz4otKc1OJD jNIcLErivF7hqQlCAumJJanZqakFqUUwWSYOTqkGRg4/2Rzhuw90Bfk+T1v7W0f0e6dAdrXB dqGD1UY9+ioSU2PeiTi7rewtr867bn+raY9J2UJt9fa9GtYbU9Zn//B1XNHrHqe50vUVv7Bh 386XlmErftw//++yc2zDdS8emZrLOjfeVl/LVelTebBgclSo0HLuloBNBnXJt5tsVX5J6f6p b/qnxFKckWioxVxUnAgAIn/9/1wCAAA= X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 9ECAC180019 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: trr7z934i6zput55crdrwgyqoqa3u5ut X-HE-Tag: 1704953295-512765 X-HE-Meta: U2FsdGVkX19EB7AKN6s5ByGXJC1z+8W794fGLCG3XgFNyvFXHsrcRP9RiRkPZIGM3rjWF/Mhla+izX7d8pr25ukmAcybSVBIS2JTimCnlj56ItJ6OE7KbebLze/Xq2escUAPvEY/dZ3uOoT/2SjZoHSGKc2rACkXcNLXDLMnkThU5LllC5QtKdu003asG2/AKFfTL+vsW0GegIzTd9c6uAKrLyFX4C6Vy/pvy23F4PNslZSPl5sX32JT3e0kLNJYvzr/RiOaxFmke1coy4vG63V8Ykes4oX0y4rw9Gx0QiTuDAlOtVQBhuWz1k82XqIuJGCXGxIdWmitNZviGJu5bmb1ie/asVq5s7iqtuSqCNDzU17MSilJSgO3VYmJIb8oei/lRA3ZS4OrJCSEHMBI77vUbIStQiYtbzczwWB6lr/VBO8/FyGGXS705PfLPDaVPMsJhccuZJJg2UHeJaOeIapnuCifefV3anUxpjszfQDjREeipIqFk8HzYTCn4hvqVvLxkkEXMf39ccRUdfAPkF6Cho2CbX7uA0VWr4kp22GJC5CdSzw3G0AQUHsD75R7UUG2FXw+Pv5KMVlBtujSAI3aM5SSmreFJBKnlFYc2OoJdhFwiQw6JfmTXIjeD5nHi9g5AtjSbf+7EgZiHruYqU4i+qTPxKhL7/UXIm3Xle41/WWXi7IfopASmZCvg7mIQaQ8YhQHg+V9fRr5wWEDOucW219k9qjz+q6zlfRMptNPsDY27zJ1CdTUS9jZTqHVQsRnt/RUJIiAGXPvSp3XxkJuzso8uxxe9Pgy3IQtAenal8puQH1a4etHOMWR8EqtqUClAWy5JBT0OEi5CazgXvpnj+plreIpGKou2FM+uRYPEDCqe4BkHN7zNSXpkZeRw79tyt7objX1E/MjWDNEv/MdwA8IKg6Tyw+wU9AMlte4w2U6jOQoNRXFAQhxxq+SFaiC038McUGtcQObPbx uolaKrO4 q5S5lYGMUdCytzjbBYnbv9llzNvhEdffjLnFnFtUBMrv+iHuf/6euILXetw== 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) { /*