From patchwork Fri Dec 22 20:28:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13503793 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 1C1BDC4706F for ; Fri, 22 Dec 2023 20:28:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F49D6B0083; Fri, 22 Dec 2023 15:28:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A7056B0085; Fri, 22 Dec 2023 15:28:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7456C6B008C; Fri, 22 Dec 2023 15:28:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6203E6B0083 for ; Fri, 22 Dec 2023 15:28:18 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 32E18A0961 for ; Fri, 22 Dec 2023 20:28:18 +0000 (UTC) X-FDA: 81595591476.11.6CE56A6 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id DEA2B18001D for ; Fri, 22 Dec 2023 20:28:15 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="afe/S8DU"; 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=1703276896; 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=CNl8JiBcrmMmxxRhHcEptB3LlVF+8Q3ivYeCXLGHndA=; b=DQVbiYBYe7/3BS4yZcWwRh25Eo/D9h4werrreHo0tarqv+kSGdCR53bPXiAk9vHctH7333 vSom/126qmRpZ7AnuNosQ8ax6bwd4blxLfoaMNSND++eemApFYp+nmCk0W4xp9INWBCEDG tCPBZTUqqhxKywGnMvagKVHrT3dHZF8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703276896; a=rsa-sha256; cv=none; b=Q5MbpadfOytGV24uTkPG4eXSMdNhNJPfDMwhRFE/FRjHyEonCMZVsUi8ZpuWcPqMoQL6Pd AJrY4nsLE+CwEmwUXhp6/79JHyks+guiCqY/jm5v7QxMSMEmUAFHCJnPxeS23gaid3Qb0c InQqSspL+6W5I1+mgcc9Voy2BMPUqY8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="afe/S8DU"; 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 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=CNl8JiBcrmMmxxRhHcEptB3LlVF+8Q3ivYeCXLGHndA=; b=afe/S8DUnq6Dl27wo2+OPipbpi EjvSFraW6Oq/IFmlNqcahk8U4+D4sfPnCE4MEmhq9zFyVZYuS0pZ9GiSjwSLfjlX6++hvGBVOvH29 m19FcdxtnSknkqbqV9mdc8XMuNjonUuvjBF4DIebcV8MY0dbNBS/RqSJwGGTMgeeEzkkFJd5mQzwm 0shXyiaAcE7lwlcyITCY6bVCbXVHakc9IF2RAvGFnRzl7ndMP07jfvjvgqg9SLi35c5owb5HXBblo 8150lRm0RNIqv+zzpwG47BM4Cl4XfCAX28nP0EIcTPziSDgfnBGH97zDEjP0HvRwo83GBY5dsadby +i1mEgAQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rGm7u-008xbL-St; Fri, 22 Dec 2023 20:28:10 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Johannes Weiner , Vlastimil Babka Subject: [PATCH 2/4] slab: Convert __kmalloc_large_node() and free_large_kmalloc() to use folios Date: Fri, 22 Dec 2023 20:28:05 +0000 Message-Id: <20231222202807.2135717-3-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231222202807.2135717-1-willy@infradead.org> References: <20231222202807.2135717-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: 99er6ds8woye1b5o9t43ncayfiyuayg4 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DEA2B18001D X-Rspam-User: X-HE-Tag: 1703276895-472945 X-HE-Meta: U2FsdGVkX1+k0SPeoTEMIaOiFPU1UP+TwsniAYwQnsn8mnLTTLwQwPQaepQue4ZB9M6n3WPst/Z+Vv+Ucq2mX8xJ3HeXap95PPsuEpJWRrviGJbi5yBdu2UFtACHFqUOGP97/ChNmbcd6OQ8wIWFsXBcIAvXqm0/XTgO70d4O+KYaVlS7Z1Gla9/VmFHTXFBX/WWMZNtzdOhpVgSRZ64Tq1s7AC9a0jCuk4zb6TePVLSazt1KJgt2cnlrCA0y/sfOFUcpJcKiVqAUF9u/REsxxXiJH14+y38snLLNUXjOh6W/YA7Aex5VEA8SdMfjXXf4W1fEpbP1WcZ9PKYpVpQmJhwdb31fVDUxyMp6SRVtVYNots+9ZGuUimwUptrn3JTTjOqNhdMSt55zBxSDJNUtHbWYyyhALckeUmhQncaM0CGvAsMGFz7Lro4E211gVxx+7v4KkQUr5LWGQFQCyfVxc9hdgCyT0yf5YeW4zYeMqTMSX+aXMKla7jnyjFEOqINIqRpP2GRfNl25FBrGIgqhPbLuLoXxK1FNwrdttCTfq2bZoRIwb3ZmYX14Qn2UB2hEZ2ofXSnLjTX/zsNLfeFkZudgYBTqiAAmCl08ARl+KXuiwNGdqmjb4PsJ2+SUDZXLysRAcR4PP+FAtaF0aRYHoRkDAK3MNBV45T0Hf/QqwQIDczyoLd0RCULhxw3sfdH4EweZq0TrmwB3MzQ3oo9DiyDzRkn+48Ul7tyW0/OAOnSnioC8z9RRjOMjuXBFm/tS6IZ++VJz09/bnVxi9l8NfhZt6NotPnNIewRuEUept6NnWt1cm+LW16syrnNvUfgLXgLNjDUs2nE8bDlPR2BIYwCycDxCJ9wVamA1Fgugxdr7zC2lwYd0M1fA2x/AiZqnRptyr//gKHSyrbC67/A22kgOYEu1mpc32mjC17cX5I2XzmzP195X6UWG0ht9fkBLvsprAqiyqZX0hEVaUR h68EouKc JSOJmU9wi6IhG5N+unVKl9Ew4neFILT95y95Ihb6FLO5T+mnhN21/xdOZPFmv9PmeOf0TX9cmDjMP5/XFAU+PyXtww3YnhqzgjiFP0/o+95IkwSOlh+1bLLCGoQOjXj5PSYlft0402r42sTUc8kAoPOFn2aonOmo/fjtrkjrH85WRq2GDUe+vxpxiYqCS5MHPUvm2hm2pxyNjumAjwXRSLjjoziJNSea10Wfr 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: Add folio_alloc_node() to replace alloc_pages_node() and then use folio APIs throughout instead of converting back to pages. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/gfp.h | 9 +++++++++ mm/slub.c | 15 +++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index de292a007138..d56c1d7b5c5a 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -247,6 +247,15 @@ struct folio *__folio_alloc_node(gfp_t gfp, unsigned int order, int nid) return __folio_alloc(gfp, order, nid, NULL); } +static inline +struct folio *folio_alloc_node(gfp_t gfp, unsigned int order, int nid) +{ + if (nid == NUMA_NO_NODE) + nid = numa_mem_id(); + + return __folio_alloc_node(gfp, order, nid); +} + /* * Allocate pages, preferring the node given as nid. When nid == NUMA_NO_NODE, * prefer the current CPU's closest node. Otherwise node must be valid and diff --git a/mm/slub.c b/mm/slub.c index 35aa706dc318..261f01915d9b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3919,18 +3919,17 @@ EXPORT_SYMBOL(kmem_cache_alloc_node); */ static void *__kmalloc_large_node(size_t size, gfp_t flags, int node) { - struct page *page; + struct folio *folio; void *ptr = NULL; unsigned int order = get_order(size); if (unlikely(flags & GFP_SLAB_BUG_MASK)) flags = kmalloc_fix_flags(flags); - flags |= __GFP_COMP; - page = alloc_pages_node(node, flags, order); - if (page) { - ptr = page_address(page); - mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, + folio = folio_alloc_node(flags, order, node); + if (folio) { + ptr = folio_address(folio); + lruvec_stat_mod_folio(folio, NR_SLAB_UNRECLAIMABLE_B, PAGE_SIZE << order); } @@ -4379,9 +4378,9 @@ static void free_large_kmalloc(struct folio *folio, void *object) kasan_kfree_large(object); kmsan_kfree_large(object); - mod_lruvec_page_state(folio_page(folio, 0), NR_SLAB_UNRECLAIMABLE_B, + lruvec_stat_mod_folio(folio, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); - __free_pages(folio_page(folio, 0), order); + folio_put(folio); } /**