From c35ff5144b0a423269dc8fe2802a765890f6898b Mon Sep 17 00:00:00 2001 From: David Christensen Date: Fri, 5 Nov 2021 16:52:13 -0500 Subject: [PATCH] feature: first pass at memory allocation --- README.md | 2 ++ TODO.md | 1 - pg_kaboom.c | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba9410b..2fdacfa 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ Currently defined weapons (more to come) are: - `fill-pgwal` :: allocate all of the space inside the $PGDATA/pg_wal directory +- `mem` :: allocate some memory + - `restart` :: do an immediate restart of the server - `rm-pgdata` :: do a `rm -Rf $PGDATA` diff --git a/TODO.md b/TODO.md index 8906a87..d2dad4f 100644 --- a/TODO.md +++ b/TODO.md @@ -8,7 +8,6 @@ - checksum invalidation - other random page corruption - delayed WAL application -- backend memory allocation - specific sizes, and progressive allocation in different contexts until OOM - more! ## testing diff --git a/pg_kaboom.c b/pg_kaboom.c index 6653e0a..b8c64cc 100644 --- a/pg_kaboom.c +++ b/pg_kaboom.c @@ -36,6 +36,7 @@ static void wpn_break_archive(WPN_ARGS); static void wpn_fill_log(WPN_ARGS); static void wpn_fill_pgdata(WPN_ARGS); static void wpn_fill_pgwal(WPN_ARGS); +static void wpn_mem(WPN_ARGS); static void wpn_restart(WPN_ARGS); static void wpn_segfault(WPN_ARGS); static void wpn_signal(WPN_ARGS); @@ -51,6 +52,7 @@ Weapon weapons[] = { { "fill-log" , &wpn_fill_log , NULL, "use all the space in the log directory" }, { "fill-pgdata" , &wpn_fill_pgdata , NULL, "use all the space in the pgdata directory" }, { "fill-pgwal" , &wpn_fill_pgwal , NULL, "use all the space in the pg_wal directory" }, + { "mem" , &wpn_mem , NULL, "allocate memory in different contexts" }, { "restart" , &wpn_restart , NULL, "force an immediate restart" }, { "segfault" , &wpn_segfault , NULL, "segfault inside a backend process" }, { "signal" , &wpn_signal , NULL, "send a signal to the postmaster (KILL by default)" }, @@ -588,6 +590,13 @@ static void wpn_xact_wrap(WPN_ARGS) { force_settings_and_restart(settings, values); } +static void wpn_mem(WPN_ARGS) { + char *size = payload ? simple_get_json_str(payload, "size") : "1GB"; + char *context = payload ? simple_get_json_str(payload, "context") : "Current"; /* TODO */ + + int64 alloc_size = DatumGetInt64(DirectFunctionCall1(pg_size_bytes, CStringGetDatum(size))); + pfree(palloc(alloc_size)); +} /* SRF to return information about the available weapons */ Datum pg_kaboom_arsenal(PG_FUNCTION_ARGS)