From patchwork Mon Aug 21 20:20:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13359785 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 45D9AEE49A5 for ; Mon, 21 Aug 2023 20:20:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10DA494000E; Mon, 21 Aug 2023 16:20:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BD4494000D; Mon, 21 Aug 2023 16:20:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA06E94000E; Mon, 21 Aug 2023 16:20:26 -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 D028B94000C for ; Mon, 21 Aug 2023 16:20:26 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A4152140CD4 for ; Mon, 21 Aug 2023 20:20:26 +0000 (UTC) X-FDA: 81149229252.27.B63D9D7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id EE3E9C000A for ; Mon, 21 Aug 2023 20:20:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UeWDfgiV; 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=1692649225; 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=ftMoTpPKDvJHF3KGIoW6evnR7Kcy68rm/mSseTTxyDE=; b=J5JeO0HaqxfaU6xS++7kIDIJIclFo/jzxvZbLRXWVAtrOSSRoWyI9iDXghY65DX6CUuAF/ pFvTCmyCxcgZh3jblzKabWLSsg5EWyMxLTYchc25qdx0T48GVSFRtchO9cYQ3e3vrlMwJj Tptc2+jarkKXfgVdHsL5f5Q+YoPs8nA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692649225; a=rsa-sha256; cv=none; b=Zl/IxljmIF2khb3pJz4U/Pl26p7kilOAD2xpG++o/dBkDytvoyBGI/tSFdmCsA40kvwDC6 iv6nDoUnoCqWH9sq95QwJOwb2jXFdruGpaba7hx8ESBj8WYOn3S3FOtA10MNuOAP6Zv+bL 6B+qnEXDWfMed97snn2GctmRR+7dNto= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UeWDfgiV; 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 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=ftMoTpPKDvJHF3KGIoW6evnR7Kcy68rm/mSseTTxyDE=; b=UeWDfgiVvfANwzOmWZAyMTV5dO PtODFzfq5fwt4KNX841Xw565F2ny38hCVRGqSFXTetiJvlP4NauQmuhso+HMwmUJ/5l0ACV4cP40O vbfJ6MWPWeP5oQ004FdUXRizGoZ8RNh8d1Uk+y+/qEJ4JTqmDRRqz/+nrlGttzhIAV0Sf/mjtGMVn +LXUpHEU+FeFspMvpWqu9dpAtPqli3bfXKZCVMi5MXgoh9DQ8FHwWGNlcaX3bNtpzDJW9cCTdpphr mmKeRz3hSoROk6kcxQM+bMmhsT/ke8RGpBF4DgJKJuuMn/kWpCvaSK6c0jbIC025wcVOXzXwf8NmC HPEzDciw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qYBNq-00CD6u-DU; Mon, 21 Aug 2023 20:20:18 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-perf-users@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com Subject: [RFC PATCH 1/4] perf: Convert perf_mmap_(alloc,free)_page to folios Date: Mon, 21 Aug 2023 21:20:13 +0100 Message-Id: <20230821202016.2910321-2-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230821202016.2910321-1-willy@infradead.org> References: <20230821202016.2910321-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: EE3E9C000A X-Rspam-User: X-Stat-Signature: 8r4pfddguob8okr5rk4crhzczcwyia7t X-Rspamd-Server: rspam03 X-HE-Tag: 1692649224-223076 X-HE-Meta: U2FsdGVkX19/pybOjwkJd65jWu8Tm6a09wLDkZfKjmuEcva3NjTeKUBc1l0A2reI908KbirvJrzX+jLNvrV9+r0cAk/omsvFg2lmM0Y/m6eELxWaT8usHSqcY7EMsjh8XucOt5c3kwK7LOnmL+F7IeldEJEenPg4Mholr6SyhQY8EkJP54NAUqbWSk6+2G/uhVgSO+efsgqEnU4V1s8dho2Utz5eMgBDu4XWiWdPHOpRpmMLR9Dk5JKaUZHlqZykg+Acma06UjwbC69qn/WhYsJUdnTSiF0YK2s8u0B6JUons12RzaZWqmvLCatWJ/+si6ID/ZTb4cpjYi7N9Ifh9VftuKFbg/4lZvbO00aPM5E4DP6Uxf+WYhzjiyAIPSyr54J7pBD5l3XY7Rw8GPeJoCps83VPNS0z2vfLA1SaZqRWFj9gTZIGYqC6RgD+2yjntIEZ6dv0foAvWSRyKqs1/4zElbXpyOnd5jg4AIFukrZn2g4ltDj/EECSXaANye57C5YHv5gONU2CwDLiaAy0XOzyPSVta9FrEpNYROITANz77nQNr3IPLTp5OjYpbjl2/opnpMx750cSSPa6kjEhwW3yfa4Bb7pH79BkqKiCo85lpNQHY5ee70uqXnpdDeyHPiXN3bJu/sz1girjBBqx6sbuZh8z+iDAj7cITOp+fZEmwgt9yOqIHSxljWif6kgclnAavaFg5qQwT9eVBGIoSMhZk6pDTks0M05ZXPcrnKQhaerH6W5HoKToFjAgHUtC9xQEweWSZzId5BCwQIn+jnroIAPXEX9EwWxNu+951E3EI010OxWLSeGjVLkkitMTBzBI//+qswh9IJra8Kqs98u/We4UHmcFbppBW3fEO4T1ovD8SEuKumaOJ6ppu50zkSavWNDe+Eb6LjycHMabWKXvMELwPtrMClrIwoiezcsufyKb/apmpvM9wBzQoiogTXNAnpqO+n9GQO205zU A9p4BLLw CHX+w1dVmnwooWcH3T4ye9RGkyE8IfhjdyAR7hI9eqcqDX+ptMimspaoRy1SiZeEgqlEcz/fbZZjYFHpwHf2Bb8jYc15wNK3Ycv09kKYP0ys+OAseZq2UqhKWkxpyYlCUI29e0kY9UtYDOR6QrxiFYi1XTHIQYOBytGzMg+9thF0BjrBnYr05j5cHTkvOjKeuqSiPB4mZ6jMLrO+F/8HE/hDZr0GNpDjK4/lH 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: Use the folio API to alloc & free memory. Also pass in the node ID instead of the CPU ID since we already did that calculation in the caller. And call numa_mem_id() instead of leaving the node ID as -1 and having the MM call numa_mem_id() each time. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Yin Fengwei Reviewed-by: Lorenzo Stoakes --- kernel/events/ring_buffer.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index fb1e180b5f0a..cc90d5299005 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -770,7 +770,7 @@ void rb_free_aux(struct perf_buffer *rb) #ifndef CONFIG_PERF_USE_VMALLOC /* - * Back perf_mmap() with regular GFP_KERNEL-0 pages. + * Back perf_mmap() with regular GFP_KERNEL pages. */ static struct page * @@ -785,25 +785,23 @@ __perf_mmap_to_page(struct perf_buffer *rb, unsigned long pgoff) return virt_to_page(rb->data_pages[pgoff - 1]); } -static void *perf_mmap_alloc_page(int cpu) +static void *perf_mmap_alloc_page(int node) { - struct page *page; - int node; + struct folio *folio; - node = (cpu == -1) ? cpu : cpu_to_node(cpu); - page = alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0); - if (!page) + folio = __folio_alloc_node(GFP_KERNEL | __GFP_ZERO, 0, node); + if (!folio) return NULL; - return page_address(page); + return folio_address(folio); } static void perf_mmap_free_page(void *addr) { - struct page *page = virt_to_page(addr); + struct folio *folio = virt_to_folio(addr); - page->mapping = NULL; - __free_page(page); + folio->mapping = NULL; + folio_put(folio); } struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) @@ -818,17 +816,17 @@ struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) if (order_base_2(size) > PAGE_SHIFT+MAX_ORDER) goto fail; - node = (cpu == -1) ? cpu : cpu_to_node(cpu); + node = (cpu == -1) ? numa_mem_id() : cpu_to_node(cpu); rb = kzalloc_node(size, GFP_KERNEL, node); if (!rb) goto fail; - rb->user_page = perf_mmap_alloc_page(cpu); + rb->user_page = perf_mmap_alloc_page(node); if (!rb->user_page) goto fail_user_page; for (i = 0; i < nr_pages; i++) { - rb->data_pages[i] = perf_mmap_alloc_page(cpu); + rb->data_pages[i] = perf_mmap_alloc_page(node); if (!rb->data_pages[i]) goto fail_data_pages; }