From 7ed67d216be4b32a119ea982e750983b0be1d2bd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Apr 2022 20:18:07 +0200 Subject: [PATCH] util/HugeAllocator: add SetName() --- src/util/HugeAllocator.cxx | 9 ++++++++- src/util/HugeAllocator.hxx | 25 ++++++++++++++++++++++++- src/util/SliceBuffer.hxx | 6 +++++- src/util/SparseBuffer.hxx | 4 ++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/util/HugeAllocator.cxx b/src/util/HugeAllocator.cxx index ce3ea1c60..48cdba720 100644 --- a/src/util/HugeAllocator.cxx +++ b/src/util/HugeAllocator.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 Max Kellermann + * Copyright 2013-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,6 +28,7 @@ */ #include "HugeAllocator.hxx" +#include "system/VmaName.hxx" #include @@ -82,6 +83,12 @@ HugeFree(void *p, size_t size) noexcept munmap(p, AlignToPageSize(size)); } +void +HugeSetName(void *p, size_t size, const char *name) noexcept +{ + SetVmaName(p, size, name); +} + void HugeForkCow(void *p, size_t size, bool enable) noexcept { diff --git a/src/util/HugeAllocator.hxx b/src/util/HugeAllocator.hxx index 786a2a722..d87517e92 100644 --- a/src/util/HugeAllocator.hxx +++ b/src/util/HugeAllocator.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 Max Kellermann + * Copyright 2013-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,6 +58,14 @@ HugeAllocate(size_t size); void HugeFree(void *p, size_t size) noexcept; +/** + * Set a name for the specified virtual memory area. + * + * This feature requires Linux 5.17. + */ +void +HugeSetName(void *p, size_t size, const char *name) noexcept; + /** * Control whether this allocation is copied to newly forked child * processes. Disabling that makes forking a little bit cheaper. @@ -88,6 +96,11 @@ HugeFree(void *p, size_t) noexcept VirtualFree(p, 0, MEM_RELEASE); } +static inline void +HugeSetName(void *, size_t, const char *) noexcept +{ +} + static inline void HugeForkCow(void *, size_t, bool) noexcept { @@ -118,6 +131,11 @@ HugeFree(void *_p, size_t) noexcept delete[] p; } +static inline void +HugeSetName(void *, size_t, const char *) noexcept +{ +} + static inline void HugeForkCow(void *, size_t, bool) noexcept { @@ -167,6 +185,11 @@ public: return *this; } + void SetName(const char *name) noexcept { + const auto v = buffer.ToVoid(); + HugeSetName(v.data, v.size, name); + } + void ForkCow(bool enable) noexcept { auto v = buffer.ToVoid(); HugeForkCow(v.data, v.size, enable); diff --git a/src/util/SliceBuffer.hxx b/src/util/SliceBuffer.hxx index a43767b75..934f970e0 100644 --- a/src/util/SliceBuffer.hxx +++ b/src/util/SliceBuffer.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2021 The Music Player Daemon Project + * Copyright 2003-2022 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -85,6 +85,10 @@ public: return n_allocated == buffer.size(); } + void SetName(const char *name) noexcept { + buffer.SetName(name); + } + void DiscardMemory() noexcept { assert(empty()); diff --git a/src/util/SparseBuffer.hxx b/src/util/SparseBuffer.hxx index bac29115d..7232609c3 100644 --- a/src/util/SparseBuffer.hxx +++ b/src/util/SparseBuffer.hxx @@ -112,6 +112,10 @@ public: return map.size(); } + void SetName(const char *name) noexcept { + buffer.SetName(name); + } + struct ReadResult { size_type undefined_size; ConstBuffer defined_buffer;