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