From patchwork Fri Apr 5 15:32:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13619215 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 ED342CD11C2 for ; Fri, 5 Apr 2024 15:32:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FD0B6B0098; Fri, 5 Apr 2024 11:32:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75E3E6B0099; Fri, 5 Apr 2024 11:32:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FD826B009A; Fri, 5 Apr 2024 11:32:40 -0400 (EDT) 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 43FCB6B0098 for ; Fri, 5 Apr 2024 11:32:40 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0CEA31A019A for ; Fri, 5 Apr 2024 15:32:40 +0000 (UTC) X-FDA: 81975870480.29.5872111 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 65B7A18002D for ; Fri, 5 Apr 2024 15:32:38 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=IGObMDuD; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712331158; a=rsa-sha256; cv=none; b=yWcULIJTzvhrL7VjwPyvpAu4n0Nto7K8JaxJHNqihIxrLF1giJKZGtcgCw01yJpKb6mVyO 5Z43n7dAb8qA6gbdWMcQWW1JHR6T5DFF47QYAn8vGTdaWtatAW0zGcm9GIPljrGFZczwEQ X5XAFz4ePGj+qPhv1S5dmfFBJQqJlt0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=IGObMDuD; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712331158; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VeeeuX9ijoNo2EFoapFGaD6A7CnQ5h19HCUBd+GWV6w=; b=P/mYtDCp0XMiPIzZbUuUH+iR7FKZYyPbgqL6cqPxM4ubIvhNClYQVCAf87HxudxIxbQheB BcgIojUXaAx05s5lLO0rSeXsPlOwfu0RRHFx1UbTfjywaz8a33oqmra79Z4PmdIMFIXiZI gzSC7Fkf1b5Cm/N4MI5WEHUaoQMVnUw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=VeeeuX9ijoNo2EFoapFGaD6A7CnQ5h19HCUBd+GWV6w=; b=IGObMDuD+uxNH20lXJhTwH7aHj eeOY4eHlDcSDO//66+lmun4Y4s5Mnq7DzU/c5JlYn38gLzAhNQ1bd2nAr9XVYbwH807okV/yHJDRa dQWNxnUl1UTsdH1H5eGiob6jF/E1ocy9JsIU5cGGGRLorQzdi/9aL+Wj/8FC+uAFk+E/9bampXUz+ mSaTg0y80ZLkpoxDhMJSKBTKPYmm2+e4zY2f9HXfNuxz6hsH0/yEp1MCxoHqSmLMvUi63B2Re6991 3TU/xK6bocGEee3l7fdPyGbqpktmpCwoHOK7ZpSQ+MPhFuHuNBKS9h/k7v/IBwTeAcunLIb+nnK2c 5hA/UT2Q==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rslYM-0000000AkxB-06vu; Fri, 05 Apr 2024 15:32:30 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 1/5] mm: Free non-hugetlb large folios in a batch Date: Fri, 5 Apr 2024 16:32:23 +0100 Message-ID: <20240405153228.2563754-2-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405153228.2563754-1-willy@infradead.org> References: <20240405153228.2563754-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 65B7A18002D X-Stat-Signature: 61gckdp9cigt6einbcicf4supwpqa5sb X-Rspam-User: X-HE-Tag: 1712331158-645147 X-HE-Meta: U2FsdGVkX19Fm6XjeVvdMUZ78eJ0/p2YQ02qNwWAav/Z2+VQNoSQc2C164WUL+pGWR3VMIc6W9mnkcrDWhdS83mKFe62nuEUXn94yFhh3ybrmZDYq30v4PwaQ4xmC/M5LavbQvWDgu+ZlZUV4VyKyq3hfbYe1ABXkQ2/+ZtrHErqNxP1FP0rNygsZiZlf2D3TxADwzqYp9Nc0Sla45rek4/R11wfXFcwWiuqPo9X/17ULErvxXqrv6l7H2ODwYXEGeVnGUPpXD7+fcqKj6/G8Mpmme5a7fJ4reth/d84gpHBbGL8TnCdDUOng93hBeL/Ybagapm7d6Zvk30YFwIsNP9pAcaerpQUtXPjRT1mdiE0ao5psJlALON5DY5IBF2w3W5/EzeomGs4NXzuc5tiP1QqRB4CJXZdS6yb0+TByCaFClK/p0NAPtUbYi9FIlBxUa4WpDdmDRPvhXPRhEgZp9u1Kud/Yi39kn6IR1qFsQjYjz8wnS2OCx9wJtgiuwyLkwnWs+0ErhK4mTq8jXLAsgpyeb85x2FQlncamDH+8q2S67hQxkJ8y53s5HA/wVtE65xfOq9AkN6giLgNVuAgEpDK/9Mrci8IBdXj/anxmRuPXdEQ5N/6ldR7mMK0Wcn3S2RRCb/4Nx51m5I2Fv3d8pvWdnm0wX2Dwhon/ubJfSDRE7+ZXvClO6i9jjJnEHZ1bjSHOxogxmOqeLh8C/iIkBwqTqG2noxAevuF2xDMsVfTo2FGgKSl+DcmspjPpRffS/Cmo8aXkPrVFyrx1I5A/YggEU07FApy4CmxHGopNjIfYwu4QJJGRwtmNUVbcwBFxn1jvn+9M8EiB5Dd3gnLnZIWy0xNt9MDO8hX4xclXt8s0YW77j3+fBx0XVDEe7uv1d9AuB7QXenqrFXNtOBnzPGOiw/DxcJadfdyfiGgrXQKFz+dTwPEZ3p6MpY8y8MAGfswUWp2I1y68aDembR oGSevdq/ AY+V+ipOUOZEh1g7gjUmFfnwtMK8vTRATMmNSfWY52Nw69qzZhsPcRdJCJsZRgrMSITbXnRRrr8kUzmI0hMDNxkPZt6KlK0rkPzeg9sQJJ12JO8uJHBncrtJGqwxm87E/ZpWUKOkcH9BOoV8Tm+Hnx560EM+tcOoemP1Dke2ykwTPW+uJSvvQ/n1trg== 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: free_unref_folios() can now handle non-hugetlb large folios, so keep normal large folios in the batch. hugetlb folios still need to be handled specially. I believe that folios freed using put_pages_list() cannot be accounted to a memcg (or the small folios would trip the "page still charged to cgroup" warning), but put an assertion in to check that. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Matthew Wilcox (Oracle) --- mm/swap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index f72364e92d5f..4643e0d53124 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -158,10 +158,11 @@ void put_pages_list(struct list_head *pages) list_for_each_entry_safe(folio, next, pages, lru) { if (!folio_put_testzero(folio)) continue; - if (folio_test_large(folio)) { - __folio_put_large(folio); + if (folio_test_hugetlb(folio)) { + free_huge_folio(folio); continue; } + VM_BUG_ON_FOLIO(folio_memcg(folio), folio); /* LRU flag must be clear because it's passed using the lru */ if (folio_batch_add(&fbatch, folio) > 0) continue; From patchwork Fri Apr 5 15:32:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13619217 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 CC492CD1299 for ; Fri, 5 Apr 2024 15:32:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB1896B0092; Fri, 5 Apr 2024 11:32:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E13BE6B009A; Fri, 5 Apr 2024 11:32:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3ED76B009C; Fri, 5 Apr 2024 11:32:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A4ECA6B0092 for ; Fri, 5 Apr 2024 11:32:50 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6FF49C05E8 for ; Fri, 5 Apr 2024 15:32:50 +0000 (UTC) X-FDA: 81975870900.03.925E1B4 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id C42EF40017 for ; Fri, 5 Apr 2024 15:32:48 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LGDaBvzJ; dmarc=none; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712331168; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BsqG5grOKnH4ugNINXZJnED8tFK/8c8jG45dU6qaWfw=; b=7NyM9nzYR26m5kyueER+lYrtnBNh+7GmhpynUIMlzbiudW4Jc8pbxGUgcB6iDnKmL/GzE9 +YPuE46HsP3Nt3yi377kiR3A760rGFvlioAB+TAlhJ/QxxVDMwijlVLOah42p+Yrey24Dc lWtcZ9bz4x9gDYJSMiWIq9ygRkQnAqk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LGDaBvzJ; dmarc=none; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712331168; a=rsa-sha256; cv=none; b=cCI8IBh0goarUKkBynNzYyx4oFw0Hl9Rp0GhjrVP0GtlC5u6+D4xfQdHwmjga0c8ef+wQb 11J7Z2FYVJmj9vXLlLNXozcL0/UtgS1kN/HeX5YLnGotdUY1sI7QqKcJ+J/LPZByfTpDlo HStb03bsEmSZFZrpAr0a+OpuLB4yskc= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=BsqG5grOKnH4ugNINXZJnED8tFK/8c8jG45dU6qaWfw=; b=LGDaBvzJv8uWb0su7LvfhLMgMy elpO9+AF2Cfg64qXs531LpmgwjA4njlHr6cCFG6tGb9LblSH6gsD4hnPAHRJbHW8cx3+cRucWDm1o VmEYnmUcVMBBMpHEb4mGOJV544wfJ+GtVEVf9zZVUeBPzcf1cWyeb58+ieaNtPnpM4Df/+znu1FrK MAUKJ+44fenOhfMISljMRZY74ZVV/p9E8FBhpVB24vKiLChPYetkhATuuT/g8a0CYiW8eSmAnw8eJ YK8dI3ECBM+qlLvqeMiZqZPCz2TD0rlhPphGQtmtsG8fwfaQW20p73/bsWhwmTCtaF2jNc52QPrh3 KUKi/AWw==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rslYM-0000000AkxD-0STN; Fri, 05 Apr 2024 15:32:30 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 2/5] mm: Combine free_the_page() and free_unref_page() Date: Fri, 5 Apr 2024 16:32:24 +0100 Message-ID: <20240405153228.2563754-3-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405153228.2563754-1-willy@infradead.org> References: <20240405153228.2563754-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: z76sbpury1p6str5g3tcd9dpnkbxkp5j X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C42EF40017 X-HE-Tag: 1712331168-306591 X-HE-Meta: U2FsdGVkX1+0dnOoPy44o7Nfx5onDqNsqsv1kfbJDZU7IHqGrkpK/BTq1t4uCGbC/HxUTWc7ktO7xrjTsAcWTYiDJ2EfFA6fFGWzd1f2L9Bx6Wowxxbs8dQA2maQ35TCDE8wSheQZCe2pp/IMH5zxfBz+l8gmpEukDcziSb/F0NaRgY5OLMCCGnBUU0R+uuy4LpRj0sQ5OelexD4WIJkTnHCF4ozMuBHoW5Mu8Vlj0OdKWNh1Q4IEGlJI9Q2Gv0y/M6VnhhW5ZoOiLyp0P2gFN7b05bvKjhyq0jedBhdMRvg2CeCNSCACxh3YGxD3TcXqKMJgmnMZNdsL1PBuZDzFUbPN+P8vRZzHlj3BOEbbc9H4mmBkojRDSYUfvh2+fIb3z5MqexHHv4FJKMdP+jwNexrQ+sm5VQ3Hg/sBT8IH6rIU7B00NBUuK23Fs1dH2hkYnn6Lb5cLva4ljeprvWn+1FS4SmCqJjwSRcXRyYp6rq/XoVCAJXTlO+N3e6DH8NqG0KldFUsHIHKsRLQZFV5X08tn3f7TinZSEjjNtHdnZt96t2UCoXTLN5a7+YrupwQbn8KQ75PUjXbXqqZnXfS7QKE4AwdNqYHxLzX8z+r4jKmZByU1Kcojt/6rB1b68nTXuVPx8zS72cSGCXhDgOZy10ktUdOaxNhRORQdWG+hYuosqvJUhbCOAwvPOmC1AOqTBjkWwutQfpFvZcrN0aCyfF+hh5yQVi/QugCOEge4f37mj1KXJKDwX3fHrT67hnM975HHxoYyM1lz1o7ClS5kGfbIzG9K8VHtaPGbdN4VZ6YXXOPmQGDty9W848hpbYizGd1vyc8JEjLStzGwbghcLY4qkw8Aid+IXRpwWpCVxx96S4rZ0bU1Gs5excaBPNusJ5u+YWlU1k/kEnHnpNU2xkoykv8AIbbVgGntOJip4ecnb423DH6OSvEWy0as+LSb251HeuVd9O3ktiHHAO 8k4MR52l Urie6SkNnrezqGGbIij+mZjhFgTy8f3YjpJWXOwDBmpCB6txrvlzEgYbh65xiQvGIUCPUO/mKgajLdZTo7noHujB48nNAeccZQTblEkBsT+/VIwv3IReJbOvg5v9hqe+9SCPGnGb3xKphQLTLQ3ltUopmS9StGvr/DrEQTePC/7n7/lEeBn0IOhpqmc/66KjFIxpDNMnRh1RRhzMOsE4nJrtobuhHyhad1AGZ 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: The pcp_allowed_order() check in free_the_page() was only being skipped by __folio_put_small() which is about to be rearranged. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page_alloc.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 808b4b720834..8d255f18f6db 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -541,14 +541,6 @@ static inline bool pcp_allowed_order(unsigned int order) return false; } -static inline void free_the_page(struct page *page, unsigned int order) -{ - if (pcp_allowed_order(order)) /* Via pcp? */ - free_unref_page(page, order); - else - __free_pages_ok(page, order, FPI_NONE); -} - /* * Higher-order pages are called "compound pages". They are structured thusly: * @@ -584,7 +576,7 @@ void destroy_large_folio(struct folio *folio) folio_undo_large_rmappable(folio); mem_cgroup_uncharge(folio); - free_the_page(&folio->page, folio_order(folio)); + free_unref_page(&folio->page, folio_order(folio)); } static inline void set_buddy_order(struct page *page, unsigned int order) @@ -2614,6 +2606,11 @@ void free_unref_page(struct page *page, unsigned int order) unsigned long pfn = page_to_pfn(page); int migratetype; + if (!pcp_allowed_order(order)) { + __free_pages_ok(page, order, FPI_NONE); + return; + } + if (!free_pages_prepare(page, order)) return; @@ -4800,11 +4797,11 @@ void __free_pages(struct page *page, unsigned int order) struct alloc_tag *tag = pgalloc_tag_get(page); if (put_page_testzero(page)) - free_the_page(page, order); + free_unref_page(page, order); else if (!head) { pgalloc_tag_sub_pages(tag, (1 << order) - 1); while (order-- > 0) - free_the_page(page + (1 << order), order); + free_unref_page(page + (1 << order), order); } } EXPORT_SYMBOL(__free_pages); @@ -4866,7 +4863,7 @@ void __page_frag_cache_drain(struct page *page, unsigned int count) VM_BUG_ON_PAGE(page_ref_count(page) == 0, page); if (page_ref_sub_and_test(page, count)) - free_the_page(page, compound_order(page)); + free_unref_page(page, compound_order(page)); } EXPORT_SYMBOL(__page_frag_cache_drain); @@ -4907,7 +4904,7 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, goto refill; if (unlikely(nc->pfmemalloc)) { - free_the_page(page, compound_order(page)); + free_unref_page(page, compound_order(page)); goto refill; } @@ -4951,7 +4948,7 @@ void page_frag_free(void *addr) struct page *page = virt_to_head_page(addr); if (unlikely(put_page_testzero(page))) - free_the_page(page, compound_order(page)); + free_unref_page(page, compound_order(page)); } EXPORT_SYMBOL(page_frag_free); From patchwork Fri Apr 5 15:32:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13619213 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 330AEC67861 for ; Fri, 5 Apr 2024 15:32:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE01E6B0085; Fri, 5 Apr 2024 11:32:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A69736B0096; Fri, 5 Apr 2024 11:32:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 909D36B0098; Fri, 5 Apr 2024 11:32:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 71E426B0085 for ; Fri, 5 Apr 2024 11:32:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 32373160161 for ; Fri, 5 Apr 2024 15:32:37 +0000 (UTC) X-FDA: 81975870354.14.70C5527 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id 6A69680027 for ; Fri, 5 Apr 2024 15:32:34 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gRINT0Mh; dmarc=none; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712331155; a=rsa-sha256; cv=none; b=mVBFDfIWa38zm2ELUYZ8N2QnT/gJ4+hehzgKCFYKGUpNIS/6UIZ5mo+iQEGtshocPlg4Va oJjbWuhafu0q0S03gtPkZjlFjIPC5Yg3qXduiuZzgUwJP15mLWGuE5yCE5BJ3XOqGcSFlm ajMz6+rauGcswhDPXCaEiqaYcpLQtHQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gRINT0Mh; dmarc=none; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712331155; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=m0vyIh5uB6p22xAiJJA+OgJNMzei5CA7Cs4sH8v9iE0=; b=jgmJRRC54QBYM/EUFLv8q6qrAAve7P8xHtgddYmMRJggTBuWY5tzYrwbIIh4tXuKUH8Ghn jD2FRMRM2GYh/PH+ikUguHNm6uQwTwqW4l87t6EVpzJiSZX/9DqwkpGFt2aK+TmQfTdtUE ne9y5wtMK/uEu0JnwBtAeuQ1Ts5x1uk= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=m0vyIh5uB6p22xAiJJA+OgJNMzei5CA7Cs4sH8v9iE0=; b=gRINT0MhFOnUzvWURQjUA7sRPJ PPyn5O4TmyrN2IHtXMOB6tnvGAo71940Oy5fc1rBosDuKTKoVDB5HwM/XbHKn+bNQ6qdp11Afs8Ck TrPsNCT8i/eHqEXe/N/dEH/fwB5RHKEd3iw1ovnvCLwI6sIUYJAQFyYFgFmDssZpSY9JHnUjxezpd 5kjfeC8FRdSgenlTCtPuj6i6yRYrim5wavDLrlkNOaaV8hYgwoazovoR6o+1eNkboODKVzZOof2Z+ Q8TkgeGushIgKbgc2v6WxCob9DGnx+uYLi7joxbtDsZdzZ4V0mDCmxzEiRHhRZ/2+7Mixi1GEt7s3 0pBzTw2w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rslYM-0000000AkxF-0pSL; Fri, 05 Apr 2024 15:32:30 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 3/5] mm: Inline destroy_large_folio() into __folio_put_large() Date: Fri, 5 Apr 2024 16:32:25 +0100 Message-ID: <20240405153228.2563754-4-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405153228.2563754-1-willy@infradead.org> References: <20240405153228.2563754-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6A69680027 X-Stat-Signature: scj4b3oqor5auq3sq4zu3yo9jqzipsxf X-HE-Tag: 1712331154-859358 X-HE-Meta: U2FsdGVkX1/lIsnPK3O5buk3B/1c7RY/M4Qwjon+6GV1EXXVI4wsM6W4aDOAo0Lw08ylrDhtVilM+KUmUKmEfmmN6kBosZ8L1Rw7gwNb6/kQAltxQKrrWZQAT1+3j6kLFh85xRRXA/KhRFq5F7hE0kK3VcX4vgRfFOwpFfhhFkCnjwpJFxe+S/3fpUfOGaQCgvKpUue1izp8DI1aXrZJeb2JX3pbxFfTOZ8PLiohApAdbxvNgf3cVKT4fZ0lG25nl/+j4+mOvMiOibohv4dceH8F/2GG+6rtWOXk33kvFu8kRMrnMJEq77DSyK+C4VWJrtIBxbvilgWg7pGpNp0XIjs7RBI3kFa3hVbFkFhHCqCTkvj7tK/jmWKvV+v8zC66emNP84zEJ3S66U4P46LUAqKKDz4ZWs57yHDJ16mR0NdfZFVP0vza7OsKdOTOjUTZ/FbTHCqFYb3kdhfvW0sfGzdVjjkZNRrNDyTX21fus3oiHrQWgPpdFj90bB2KpgH12DcDSuyg+DLm1Qh1Hg2Lq+nQCaBRcQU26WratOD3DulGUlMn1h/md4usg923J8Y1koaJ8VBBrNCkqfuj9rTEmtL6AF8mUovIOe14iYamZ9lzRGpUayA8tLGd72PlpzhjduT9PV/4SNFBOWs6rl+wvN/5+AsFuJuC7RW+wZ+dXDna3CBpOrd48oS4azRkXxQAMftLazCEeHQMiEXZo+A1Y9OWqke2A9KgKRp4fHPY0HzK7jJIoUugeTD9ezgY1xMxfsomsMvMaUU3gaEzCgBE313eRpJ+uro39ddsdXF2j/kCVB+Xdp+6/XNRMldpu6MpC4cYCvIJ3KRTfRxWgkNjvdC7noj4X+zlN7LiXoPdB9YFiuaqnQ2Ri6uJ16b6mCsWrvOppZahnVpldwQM0XEuROOopgf0i3XSDyQ2DpLgO6S6IdLkcY2t9W5PBGBrwksWuUagGEK698Sk9Ob1vDp ZWtABEEV 6aG232UmbSPnn71qAQ+pNJ53fRJDqCv2wPkbPpGZaJ8aZrgqEK4sAqeonIum8zpUL1lLx5nRuhN6iRjjKsldXvqoILgQfWcuMKNgrIrud77tqoEEvIwqO7rQxjyu0w3u9XslSXJbeiEXkqFWBb4KhW3iVahgi/H3Pw4obeXEYUpdWpvjljjuKy0bcU0XqjNwycyAASikmwR7WkeoURNBMiHjJUiqk/+GIT/hj 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: destroy_large_folio() has only one caller, move its contents there. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/mm.h | 2 -- mm/page_alloc.c | 14 -------------- mm/swap.c | 13 ++++++++++--- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index d7d311d13712..b9173e230804 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1318,8 +1318,6 @@ void folio_copy(struct folio *dst, struct folio *src); unsigned long nr_free_buffer_pages(void); -void destroy_large_folio(struct folio *folio); - /* Returns the number of bytes in this potentially compound page. */ static inline unsigned long page_size(struct page *page) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8d255f18f6db..171b7863868e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -565,20 +565,6 @@ void prep_compound_page(struct page *page, unsigned int order) prep_compound_head(page, order); } -void destroy_large_folio(struct folio *folio) -{ - if (folio_test_hugetlb(folio)) { - free_huge_folio(folio); - return; - } - - if (folio_test_large_rmappable(folio)) - folio_undo_large_rmappable(folio); - - mem_cgroup_uncharge(folio); - free_unref_page(&folio->page, folio_order(folio)); -} - static inline void set_buddy_order(struct page *page, unsigned int order) { set_page_private(page, order); diff --git a/mm/swap.c b/mm/swap.c index 4643e0d53124..4cfb98304742 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -127,9 +127,16 @@ static void __folio_put_large(struct folio *folio) * (it's never listed to any LRU lists) and no memcg routines should * be called for hugetlb (it has a separate hugetlb_cgroup.) */ - if (!folio_test_hugetlb(folio)) - page_cache_release(folio); - destroy_large_folio(folio); + if (folio_test_hugetlb(folio)) { + free_huge_folio(folio); + return; + } + + page_cache_release(folio); + if (folio_test_large_rmappable(folio)) + folio_undo_large_rmappable(folio); + mem_cgroup_uncharge(folio); + free_unref_page(&folio->page, folio_order(folio)); } void __folio_put(struct folio *folio) From patchwork Fri Apr 5 15:32:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13619214 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 AF385CD1284 for ; Fri, 5 Apr 2024 15:32:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 450B26B0096; Fri, 5 Apr 2024 11:32:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D99A6B0098; Fri, 5 Apr 2024 11:32:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27A6F6B0099; Fri, 5 Apr 2024 11:32:39 -0400 (EDT) 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 0C7EF6B0096 for ; Fri, 5 Apr 2024 11:32:39 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D0775C03B9 for ; Fri, 5 Apr 2024 15:32:38 +0000 (UTC) X-FDA: 81975870396.12.DEEF9A8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id 2D2DE140038 for ; Fri, 5 Apr 2024 15:32:36 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OeSXetSY; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712331157; a=rsa-sha256; cv=none; b=Lbg4nX+R6OmTMdApEbwt1t2lv49oUQB9SC84Hgh37Ylg9Vr36bMWHTIiYdVykgH/Qbh838 0lCYrPyqbN1Dgywyo9saSWjGtkrA5P2fDCKOBohjya9dgcyj9e3ZjaiL8SoBjITzWJSghd 2fz5Kz4jolDQ50L8XwRATvXDgQO1e2E= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OeSXetSY; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712331157; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KZzCy3yNnx6XbjQUrLV2VOUZ7g9S+C13lklXEbnwNVg=; b=FX8kNCUL0e0v9+l2S8XpO9zNKxoI78FT4yjcbnGdMEMrclv9O0ZNY2nBBtlR3jGXTj1PZT LrEBipuVkRuqJpfY9GuRDlzyjvoQGwyReY+HjkB1dvYrczMf0Gbz/yDBksbW0j/S+3jmU6 MNIIRcCXewUvIFqWw8GIwnTzCxwaEh4= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=KZzCy3yNnx6XbjQUrLV2VOUZ7g9S+C13lklXEbnwNVg=; b=OeSXetSYwJHJl6y3UtpgKUmliJ wq6ROJlZ8xHZevc33YgYYTAUnwr2SpkdUxP8djPFV1SiRHEsapJF+zx7Hu3XQP8qfQbCOhon9F1do mmZBzR8rtD35oG1ByCE8RRfy2pfoQq83wMPf7M+anij+o+6U/ljzqgdhbVJwMV6VvTZeXA4kPmFgr Oz9zqidLKs3tg3A8uGjQk4UeMnylpClNVp4RqDXjRQP2+U7NzWuC0OfIWnxFiUqYCBsWBYRLfdLIO SM9BKBLb0GM92cbH0IBrDc+HJsUPYFk6v27vmZvMdeh4lQb2da+wexTvSzPZmdqECcnfjlBgEXl7k PlpLpoOA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rslYM-0000000AkxH-2ZuN; Fri, 05 Apr 2024 15:32:30 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 4/5] mm: Combine __folio_put_small, __folio_put_large and __folio_put Date: Fri, 5 Apr 2024 16:32:26 +0100 Message-ID: <20240405153228.2563754-5-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405153228.2563754-1-willy@infradead.org> References: <20240405153228.2563754-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2D2DE140038 X-Stat-Signature: c813ikdx3pr515w491o9jdtw1cybc88f X-HE-Tag: 1712331156-31558 X-HE-Meta: U2FsdGVkX19ArANV9arlc45D1ilpGS0fmHROuFFEFgGSgm0O3FtpvEFtN31JOTAAyiUK0C0247hVCx0gg8bXEb7Y9bt9REq1E/SL2585HsBFdE6PJjFRMkhgh0eOYRHoUqDp4d7ugjww1LgLt8iEU8EioFOj1GkN5mLZqR7M2AOjkIncymPKWThIHbggxllRxEJGJTQzc87OyL8jiDC6G8vuqyrVBZmyttlBzX93iKge+sA9lYjXP49OQqpm66+hwe56JEmaWe3Qjma7ZY5yNInX/w7520hDb1ZWG0mcdhzlFRepMZnQsL5A/ZtQed0szEQ80NuSUAS2exEH452ynS5fr+N9e/nQd7szB0CIt0Lcj556DqTC70qLevF5NjNAX5R4tK14Rmj7n2JRsFJDFdq5VyOffqjcL8X9+pyghQXVMCgFMna66R0jdHC0EgRBo+hGI9PvPO6t1qh9E/FTFxvi12uGEVrp5Ei2KZFN0Z/h8QHoZyIOUkwlY9dWEUzdC8OKpiVNLq6p+ecL2f7EXAAtvC7gX5IjBfT7ilhxlAOBPxF14GwSqwN8iGa+mOzqvYg1dBmdYZ0ZQnJ8jk232M4La0mhLqXsXgYFeE1ztdjwtH3SwxkP4UHoB/xEEYvvxU4WvdlvJgc97gAGvaEMKnbUXBUwPIKUqbxYhSLOG+29hJYgiKVEx95gOBQPR+AQrAru/ynmooy2KKLhO8kfjMLIW6tH5sY/Yp91FgCa9cddN5AZl8t0No+24HyCqiSED6m/B/UFdFXuXf3HZ450HDW2I/9AwyTP4gXdxBNDl7/ZDbNIRD7Npe5kEW2HA3baDUnzatB4njZw5U3IX60ff1gjffASoYapa5IOVZxAhlpNmZeLjTY594KzYuAE61VNNV1vqB0ZjQEvNvgeVbYffYB1A8dlWmWwGu2vLed4jX9gbM8+tSiTsxttVDepdWqAa0y79Gg+7uo5hFKSAHw vgw2amQZ bx6+e1WnXdU1wxtcOp4OdWHUflRV9UGZjhF9wnFjuumszrLwajKf4dS4C6C6eOEOrKHR2Yk/MfC37L1iXdZOuyery/7wRGdhpP8LbhmFZSMZSsObXRv+2OifHAIrvjCZEFxcwI//E1o3gdpudQ+A7SZI7CbPHqctWL5zfvDbWuI5rjfCLAdwrbZHhRcNNHw1iRpLTm5pnQyBEE9kzEhyOzD3CLbCQQ66O+xYO 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: It's now obvious that __folio_put_small() and __folio_put_large() do almost exactly the same thing. Inline them both into __folio_put(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/swap.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 4cfb98304742..15a7da725576 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -112,42 +112,22 @@ static void page_cache_release(struct folio *folio) unlock_page_lruvec_irqrestore(lruvec, flags); } -static void __folio_put_small(struct folio *folio) -{ - page_cache_release(folio); - mem_cgroup_uncharge(folio); - free_unref_page(&folio->page, 0); -} - -static void __folio_put_large(struct folio *folio) +void __folio_put(struct folio *folio) { - /* - * __page_cache_release() is supposed to be called for thp, not for - * hugetlb. This is because hugetlb page does never have PageLRU set - * (it's never listed to any LRU lists) and no memcg routines should - * be called for hugetlb (it has a separate hugetlb_cgroup.) - */ - if (folio_test_hugetlb(folio)) { + if (unlikely(folio_is_zone_device(folio))) { + free_zone_device_page(&folio->page); + return; + } else if (folio_test_hugetlb(folio)) { free_huge_folio(folio); return; } page_cache_release(folio); - if (folio_test_large_rmappable(folio)) + if (folio_test_large(folio) && folio_test_large_rmappable(folio)) folio_undo_large_rmappable(folio); mem_cgroup_uncharge(folio); free_unref_page(&folio->page, folio_order(folio)); } - -void __folio_put(struct folio *folio) -{ - if (unlikely(folio_is_zone_device(folio))) - free_zone_device_page(&folio->page); - else if (unlikely(folio_test_large(folio))) - __folio_put_large(folio); - else - __folio_put_small(folio); -} EXPORT_SYMBOL(__folio_put); /** From patchwork Fri Apr 5 15:32:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13619216 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 BE916C67861 for ; Fri, 5 Apr 2024 15:32:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 514826B009B; Fri, 5 Apr 2024 11:32:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49E776B009A; Fri, 5 Apr 2024 11:32:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33DC46B009B; Fri, 5 Apr 2024 11:32:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 110356B007B for ; Fri, 5 Apr 2024 11:32:45 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 347241C1548 for ; Fri, 5 Apr 2024 15:32:43 +0000 (UTC) X-FDA: 81975870606.05.266EDF4 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id 574AEC0015 for ; Fri, 5 Apr 2024 15:32:41 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ff3mvM2X; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712331161; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FDx9UCg5WPBsMvmDckuQZC/GRK/EaUAdzC0qPoe/GWg=; b=UySJKeiPyJ/fj5+hiFWF0FULuJIb6zRghL/fHnh1zi1tmBRnJ0YGUoCoYT2XYuKA3t+9vF iez0RhZkBsKIxzPROzj/go0Mpl4J6vbfpxB/p2uW2633rWMtvmb7J27Q4yatrfcQMgm5Mr A1KQv7JcgKLRUd5qRngJqtXIZQT7yKo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ff3mvM2X; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712331161; a=rsa-sha256; cv=none; b=sCXh1Ru677Q0L/lXFmwtLVxNzqjSmU9u3qSOKJRHjiWI49KM9IRaU4D5ySBGL4c6IPFt/2 DeNjXBKhKYjZAFeLsddNMt+r43BNkIwogSMLQAAy5Qbcco3iP+HWLKdutzXokF5t+lmlSP nF8JpfX/Md1dcXAiJ5OtqP2LiWN3Zm4= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=FDx9UCg5WPBsMvmDckuQZC/GRK/EaUAdzC0qPoe/GWg=; b=Ff3mvM2X1s6PGIYniozcTHGyhV rS2BEuaOFIV+QTXarI7ObJ1WMZuZrANMBAsr1xVjKUe7PNH9mlxfd6fvEDpOj0ao0j4CU5d7LqtP2 W5JrwBl9C6qK3F/q56zhlM04i/ZEbqs1gdPK19RdllP2NxulTxZtw68fCT9S1izYrOFhqYmzit/jf x+zNSkp2dLSlpnhizeSvyJ6sJHr1XnKd6uOZPhdwS9GVJLbO9ar4CRRQkwxIh+51ocT9jKf+6HmR+ Vw6/4oSTenT+Wt5TX/J1CHlruN9ja5eJFg0O+xJCMvbd6GFnV7lteDPYdDG/svzOD0HqUo8vSRmru dh2bEz1g==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rslYM-0000000AkxJ-2uzj; Fri, 05 Apr 2024 15:32:30 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 5/5] mm: Convert free_zone_device_page to free_zone_device_folio Date: Fri, 5 Apr 2024 16:32:27 +0100 Message-ID: <20240405153228.2563754-6-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405153228.2563754-1-willy@infradead.org> References: <20240405153228.2563754-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 574AEC0015 X-Rspam-User: X-Stat-Signature: 74hc8bswhcms3ibqzhj9j4zmke5khipk X-Rspamd-Server: rspam01 X-HE-Tag: 1712331161-359400 X-HE-Meta: U2FsdGVkX1/DqCJvN1lzEyMHy8NxUCmllFqcc2K/9eovCqGl2DBPOVVzn1xdoUr1yhU8gof4psdy+eBaX1VpAJ+mCT9CKgkpDOgTfphUfh7y6GZUqfQ7FQ6KDgPzYdCSjCUS4uXujCU2vbCdHmXiiX0xncOdlclsR6Y86sG+w3h5uDgFbmq8O/9pFHwD/UPulXdgd6Mg+ZUcsqyIb9a8u5LTpAAZJJ4QE7AlN/iU1Du4e2FuForOMyTUBhPSvzT88rvXEVvENM9dDLX5fseoTIqYxhH6LRWMrhKOuMm76QU8epeDhDfAKcu/Wgb9qIHBv4f6jmpZffz757T15VG1MjnshsAGtGU6R7F4Of0EEdyCMeFyKr8uPoeBz3U/WcLJ/1RQEaCBKk+fH8RR8LzAmWP653QebzTagQbwDl6gjO5mNN/pZafylTgsyteui+T6SAGDtE6DRN/IKIkq59dtsIpUTazx6eTvkNK5FlHOu8OZtddUFTWfb1nqtftZNdevymos+EO1qPmQbi8XsGGOOuJCq2+FXFWKDERByL4lD2n+dZrmdWKdOvW45QXWbJiQ6GKNOAT2nrKR6npcDPlfgQ7OLSnShzJhUS+XIX2GYetfys/bsA1cskuZ8n5faTXeMBwrldJjRphEWojIChkH7Sd5FqReRCCg+TNolG938Uo0Dv6iRHAkHA+xe+6sZzGe5jmRAXVLduUP7MBvvfRdFgYuMSleMQt2H6rGuu6+59uIEsvzFhAXvXWhwQYlIKBmrK/eLarS9sp+WS4BONj/PJapHPMLrxTpHax5AyuD/BUU4JvzNO62Do/2A4VCxs48wkZPTj+wXKVjZqIhvfX1mWdpk+WJM3x9IwI1Rs36kCjnFtfJraTKCTrZmrjI8qfJunqTw4EgSIRq+wtyveVSC+8lliE9wOR65gQ8fCNZJ5ycp56c4SnyWp6LJezk3aBzr0PvX07YfH6O/nPL1dk /dH2Jeps c4ah2MANGV2o2NemTlkAqBwdcdqMHk1HaMLmaE/dFopj9gbwcyYaBQb0hKVQ0kB188ujRH+N61jAuFa/REUj0r7bfsoWMwwQquvCBc7nDTOOOkHqp5wFhkBSN/1q6Mcq3X1auB/156XxyrbiZ/YupADHGPdOsOwgtzqIVMqyGIS/Kz/m57I9dWE79pKa9pWWAsfzkIx8vphjU0ZzCnfEqcs+NjaGhxoHgF3Z1 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: Both callers already have a folio; pass it in and save a few calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/internal.h | 2 +- mm/memremap.c | 30 ++++++++++++++++-------------- mm/swap.c | 4 ++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 56eed0b6eecb..57c1055d5568 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1149,7 +1149,7 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end); int numa_migrate_prep(struct folio *folio, struct vm_fault *vmf, unsigned long addr, int page_nid, int *flags); -void free_zone_device_page(struct page *page); +void free_zone_device_folio(struct folio *folio); int migrate_device_coherent_page(struct page *page); /* diff --git a/mm/memremap.c b/mm/memremap.c index 9e9fb1972fff..e1776693e2ea 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -456,21 +456,23 @@ struct dev_pagemap *get_dev_pagemap(unsigned long pfn, } EXPORT_SYMBOL_GPL(get_dev_pagemap); -void free_zone_device_page(struct page *page) +void free_zone_device_folio(struct folio *folio) { - if (WARN_ON_ONCE(!page->pgmap->ops || !page->pgmap->ops->page_free)) + if (WARN_ON_ONCE(!folio->page.pgmap->ops || + !folio->page.pgmap->ops->page_free)) return; - mem_cgroup_uncharge(page_folio(page)); + mem_cgroup_uncharge(folio); /* * Note: we don't expect anonymous compound pages yet. Once supported * and we could PTE-map them similar to THP, we'd have to clear * PG_anon_exclusive on all tail pages. */ - VM_BUG_ON_PAGE(PageAnon(page) && PageCompound(page), page); - if (PageAnon(page)) - __ClearPageAnonExclusive(page); + if (folio_test_anon(folio)) { + VM_BUG_ON_FOLIO(folio_test_large(folio), folio); + __ClearPageAnonExclusive(folio_page(folio, 0)); + } /* * When a device managed page is freed, the folio->mapping field @@ -481,20 +483,20 @@ void free_zone_device_page(struct page *page) * * For other types of ZONE_DEVICE pages, migration is either * handled differently or not done at all, so there is no need - * to clear page->mapping. + * to clear folio->mapping. */ - page->mapping = NULL; - page->pgmap->ops->page_free(page); + folio->mapping = NULL; + folio->page.pgmap->ops->page_free(folio_page(folio, 0)); - if (page->pgmap->type != MEMORY_DEVICE_PRIVATE && - page->pgmap->type != MEMORY_DEVICE_COHERENT) + if (folio->page.pgmap->type != MEMORY_DEVICE_PRIVATE && + folio->page.pgmap->type != MEMORY_DEVICE_COHERENT) /* - * Reset the page count to 1 to prepare for handing out the page + * Reset the refcount to 1 to prepare for handing out the page * again. */ - set_page_count(page, 1); + folio_set_count(folio, 1); else - put_dev_pagemap(page->pgmap); + put_dev_pagemap(folio->page.pgmap); } void zone_device_page_init(struct page *page) diff --git a/mm/swap.c b/mm/swap.c index 15a7da725576..f0d478eee292 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -115,7 +115,7 @@ static void page_cache_release(struct folio *folio) void __folio_put(struct folio *folio) { if (unlikely(folio_is_zone_device(folio))) { - free_zone_device_page(&folio->page); + free_zone_device_folio(folio); return; } else if (folio_test_hugetlb(folio)) { free_huge_folio(folio); @@ -984,7 +984,7 @@ void folios_put_refs(struct folio_batch *folios, unsigned int *refs) if (put_devmap_managed_page_refs(&folio->page, nr_refs)) continue; if (folio_ref_sub_and_test(folio, nr_refs)) - free_zone_device_page(&folio->page); + free_zone_device_folio(folio); continue; }