Skip to content

Commit

Permalink
feature: first pass at memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
pgguru committed Nov 5, 2021
1 parent 8fa9c64 commit c35ff51
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pg_kaboom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)" },
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c35ff51

Please sign in to comment.