From patchwork Tue Feb 27 07:25:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13573302 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 63585C5478C for ; Tue, 27 Feb 2024 07:25:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 004834401F8; Tue, 27 Feb 2024 02:25:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EF48B4401F0; Tue, 27 Feb 2024 02:25:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE3BF4401F8; Tue, 27 Feb 2024 02:25:28 -0500 (EST) 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 CE3524401F0 for ; Tue, 27 Feb 2024 02:25:28 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A0A90160A97 for ; Tue, 27 Feb 2024 07:25:28 +0000 (UTC) X-FDA: 81836748336.16.DD2C3AD Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by imf04.hostedemail.com (Postfix) with ESMTP id 1C4644000E for ; Tue, 27 Feb 2024 07:25:26 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UI8fmd6H; spf=pass (imf04.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709018727; 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:references:dkim-signature; bh=VGjD+fs6MaL8s+YlU8C18DqeOu1ojnrtCuZHeWNTOVc=; b=3YDq46usNchTmy6laA2lhciwnuYuOgDxxBCzoLfKi7976spJjZEk3Pb7qz7Wn3Gtth05gr pdvof9j9uqBYKTRDlLyF6sNMQ0b+KLqEqo2QuGQk4OKtVZXKjHFU1uyxgbxRAEpSSNkKjW w8U+OMgdtgabNNQzV6rCMvb6Mpy4ujk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709018727; a=rsa-sha256; cv=none; b=Y4ANcOlpj+OIGjlTgDUYHp83R/JGC5NJ63MEMGdcDLL4e0IpGxA7yGJQo99FizIJPDWAVA ln4ie831Y01Gi/QS1O1BrINE2OeXQQNIBE5szPSs4kN6J2VM3A4W/gUyX9UGnKOtBTyvNs TdC0Hn3QNxtNkuEQzJQGwgcv0JkJ+T0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UI8fmd6H; spf=pass (imf04.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709018725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VGjD+fs6MaL8s+YlU8C18DqeOu1ojnrtCuZHeWNTOVc=; b=UI8fmd6HvNqfoOwePgAUJRRgfnOkck8lzUa9M5NlNrxDKF3XCrdKqtEKQcNV6vHLguDlvo AjpIzxMJhBFfk5RlvZXpP7r2XQXCjWEofVqtV1hRo7gBT2UOQmlSQF0GQzbkdbAsPmVit+ prD9pdYtPS/1muHf/ydwR+aWWpwLje8= From: Kent Overstreet To: linux-mm@kvack.org Cc: paulmck@kernel.org, Kent Overstreet Subject: [PATCH 1/2] mm: vmalloc_bytes() Date: Tue, 27 Feb 2024 02:25:14 -0500 Message-ID: <20240227072515.3736069-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: x8wh8fqhfezjstqcwzdtp9s87wmxa1sj X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1C4644000E X-Rspam-User: X-HE-Tag: 1709018726-38414 X-HE-Meta: U2FsdGVkX183JzMDuA+nqZAEt/NbzpdUCeyfAWdvqr7CYw+dNN2WiYKCLlLU72L5gOYkXShSdnEYmeKjUd/eFRvNwlCPcnnEYsxWTyfikhnjh2JWdP0dz3Qd+R3jJ6iSvDNFY4L5aw8wFZMGP2Thd1tZtFRm/93iK1ZwqeT0Ee29Tg2PuA7ySZJwmRigCC6PC2HM/M5Y6bHFZLjsSeLOh2r9lwNJVGKHYMJ05xJuZ078fhHvkYFVW9o4l6ftAuxAmvc0vdbmECBoMpbscXz/pNXmK3APuVIyu6amtVs9sR9r6zqCnylaVhfVUflggQihiTPQzATnb9vGGS8Egr3qMqIgSD2ghLx2wjy/tbCAUl0/IHyAIiBd7LsEWYnRmuoSuYFzM+JY8VCT+RYL+1PRwALAcPK2QxITaOTIB6tqJqu+dbRzsp58SGAAM0CSfXHOGX6FqlMnBZoNzRqtCV73hULtRW4NkG3SgVg1mb2O2oXDwphjJ20hah6hV3p1xQeiXhubUzNqvbN/Jyx4zu53oYPUhPp2skkJE3p7lUFhCTqktlw+VsECKHIMMogT3ZItT9d1BllHmTeFDbgRvUWwIU67HH3ELMih+IIwGPncZNnbnPt4baUFP19tmFR+A5+C5uH8wfa+edyl0BcOlpKyiuz4Qy3BYLoWUFH489R1NdV02tMKA8S1g/Ka8gWhs25Dmu9CuU/zBJ2r7PFDGQMKq2GDWmf6jyzzC/AZYV8TkktQrNFsgTeiP8u/n16+D9ob8y/YQoQ/UYFj5EEK/ol/JgYxqToDkYpO1lIA4I1cheE5yWNhB83kBPuJMTXwBVgnjMObc1lB7/21m1UNOmOgnRP6cqCjtawFaGLFaQic6xKtxEvxhVFF+joS/LZeKoj5 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 a __ksize() equivalent for vmalloc. This is being added so we can track amount of memory stranded waiting for an RCU grace period. Cc: linux-mm@kvack.org Signed-off-by: Kent Overstreet --- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index c720be70c8dd..3a6e29de8818 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -160,6 +160,7 @@ extern void *vcalloc(size_t n, size_t size) __alloc_size(1, 2); extern void vfree(const void *addr); extern void vfree_atomic(const void *addr); +extern size_t vmalloc_bytes(const void *addr); extern void *vmap(struct page **pages, unsigned int count, unsigned long flags, pgprot_t prot); diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d12a17fc0c17..3642fca84c34 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2848,6 +2848,26 @@ void vfree(const void *addr) } EXPORT_SYMBOL(vfree); +/** + * vmalloc_bytes - Return size of a vmalloc() allocation + * @addr: Memory base address + * + * Returns the size of the allocation as passed to vmalloc() rounded up to + * PAGE_SIZE; does not include extra internal allocations. + */ +size_t vmalloc_bytes(const void *addr) +{ + struct vm_struct *vm = find_vm_area(addr); + if (unlikely(!vm)) { + WARN(1, KERN_ERR "vmalloc_bytes() called on nonexistent vm area (%p)\n", + addr); + return 0; + } + + return vm->nr_pages * PAGE_SIZE; +} +EXPORT_SYMBOL(vmalloc_bytes); + /** * vunmap - release virtual mapping obtained by vmap() * @addr: memory base address From patchwork Tue Feb 27 07:25:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13573301 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 44851C54E49 for ; Tue, 27 Feb 2024 07:25:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 757734401F9; Tue, 27 Feb 2024 02:25:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 705214401F0; Tue, 27 Feb 2024 02:25:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CCB34401F9; Tue, 27 Feb 2024 02:25:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 495884401F0 for ; Tue, 27 Feb 2024 02:25:29 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E500240B06 for ; Tue, 27 Feb 2024 07:25:28 +0000 (UTC) X-FDA: 81836748336.13.830D2E2 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) by imf14.hostedemail.com (Postfix) with ESMTP id 3C5A6100005 for ; Tue, 27 Feb 2024 07:25:26 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=L9QJ4uu8; spf=pass (imf14.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.185 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709018727; a=rsa-sha256; cv=none; b=lZz+4dpzH0/NgOQBk3b+ylMp8OVZWxM8L0HHnGj4wvoGfHj4Xtm2gUFPU+FjasOJCPCinC rsR+/R7fVWjxm0irezvSTLKsQt4UodgI2q1AehsZ/sJHZ8SezM8b81q3g2h7pUumhKIRCt /F6qqlq0zd7Mgpujo0LmrR6coKb0m+Y= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=L9QJ4uu8; spf=pass (imf14.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.185 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709018727; 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=D7/GAs5gztsadtH3015fa8qhYk0TcWQZMe5LXpw2dAc=; b=XSCQXugzgkeZXdOaH6ftqOOtfNsjqlVTyaKCESE0dv0Wxgj7AaP+Zb9rNbZ9Q10KLnzXsD ttoOtOtLwn3bTSFfJUpuyN3pnREnB5UV46PqcecgH4yHnGvEK+PhuRG7d0LcHMxjkaDkWg zP/YT0lJVazQ+cTYjfICinC3Fr61aRA= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709018725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D7/GAs5gztsadtH3015fa8qhYk0TcWQZMe5LXpw2dAc=; b=L9QJ4uu8+ZG9wL4X+YEPIZzj0j5nvTyBQaGmpC2coWTgnvvZMpscuq6nz3wKwMmtt4hMgU oGgArp3JItZrFTcOmGlIr73VBYMArf2UtOhL7tIOh9hYaCmx4mUKBhAnK+c/9znpTwN3JW ujnGlknhvUMq0I+x0QB6HvM98+tr4to= From: Kent Overstreet To: linux-mm@kvack.org Cc: paulmck@kernel.org, Kent Overstreet Subject: [PATCH 2/2] mm: __kvsize() Date: Tue, 27 Feb 2024 02:25:15 -0500 Message-ID: <20240227072515.3736069-2-kent.overstreet@linux.dev> In-Reply-To: <20240227072515.3736069-1-kent.overstreet@linux.dev> References: <20240227072515.3736069-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3C5A6100005 X-Stat-Signature: a1ib6eaq8agzxgpjgp5if8dadugkic4a X-Rspam-User: X-HE-Tag: 1709018726-989501 X-HE-Meta: U2FsdGVkX18PfsCY8cagrcNt4HudjD/5uRmjBrtSNoZ/EHAsx5dcP5l1dYgaNRN1cXciYIleFbJkrTNMtemzNsq/oTjgG15uArIQ/o0tT+Uw5cKQ278DlBBTSjPR63NU3wLCxdeyyLK7CjRJE4TLHTRbvStl3nUFx4GPylk3GupqHJd5JKtop/2x1mhuxSwissBV69dS7gJT9pouMDmTkQUi/DhMb70sLT+qkpMVrVZILo14W91Mqz/S3CYOUkaodwPOi9le22EhlpZghfR8OKXAUxMAZ0ZLPJI1lnjCp4iGG8ns9c3R+5T6hQ4xMq9P9PUtQHdtbwP6b1dVisYgt0W6ZN5QpqjOcOUPJsHWuaK5DbpuDWY1RdShDjYrBjG+K+U1NGEvPRvkU0v1e5a7lawG2bBO9wxmbnLc7fshdg8XI0N8asS3PuJkcWZvl4z5owEoi1tMJWwwtSMG/pWRihbVl6qhZLkpXskgRbAVatKsYxww5X0tKJNtAJgndV4uVHAQmafeSfv9kWVQMsbNWexlAsHUHbh9Uy0lSQTMz0yUwjF6ktCG4NUdjNHzETMZ5ByjjPQkl8oYJl4eQ8IVCRZFhWEh+rRph0/4Q4dHcvFfKnz2HwAmFZ5EgbMVEp5OAqtc9UP6FmJgXhV3/68e3Bhtpq0jZpAPGwPt7YAWKpagnUshjS3flEluEW4SjKyP2TpaLt95GorJpmESNdlArO4Hkkcc8T3rTcEVSbk7woJPb4DXPUTXFDZO6C9l0T5xQOmQ+szVGNt2XbbHbyJRfkYNrgUU+JtJ8uPF5cqByJf6/kRawRed+ozOS6kO3n2+E2Vsu4mw05fElzhULPdS+kkJI0spVyEyLmiiZQZwfq93IylPKn1WLlb4RQO1n1YY5HZnzRzfnU4yA6PJ2+GwnjI1hzrLf4Fyzpq2QfVyFhubJ36SW5uXnmNBPKjymzxWghiqtISaPQh9MtCoZR3 FA63TxtN RG2I85z4uZD0FJuiYIeoUV3xPUJ8s9xY4/C4T3bSJavL+0LsvFuY5I1xbfaLmsJnXn48+Z9umH2o2vkdcdJQ5gvOFLd142K2XUCRT2y++p2hVdfTtxDIGPyz20yLSEqOZnt+QYQ8W/MrFrHDF+//1DSCkLTQg0VsDqNXwC+0fBNyi10+gszK87D84mg== 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 a __ksize() equivalent for kvmalloc. Cc: linux-mm@kvack.org Signed-off-by: Kent Overstreet --- include/linux/slab.h | 1 + mm/slab_common.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/slab.h b/include/linux/slab.h index b5f5ee8308d0..9ef26837c72d 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -227,6 +227,7 @@ void * __must_check krealloc(const void *objp, size_t new_size, gfp_t flags) __r void kfree(const void *objp); void kfree_sensitive(const void *objp); size_t __ksize(const void *objp); +size_t __kvsize(const void *objp); DEFINE_FREE(kfree, void *, if (_T) kfree(_T)) diff --git a/mm/slab_common.c b/mm/slab_common.c index 238293b1dbe1..6ec0f6543f34 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -972,6 +972,19 @@ size_t __ksize(const void *object) return slab_ksize(folio_slab(folio)->slab_cache); } +/** + * __kvsize -- Report full size of underlying allocation + * @object: pointer to the object + * + * __ksize equivalent, but for kvmalloc + */ +size_t __kvsize(const void *addr) +{ + return is_vmalloc_addr(addr) + ? vmalloc_bytes(addr) + : __ksize(addr); +} + gfp_t kmalloc_fix_flags(gfp_t flags) { gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;